relay

package
v0.0.0-...-10d9ced Latest Latest
Warning

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

Go to latest
Published: Jan 25, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package relay implements the core logic of the relay via which a tcp_endpoints.RelayDialer and tcp_endpoints.RelayListener connect

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HandleClientConnection

func HandleClientConnection(relayState *RelayData) http.HandlerFunc

HandleClientConnection passes a ConnectionRequest to a waiting ListeningServer and waits for a socket to be received from a callback connection with which to connect an ConnectingClient connection

func HandleServerCallBackConnection

func HandleServerCallBackConnection(relayState *RelayData) http.HandlerFunc

HandleServerCallBackConnection manages the server callback upon receiving a client request, and passes the connection to the waiting client handler for gluing

func HandleServerLongTermConnection

func HandleServerLongTermConnection(relayState *RelayData) http.HandlerFunc

HandleServerLongTermConnection maintains a persistent connection on behalf of an ListeningServer and passes connection requests back to the underlying ExportingServer when received

func MaintainConnection

func MaintainConnection() int

Types

type ClientData

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

ClientData contains a message for a server and channel for communicating back to the respective importer

func InitClientData

func InitClientData(cr api.ConnectionRequest) *ClientData

type ConnectingClient

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

ConnectingClient is created every time a client dials a server and is waiting for a socket that connects to server at relay.

func InitConnectingClient

func InitConnectingClient(freshCTX context.Context) *ConnectingClient

type ListeningServer

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

ListeningServer is a relay side representation of a server listening for connections via the relay. It is created every time a server reaches out to create a persistent connection. Messages are passed to the handler maintaining the persistent connection via the channel below

func InitListeningServer

func InitListeningServer(freshCTX context.Context) *ListeningServer

type Relay

type Relay struct {
	Data StateManager
	Mux  http.Handler
	// contains filtered or unexported fields
}

Relay contains Data for running relay code

func NewRelay

func NewRelay() *Relay

NewRelay returns a Relay with all initialised data structures and handler functions. To start the relay it's mux needs to be passed to a http.Server and then start the server

type RelayData

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

RelayData contains dbs of listeningServers advertising services and connectingClients waiting for callback connections

func (RelayData) AddConnectingClient

func (db RelayData) AddConnectingClient(id string, imp *ConnectingClient)

AddConnectingClient is called when a ConnectingClient is waiting on a connection to finish connecting

func (RelayData) AddListeningServer

func (db RelayData) AddListeningServer(id string, exp *ListeningServer)

AddListeningServer is called when a new server wishes to advertise via the relay

func (RelayData) NotifyConnectingClient

func (db RelayData) NotifyConnectingClient(id string, connection *ServerConn) error

NotifyConnectingClient return an error if the server to access does not exist in the db nil otherwise

func (RelayData) NotifyListeningServer

func (db RelayData) NotifyListeningServer(id string, msg *ClientData) error

NotifyListeningServer return an error if the server to access does not exist in the db nil otherwise

func (RelayData) RemoveConnectingClient

func (db RelayData) RemoveConnectingClient(id string)

RemoveConnectingClient is used for cleanup of a ConnectingClient that is no longer is waiting on a connection via the relay

func (RelayData) RemoveListeningServer

func (db RelayData) RemoveListeningServer(id string)

RemoveListeningServer is used for cleanup of listeningServers no longer advertising via the relay

type ServerConn

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

type StateManager

type StateManager interface {
	AddListeningServer(expID string, exp *ListeningServer)
	RemoveListeningServer(expID string)
	NotifyListeningServer(expID string, msg *ClientData) error
	AddConnectingClient(impID string, imp *ConnectingClient)
	RemoveConnectingClient(impID string)
	NotifyConnectingClient(impID string, connection *ServerConn) error
}

StateManager represents the relays internal state with respect to all listeningServers and connectingClients it is currently serving

Jump to

Keyboard shortcuts

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