proxy.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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. import (
  8. "context"
  9. "github.com/xtls/xray-core/common/net"
  10. "github.com/xtls/xray-core/common/protocol"
  11. "github.com/xtls/xray-core/features/routing"
  12. "github.com/xtls/xray-core/transport"
  13. "github.com/xtls/xray-core/transport/internet"
  14. "github.com/xtls/xray-core/transport/internet/stat"
  15. )
  16. // An Inbound processes inbound connections.
  17. type Inbound interface {
  18. // Network returns a list of networks that this inbound supports. Connections with not-supported networks will not be passed into Process().
  19. Network() []net.Network
  20. // Process processes a connection of given network. If necessary, the Inbound can dispatch the connection to an Outbound.
  21. Process(context.Context, net.Network, stat.Connection, routing.Dispatcher) error
  22. }
  23. // An Outbound process outbound connections.
  24. type Outbound interface {
  25. // Process processes the given connection. The given dialer may be used to dial a system outbound connection.
  26. Process(context.Context, *transport.Link, internet.Dialer) error
  27. }
  28. // UserManager is the interface for Inbounds and Outbounds that can manage their users.
  29. type UserManager interface {
  30. // AddUser adds a new user.
  31. AddUser(context.Context, *protocol.MemoryUser) error
  32. // RemoveUser removes a user by email.
  33. RemoveUser(context.Context, string) error
  34. }
  35. type GetInbound interface {
  36. GetInbound() Inbound
  37. }
  38. type GetOutbound interface {
  39. GetOutbound() Outbound
  40. }