p2pproto

package
v0.34.8 Latest Latest
Warning

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

Go to latest
Published: Oct 17, 2026 License: GPL-3.0 Imports: 4 Imported by: 0 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 p2pproto holds the messages npc and the bridge exchange on a P2P control stream before it turns into a TLS stream for the hole punching library, and the names both sides agree on.

A visitor opens a stream with WorkP2P and sends a Request; the bridge sends the provider an Invite (P2PPunchStart) on its signal connection, the provider opens a stream with WorkP2PSession carrying a Join, and the bridge answers both with a Reply once the session exists. After an accepting Reply, npc runs a TLS client handshake that pins the bridge certificate and the bridge a TLS server handshake with it; the TLS stream then carries the punching session.

Index

Constants

View Source
const (
	CodeRefused     = "refused"     // unknown, disabled or misconfigured task, P2P off on the server
	CodeUnsupported = "unsupported" // the peer's npc is too old
	CodeOffline     = "offline"     // the provider is not connected
	CodeBusy        = "busy"        // the server's session limits refused the session
)

Reply codes. An empty code accepts the request.

View Source
const (
	// TransportMode is the upper-layer transport both sides offer.
	TransportMode = "quic"
)

Variables

View Source
var ErrMessageSize = errors.New("p2p message length out of range")

ErrMessageSize is a message whose length prefix is out of range.

Functions

func Read

func Read(c *conn.Conn, v any) error

Read reads one message written by Write into v.

func Write

func Write(c *conn.Conn, v any) error

Write sends v as one length-prefixed JSON message.

Types

type Invite

type Invite struct {
	SessionID string `json:"session_id"` // the invitation id
	Token     string `json:"token"`      // one-time join token
}

Invite asks the provider on its signal connection to join a session.

type Join

type Join struct {
	SessionID string `json:"session_id"`
	Token     string `json:"token"`
	ServerIP  string `json:"server_ip,omitempty"` // as in Request
	Decline   string `json:"decline,omitempty"`   // the provider refuses the session, and why
}

Join answers an invitation.

type RefusedError

type RefusedError struct {
	Code    string
	Message string
}

RefusedError is a Reply that did not accept the request.

func (*RefusedError) Error

func (e *RefusedError) Error() string

type Reply

type Reply struct {
	Code      string `json:"code,omitempty"`
	Message   string `json:"message,omitempty"`
	SessionID string `json:"session_id,omitempty"`
}

Reply answers a Request or a Join.

func (Reply) Err

func (r Reply) Err() error

Err returns the reply as an error: nil when it accepts, a *RefusedError otherwise.

type Request

type Request struct {
	Password   string `json:"password"`             // MD5 of the task password
	Background bool   `json:"background,omitempty"` // the visitor relays meanwhile; nobody waits for the session
	ServerIP   string `json:"server_ip,omitempty"`  // the server address the client's bridge connection reached, when known
}

Request opens a session as the visitor.

Jump to

Keyboard shortcuts

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