p2p

package
v0.0.0-...-d7c40c9 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2023 License: GPL-3.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NOPHandshakeFunc

func NOPHandshakeFunc(Peer) error

Types

type Decoder

type Decoder interface {
	Decode(io.Reader, *RPC) error
}

type DefaultDecoder

type DefaultDecoder struct{}

func (DefaultDecoder) Decode

func (dec DefaultDecoder) Decode(r io.Reader, msg *RPC) error

type GOBDecoder

type GOBDecoder struct{}

func (GOBDecoder) Decode

func (dec GOBDecoder) Decode(r io.Reader, msg *RPC) error

type HandshakeFunc

type HandshakeFunc func(Peer) error

HandshakeFunc

type Peer

type Peer interface {
	Close() error
}

Peer is an interface that represents the remote node

type RPC

type RPC struct {
	From    net.Addr
	Payload []byte
}

RPC holds any arbitrary data that is being sent over the each transport between two nodes in the network

type TCPPeer

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

TCPPeer represents the remote node over a TCP established connection

func NewTCPPeer

func NewTCPPeer(conn net.Conn, outbound bool) *TCPPeer

func (*TCPPeer) Close

func (p *TCPPeer) Close() error

Close implements the Peer interface

type TCPTransport

type TCPTransport struct {
	TCPTransportOpts
	// contains filtered or unexported fields
}

func NewTCPTransport

func NewTCPTransport(opts TCPTransportOpts) *TCPTransport

func (*TCPTransport) Consume

func (t *TCPTransport) Consume() <-chan RPC

Consume implements the Transport interface, which will return read only channel for reading the incoming messages received from another peer in the network

func (*TCPTransport) ListenAndAccept

func (t *TCPTransport) ListenAndAccept() error

type TCPTransportOpts

type TCPTransportOpts struct {
	ListenAddr    string
	HandshakeFunc HandshakeFunc
	Decoder       Decoder
	OnPeer        func(Peer) error
}

type Transport

type Transport interface {
	ListenAndAccept() error
	Consume() <-chan RPC
}

Transport is anything that handles the communication between the nodes in the network This can be of the form (TCP< UDP, websockets, ...)

Jump to

Keyboard shortcuts

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