Documentation
¶
Overview ¶
Package inbound holds the listener plumbing the node servers share.
Index ¶
- func OptionalALPN(config tls.ServerConfig) tls.ServerConfig
- func StartStream(l *Listener, logger logger.ContextLogger, tlsConfig tls.ServerConfig, ...) error
- func UserContext(ctx context.Context, metadata *boxAdapter.InboundContext, userID int) context.Context
- type ConnectionHandler
- type Listener
- func (l *Listener) Close() error
- func (l *Listener) CloseStream(transport boxAdapter.V2RayServerTransport) error
- func (l *Listener) ListenTCP() (net.Listener, error)
- func (l *Listener) ListenUDP() (net.PacketConn, error)
- func (l *Listener) PacketWriter() N.PacketWriter
- func (l *Listener) ServeTCP(tcpListener net.Listener, handler ConnectionHandler)
- func (l *Listener) Start() error
- func (l *Listener) UDPAddr() M.Socksaddr
- type NodeOptions
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func OptionalALPN ¶
func OptionalALPN(config tls.ServerConfig) tls.ServerConfig
OptionalALPN lets clients that offer no ALPN complete a QUIC handshake with a server that advertises one. QUIC servers must otherwise refuse them (RFC 9001, section 8.1), and clients that do offer one must refuse a server that selects none, so neither a fixed list nor an empty one serves both. The panel's sing-box profiles set no ALPN while mihomo offers h3.
func StartStream ¶
func StartStream( l *Listener, logger logger.ContextLogger, tlsConfig tls.ServerConfig, transport boxAdapter.V2RayServerTransport, handler func(ctx context.Context, conn net.Conn, metadata boxAdapter.InboundContext, onClose N.CloseHandlerFunc), ) error
StartStream serves a TCP based protocol: through transport when one is configured, which then owns TLS, or with a TLS handshake per connection.
func UserContext ¶
func UserContext(ctx context.Context, metadata *boxAdapter.InboundContext, userID int) context.Context
UserContext tags ctx with the panel user ID for the router and returns the metadata user name sing-box components log with.
Types ¶
type ConnectionHandler ¶
type ConnectionHandler func(ctx context.Context, conn net.Conn, metadata boxAdapter.InboundContext)
ConnectionHandler takes an accepted TCP connection in its own goroutine.
type Listener ¶
type Listener struct {
// contains filtered or unexported fields
}
func (*Listener) CloseStream ¶
func (l *Listener) CloseStream(transport boxAdapter.V2RayServerTransport) error
CloseStream closes the sockets, then the transport once nothing serves it any more. sing-box's QUIC transport sets its listener up inside ServePacket, so closing it earlier races with that.
func (*Listener) ListenTCP ¶
ListenTCP binds the TCP port. With PROXY protocol on, accepted connections read their header lazily in the connection's own goroutine, so a client that never sends one cannot stall the accept loop.
func (*Listener) PacketWriter ¶
func (l *Listener) PacketWriter() N.PacketWriter
func (*Listener) ServeTCP ¶
func (l *Listener) ServeTCP(tcpListener net.Listener, handler ConnectionHandler)
ServeTCP accepts on tcpListener until it is closed.
type NodeOptions ¶
type NodeOptions struct {
Context context.Context
Logger logger.ContextLogger
Router adapter.Router
Config *adapter.NodeConfig
Server option.ServerOptions
}
NodeOptions is what every node server is built from.
func (NodeOptions) NewListener ¶
func (o NodeOptions) NewListener(network []string, packetHandler boxAdapter.PacketHandler, udpFragment bool) (*Listener, error)
NewListener binds to the panel's port with the local listen options.
func (NodeOptions) NewTLSServer ¶ added in v1.0.1
func (o NodeOptions) NewTLSServer() (tls.ServerConfig, error)
NewTLSServer is sing-box's TLS server for the node, except that with ACME a client asking for a name no certificate covers gets the node's own certificate, as with a fixed certificate. A CDN in front of the node asks for its own name; a strict match would refuse it, and certmagic's fallback name is not exposed by sing-box.
func (NodeOptions) StreamRouter ¶
func (o NodeOptions) StreamRouter() (boxAdapter.ConnectionRouterEx, error)
StreamRouter wraps the router with UoT and, unless disabled locally, sing-mux, the way sing-box's TCP inbounds do.
type Options ¶
type Options struct {
Context context.Context
Logger logger.ContextLogger
Listen boxOption.ListenOptions
// Network is the sing-box listener's own networks; set it to UDP for a
// packet handler. TCP is always accepted through ServeTCP.
Network []string
PacketHandler boxAdapter.PacketHandler
ProxyProtocol bool
ProxyProtocolTrusted []string
}