Skip to content

Commit 0b5c32a

Browse files
committed
Crazy sekai overturns the small pond
1 parent 0b42f26 commit 0b5c32a

File tree

140 files changed

+2849
-1558
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

140 files changed

+2849
-1558
lines changed

adapter/conn_router.go

Lines changed: 0 additions & 104 deletions
This file was deleted.

adapter/handler.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,53 @@ import (
66

77
"github.com/sagernet/sing/common/buf"
88
E "github.com/sagernet/sing/common/exceptions"
9+
M "github.com/sagernet/sing/common/metadata"
910
N "github.com/sagernet/sing/common/network"
1011
)
1112

13+
// Deprecated
1214
type ConnectionHandler interface {
1315
NewConnection(ctx context.Context, conn net.Conn, metadata InboundContext) error
1416
}
1517

18+
type ConnectionHandlerEx interface {
19+
NewConnectionEx(ctx context.Context, conn net.Conn, metadata InboundContext, onClose N.CloseHandlerFunc)
20+
}
21+
22+
// Deprecated: use PacketHandlerEx instead
1623
type PacketHandler interface {
1724
NewPacket(ctx context.Context, conn N.PacketConn, buffer *buf.Buffer, metadata InboundContext) error
1825
}
1926

27+
type PacketHandlerEx interface {
28+
NewPacketEx(buffer *buf.Buffer, source M.Socksaddr)
29+
}
30+
31+
// Deprecated: use OOBPacketHandlerEx instead
2032
type OOBPacketHandler interface {
2133
NewPacket(ctx context.Context, conn N.PacketConn, buffer *buf.Buffer, oob []byte, metadata InboundContext) error
2234
}
2335

36+
type OOBPacketHandlerEx interface {
37+
NewPacketEx(buffer *buf.Buffer, oob []byte, source M.Socksaddr)
38+
}
39+
40+
// Deprecated
2441
type PacketConnectionHandler interface {
2542
NewPacketConnection(ctx context.Context, conn N.PacketConn, metadata InboundContext) error
2643
}
2744

45+
type PacketConnectionHandlerEx interface {
46+
NewPacketConnectionEx(ctx context.Context, conn N.PacketConn, metadata InboundContext, onClose N.CloseHandlerFunc)
47+
}
48+
2849
type UpstreamHandlerAdapter interface {
2950
N.TCPConnectionHandler
3051
N.UDPConnectionHandler
3152
E.Handler
3253
}
54+
55+
type UpstreamHandlerAdapterEx interface {
56+
N.TCPConnectionHandlerEx
57+
N.UDPConnectionHandlerEx
58+
}

adapter/inbound.go

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@ package adapter
22

33
import (
44
"context"
5-
"net"
65
"net/netip"
76

87
"github.com/sagernet/sing-box/common/process"
98
"github.com/sagernet/sing-box/option"
109
M "github.com/sagernet/sing/common/metadata"
11-
N "github.com/sagernet/sing/common/network"
1210
)
1311

1412
type Inbound interface {
@@ -17,11 +15,14 @@ type Inbound interface {
1715
Tag() string
1816
}
1917

20-
type InjectableInbound interface {
18+
type TCPInjectableInbound interface {
2119
Inbound
22-
Network() []string
23-
NewConnection(ctx context.Context, conn net.Conn, metadata InboundContext) error
24-
NewPacketConnection(ctx context.Context, conn N.PacketConn, metadata InboundContext) error
20+
ConnectionHandlerEx
21+
}
22+
23+
type UDPInjectableInbound interface {
24+
Inbound
25+
PacketConnectionHandlerEx
2526
}
2627

2728
type InboundContext struct {
@@ -43,16 +44,18 @@ type InboundContext struct {
4344

4445
// cache
4546

46-
InboundDetour string
47-
LastInbound string
48-
OriginDestination M.Socksaddr
49-
InboundOptions option.InboundOptions
50-
DestinationAddresses []netip.Addr
51-
SourceGeoIPCode string
52-
GeoIPCode string
53-
ProcessInfo *process.Info
54-
QueryType uint16
55-
FakeIP bool
47+
InboundDetour string
48+
LastInbound string
49+
OriginDestination M.Socksaddr
50+
// Deprecated
51+
InboundOptions option.InboundOptions
52+
UDPDisableDomainUnmapping bool
53+
DestinationAddresses []netip.Addr
54+
SourceGeoIPCode string
55+
GeoIPCode string
56+
ProcessInfo *process.Info
57+
QueryType uint16
58+
FakeIP bool
5659

5760
// rule cache
5861

adapter/outbound.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package adapter
22

33
import (
4-
"context"
5-
"net"
6-
74
N "github.com/sagernet/sing/common/network"
85
)
96

@@ -15,6 +12,4 @@ type Outbound interface {
1512
Network() []string
1613
Dependencies() []string
1714
N.Dialer
18-
NewConnection(ctx context.Context, conn net.Conn, metadata InboundContext) error
19-
NewPacketConnection(ctx context.Context, conn N.PacketConn, metadata InboundContext) error
2015
}

adapter/router.go

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package adapter
22

33
import (
44
"context"
5+
"net"
56
"net/http"
67
"net/netip"
78

@@ -30,6 +31,7 @@ type Router interface {
3031
FakeIPStore() FakeIPStore
3132

3233
ConnectionRouter
34+
ConnectionRouterEx
3335

3436
GeoIPReader() *geoip.Reader
3537
LoadGeosite(code string) (Rule, error)
@@ -66,34 +68,24 @@ type Router interface {
6668
ResetNetwork() error
6769
}
6870

69-
func ContextWithRouter(ctx context.Context, router Router) context.Context {
70-
return service.ContextWith(ctx, router)
71+
// Deprecated: Use ConnectionRouterEx instead.
72+
type ConnectionRouter interface {
73+
RouteConnection(ctx context.Context, conn net.Conn, metadata InboundContext) error
74+
RoutePacketConnection(ctx context.Context, conn N.PacketConn, metadata InboundContext) error
7175
}
7276

73-
func RouterFromContext(ctx context.Context) Router {
74-
return service.FromContext[Router](ctx)
75-
}
76-
77-
type HeadlessRule interface {
78-
Match(metadata *InboundContext) bool
79-
String() string
77+
type ConnectionRouterEx interface {
78+
ConnectionRouter
79+
RouteConnectionEx(ctx context.Context, conn net.Conn, metadata InboundContext, onClose N.CloseHandlerFunc)
80+
RoutePacketConnectionEx(ctx context.Context, conn N.PacketConn, metadata InboundContext, onClose N.CloseHandlerFunc)
8081
}
8182

82-
type Rule interface {
83-
HeadlessRule
84-
Service
85-
Type() string
86-
UpdateGeosite() error
87-
Outbound() string
83+
func ContextWithRouter(ctx context.Context, router Router) context.Context {
84+
return service.ContextWith(ctx, router)
8885
}
8986

90-
type DNSRule interface {
91-
Rule
92-
DisableCache() bool
93-
RewriteTTL() *uint32
94-
ClientSubnet() *netip.Prefix
95-
WithAddressLimit() bool
96-
MatchAddressLimit(metadata *InboundContext) bool
87+
func RouterFromContext(ctx context.Context) Router {
88+
return service.FromContext[Router](ctx)
9789
}
9890

9991
type RuleSet interface {

adapter/rule.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package adapter
2+
3+
import (
4+
C "github.com/sagernet/sing-box/constant"
5+
)
6+
7+
type HeadlessRule interface {
8+
Match(metadata *InboundContext) bool
9+
String() string
10+
}
11+
12+
type Rule interface {
13+
HeadlessRule
14+
Service
15+
Type() string
16+
UpdateGeosite() error
17+
Action() RuleAction
18+
}
19+
20+
type DNSRule interface {
21+
Rule
22+
WithAddressLimit() bool
23+
MatchAddressLimit(metadata *InboundContext) bool
24+
}
25+
26+
type RuleAction interface {
27+
Type() string
28+
String() string
29+
}
30+
31+
func IsFinalAction(action RuleAction) bool {
32+
switch action.Type() {
33+
case C.RuleActionTypeSniff, C.RuleActionTypeResolve:
34+
return false
35+
default:
36+
return true
37+
}
38+
}

0 commit comments

Comments
 (0)