connections

package
v0.3.8 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2019 License: MIT Imports: 22 Imported by: 5

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ConnectionStateName allows conversion of states to their string representations
	ConnectionStateName = []string{"Disconnected", "Connecting", "Connected", "Authenticated", "Synced", "Failed", "Killed"}

	// ConnectionStateToType allows conversion of strings to their state type
	ConnectionStateToType = map[string]ConnectionState{"Disconnected": DISCONNECTED, "Connecting": CONNECTING,
		"Connected": CONNECTED, "Authenticated": AUTHENTICATED, "Synced": SYNCED, "Failed": FAILED, "Killed": KILLED}
)

Functions

This section is empty.

Types

type ConnectionState

type ConnectionState int

ConnectionState defines the various states a connection can be in from disconnected to authenticated

const (
	DISCONNECTED ConnectionState = iota
	CONNECTING
	CONNECTED
	AUTHENTICATED
	SYNCED
	FAILED
	KILLED
)

Connection States DISCONNECTED - No existing connection has been made, or all attempts have failed CONNECTING - We are in the process of attempting to connect to a given endpoint CONNECTED - We have connected but not yet authenticated AUTHENTICATED - im.ricochet.auth-hidden-server has succeeded on the connection. SYNCED - we have pulled all the messages for groups from the server and are ready to send

type Engine

type Engine interface {
	ACN() connectivity.ACN
	EventManager() event.Manager
	Shutdown()
}

Engine (ProtocolEngine) encapsulates the logic necessary to make and receive Cwtch connections. Note: ProtocolEngine doesn't have access to any information necessary to encrypt or decrypt GroupMessages

func NewProtocolEngine

func NewProtocolEngine(identity primitives.Identity, privateKey ed25519.PrivateKey, acn connectivity.ACN, eventManager event.Manager, knownPeers []string, blockedPeers []string) Engine

NewProtocolEngine initializes a new engine that runs Cwtch using the given parameters

type Manager

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

Manager encapsulates all the logic necessary to manage outgoing peer and server connections.

func NewConnectionsManager

func NewConnectionsManager(acn connectivity.ACN) *Manager

NewConnectionsManager creates a new instance of Manager.

func (*Manager) GetPeerServerConnectionForOnion

func (m *Manager) GetPeerServerConnectionForOnion(host string) (psc *PeerServerConnection)

GetPeerServerConnectionForOnion safely returns a given host connection

func (*Manager) ManageServerConnection

func (m *Manager) ManageServerConnection(host string, engine Engine, messageHandler func(string, *protocol.GroupMessage))

ManageServerConnection creates a new ServerConnection for Host with the given callback handler. If there is an establish connection, it is replaced with a new one, assuming this came from a new JoinServer from a new Group being joined. If it is still connecting to a server, the second request will be abandonded

func (*Manager) SetServerSynced

func (m *Manager) SetServerSynced(onion string)

SetServerSynced is a helper for peerserver connections and engine to call when a Fetch is done to set the state of the connection to SYNCED

func (*Manager) Shutdown

func (m *Manager) Shutdown()

Shutdown closes all connections under management (freeing their goroutines)

type PeerApp

type PeerApp struct {
	applications.AuthApp

	MessageHandler    func(string, string, []byte)
	IsBlocked         func(string) bool
	OnAcknowledgement func(string, string)
	OnAuth            func(string)
	OnClose           func(string)
	OnConnecting      func(string)
	// contains filtered or unexported fields
}

PeerApp encapsulates the behaviour of a Cwtch Peer

func (*PeerApp) Init

func (pa *PeerApp) Init(connection tapir.Connection)

Init is run when the connection is first started.

func (PeerApp) NewInstance

func (pa PeerApp) NewInstance() tapir.Application

NewInstance should always return a new instantiation of the application.

func (PeerApp) SendMessage

func (pa PeerApp) SendMessage(message PeerMessage)

SendMessage sends the peer a preformatted message NOTE: This is a stub, we will likely want to extend this to better reflect the desired protocol

type PeerMessage

type PeerMessage struct {
	ID      string // A unique Message ID (primarily used for acknowledgments)
	Context string // A unique context identifier i.e. im.cwtch.chat
	Data    []byte // The serialized data packet.
}

PeerMessage is an encapsulation that can be used by higher level applications

type PeerServerConnection

type PeerServerConnection struct {
	connection.AutoConnectionHandler
	Server string

	GroupMessageHandler func(string, *protocol.GroupMessage)
	// contains filtered or unexported fields
}

PeerServerConnection encapsulates a single Peer->Server connection

func NewPeerServerConnection

func NewPeerServerConnection(engine Engine, serverhostname string) *PeerServerConnection

NewPeerServerConnection creates a new Peer->Server outbound connection

func (*PeerServerConnection) Break

func (psc *PeerServerConnection) Break() error

Break makes Run() return and prevents processing, but doesn't close the connection.

func (*PeerServerConnection) Close

func (psc *PeerServerConnection) Close()

Close shuts down the connection (freeing the handler goroutines)

func (*PeerServerConnection) GetState

func (psc *PeerServerConnection) GetState() ConnectionState

GetState returns the current connection state

func (*PeerServerConnection) HandleFetchDone

func (psc *PeerServerConnection) HandleFetchDone()

HandleFetchDone calls the supplied callback for when a fetch connection is closed

func (*PeerServerConnection) HandleGroupMessage

func (psc *PeerServerConnection) HandleGroupMessage(gm *protocol.GroupMessage)

HandleGroupMessage passes the given group message back to the profile.

func (*PeerServerConnection) Run

func (psc *PeerServerConnection) Run() error

Run manages the setup and teardown of a peer server connection

func (*PeerServerConnection) SendGroupMessage

func (psc *PeerServerConnection) SendGroupMessage(gm *protocol.GroupMessage) error

SendGroupMessage sends the given protocol message to the Server.

func (*PeerServerConnection) WaitTilSynced

func (psc *PeerServerConnection) WaitTilSynced()

WaitTilSynced waits until the underlying connection is authenticated

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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