cotillartc

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: 18 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 cotillartc provides the WebRTC transport for Cotilla ephemeral burner rooms, built on pion/webrtc. Primary connections (PionTransport) carry strictly DataChannel overlay/protocol traffic; secondary per-call media connections (CallMediaTransport) carry MLS-scoped SFrame audio/video tracks.

Index

Constants

View Source
const (
	MediaKindAudio = "audio"
	MediaKindVideo = "video"
)
View Source
const DefaultSTUNCSV = "stun:stun.l.google.com:19302,stun:stun.cloudflare.com:3478"

DefaultSTUNCSV is the comma-separated default STUN server list for CLI/config defaults.

Variables

View Source
var DefaultSTUNURLs = []string{
	"stun:stun.l.google.com:19302",
	"stun:stun.cloudflare.com:3478",
}

DefaultSTUNURLs are public STUN servers used for NAT traversal when no custom ICE servers are configured and STUN has not been explicitly disabled.

Functions

func DialSignalingWS

func DialSignalingWS(ctx context.Context, wsURL string, id *cot.Identity, tr *PionTransport, node *cot.Node, opts ...DialSignalingOption) (string, error)

DialSignalingWS executes an authenticated 1:1 WebRTC DataChannel handshake with the signaling server over /ws, closes the WebSocket immediately once the handshake completes, and registers the signaling server as a gateway peer on node.

func ParseCSV added in v0.0.3

func ParseCSV(raw string) []string

ParseCSV splits a comma-separated list into trimmed non-empty entries.

Types

type CallMediaStats

type CallMediaStats struct {
	EncryptedAudio uint64 `json:"encrypted_audio"`
	EncryptedVideo uint64 `json:"encrypted_video"`
	DecryptedAudio uint64 `json:"decrypted_audio"`
	DecryptedVideo uint64 `json:"decrypted_video"`
	Rejected       uint64 `json:"rejected"`
}

CallMediaStats tracks encrypted/decrypted frame counts on a CallMediaTransport.

type CallMediaTransport

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

CallMediaTransport manages dedicated secondary WebRTC PeerConnections strictly scoped to active MLS channel or 1:1 DM calls with RFC 9605 SFrame encryption.

func NewCallMediaTransport

func NewCallMediaTransport(self string, stunURLs []string, signalSender func(scopeID, target, kind, payload string) error) *CallMediaTransport

NewCallMediaTransport constructs a scoped secondary WebRTC transport for SFrame A/V calls.

func (*CallMediaTransport) AcceptAnswer

func (t *CallMediaTransport) AcceptAnswer(scopeID, peerAddr, answerSDP string) error

AcceptAnswer applies a remote secondary Answer SDP.

func (*CallMediaTransport) AcceptOffer

func (t *CallMediaTransport) AcceptOffer(scopeID, peerAddr, offerSDP string) (string, error)

AcceptOffer accepts a remote secondary call Offer SDP and returns an Answer SDP.

func (*CallMediaTransport) AddCandidate

func (t *CallMediaTransport) AddCandidate(scopeID, peerAddr, candidateJSON string) error

AddCandidate applies a serialized trickle ICE candidate JSON to an open/pending secondary PeerConnection.

func (*CallMediaTransport) AttachNode

func (t *CallMediaTransport) AttachNode(n *cot.Node, base cot.Hooks) cot.Hooks

AttachNode wires a cotilla.Node's Hooks onto t while preserving any existing hook handlers in base.

func (*CallMediaTransport) Close

func (t *CallMediaTransport) Close()

Close closes every secondary PeerConnection and zeroes all SFrame keyrings.

func (*CallMediaTransport) ClosePeer

func (t *CallMediaTransport) ClosePeer(scopeID, peerAddr string)

ClosePeer tears down ONLY the secondary media connection for (scopeID, peerAddr).

func (*CallMediaTransport) CloseScope

func (t *CallMediaTransport) CloseScope(scopeID string)

CloseScope closes all secondary PeerConnections and clears SFrame keys for scopeID.

func (*CallMediaTransport) ConnectedPeers

func (t *CallMediaTransport) ConnectedPeers(scopeID string) []string

ConnectedPeers returns peer addresses currently connected for secondary media in scopeID.

func (*CallMediaTransport) CreateOffer

func (t *CallMediaTransport) CreateOffer(scopeID, peerAddr string) (string, error)

CreateOffer allocates a secondary media PeerConnection for (scopeID, peerAddr) and returns the local Offer SDP.

func (*CallMediaTransport) HandlePresence

func (t *CallMediaTransport) HandlePresence(scopeID, from string, payload *cot.CallPresencePayload)

HandlePresence handles a peer call join/update/leave, initiating the secondary WebRTC offer from the deterministic lower address to avoid SDP glare.

func (*CallMediaTransport) HandleSignal

func (t *CallMediaTransport) HandleSignal(sig *cot.CallSignalPayload)

HandleSignal processes an authenticated & decrypted secondary WebRTC signal for scopeID.

func (*CallMediaTransport) HasPeer

func (t *CallMediaTransport) HasPeer(scopeID, peerAddr string) bool

HasPeer reports whether an active or connecting secondary PeerConnection exists for (scopeID, peerAddr).

func (*CallMediaTransport) InitiateCallPeers

func (t *CallMediaTransport) InitiateCallPeers(scopeID string, peers []cot.CallPeerState)

InitiateCallPeers initiates secondary WebRTC offers toward already-active call peers for which the local node holds the deterministic lower address.

func (*CallMediaTransport) OnError

func (t *CallMediaTransport) OnError(cb func(scopeID, peerAddr, op string, err error))

OnError registers a callback invoked when asynchronous secondary call signaling/ICE fails.

func (*CallMediaTransport) OnMediaFrame

func (t *CallMediaTransport) OnMediaFrame(cb func(scopeID, fromPeer, mediaKind string, kid uint64, plaintext []byte))

OnMediaFrame registers the handler invoked after an inbound RTP media frame passes SFrame AEAD decryption.

func (*CallMediaTransport) OnPeerState

func (t *CallMediaTransport) OnPeerState(cb func(scopeID, peerAddr string, state webrtc.PeerConnectionState))

OnPeerState registers a callback when a secondary call PeerConnection changes state.

func (*CallMediaTransport) RevokeAndClosePeer

func (t *CallMediaTransport) RevokeAndClosePeer(scopeID, peerAddr string)

RevokeAndClosePeer immediately zeroes peerAddr's SFrame keys in scopeID and closes its secondary PC.

func (*CallMediaTransport) SetICEServers added in v0.0.3

func (t *CallMediaTransport) SetICEServers(servers []ICEServer)

SetICEServers updates the STUN/TURN servers used for subsequent call PeerConnections.

func (*CallMediaTransport) Stats

Stats returns a snapshot of encrypted, decrypted, and rejected SFrame frame counters.

func (*CallMediaTransport) UpdateSFrameBundle

func (t *CallMediaTransport) UpdateSFrameBundle(bundle *cot.SFrameKeyBundle, grace time.Duration) error

UpdateSFrameBundle installs rotated SFrame epoch keys for scopeID.

func (*CallMediaTransport) WriteAudioFrame

func (t *CallMediaTransport) WriteAudioFrame(scopeID string, opusFrame []byte, duration time.Duration) error

WriteAudioFrame SFrame-encrypts an encoded Opus packet and writes it exclusively onto scopeID's secondary PeerConnections (fail-closed if no SFrame sender key is installed).

func (*CallMediaTransport) WriteVideoFrame

func (t *CallMediaTransport) WriteVideoFrame(scopeID string, vp8Frame []byte, duration time.Duration) error

WriteVideoFrame SFrame-encrypts an encoded VP8 frame and writes it exclusively onto scopeID's secondary PeerConnections (fail-closed if no SFrame sender key is installed).

type DialSignalingOption added in v0.0.3

type DialSignalingOption func(*dialSignalingConfig)

DialSignalingOption customizes outbound signaling WebSocket handshakes.

func WithInheritServerICE added in v0.0.3

func WithInheritServerICE(inherit bool) DialSignalingOption

WithInheritServerICE controls whether ICE servers advertised in the server's /ws offer are applied to the transport before accepting the offer (defaults to true).

func WithUserAgent added in v0.0.3

func WithUserAgent(ua string) DialSignalingOption

WithUserAgent sets the HTTP User-Agent header sent on the /ws signaling request.

type ICEServer added in v0.0.3

type ICEServer struct {
	URLs       []string `json:"urls"`
	Username   string   `json:"username,omitempty"`
	Credential string   `json:"credential,omitempty"`
}

ICEServer describes a STUN or TURN server configuration compatible with both pion/webrtc and the browser RTCIceServer dictionary.

func CloneICEServers added in v0.0.3

func CloneICEServers(servers []ICEServer) []ICEServer

CloneICEServers returns a deep copy of servers, omitting empty entries.

func ParseICEServers added in v0.0.3

func ParseICEServers(stunCSV, turnCSV, turnUser, turnCred string) []ICEServer

ParseICEServers builds an ICEServer list from comma-separated STUN URLs and optional TURN URLs/credentials.

func STUNURLsToICEServers added in v0.0.3

func STUNURLsToICEServers(urls []string) []ICEServer

STUNURLsToICEServers wraps plain STUN/TURN URLs into an ICEServer slice.

type PionTransport

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

PionTransport is a DataChannel-only cotilla.Transport backed by pion/webrtc.

func New

func New(self string, stunURLs []string, onData func(from string, data []byte)) *PionTransport

New creates a DataChannel-only WebRTC overlay transport for the local address `self`.

func NewWithOptions added in v0.0.3

func NewWithOptions(self string, opts TransportOptions, onData func(from string, data []byte)) (*PionTransport, error)

NewWithOptions creates a DataChannel-only WebRTC overlay transport with full ICE/TURN and UDP mux options.

func (*PionTransport) AcceptAnswer

func (t *PionTransport) AcceptAnswer(peerAddr, answerSDP string) error

AcceptAnswer completes the handshake for an offered connection.

func (*PionTransport) AcceptOffer

func (t *PionTransport) AcceptOffer(peerAddr, offerSDP string) (string, error)

AcceptOffer handles an inbound offer from peerAddr and returns the local answer SDP.

func (*PionTransport) Broadcast

func (t *PionTransport) Broadcast(data []byte)

Broadcast delivers to every open peer channel.

func (*PionTransport) Close

func (t *PionTransport) Close()

Close tears down all connections.

func (*PionTransport) ClosePeer

func (t *PionTransport) ClosePeer(addr string)

ClosePeer closes and cleans up an existing connection to addr.

func (*PionTransport) CreateOffer

func (t *PionTransport) CreateOffer(peerAddr string) (string, error)

CreateOffer starts a connection to peerAddr and returns the local SDP offer (with ICE candidates gathered).

func (*PionTransport) HasActiveOrPending

func (t *PionTransport) HasActiveOrPending(addr string) bool

HasActiveOrPending returns true if addr currently has an open or in-progress connection.

func (*PionTransport) OnClose

func (t *PionTransport) OnClose(f func(addr string))

OnClose registers a callback fired when a peer's data channel or connection closes.

func (*PionTransport) OnOpen

func (t *PionTransport) OnOpen(f func(addr string))

OnOpen registers a callback fired when a peer's data channel opens.

func (*PionTransport) OnStateChange

func (t *PionTransport) OnStateChange(f func(addr string, state webrtc.PeerConnectionState))

OnStateChange registers a callback fired when a peer's connection state transitions.

func (*PionTransport) PeerTransceiverCount

func (t *PionTransport) PeerTransceiverCount(addr string) int

PeerTransceiverCount returns the number of RTP transceivers on the primary overlay connection to addr, or -1 if not connected. Overlay connections must remain DataChannel-only (0 transceivers).

func (*PionTransport) Peers

func (t *PionTransport) Peers() []string

Peers returns addresses with an open data channel.

func (*PionTransport) PendingLocalOffer added in v0.0.3

func (t *PionTransport) PendingLocalOffer(addr string) string

PendingLocalOffer returns the local SDP offer if addr currently has a pending outbound HaveLocalOffer connection, allowing impolite glare handlers to re-transmit lost offers.

func (*PionTransport) Send

func (t *PionTransport) Send(addr string, data []byte) error

Send delivers data to one peer over its data channel.

func (*PionTransport) SetICEServers added in v0.0.3

func (t *PionTransport) SetICEServers(servers []ICEServer)

SetICEServers updates the STUN/TURN servers used for subsequent PeerConnections.

type TransportOptions added in v0.0.3

type TransportOptions struct {
	ICEServers []ICEServer
	UDPPort    int
	NAT1To1IPs []string
}

TransportOptions configures ICE servers, single-port UDP multiplexing, and public IP hints.

Jump to

Keyboard shortcuts

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