proxy.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // Package proxy contains all proxies used by V2Ray.
  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. "v2ray.com/core"
  10. "v2ray.com/core/common/net"
  11. "v2ray.com/core/common/protocol"
  12. "v2ray.com/core/transport/internet"
  13. )
  14. // An Inbound processes inbound connections.
  15. type Inbound interface {
  16. // Network returns a list of network that this inbound supports. Connections with not-supported networks will not be passed into Process().
  17. Network() net.NetworkList
  18. // Process processes a connection of given network. If necessary, the Inbound can dispatch the connection to an Outbound.
  19. Process(context.Context, net.Network, internet.Connection, core.Dispatcher) error
  20. }
  21. // An Outbound process outbound connections.
  22. type Outbound interface {
  23. // Process processes the given connection. The given dialer may be used to dial a system outbound connection.
  24. Process(context.Context, *core.Link, Dialer) error
  25. }
  26. // Dialer is used by OutboundHandler for creating outbound connections.
  27. type Dialer interface {
  28. // Dial dials a system connection to the given destination.
  29. Dial(ctx context.Context, destination net.Destination) (internet.Connection, error)
  30. }
  31. // UserManager is the interface for Inbounds and Outbounds that can manage their users.
  32. type UserManager interface {
  33. // AddUser adds a new user.
  34. AddUser(context.Context, *protocol.MemoryUser) error
  35. // RemoveUser removes a user by email.
  36. RemoveUser(context.Context, string) error
  37. }
  38. type GetInbound interface {
  39. GetInbound() Inbound
  40. }
  41. type GetOutbound interface {
  42. GetOutbound() Outbound
  43. }