2022-06-30 13:27:56 +00:00
|
|
|
package adapter
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"net"
|
2022-07-07 13:47:21 +00:00
|
|
|
"net/netip"
|
2022-06-30 13:27:56 +00:00
|
|
|
|
2022-07-05 05:23:47 +00:00
|
|
|
"github.com/sagernet/sing-box/common/geoip"
|
2022-07-11 10:44:59 +00:00
|
|
|
"github.com/sagernet/sing-dns"
|
2022-08-04 14:01:20 +00:00
|
|
|
"github.com/sagernet/sing-tun"
|
2022-07-14 15:06:03 +00:00
|
|
|
"github.com/sagernet/sing/common/control"
|
2022-07-08 15:03:57 +00:00
|
|
|
N "github.com/sagernet/sing/common/network"
|
2022-07-07 13:47:21 +00:00
|
|
|
|
|
|
|
"golang.org/x/net/dns/dnsmessage"
|
2022-06-30 13:27:56 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type Router interface {
|
2022-07-05 05:23:47 +00:00
|
|
|
Service
|
2022-07-14 15:06:03 +00:00
|
|
|
|
2022-07-21 13:03:41 +00:00
|
|
|
Outbounds() []Outbound
|
2022-06-30 13:27:56 +00:00
|
|
|
Outbound(tag string) (Outbound, bool)
|
2022-07-06 15:11:48 +00:00
|
|
|
DefaultOutbound(network string) Outbound
|
2022-07-14 15:06:03 +00:00
|
|
|
|
2022-06-30 13:27:56 +00:00
|
|
|
RouteConnection(ctx context.Context, conn net.Conn, metadata InboundContext) error
|
|
|
|
RoutePacketConnection(ctx context.Context, conn N.PacketConn, metadata InboundContext) error
|
2022-07-14 15:06:03 +00:00
|
|
|
|
2022-07-05 05:23:47 +00:00
|
|
|
GeoIPReader() *geoip.Reader
|
2022-07-08 03:00:46 +00:00
|
|
|
LoadGeosite(code string) (Rule, error)
|
2022-07-14 15:06:03 +00:00
|
|
|
|
2022-07-07 13:47:21 +00:00
|
|
|
Exchange(ctx context.Context, message *dnsmessage.Message) (*dnsmessage.Message, error)
|
2022-07-11 10:44:59 +00:00
|
|
|
Lookup(ctx context.Context, domain string, strategy dns.DomainStrategy) ([]netip.Addr, error)
|
2022-07-07 13:47:21 +00:00
|
|
|
LookupDefault(ctx context.Context, domain string) ([]netip.Addr, error)
|
2022-07-14 15:06:03 +00:00
|
|
|
|
|
|
|
InterfaceBindManager() control.BindManager
|
2022-07-15 03:51:51 +00:00
|
|
|
DefaultInterface() string
|
2022-07-10 00:18:52 +00:00
|
|
|
AutoDetectInterface() bool
|
2022-07-24 09:46:25 +00:00
|
|
|
DefaultMark() int
|
2022-08-04 14:01:20 +00:00
|
|
|
NetworkMonitor() tun.NetworkUpdateMonitor
|
|
|
|
InterfaceMonitor() tun.DefaultInterfaceMonitor
|
2022-08-15 03:40:49 +00:00
|
|
|
PackageManager() tun.PackageManager
|
2022-07-19 14:16:49 +00:00
|
|
|
Rules() []Rule
|
|
|
|
SetTrafficController(controller TrafficController)
|
2022-07-02 06:07:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
type Rule interface {
|
2022-07-05 05:23:47 +00:00
|
|
|
Service
|
2022-07-19 14:16:49 +00:00
|
|
|
Type() string
|
2022-07-05 05:23:47 +00:00
|
|
|
UpdateGeosite() error
|
2022-07-02 14:55:10 +00:00
|
|
|
Match(metadata *InboundContext) bool
|
2022-07-02 06:07:50 +00:00
|
|
|
Outbound() string
|
|
|
|
String() string
|
2022-06-30 13:27:56 +00:00
|
|
|
}
|
2022-07-24 06:05:06 +00:00
|
|
|
|
|
|
|
type DNSRule interface {
|
|
|
|
Rule
|
|
|
|
DisableCache() bool
|
|
|
|
}
|