github.com/laof/lite-speed-test@v0.0.0-20230930011949-1f39b7037845/proxy/trojan/trojan.go (about) 1 package trojan 2 3 import ( 4 "context" 5 "fmt" 6 "net" 7 8 C "github.com/laof/lite-speed-test/constant" 9 "github.com/laof/lite-speed-test/outbound" 10 "github.com/laof/lite-speed-test/tunnel" 11 ) 12 13 type Client struct { 14 ctx context.Context 15 trojan *outbound.Trojan 16 } 17 18 func (c Client) DialConn(addr *tunnel.Address, _ tunnel.Tunnel) (net.Conn, error) { 19 meta := &C.Metadata{ 20 NetWork: 0, 21 Type: 0, 22 SrcPort: "", 23 DstPort: fmt.Sprintf("%d", addr.Port), 24 } 25 switch addr.AddressType { 26 case tunnel.IPv4: 27 case tunnel.IPv6: 28 meta.DstIP = addr.IP 29 case tunnel.DomainName: 30 meta.Host = addr.DomainName 31 } 32 return c.trojan.DialContext(c.ctx, meta) 33 } 34 35 func (c Client) Close() error { 36 return nil 37 } 38 39 func NewClient(ctx context.Context, trojan *outbound.Trojan) Client { 40 return Client{ 41 ctx: ctx, 42 trojan: trojan, 43 } 44 }