2020-11-25 11:01:53 +00:00
|
|
|
// Package proxy contains all proxies used by Xray.
|
|
|
|
//
|
|
|
|
// To implement an inbound or outbound proxy, one needs to do the following:
|
|
|
|
// 1. Implement the interface(s) below.
|
|
|
|
// 2. Register a config creator through common.RegisterConfig.
|
|
|
|
package proxy
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
2020-12-04 01:36:16 +00:00
|
|
|
"github.com/xtls/xray-core/common/net"
|
|
|
|
"github.com/xtls/xray-core/common/protocol"
|
2023-06-30 13:13:36 +00:00
|
|
|
"github.com/xtls/xray-core/common/session"
|
2020-12-04 01:36:16 +00:00
|
|
|
"github.com/xtls/xray-core/features/routing"
|
|
|
|
"github.com/xtls/xray-core/transport"
|
|
|
|
"github.com/xtls/xray-core/transport/internet"
|
2021-12-15 00:28:47 +00:00
|
|
|
"github.com/xtls/xray-core/transport/internet/stat"
|
2020-11-25 11:01:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// An Inbound processes inbound connections.
|
|
|
|
type Inbound interface {
|
|
|
|
// Network returns a list of networks that this inbound supports. Connections with not-supported networks will not be passed into Process().
|
|
|
|
Network() []net.Network
|
|
|
|
|
|
|
|
// Process processes a connection of given network. If necessary, the Inbound can dispatch the connection to an Outbound.
|
2023-06-30 13:13:36 +00:00
|
|
|
Process(context.Context, net.Network, stat.Connection, routing.Dispatcher, *map[session.ID]*stat.UserIpRestriction, *stat.UserIpRestriction) error
|
2020-11-25 11:01:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// An Outbound process outbound connections.
|
|
|
|
type Outbound interface {
|
|
|
|
// Process processes the given connection. The given dialer may be used to dial a system outbound connection.
|
|
|
|
Process(context.Context, *transport.Link, internet.Dialer) error
|
|
|
|
}
|
|
|
|
|
|
|
|
// UserManager is the interface for Inbounds and Outbounds that can manage their users.
|
|
|
|
type UserManager interface {
|
|
|
|
// AddUser adds a new user.
|
|
|
|
AddUser(context.Context, *protocol.MemoryUser) error
|
|
|
|
|
|
|
|
// RemoveUser removes a user by email.
|
|
|
|
RemoveUser(context.Context, string) error
|
|
|
|
}
|
|
|
|
|
|
|
|
type GetInbound interface {
|
|
|
|
GetInbound() Inbound
|
|
|
|
}
|
|
|
|
|
|
|
|
type GetOutbound interface {
|
|
|
|
GetOutbound() Outbound
|
|
|
|
}
|