proxy.go 1.7 KB

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