chirp

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Feb 5, 2024 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package chirp describes peer-to-peer communication protocol.

Index

Constants

View Source
const (
	// Endpoint is the base path of service
	Endpoint string = "/v1"
)

Variables

View Source
var AuthUserAndGetYoMoCredential func(publicKey string) (appID, credential string, ok bool)

AuthUserAndGetYoMoCredential is used to authenticate user by `publickey` and get credential used to connect to YoMo

Functions

func DumpConnectionsState

func DumpConnectionsState()

DumpConnectionsState prints the user and room information to stdout.

func DumpNodeState

func DumpNodeState()

DumpNodeState prints the user and room information to stdout.

func GetOrCreateRealm

func GetOrCreateRealm(appID string, credential string) (realm *node)

GetOrCreateRealm get or create realm by appID, if realm is created, it will connect to yomo zipper with credential.

func NewSigChannelJoined

func NewSigChannelJoined(chName string) *psig.Signalling

NewSigChannelJoined create OpChannelJoin message.

func NewSigPeerOffline

func NewSigPeerOffline(chid string, p *Peer) *psig.Signalling

NewSigPeerOffline create OpPeerOffline message.

func NewSigPeerOnline

func NewSigPeerOnline(chid string, p *Peer) *psig.Signalling

NewSigPeerOnline create OpPeerOnline message.

Types

type Channel

type Channel struct {
	UniqID string // uniq id
	// contains filtered or unexported fields
}

Channel describes a message channel.

func (*Channel) AddPeer

func (c *Channel) AddPeer(p *Peer)

AddPeer add peer to this channel.

func (*Channel) Broadcast

func (c *Channel) Broadcast(sig *psig.Signalling)

Broadcast message to all peers in this channel by yomo, yomo create a distributed cloud network, peers from different location will connect to different nodes in this network, so the message will be broadcast to all nodes.

func (*Channel) Dispatch

func (c *Channel) Dispatch(sig *psig.Signalling)

Dispatch messages to all peers in this channel of current node.

func (*Channel) RemovePeer

func (c *Channel) RemovePeer(p *Peer)

RemovePeer remove peer from this channel.

type Connection

type Connection interface {
	// RemoteAddr returns the client network address.
	RemoteAddr() string
	// Write the data to the connection
	Write(msg []byte) error
	// RawWrite write the raw bytes to the connection, this is a low-level implementation
	RawWrite(buf []byte) (int, error)
}

Connection is connection either WebSocket or WebTransport

func NewWebSocketConnection

func NewWebSocketConnection(conn net.Conn) Connection

NewWebSocketConnection creates a new WebSocketConnection

func NewWebTransportConnection

func NewWebTransportConnection(conn quic.Connection) Connection

NewWebTransportConnection creates a new WebTransportConnection

type Peer

type Peer struct {
	// Sid describes the unique id of this peer on this node, only used for backend.
	Sid string
	// Cid describes the unique id of this peer on who geo-distributed network, set by developer.
	Cid string
	// Channel describes the channel which this peer joined.
	Channels map[string]*Channel
	// contains filtered or unexported fields
}

Peer describes user on this node.

func (*Peer) BroadcastToChannel

func (p *Peer) BroadcastToChannel(sig *psig.Signalling)

BroadcastToChannel will broadcast message to channel.

func (*Peer) Disconnect

func (p *Peer) Disconnect()

Disconnect clears resources of this peer when leave.

func (*Peer) HandleSignal

func (p *Peer) HandleSignal(r io.Reader) error

HandleSignal handle message sent from connection.

func (*Peer) Join

func (p *Peer) Join(channelName string)

Join this peer to channel named `channelName`.

func (*Peer) Leave

func (p *Peer) Leave(channelName string)

Leave a channel

func (*Peer) NotifyBack

func (p *Peer) NotifyBack(sig *psig.Signalling)

NotifyBack to peer with message.

type WebSocketConnection

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

WebSocketConnection is a WebSocket connection

func (*WebSocketConnection) RawWrite added in v0.2.3

func (c *WebSocketConnection) RawWrite(buf []byte) (int, error)

RawWrite write the raw bytes to the connection, this is a low-level implementation

func (*WebSocketConnection) RemoteAddr

func (c *WebSocketConnection) RemoteAddr() string

RemoteAddr returns the client network address.

func (*WebSocketConnection) Write

func (c *WebSocketConnection) Write(msg []byte) error

Write the data to the connection

type WebTransportConnection

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

WebTransportConnection is a WebTransport connection

func (*WebTransportConnection) RawWrite added in v0.2.3

func (c *WebTransportConnection) RawWrite(buf []byte) (int, error)

RawWrite write the raw bytes to the connection, this is a low-level implementation

func (*WebTransportConnection) RemoteAddr

func (c *WebTransportConnection) RemoteAddr() string

RemoteAddr returns the client network address.

func (*WebTransportConnection) Write

func (c *WebTransportConnection) Write(msg []byte) error

Write the data to the connection

Jump to

Keyboard shortcuts

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