proxy.go 1.8 KB

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