github.com/v2fly/v2ray-core/v5@v5.16.2-0.20240507031116-8191faa6e095/proxy/proxy.go (about)

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