protocol

package
v0.0.0-...-1c82f41 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Connection

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

Connection represents a connection with a peer and enables communication

func NewConnection

func NewConnection(ip *net.IP, options ...ConnectionOptionFunc) (*Connection, error)

NewConnection creates a new connection object with the specified peer

func (*Connection) Close

func (c *Connection) Close()

Close closes the connection, if open

func (*Connection) Do

func (c *Connection) Do(messageType protocols.ProtocolMessageType, data interface{}) error

Do send a request over the websocket

func (*Connection) Handshake

func (c *Connection) Handshake() error

Handshake performs the RPC handshake. This should be called before any other method

func (*Connection) ReadOne

func (c *Connection) ReadOne(timeout time.Duration) (*protocols.Message, error)

ReadOne reads and returns one message from the connection

func (*Connection) ReadSync

func (c *Connection) ReadSync(handler PeerResponseHandlerFunc) error

ReadSync Reads for async responses over the connection in a synchronous fashion, blocking anything else

func (*Connection) RequestPeers

func (c *Connection) RequestPeers() error

RequestPeers asks the current peer to respond with their current peer list

type ConnectionOptionFunc

type ConnectionOptionFunc func(connection *Connection) error

ConnectionOptionFunc can be used to customize a new Connection

func WithHandshakeTimeout

func WithHandshakeTimeout(timeout time.Duration) ConnectionOptionFunc

WithHandshakeTimeout sets the handshake timeout

type PeerResponseHandlerFunc

type PeerResponseHandlerFunc func(*protocols.Message, error)

PeerResponseHandlerFunc is a function that will be called when a response is returned from a peer

Jump to

Keyboard shortcuts

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