network.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. package adapter
  2. import (
  3. "time"
  4. C "github.com/sagernet/sing-box/constant"
  5. "github.com/sagernet/sing-tun"
  6. "github.com/sagernet/sing/common/control"
  7. )
  8. type NetworkManager interface {
  9. Lifecycle
  10. Initialize(ruleSets []RuleSet)
  11. InterfaceFinder() control.InterfaceFinder
  12. UpdateInterfaces() error
  13. DefaultNetworkInterface() *NetworkInterface
  14. NetworkInterfaces() []NetworkInterface
  15. AutoDetectInterface() bool
  16. AutoDetectInterfaceFunc() control.Func
  17. ProtectFunc() control.Func
  18. DefaultOptions() NetworkOptions
  19. RegisterAutoRedirectOutputMark(mark uint32) error
  20. AutoRedirectOutputMark() uint32
  21. AutoRedirectOutputMarkFunc() control.Func
  22. NetworkMonitor() tun.NetworkUpdateMonitor
  23. InterfaceMonitor() tun.DefaultInterfaceMonitor
  24. PackageManager() tun.PackageManager
  25. NeedWIFIState() bool
  26. WIFIState() WIFIState
  27. UpdateWIFIState()
  28. ResetNetwork()
  29. }
  30. type NetworkOptions struct {
  31. BindInterface string
  32. RoutingMark uint32
  33. DomainResolver string
  34. DomainResolveOptions DNSQueryOptions
  35. NetworkStrategy *C.NetworkStrategy
  36. NetworkType []C.InterfaceType
  37. FallbackNetworkType []C.InterfaceType
  38. FallbackDelay time.Duration
  39. }
  40. type InterfaceUpdateListener interface {
  41. InterfaceUpdated()
  42. }
  43. type WIFIState struct {
  44. SSID string
  45. BSSID string
  46. }
  47. type NetworkInterface struct {
  48. control.Interface
  49. Type C.InterfaceType
  50. DNSServers []string
  51. Expensive bool
  52. Constrained bool
  53. }