chore: change C.PacketAdapter from a struct to an interface
This commit is contained in:
23
listener/config/tuic.go
Normal file
23
listener/config/tuic.go
Normal file
@ -0,0 +1,23 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
type TuicServer struct {
|
||||
Enable bool
|
||||
Listen string
|
||||
Token []string
|
||||
Certificate string
|
||||
PrivateKey string
|
||||
CongestionController string
|
||||
MaxIdleTime int
|
||||
AuthenticationTimeout int
|
||||
ALPN []string
|
||||
MaxUdpRelayPacketSize int
|
||||
}
|
||||
|
||||
func (t TuicServer) String() string {
|
||||
b, _ := json.Marshal(t)
|
||||
return string(b)
|
||||
}
|
85
listener/config/tun.go
Normal file
85
listener/config/tun.go
Normal file
@ -0,0 +1,85 @@
|
||||
package config
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/netip"
|
||||
|
||||
C "github.com/Dreamacro/clash/constant"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
type ListenPrefix netip.Prefix
|
||||
|
||||
func (p ListenPrefix) MarshalJSON() ([]byte, error) {
|
||||
prefix := netip.Prefix(p)
|
||||
if !prefix.IsValid() {
|
||||
return json.Marshal(nil)
|
||||
}
|
||||
return json.Marshal(prefix.String())
|
||||
}
|
||||
|
||||
func (p ListenPrefix) MarshalYAML() (interface{}, error) {
|
||||
prefix := netip.Prefix(p)
|
||||
if !prefix.IsValid() {
|
||||
return nil, nil
|
||||
}
|
||||
return prefix.String(), nil
|
||||
}
|
||||
|
||||
func (p *ListenPrefix) UnmarshalJSON(bytes []byte) error {
|
||||
var value string
|
||||
err := json.Unmarshal(bytes, &value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
prefix, err := netip.ParsePrefix(value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*p = ListenPrefix(prefix)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *ListenPrefix) UnmarshalYAML(node *yaml.Node) error {
|
||||
var value string
|
||||
err := node.Decode(&value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
prefix, err := netip.ParsePrefix(value)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*p = ListenPrefix(prefix)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p ListenPrefix) Build() netip.Prefix {
|
||||
return netip.Prefix(p)
|
||||
}
|
||||
|
||||
type Tun struct {
|
||||
Enable bool
|
||||
Device string
|
||||
Stack C.TUNStack
|
||||
DNSHijack []netip.AddrPort
|
||||
AutoRoute bool
|
||||
AutoDetectInterface bool
|
||||
RedirectToTun []string
|
||||
|
||||
MTU uint32
|
||||
Inet4Address []ListenPrefix
|
||||
Inet6Address []ListenPrefix
|
||||
StrictRoute bool
|
||||
Inet4RouteAddress []ListenPrefix
|
||||
Inet6RouteAddress []ListenPrefix
|
||||
IncludeUID []uint32
|
||||
IncludeUIDRange []string
|
||||
ExcludeUID []uint32
|
||||
ExcludeUIDRange []string
|
||||
IncludeAndroidUser []int
|
||||
IncludePackage []string
|
||||
ExcludePackage []string
|
||||
EndpointIndependentNat bool
|
||||
UDPTimeout int64
|
||||
}
|
Reference in New Issue
Block a user