Skip to content

Commit

Permalink
Crazy sekai overturns the small pond
Browse files Browse the repository at this point in the history
  • Loading branch information
nekohasekai committed Oct 22, 2024
1 parent 0b42f26 commit 0b5c32a
Show file tree
Hide file tree
Showing 140 changed files with 2,849 additions and 1,558 deletions.
104 changes: 0 additions & 104 deletions adapter/conn_router.go

This file was deleted.

26 changes: 26 additions & 0 deletions adapter/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,53 @@ import (

"github.com/sagernet/sing/common/buf"
E "github.com/sagernet/sing/common/exceptions"
M "github.com/sagernet/sing/common/metadata"
N "github.com/sagernet/sing/common/network"
)

// Deprecated
type ConnectionHandler interface {
NewConnection(ctx context.Context, conn net.Conn, metadata InboundContext) error
}

type ConnectionHandlerEx interface {
NewConnectionEx(ctx context.Context, conn net.Conn, metadata InboundContext, onClose N.CloseHandlerFunc)
}

// Deprecated: use PacketHandlerEx instead
type PacketHandler interface {
NewPacket(ctx context.Context, conn N.PacketConn, buffer *buf.Buffer, metadata InboundContext) error
}

type PacketHandlerEx interface {
NewPacketEx(buffer *buf.Buffer, source M.Socksaddr)
}

// Deprecated: use OOBPacketHandlerEx instead
type OOBPacketHandler interface {
NewPacket(ctx context.Context, conn N.PacketConn, buffer *buf.Buffer, oob []byte, metadata InboundContext) error
}

type OOBPacketHandlerEx interface {
NewPacketEx(buffer *buf.Buffer, oob []byte, source M.Socksaddr)
}

// Deprecated
type PacketConnectionHandler interface {
NewPacketConnection(ctx context.Context, conn N.PacketConn, metadata InboundContext) error
}

type PacketConnectionHandlerEx interface {
NewPacketConnectionEx(ctx context.Context, conn N.PacketConn, metadata InboundContext, onClose N.CloseHandlerFunc)
}

type UpstreamHandlerAdapter interface {
N.TCPConnectionHandler

Check failure on line 50 in adapter/handler.go

View workflow job for this annotation

GitHub Actions / Build

SA1019: N.TCPConnectionHandler is deprecated: Use TCPConnectionHandlerEx instead. (staticcheck)
N.UDPConnectionHandler

Check failure on line 51 in adapter/handler.go

View workflow job for this annotation

GitHub Actions / Build

SA1019: N.UDPConnectionHandler is deprecated: Use UDPConnectionHandlerEx instead. (staticcheck)
E.Handler

Check failure on line 52 in adapter/handler.go

View workflow job for this annotation

GitHub Actions / Build

SA1019: E.Handler is deprecated: wtf is this? (staticcheck)
}

type UpstreamHandlerAdapterEx interface {
N.TCPConnectionHandlerEx
N.UDPConnectionHandlerEx
}
35 changes: 19 additions & 16 deletions adapter/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@ package adapter

import (
"context"
"net"
"net/netip"

"github.com/sagernet/sing-box/common/process"
"github.com/sagernet/sing-box/option"
M "github.com/sagernet/sing/common/metadata"
N "github.com/sagernet/sing/common/network"
)

type Inbound interface {
Expand All @@ -17,11 +15,14 @@ type Inbound interface {
Tag() string
}

type InjectableInbound interface {
type TCPInjectableInbound interface {
Inbound
Network() []string
NewConnection(ctx context.Context, conn net.Conn, metadata InboundContext) error
NewPacketConnection(ctx context.Context, conn N.PacketConn, metadata InboundContext) error
ConnectionHandlerEx
}

type UDPInjectableInbound interface {
Inbound
PacketConnectionHandlerEx
}

type InboundContext struct {
Expand All @@ -43,16 +44,18 @@ type InboundContext struct {

// cache

InboundDetour string
LastInbound string
OriginDestination M.Socksaddr
InboundOptions option.InboundOptions
DestinationAddresses []netip.Addr
SourceGeoIPCode string
GeoIPCode string
ProcessInfo *process.Info
QueryType uint16
FakeIP bool
InboundDetour string
LastInbound string
OriginDestination M.Socksaddr
// Deprecated
InboundOptions option.InboundOptions

Check failure on line 51 in adapter/inbound.go

View workflow job for this annotation

GitHub Actions / Build

SA1019: option.InboundOptions is deprecated: Use rule action instead (staticcheck)
UDPDisableDomainUnmapping bool
DestinationAddresses []netip.Addr
SourceGeoIPCode string
GeoIPCode string
ProcessInfo *process.Info
QueryType uint16
FakeIP bool

// rule cache

Expand Down
5 changes: 0 additions & 5 deletions adapter/outbound.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package adapter

import (
"context"
"net"

N "github.com/sagernet/sing/common/network"
)

Expand All @@ -15,6 +12,4 @@ type Outbound interface {
Network() []string
Dependencies() []string
N.Dialer
NewConnection(ctx context.Context, conn net.Conn, metadata InboundContext) error
NewPacketConnection(ctx context.Context, conn N.PacketConn, metadata InboundContext) error
}
36 changes: 14 additions & 22 deletions adapter/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package adapter

import (
"context"
"net"
"net/http"
"net/netip"

Expand Down Expand Up @@ -30,6 +31,7 @@ type Router interface {
FakeIPStore() FakeIPStore

ConnectionRouter
ConnectionRouterEx

GeoIPReader() *geoip.Reader
LoadGeosite(code string) (Rule, error)
Expand Down Expand Up @@ -66,34 +68,24 @@ type Router interface {
ResetNetwork() error
}

func ContextWithRouter(ctx context.Context, router Router) context.Context {
return service.ContextWith(ctx, router)
// Deprecated: Use ConnectionRouterEx instead.
type ConnectionRouter interface {
RouteConnection(ctx context.Context, conn net.Conn, metadata InboundContext) error
RoutePacketConnection(ctx context.Context, conn N.PacketConn, metadata InboundContext) error
}

func RouterFromContext(ctx context.Context) Router {
return service.FromContext[Router](ctx)
}

type HeadlessRule interface {
Match(metadata *InboundContext) bool
String() string
type ConnectionRouterEx interface {
ConnectionRouter
RouteConnectionEx(ctx context.Context, conn net.Conn, metadata InboundContext, onClose N.CloseHandlerFunc)
RoutePacketConnectionEx(ctx context.Context, conn N.PacketConn, metadata InboundContext, onClose N.CloseHandlerFunc)
}

type Rule interface {
HeadlessRule
Service
Type() string
UpdateGeosite() error
Outbound() string
func ContextWithRouter(ctx context.Context, router Router) context.Context {
return service.ContextWith(ctx, router)
}

type DNSRule interface {
Rule
DisableCache() bool
RewriteTTL() *uint32
ClientSubnet() *netip.Prefix
WithAddressLimit() bool
MatchAddressLimit(metadata *InboundContext) bool
func RouterFromContext(ctx context.Context) Router {
return service.FromContext[Router](ctx)
}

type RuleSet interface {
Expand Down
38 changes: 38 additions & 0 deletions adapter/rule.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package adapter

import (
C "github.com/sagernet/sing-box/constant"
)

type HeadlessRule interface {
Match(metadata *InboundContext) bool
String() string
}

type Rule interface {
HeadlessRule
Service
Type() string
UpdateGeosite() error
Action() RuleAction
}

type DNSRule interface {
Rule
WithAddressLimit() bool
MatchAddressLimit(metadata *InboundContext) bool
}

type RuleAction interface {
Type() string
String() string
}

func IsFinalAction(action RuleAction) bool {
switch action.Type() {
case C.RuleActionTypeSniff, C.RuleActionTypeResolve:
return false
default:
return true
}
}
Loading

1 comment on commit 0b5c32a

@zcluo

This comment was marked as spam.

Please sign in to comment.