proxy.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Package proxy contains all proxies used by V2Ray.
  2. package proxy
  3. import (
  4. "context"
  5. "v2ray.com/core/common/net"
  6. "v2ray.com/core/common/protocol"
  7. "v2ray.com/core/transport/internet"
  8. "v2ray.com/core/transport/ray"
  9. )
  10. type HandlerState int
  11. const (
  12. HandlerStateStopped = HandlerState(0)
  13. HandlerStateRunning = HandlerState(1)
  14. )
  15. type SessionInfo struct {
  16. Source net.Destination
  17. Destination net.Destination
  18. User *protocol.User
  19. Inbound *InboundHandlerMeta
  20. }
  21. type InboundHandlerMeta struct {
  22. Tag string
  23. Address net.Address
  24. Port net.Port
  25. AllowPassiveConnection bool
  26. StreamSettings *internet.StreamConfig
  27. }
  28. type OutboundHandlerMeta struct {
  29. Tag string
  30. Address net.Address
  31. StreamSettings *internet.StreamConfig
  32. ProxySettings *internet.ProxyConfig
  33. }
  34. func (v *OutboundHandlerMeta) GetDialerOptions() internet.DialerOptions {
  35. return internet.DialerOptions{
  36. Stream: v.StreamSettings,
  37. Proxy: v.ProxySettings,
  38. }
  39. }
  40. // An InboundHandler handles inbound network connections to V2Ray.
  41. type InboundHandler interface {
  42. // Listen starts a InboundHandler.
  43. Start() error
  44. // Close stops the handler to accepting anymore inbound connections.
  45. Close()
  46. // Port returns the port that the handler is listening on.
  47. Port() net.Port
  48. Network() net.NetworkList
  49. }
  50. // An OutboundHandler handles outbound network connection for V2Ray.
  51. type OutboundHandler interface {
  52. // Dispatch sends one or more Packets to its destination.
  53. Dispatch(destination net.Destination, ray ray.OutboundRay)
  54. }
  55. // Dialer is used by OutboundHandler for creating outbound connections.
  56. type Dialer interface {
  57. Dial(ctx context.Context, destination net.Destination) (internet.Connection, error)
  58. }