netceptor

package
v0.0.0-...-71dd234 Latest Latest
Warning

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

Go to latest
Published: Jun 25, 2020 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Overview

Package netceptor is the networking layer of Receptor.

Index

Constants

View Source
const (
	// MsgTypeData is a normal data-containing message
	MsgTypeData = 0
	// MsgTypeRoute is a routing update
	MsgTypeRoute = 1
	// MsgTypeServiceAdvertisement is an advertisement for a service
	MsgTypeServiceAdvertisement = 2
	// MsgTypeReject indicates a rejection
	MsgTypeReject = 3
)
View Source
const MTU = 16384

MTU is the largest message sendable over the Netecptor network

View Source
const RouteUpdateTime = 10 * time.Second

RouteUpdateTime is the interval at which regular route updates will be sent

View Source
const SeenUpdateExpireTime = 1 * time.Hour

SeenUpdateExpireTime is the age after which routing update IDs can be discarded

View Source
const ServiceAdTime = 60 * time.Second

ServiceAdTime is the interval at which regular service advertisements will be sent

Variables

View Source
var ErrTimeout error = &TimeoutError{}

ErrTimeout is returned for an expired deadline.

Functions

func AddBackend

func AddBackend()

AddBackend adds a backend to the wait group

func BackendCount

func BackendCount() int32

BackendCount returns the number of backends that ever registered

func BackendWait

func BackendWait()

BackendWait waits for the backend wait group

func DoneBackend

func DoneBackend()

DoneBackend signals to the wait group that the backend is done

func GetClientTLSConfig

func GetClientTLSConfig(name string, expectedHostName string) (*tls.Config, error)

GetClientTLSConfig retrieves a server TLS config by name

func GetServerTLSConfig

func GetServerTLSConfig(name string) (*tls.Config, error)

GetServerTLSConfig retrieves a server TLS config by name

Types

type Addr

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

Addr represents an endpoint address on the Netceptor network

func NewAddr

func NewAddr(node string, service string) Addr

NewAddr generates a Receptor network address from a node ID and service name

func (Addr) Network

func (a Addr) Network() string

Network returns the network name, which is always just "netceptor"

func (Addr) String

func (a Addr) String() string

String formats this address as a string

type Backend

type Backend interface {
	Start(sessFunc BackendSessFunc, errFunc ErrorFunc)
}

Backend is the interface for back-ends that the Receptor network can run over

type BackendSessFunc

type BackendSessFunc func(BackendSession) error

BackendSessFunc is a function run by a backend, that runs the Netceptor protocol (or some other protocol)

type BackendSession

type BackendSession interface {
	Send([]byte) error
	Recv() ([]byte, error)
	Close() error
}

BackendSession is the interface for a single session of a back-end Backends must be DATAGRAM ORIENTED, meaning that Recv() must return whole packets sent by Send(). If the underlying protocol is stream oriented, then the backend must deal with any required buffering.

type Conn

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

Conn implements the net.Conn interface via the Receptor network

func (*Conn) Close

func (c *Conn) Close() error

Close closes the writer side of the connection

func (*Conn) LocalAddr

func (c *Conn) LocalAddr() net.Addr

LocalAddr returns the local address of this connection

func (*Conn) Read

func (c *Conn) Read(b []byte) (n int, err error)

Read reads data from the connection

func (*Conn) RemoteAddr

func (c *Conn) RemoteAddr() net.Addr

RemoteAddr returns the remote address of this connection

func (*Conn) SetDeadline

func (c *Conn) SetDeadline(t time.Time) error

SetDeadline sets both read and write deadlines

func (*Conn) SetReadDeadline

func (c *Conn) SetReadDeadline(t time.Time) error

SetReadDeadline sets the read deadline

func (*Conn) SetWriteDeadline

func (c *Conn) SetWriteDeadline(t time.Time) error

SetWriteDeadline sets the write deadline

func (*Conn) Write

func (c *Conn) Write(b []byte) (n int, err error)

Write writes data to the connection

type ConnStatus

type ConnStatus struct {
	NodeID string
	Cost   float64
}

ConnStatus holds information about a single connection in the Status struct.

type ErrorFunc

type ErrorFunc func(error, bool)

ErrorFunc is a function parameter used to process errors. The boolean parameter indicates whether the error is fatal (i.e. the associated process is going to exit).

type Listener

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

Listener implements the net.Listener interface via the Receptor network

func (*Listener) Accept

func (li *Listener) Accept() (net.Conn, error)

Accept accepts a connection via the listener

func (*Listener) Addr

func (li *Listener) Addr() net.Addr

Addr returns the local address of this listener

func (*Listener) Close

func (li *Listener) Close() error

Close closes the listener

type Netceptor

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

Netceptor is the main object of the Receptor mesh network protocol

var MainInstance *Netceptor

MainInstance is the global instance of Netceptor instantiated by the command-line main() function

func New

func New(NodeID string, AllowedPeers []string) *Netceptor

New constructs a new Receptor network protocol instance

func (*Netceptor) Dial

func (s *Netceptor) Dial(node string, service string, tls *tls.Config) (*Conn, error)

Dial returns a stream connection compatible with Go's net.Conn.

func (*Netceptor) GetServiceInfo

func (s *Netceptor) GetServiceInfo(NodeID string, Service string) (*ServiceAdvertisement, bool)

GetServiceInfo returns the advertising info, if any, for a service on a node

func (*Netceptor) Listen

func (s *Netceptor) Listen(service string, tls *tls.Config) (*Listener, error)

Listen returns a stream listener compatible with Go's net.Listener. If service is blank, generates and uses an ephemeral service name.

func (*Netceptor) ListenAndAdvertise

func (s *Netceptor) ListenAndAdvertise(service string, tls *tls.Config, tags map[string]string) (*Listener, error)

ListenAndAdvertise listens for stream connections on a service and also advertises it via broadcasts.

func (*Netceptor) ListenPacket

func (s *Netceptor) ListenPacket(service string) (*PacketConn, error)

ListenPacket returns a datagram connection compatible with Go's net.PacketConn. If service is blank, generates and uses an ephemeral service name.

func (*Netceptor) ListenPacketAndAdvertise

func (s *Netceptor) ListenPacketAndAdvertise(service string, tags map[string]string) (*PacketConn, error)

ListenPacketAndAdvertise returns a datagram listener, and also broadcasts service advertisements to the Receptor network as long as the listener remains open.

func (*Netceptor) NodeID

func (s *Netceptor) NodeID() string

NodeID returns the local Node ID of this Netceptor instance

func (*Netceptor) RunBackend

func (s *Netceptor) RunBackend(b Backend, connectionCost float64, errf func(error, bool))

RunBackend runs the Netceptor protocol on a backend object

func (*Netceptor) Shutdown

func (s *Netceptor) Shutdown()

Shutdown shuts down a Receptor network protocol instance

func (*Netceptor) Status

func (s *Netceptor) Status() Status

Status returns the current state of the Netceptor object

type PacketConn

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

PacketConn implements the net.PacketConn interface via the Receptor network

func (*PacketConn) Close

func (nc *PacketConn) Close() error

Close closes the connection.

func (*PacketConn) LocalAddr

func (nc *PacketConn) LocalAddr() net.Addr

LocalAddr returns the local address the connection is bound to.

func (*PacketConn) LocalService

func (nc *PacketConn) LocalService() string

LocalService returns the local service name of the connection.

func (*PacketConn) ReadFrom

func (nc *PacketConn) ReadFrom(p []byte) (n int, addr net.Addr, err error)

ReadFrom reads a packet from the network and returns its data and address.

func (*PacketConn) SetDeadline

func (nc *PacketConn) SetDeadline(t time.Time) error

SetDeadline sets both the read and write deadlines.

func (*PacketConn) SetReadDeadline

func (nc *PacketConn) SetReadDeadline(t time.Time) error

SetReadDeadline sets the read deadline.

func (*PacketConn) SetWriteDeadline

func (nc *PacketConn) SetWriteDeadline(t time.Time) error

SetWriteDeadline sets the write deadline.

func (*PacketConn) WriteTo

func (nc *PacketConn) WriteTo(p []byte, addr net.Addr) (n int, err error)

WriteTo writes a packet to an address on the network.

type ServiceAdvertisement

type ServiceAdvertisement struct {
	NodeID  string
	Service string
	Time    time.Time
	Tags    map[string]string
}

ServiceAdvertisement is the data associated with a service advertisement

type Status

type Status struct {
	NodeID         string
	Connections    []*ConnStatus
	RoutingTable   map[string]string
	Advertisements []*ServiceAdvertisement
}

Status is the struct returned by Netceptor.Status(). It represents a public view of the internal status of the Netceptor object.

type TLSClientCfg

type TLSClientCfg struct {
	Name               string `required:"true" description:"Name of this TLS client configuration"`
	Cert               string `required:"false" description:"Client certificate filename"`
	Key                string `required:"false" description:"Client private key filename"`
	RootCAs            string `required:"false" description:"Root CA bundle to use instead of system trust"`
	InsecureSkipVerify bool   `required:"false" description:"Accept any server cert" default:"false"`
}

TLSClientCfg stores the configuration options for a TLS client

func (TLSClientCfg) Prepare

func (cfg TLSClientCfg) Prepare() error

Prepare creates the tls.config and stores it in the global map

type TLSServerCfg

type TLSServerCfg struct {
	Name              string `required:"true" description:"Name of this TLS server configuration"`
	Cert              string `required:"true" description:"Server certificate filename"`
	Key               string `required:"true" description:"Server private key filename"`
	RequireClientCert bool   `description:"Require client certificates" default:"false"`
	ClientCAs         string `description:"Filename of CA bundle to verify client certs with"`
}

TLSServerCfg stores the configuration options for a TLS server

func (TLSServerCfg) Prepare

func (cfg TLSServerCfg) Prepare() error

Prepare creates the tls.config and stores it in the global map

type TimeoutError

type TimeoutError struct{}

TimeoutError is returned for an expired deadline.

func (*TimeoutError) Error

func (e *TimeoutError) Error() string

Error returns a string describing the error.

func (*TimeoutError) Temporary

func (e *TimeoutError) Temporary() bool

Temporary returns true if a retry is likely a good idea.

func (*TimeoutError) Timeout

func (e *TimeoutError) Timeout() bool

Timeout returns true if this error was a timeout.

Jump to

Keyboard shortcuts

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