p2p

package
v0.0.0-...-7ff3436 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NOHandshakeFunc

func NOHandshakeFunc(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

type Peer

type Peer interface {
	Close() error
}

Interface that represents the remote node

type RPC

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

type TCPPeer

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

func NewTCPPeer

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

func (*TCPPeer) Close

func (p *TCPPeer) Close() error

TCPPeer implements peer interface

type TCPTransport

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

Mutex will protect the peers

func NewTCPTransport

func NewTCPTransport(opts TCPTransportOpts) *TCPTransport

func (*TCPTransport) Consume

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

Consume implements the transport interface. Returns read-only channel for reading the incoming messages.

func (*TCPTransport) ListenAndAccept

func (t *TCPTransport) ListenAndAccept() error

type TCPTransportOpts

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

type Transport

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

Communication between nodes (tcp,UDP, websockets,....)

Jump to

Keyboard shortcuts

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