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 ¶
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.
const (
// TransportMode is the upper-layer transport both sides offer.
TransportMode = "quic"
)
Variables ¶
var ErrMessageSize = errors.New("p2p message length out of range")
ErrMessageSize is a message whose length prefix is out of range.
Functions ¶
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 ¶
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.
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.