proxy.go 1.6 KB

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