peerprotocol

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Apr 8, 2024 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

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

func WithNetworkID added in v0.8.0

func WithNetworkID(networkID string) ConnectionOptionFunc

WithNetworkID sets the network ID for the peer

func WithPeerKeyPair added in v0.8.0

func WithPeerKeyPair(keypair tls.Certificate) ConnectionOptionFunc

WithPeerKeyPair sets the keypair for the peer

func WithPeerPort added in v0.8.0

func WithPeerPort(port uint16) ConnectionOptionFunc

WithPeerPort sets the port for the peer

type FullNodeProtocol

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

FullNodeProtocol is for interfacing with full nodes via the peer protocol

func NewFullNodeProtocol

func NewFullNodeProtocol(connection *Connection) (*FullNodeProtocol, error)

NewFullNodeProtocol returns a new instance of the full node protocol

func (*FullNodeProtocol) RequestBlock added in v0.8.0

func (c *FullNodeProtocol) RequestBlock(data *protocols.RequestBlock) error

RequestBlock asks the current peer to respond with a block

func (*FullNodeProtocol) RequestPeers

func (c *FullNodeProtocol) RequestPeers() error

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

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