signaling

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: BSD-2-Clause Imports: 16 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 signaling implements the Cotilla zero-knowledge 1:1 WebRTC signaling gateway hub.

In accordance with the pure WebRTC signaling isolation architecture:

  • /ws strictly handles the 1:1 authenticated WebRTC negotiation (register -> offer -> answer -> ok) to establish a direct WebRTC DataChannel connection between the newcomer and the server.
  • Once the WebRTC DataChannel is opened, /ws is immediately closed.
  • All peer discovery (PortPeerRequest -> PortPeerResponse / PortRootIntro) and WebRTC overlay peering (PortWebRTCSignal) happen exclusively through the Cotilla Packet protocol over WebRTC DataChannels.

Index

Constants

View Source
const (
	DefaultMinAnchors        = 50
	DefaultIntroFanout       = 5
	DefaultAnchorQueryPeriod = 2 * time.Second
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Hub

type Hub struct {
	// contains filtered or unexported fields
}

Hub is the zero-knowledge signaling rendezvous hub and overlay anchor pool manager.

func NewHub

func NewHub() *Hub

NewHub creates a signaling Hub with production defaults (50 anchors, 5 intro fanout).

func NewHubWithConfig

func NewHubWithConfig(targetPool, introFanout int, stunURLs []string) *Hub

NewHubWithConfig creates a signaling Hub with custom pool target, intro fanout, and STUN URLs.

func NewHubWithOptions

func NewHubWithOptions(targetPool, introFanout int, trOpts cotillartc.TransportOptions) (*Hub, error)

NewHubWithOptions creates a signaling Hub with full PionTransport options.

func NewHubWithTarget

func NewHubWithTarget(targetPool int) *Hub

NewHubWithTarget creates a signaling Hub targeting targetPool active anchors.

func (*Hub) Anchors

func (h *Hub) Anchors() []string

Anchors returns a sorted snapshot of the current anchor pool.

func (*Hub) Close

func (h *Hub) Close()

Close shuts down the hub, stops background goroutines, and waits boundedly for them to exit.

func (*Hub) HandleHealth

func (h *Hub) HandleHealth(w http.ResponseWriter, r *http.Request)

HandleHealth serves the JSON health & anchor-pool status endpoint.

func (*Hub) HandlePeerClose

func (h *Hub) HandlePeerClose(peerAddr string)

HandlePeerClose removes a disconnected peer, promotes connected leaves if needed, and triggers anchor solicitation.

func (*Hub) HandlePeerOpen

func (h *Hub) HandlePeerOpen(peerAddr string)

HandlePeerOpen registers a peer in the overlay and anchor pool and sends PortRootIntro.

func (*Hub) HandleWS

func (h *Hub) HandleWS(w http.ResponseWriter, r *http.Request)

HandleWS handles the 1:1 authenticated WebRTC DataChannel handshake on /ws.

func (*Hub) HasAnchor

func (h *Hub) HasAnchor(addr string) bool

HasAnchor reports whether addr is currently in the anchor pool.

func (*Hub) IntroFanout

func (h *Hub) IntroFanout() int

func (*Hub) LastRegisterTS

func (h *Hub) LastRegisterTS(peerAddr string) int64

LastRegisterTS returns the last accepted register timestamp for peerAddr.

func (*Hub) Node

func (h *Hub) Node() *cot.Node

func (*Hub) SeedAnchor

func (h *Hub) SeedAnchor(addr string)

SeedAnchor inserts addr directly into the anchor pool (used in unit tests).

func (*Hub) SelfAddr

func (h *Hub) SelfAddr() string

func (*Hub) SetQueryCooldown

func (h *Hub) SetQueryCooldown(d time.Duration)

SetQueryCooldown overrides the minimum interval between anchor solicitations.

func (*Hub) SolicitAnchors

func (h *Hub) SolicitAnchors()

SolicitAnchors broadcasts PortAnchorSolicit over DataChannels if anchorPool is below targetPool.

func (*Hub) StartSupervisor

func (h *Hub) StartSupervisor(ctx context.Context, interval time.Duration)

StartSupervisor runs the periodic replay-cache pruner and anchor replenishment loop.

func (*Hub) TargetPool

func (h *Hub) TargetPool() int

func (*Hub) Transport

func (h *Hub) Transport() *cotillartc.PionTransport

type WSMessage

type WSMessage struct {
	Type       string                  `json:"type"`                  // "register" | "offer" | "answer" | "ok" | "error"
	Peer       string                  `json:"peer"`                  // sender Ed25519 public address
	Target     string                  `json:"target,omitempty"`      // target Ed25519 address (for "offer" / "answer")
	SDP        string                  `json:"sdp,omitempty"`         // bundled WebRTC SDP offer/answer description
	Timestamp  int64                   `json:"timestamp,omitempty"`   // unix ms for replay protection
	Signature  string                  `json:"signature,omitempty"`   // Ed25519 hex signature over CanonicalSignalingMsg
	Error      string                  `json:"error,omitempty"`       // error description
	ICEServers *[]cotillartc.ICEServer `json:"ice_servers,omitempty"` // explicit STUN/TURN hints advertised on "offer" (including empty [] when disabled)
}

WSMessage is the JSON wire envelope exchanged strictly during the 1:1 /ws handshake.

Jump to

Keyboard shortcuts

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