structs

package
v0.0.0-...-24c75d5 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DATA_CANDIDATE uint8 = 0

As per CL5 spec, there are two kinds of candidates - data and voice.

View Source
var VOICE_CANDIDATE uint8 = 1

Functions

This section is empty.

Types

type Client

type Client struct {
	Conn           *websocket.Conn
	Session        uint64
	Username       string
	ULID           ulid.ULID
	UGI            ulid.ULID
	Mode           uint   // 0 - none, 1 - host, 2 - peer
	Authorization  any    // session token
	Lobby          string // lobby id
	InLobby        bool
	Mux            *sync.RWMutex  // To prevent concurrent writes to the websocket connection
	Metadata       map[string]any // arbitrary metadata that the client can specify
	PublicKey      string
	TransitionDone chan bool
}

func (*Client) AmIAHost

func (c *Client) AmIAHost() bool

func (*Client) AmIAuthorized

func (c *Client) AmIAuthorized() bool

func (*Client) AmIInALobby

func (c *Client) AmIInALobby() bool

func (*Client) AmINew

func (c *Client) AmINew() bool

func (*Client) AmIPeer

func (c *Client) AmIPeer() bool

func (*Client) ClearLobby

func (c *Client) ClearLobby()

func (*Client) ClearMode

func (c *Client) ClearMode()

func (*Client) SetHostMode

func (c *Client) SetHostMode()

func (*Client) SetLobby

func (c *Client) SetLobby(lobby string)

func (*Client) SetPeerMode

func (c *Client) SetPeerMode()

func (*Client) StoreAuthorization

func (c *Client) StoreAuthorization(token string)

type Game

type Game struct {
	Mutex   sync.RWMutex
	Lobbies map[string]*Lobby
	Clients []*Client
}

type GameStore

type GameStore struct {
	Mutex sync.RWMutex
	Games map[string]*Game
}

type HostConfigPacket

type HostConfigPacket struct {
	Opcode   string         `json:"opcode" validate:"required" label:"opcode"`
	Payload  *LobbySettings `json:"payload" validate:"required" label:"payload"`
	Listener string         `json:"listener,omitempty" validate:"omitempty,omitnil" label:"listener"` // For clients to listen to server replies
}

type InitOK

type InitOK struct {
	User      string `json:"user"`
	Id        string `json:"id"`
	SessionID any    `json:"session_id"`
	Game      string `json:"game"`
	Developer string `json:"developer"`
}

JSON structure for signaling INIT_OK response.

type InitPacket

type InitPacket struct {
	Opcode   string `json:"opcode" validate:"required" label:"opcode"`
	Payload  any    `json:"payload" validate:"required" label:"payload"` // required,ulid|jwt
	Listener string `json:"listener,omitempty" validate:"omitempty,omitnil" label:"listener"`
}

type Lobby

type Lobby struct {
	Mutex    sync.RWMutex
	Host     *Client
	Settings *LobbySettings
	Clients  []*Client
}

type LobbyInfo

type LobbyInfo struct {
	LobbyHostID       string `json:"lobby_host_id"`
	LobbyHostUsername string `json:"lobby_host_username"`
	MaximumPeers      int    `json:"max_peers"`
	CurrentPeers      int    `json:"current_peers"`
	PasswordRequired  bool   `json:"password_required"`
	Reclaimable       bool   `json:"reclaimable"`
}

type LobbySettings

type LobbySettings struct {
	LobbyID             string `json:"lobby_id" label:"lobby_id" validate:"required"`
	UseServerRelay      bool   `json:"use_server_relay" validate:"boolean" label:"use_server_relay"`
	AllowHostReclaim    bool   `json:"allow_host_reclaim" validate:"boolean" label:"allow_host_reclaim"`
	AllowPeersToReclaim bool   `json:"allow_peers_to_claim_host" validate:"boolean" label:"allow_peers_to_claim_host"`
	MaximumPeers        int    `json:"max_peers" validate:"min=0" label:"max_peers"`
	Password            string `json:"password" validate:"omitempty,omitnil,max=128" label:"password"`
	Locked              bool   `json:"locked" validate:"boolean" label:"locked"`
	PublicKey           string `json:"pubkey,omitempty" validate:"omitempty,omitnil" label:"pubkey"`
	ReclaimInProgress   bool   `json:"reclaim_in_progress,omitempty" validate:"omitempty,omitnil"` // This is an internal flag, not to be used by clients.
}

type NewHostParams

type NewHostParams struct {
	ID        string `json:"id"`
	User      string `json:"user"`
	LobbyID   string `json:"lobby_id"`
	PublicKey string `json:"pubkey,omitempty"`
}

Declare the packet format for the NEW_HOST signaling event.

type NewPeerParams

type NewPeerParams struct {
	ID        string `json:"id"`
	User      string `json:"user"`
	PublicKey string `json:"pubkey,omitempty"`
}

Declare the packet format for the NEW_PEER signaling event.

type PeerConfigPacket

type PeerConfigPacket struct {
	Opcode   string            `json:"opcode" validate:"required" label:"opcode"`
	Payload  *PeerConfigParams `json:"payload" validate:"required_with=LobbyID" label:"payload"`
	Listener string            `json:"listener,omitempty" validate:"omitempty,omitnil" label:"listener"` // For clients to listen to server replies
}

Declare the packet format for the CONFIG_PEER signaling command.

type PeerConfigParams

type PeerConfigParams struct {
	LobbyID   string `json:"lobby_id" validate:"required" label:"lobby_id"`
	Password  string `json:"password" validate:"omitempty,max=128" label:"password"`
	PublicKey string `json:"pubkey,omitempty" validate:"omitempty,omitnil" label:"pubkey"`
}

type PeerInfo

type PeerInfo struct {
	ID   string `json:"id"`
	User string `json:"user"`
}

type Relay

type Relay struct {
	Server           *Server
	Conn             *webrtc.PeerConnection
	Channels         map[string]*webrtc.DataChannel
	UGI              ulid.ULID
	Peer             *Client
	Lobby            string // lobby id
	Running          bool
	RequestShutdown  chan bool // used to shutdown the relay.
	ShutdownComplete chan bool // used to wait for shutdown to complete.
}

type RelayCandidate

type RelayCandidate struct {
	Type     uint8                      `json:"type" validate:"required" label:"type"`
	Contents *webrtc.SessionDescription `json:"contents" validate:"required" label:"contents"`
}

Declare the packet format for handling relay candidate data.

type RelayCandidatePacket

type RelayCandidatePacket struct {
	Opcode    string          `json:"opcode" validate:"required" label:"opcode"`                               // Required for protocol compliance
	Payload   *RelayCandidate `json:"payload,omitempty" validate:"omitempty,omitnil,required" label:"payload"` // Required for protocol compliance
	Origin    *PeerInfo       `json:"origin,omitempty" validate:"omitempty,omitnil" label:"origin"`            // Relay -> Peer, identifies client that sent the message
	Recipient string          `json:"recipient,omitempty" validate:"omitempty,omitnil" label:"recipient"`      // Peer -> Relay, identifies client that should receive the message
}

type RelayInboundIce

type RelayInboundIce struct {
	Type     uint8                    `json:"type" validate:"required" label:"type"`
	Contents *webrtc.ICECandidateInit `json:"contents" validate:"required" label:"contents"`
}

Declare the packet format for handling relay inbound ICE data.

type RelayInboundIcePacket

type RelayInboundIcePacket struct {
	Opcode    string           `json:"opcode" validate:"required" label:"opcode"`                               // Required for protocol compliance
	Payload   *RelayInboundIce `json:"payload,omitempty" validate:"omitempty,omitnil,required" label:"payload"` // Required for protocol compliance
	Origin    *PeerInfo        `json:"origin,omitempty" validate:"omitempty,omitnil" label:"origin"`            // Relay -> Peer, identifies client that sent the message
	Recipient string           `json:"recipient,omitempty" validate:"omitempty,omitnil" label:"recipient"`      // Peer -> Relay, identifies client that should receive the message
}

type RelayOutboundIce

type RelayOutboundIce struct {
	Type     uint8                `json:"type" validate:"required" label:"type"`
	Contents *webrtc.ICECandidate `json:"contents" validate:"required" label:"contents"`
}

Declare the packet format for handling relay outbound ICE data.

type RelayOutboundIcePacket

type RelayOutboundIcePacket struct {
	Opcode    string            `json:"opcode" validate:"required" label:"opcode"`                               // Required for protocol compliance
	Payload   *RelayOutboundIce `json:"payload,omitempty" validate:"omitempty,omitnil,required" label:"payload"` // Required for protocol compliance
	Origin    *PeerInfo         `json:"origin,omitempty" validate:"omitempty,omitnil" label:"origin"`            // Relay -> Peer, identifies client that sent the message
	Recipient string            `json:"recipient,omitempty" validate:"omitempty,omitnil" label:"recipient"`      // Peer -> Relay, identifies client that should receive the message
}

type RelayPacket

type RelayPacket struct {
	Opcode    string    `json:"opcode" validate:"required" label:"opcode"`                               // Required for protocol compliance
	Payload   any       `json:"payload,omitempty" validate:"omitempty,omitnil,required" label:"payload"` // Required for protocol compliance
	Origin    *PeerInfo `json:"origin,omitempty" validate:"omitempty,omitnil" label:"origin"`            // Relay -> Peer, identifies client that sent the message
	Recipient string    `json:"recipient,omitempty" validate:"omitempty,omitnil" label:"recipient"`      // Peer -> Relay, identifies client that should receive the message
	Channel   string    `json:"channel,omitempty" validate:"omitempty,omitnil" label:"channel"`          // Used to specify what channel the relayed packet belongs to
}

Declare the packet format for webrtc relay.

type RootError

type RootError struct {
	Errors []map[string]string `json:"Validation error"`
}

type Server

type Server struct {
	AuthorizedOriginsStorage []*regexp.Regexp
	Mux                      *sync.RWMutex
	Games                    *GameStore
	Sessions                 *SessionStore
	TURNOnly                 bool
	Relays                   map[*Client]*Relay
	RelayLock                *sync.RWMutex
	PacketValidator          *validator.Validate
	WebsocketConnCounter     uint64
}

type Session

type Session struct {
	Client *Client
	Reset  chan bool
	Delete chan bool
	Done   chan bool
	Closed bool
}

type SessionStore

type SessionStore struct {
	Mutex    sync.RWMutex
	Sessions map[string]*Session
}

type SignalPacket

type SignalPacket struct {
	Opcode    string    `json:"opcode" validate:"required" label:"opcode"`                               // Required for protocol compliance
	Payload   any       `json:"payload,omitempty" validate:"omitempty,omitnil,required" label:"payload"` // Required for protocol compliance
	Origin    *PeerInfo `json:"origin,omitempty" validate:"omitempty,omitnil" label:"origin"`            // Server -> Client, identifies client that sent the message
	Recipient string    `json:"recipient,omitempty" validate:"omitempty,omitnil" label:"recipient"`      // Client -> Server, identifies client that should receive the message
	Listener  string    `json:"listener,omitempty" validate:"omitempty,omitnil" label:"listener"`        // For clients to listen to server replies
}

Declare the packet format for signaling.

Jump to

Keyboard shortcuts

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