transport

package
v0.0.0-...-060d5e1 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Message

type Message struct {
	From    string
	Payload []byte
}

Message is a struct that represents a message sent between nodes.

type Node

type Node interface {
	net.Conn
	Send([]byte) error
}

Node is an interface representing a node in the network.

type TCPNode

type TCPNode struct {
	// The underlying TCP connection of the peer
	net.Conn
	// contains filtered or unexported fields
}

TCPNode represents the remote node over a TCP established connection.

func NewTCPNode

func NewTCPNode(conn net.Conn) *TCPNode

func (*TCPNode) CloseStream

func (p *TCPNode) CloseStream()

func (*TCPNode) Send

func (p *TCPNode) Send(b []byte) error

type TCPTransport

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

func NewTCPTransport

func NewTCPTransport(opts ...TCPTransportOption) (*TCPTransport, error)

Create a new TCPTransport with the given configuration.

func (*TCPTransport) Addr

func (t *TCPTransport) Addr() string

Implement the Transport interface by returning the address of the TCPTransport.

func (*TCPTransport) Close

func (t *TCPTransport) Close() error

Implement the Transport interface closing the listener.

func (*TCPTransport) ListenAndAccept

func (t *TCPTransport) ListenAndAccept() error

Implement the Transport interface listening and handling incoming connections.

type TCPTransportOption

type TCPTransportOption func(*tcpTransportOpts) error

TCPTransportOption is a function that updates the tcpTransportOpts struct.

func WithListenAddr

func WithListenAddr(addr string) TCPTransportOption

WithListenAddr is a configuration function that updates the listen address.

func WithLogger

func WithLogger(logger *slog.Logger) TCPTransportOption

WithLogger is a configuration function that updates the logger.

type Transport

type Transport interface {
	// Addr returns the address of the transport.
	Addr() string
	// Close closes the transport.
	Close() error
	// ListenAndAccept listens for incoming connections and accepts them.
	ListenAndAccept() error
}

Transport is anything that handles network communication between nodes.

Jump to

Keyboard shortcuts

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