peerbroker

package
v0.3.5 Latest Latest
Warning

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

Go to latest
Published: Apr 5, 2022 License: AGPL-3.0 Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dial

func Dial(stream proto.DRPCPeerBroker_NegotiateConnectionClient, iceServers []webrtc.ICEServer, opts *peer.ConnOptions) (*peer.Conn, error)

Dial consumes the PeerBroker gRPC connection negotiation stream to produce a WebRTC peered connection.

func ProxyDial

func ProxyDial(client proto.DRPCPeerBrokerClient, options ProxyOptions) (io.Closer, error)

ProxyDial writes client negotiation streams over PubSub.

PubSub is used to geodistribute WebRTC handshakes. All negotiation messages are small in size (<=8KB), and we don't require delivery guarantees because connections can always be renegotiated.

┌────────────────────┐   ┌─────────────────────────────┐
│      coderd        │   │          coderd             │

┌─────────────────────┐ │/<agent-id>/connect │ │ /<agent-id>/listen │ │ client │ │ │ │ │ ┌─────┐ │ ├──►│Creates a stream ID │◄─►│Subscribe() to the <agent-id>│◄──┤agent│ │NegotiateConnection()│ │and Publish() to the│ │channel. Parse the stream ID │ └─────┘ └─────────────────────┘ │<agent-id> channel: │ │from payloads to create new │

│                    │   │NegotiateConnection() streams│
│<stream-id><payload>│   │or write to existing ones.   │
└────────────────────┘   └─────────────────────────────┘

func ProxyListen

func ProxyListen(ctx context.Context, connListener net.Listener, options ProxyOptions) error

ProxyListen accepts client negotiation streams over PubSub and writes them to the listener as new NegotiateConnection() streams.

Types

type ICEServersFunc

type ICEServersFunc func(ctx context.Context) ([]webrtc.ICEServer, error)

ICEServersFunc returns ICEServers when a new connection is requested.

type Listener

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

func Listen

func Listen(connListener net.Listener, iceServersFunc ICEServersFunc, opts *peer.ConnOptions) (*Listener, error)

Listen consumes the transport as the server-side of the PeerBroker dRPC service. The Accept function must be serviced, or new connections will hang.

func (*Listener) Accept

func (l *Listener) Accept() (*peer.Conn, error)

Accept blocks until a connection arrives or the listener is closed.

func (*Listener) Close

func (l *Listener) Close() error

Close ends the listener. This will block all new WebRTC connections from establishing, but will not close active connections.

type ProxyOptions

type ProxyOptions struct {
	ChannelID string
	Logger    slog.Logger
	Pubsub    database.Pubsub
}

ProxyOptions provides values to configure a proxy.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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