p2p

package
v0.28.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2026 License: MIT Imports: 5 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func NewTunnelDialer(inner dialer.Dialer, t Tunnel, opts ...TunnelOption) dialer.Dialer

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

func SupportedDialer(name string) bool

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL