proxy.go 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. "v2ray.com/core/transport/ray"
  14. )
  15. // An Inbound processes inbound connections.
  16. type Inbound interface {
  17. // Network returns a list of network that this inbound supports. Connections with not-supported networks will not be passed into Process().
  18. Network() net.NetworkList
  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, core.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, ray.OutboundRay, Dialer) error
  26. }
  27. // Dialer is used by OutboundHandler for creating outbound connections.
  28. type Dialer interface {
  29. // Dial dials a system connection to the given destination.
  30. Dial(ctx context.Context, destination net.Destination) (internet.Connection, error)
  31. }
  32. // UserManager is the interface for Inbounds and Outbounds that can manage their users.
  33. type UserManager interface {
  34. // AddUser adds a new user.
  35. AddUser(context.Context, *protocol.User) error
  36. // RemoveUser removes an user by email.
  37. RemoveUser(context.Context, string) error
  38. }
  39. type GetInbound interface {
  40. GetInbound() Inbound
  41. }
  42. type GetOutbound interface {
  43. GetOutbound() Outbound
  44. }