github.com/xraypb/Xray-core@v1.8.1/proxy/proxy.go (about) 1 // Package proxy contains all proxies used by Xray. 2 // 3 // To implement an inbound or outbound proxy, one needs to do the following: 4 // 1. Implement the interface(s) below. 5 // 2. Register a config creator through common.RegisterConfig. 6 package proxy 7 8 import ( 9 "context" 10 11 "github.com/xraypb/Xray-core/common/net" 12 "github.com/xraypb/Xray-core/common/protocol" 13 "github.com/xraypb/Xray-core/features/routing" 14 "github.com/xraypb/Xray-core/transport" 15 "github.com/xraypb/Xray-core/transport/internet" 16 "github.com/xraypb/Xray-core/transport/internet/stat" 17 ) 18 19 // An Inbound processes inbound connections. 20 type Inbound interface { 21 // Network returns a list of networks that this inbound supports. Connections with not-supported networks will not be passed into Process(). 22 Network() []net.Network 23 24 // Process processes a connection of given network. If necessary, the Inbound can dispatch the connection to an Outbound. 25 Process(context.Context, net.Network, stat.Connection, routing.Dispatcher) error 26 } 27 28 // An Outbound process outbound connections. 29 type Outbound interface { 30 // Process processes the given connection. The given dialer may be used to dial a system outbound connection. 31 Process(context.Context, *transport.Link, internet.Dialer) error 32 } 33 34 // UserManager is the interface for Inbounds and Outbounds that can manage their users. 35 type UserManager interface { 36 // AddUser adds a new user. 37 AddUser(context.Context, *protocol.MemoryUser) error 38 39 // RemoveUser removes a user by email. 40 RemoveUser(context.Context, string) error 41 } 42 43 type GetInbound interface { 44 GetInbound() Inbound 45 } 46 47 type GetOutbound interface { 48 GetOutbound() Outbound 49 }