protocol

package
v0.0.0-...-a622927 Latest Latest
Warning

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

Go to latest
Published: Sep 25, 2024 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	IncomingMessage = 0x1
	IncomingStream  = 0x2
)

Variables

This section is empty.

Functions

func DumbHandShakeFunc

func DumbHandShakeFunc(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 {
	net.Conn
	Send([]byte) error
	CloseStream()
}

Peer is the interface representation of a remote node.

type RPC

type RPC struct {
	From    string
	Payload []byte
	Stream  bool
}

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

type TCPPeer

type TCPPeer struct {
	// The peer connection it self. TCP in this case
	net.Conn
	// contains filtered or unexported fields
}

TCPPeer is the network remote node over a TCP transport estabilished connection

func NewTCPPeer

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

func (*TCPPeer) CloseStream

func (p *TCPPeer) CloseStream()

func (*TCPPeer) Send

func (p *TCPPeer) Send(data []byte) error

type TCPTransport

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

func NewTCPTranport

func NewTCPTranport(options TCPTransportOptions) *TCPTransport

func (*TCPTransport) Addr

func (t *TCPTransport) Addr() string

Addr implements the Transport interface returns the address. transport is accepting new connections.

func (*TCPTransport) Close

func (t *TCPTransport) Close() error

Close implements the Transport interface

func (*TCPTransport) Consume

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

Consume implements the Transport interface, returns a read-only of incoming messages received from a connected peer in the network.

func (*TCPTransport) Dial

func (t *TCPTransport) Dial(addr string) error

Dial implements the Transport interface

func (*TCPTransport) ListenAndAccept

func (t *TCPTransport) ListenAndAccept() error

type TCPTransportOptions

type TCPTransportOptions struct {
	ListenAddr    string
	HandShakeFunc HandShakeFunc
	Decoder       Decoder
	OnPeer        func(Peer) error
}

type Transport

type Transport interface {
	Addr() string
	Dial(string) error
	ListenAndAccept() error
	Consume() <-chan RPC
	Close() error
}

Transport is anything that handles the communication between the nodes in the network. This can be TCP, UDP, websockets, ...

Jump to

Keyboard shortcuts

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