Documentation
¶
Overview ¶
Package clientcontext sends client metadata from a client to its server at the start of each proxied connection, and exposes it to the server's connection trackers.
On the client, an Injector installed into the box context wraps the outbounds sing-box creates, so every dial through an outbound enabled for injection sends the metadata, whether it comes from the router or from a direct caller such as a DNS detour or a probe. On the server, a Manager added with router.AppendTracker reads it. Trackers added to the router after the Manager can read it from the connection with InfoFromConn.
Index ¶
- type ClientInfo
- type GetClientInfoFn
- type Injector
- type Manager
- func (m *Manager) MatchBounds() MatchBounds
- func (m *Manager) RoutedConnection(ctx context.Context, conn net.Conn, metadata adapter.InboundContext, ...) net.Conn
- func (m *Manager) RoutedPacketConnection(ctx context.Context, conn N.PacketConn, metadata adapter.InboundContext, ...) N.PacketConn
- func (m *Manager) SetBounds(bounds MatchBounds)
- type MatchBounds
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ClientInfo ¶
type ClientInfo struct {
DeviceID string
Platform string
IsPro bool
CountryCode string
Version string
}
ClientInfo holds information about the client user/device. The zero ClientInfo identifies no client: probes send it, and InfoFromConn reports no info for a connection that carries it.
func InfoFromConn ¶
func InfoFromConn(conn any) (ClientInfo, bool)
InfoFromConn returns ClientInfo from a Manager-wrapped connection. It reports false if none is present.
type GetClientInfoFn ¶
type GetClientInfoFn func() ClientInfo
GetClientInfoFn returns the ClientInfo to send on a new connection.
type Injector ¶
type Injector struct {
// contains filtered or unexported fields
}
Injector sends ClientInfo to the server on connections dialed through outbounds enabled for injection. Dials marked with github.com/getlantern/lantern-box/adapter.ContextWithProbe exchange the zero ClientInfo and are not attributed to a client. It is safe for concurrent use.
func NewInjector ¶
func NewInjector(getInfo GetClientInfoFn, outboundTags ...string) *Injector
NewInjector returns an Injector that sends getInfo() on dials through outbounds whose tag is in outboundTags. Their peers must support the client-info exchange.
func (*Injector) AddOutboundTags ¶
AddOutboundTags enables injection for the given outbound tags. Their peers must support the client-info exchange. It applies from the next dial; open connections are unaffected.
func (*Injector) Install ¶
Install replaces the outbound registry in ctx with one whose outbounds send client info through i. It must be called after the registries are added to ctx (e.g. by box.Context) and before box.New. It returns an error if ctx has no outbound registry or already has an Injector installed.
func (*Injector) RemoveOutboundTags ¶
RemoveOutboundTags disables injection for the given outbound tags. It applies from the next dial; connections already open are unaffected.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager decodes ClientInfo from client-info frames and exposes it on the wrapped connection.
func NewManager ¶
func NewManager(bounds MatchBounds, logger log.ContextLogger) *Manager
NewManager returns a new Manager.
func (*Manager) MatchBounds ¶
func (m *Manager) MatchBounds() MatchBounds
func (*Manager) RoutedConnection ¶
func (*Manager) RoutedPacketConnection ¶
func (m *Manager) RoutedPacketConnection(ctx context.Context, conn N.PacketConn, metadata adapter.InboundContext, matchedRule adapter.Rule, matchOutbound adapter.Outbound) N.PacketConn
func (*Manager) SetBounds ¶
func (m *Manager) SetBounds(bounds MatchBounds)
type MatchBounds ¶
MatchBounds specifies inbound and outbound matching rules. The empty string and "any" are treated as a wildcard.