Documentation
¶
Overview ¶
Package p2p adapts any dialer to run on top of a tunnel supplied by a p2p plugin. The inner dialer's base connection (options.Dialer) is replaced with the tunnel's data stream — a net.Conn carried over the TNET↔host gRPC connection. The peer-facing protocol stays owned by the inner dialer — p2p only supplies the tunnel base.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewTunnelDialer ¶
NewTunnelDialer wraps inner so that every Dial dials "through" a tunnel to the target peer, as if it were inner's plain base connection. The tunnel is opened lazily inside the base dialer: mux inners (mtcp etc.) hit their session cache without touching the base and must not leak an unused tunnel per dial. Inner protocol (tls/ws/mux...) stays untouched; its Handshake is forwarded by tunnelDialer so it triggers at Transport.Handshake. Fail-closed: any provider error aborts the dial.
func SupportedDialer ¶
SupportedDialer reports whether a dialer type may be used as the inner protocol on top of a p2p tunnel. The wrapper's implicit contract is "inner dials one plain conn via options.Dialer and uses it as its base" — a byte stream for the stream dialers (mux inners dial it once per session and multiplex streams over it), a datagram stream for udp. kcp/quic bases break that contract and destroy tunnels. Fail closed: new dialers are unsupported until verified.
Types ¶
type Tunnel ¶
type Tunnel interface {
Dial(ctx context.Context, network, peer string) (net.Conn, error)
Close() error
}
Tunnel opens tunnels to a peer over the plugin control protocol. It is the wrapper's only contact with the p2p plugin; peer is an opaque string (the plugin defines its semantics). network is "tcp" or "udp" and selects the data stream's semantics: "udp" preserves datagram boundaries, so a datagram dialer gets a datagram conn instead of a byte stream.
type TunnelOption ¶
type TunnelOption func(*tunnelDialer)
TunnelOption configures the tunnel wrapper.
func WithTunnelNetwork ¶
func WithTunnelNetwork(network string) TunnelOption
WithTunnelNetwork overrides the tunnel network the wrapper requests, instead of deriving it from the inner dialer (udp4/udp6 -> udp, else tcp). The tun link asks for "ip": datagram-shaped like udp, but session-scoped on the host side, so the link ends on a lost peer session and the consumer re-dials. An empty network (the default) keeps the derived value.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package plugin implements p2p.Tunnel over the plugin control protocol (github.com/dolfly/plugin/p2p).
|
Package plugin implements p2p.Tunnel over the plugin control protocol (github.com/dolfly/plugin/p2p). |
|
Package streamconn adapts a gRPC bidirectional Tunnel byte stream (the p2p plugin's data plane) to a net.Conn for the TNET side.
|
Package streamconn adapts a gRPC bidirectional Tunnel byte stream (the p2p plugin's data plane) to a net.Conn for the TNET side. |