Documentation ¶
Overview ¶
Package netceptor is the networking layer of Receptor.
Index ¶
- Constants
- Variables
- func AddBackend()
- func BackendCount() int32
- func BackendWait()
- func DoneBackend()
- func GetClientTLSConfig(name string, expectedHostName string) (*tls.Config, error)
- func GetServerTLSConfig(name string) (*tls.Config, error)
- type Addr
- type Backend
- type BackendSessFunc
- type BackendSession
- type Conn
- func (c *Conn) Close() error
- func (c *Conn) LocalAddr() net.Addr
- func (c *Conn) Read(b []byte) (n int, err error)
- func (c *Conn) RemoteAddr() net.Addr
- func (c *Conn) SetDeadline(t time.Time) error
- func (c *Conn) SetReadDeadline(t time.Time) error
- func (c *Conn) SetWriteDeadline(t time.Time) error
- func (c *Conn) Write(b []byte) (n int, err error)
- type ConnStatus
- type ErrorFunc
- type Listener
- type Netceptor
- func (s *Netceptor) Dial(node string, service string, tls *tls.Config) (*Conn, error)
- func (s *Netceptor) GetServiceInfo(NodeID string, Service string) (*ServiceAdvertisement, bool)
- func (s *Netceptor) Listen(service string, tls *tls.Config) (*Listener, error)
- func (s *Netceptor) ListenAndAdvertise(service string, tls *tls.Config, tags map[string]string) (*Listener, error)
- func (s *Netceptor) ListenPacket(service string) (*PacketConn, error)
- func (s *Netceptor) ListenPacketAndAdvertise(service string, tags map[string]string) (*PacketConn, error)
- func (s *Netceptor) NodeID() string
- func (s *Netceptor) RunBackend(b Backend, connectionCost float64, errf func(error, bool))
- func (s *Netceptor) Shutdown()
- func (s *Netceptor) Status() Status
- type PacketConn
- func (nc *PacketConn) Close() error
- func (nc *PacketConn) LocalAddr() net.Addr
- func (nc *PacketConn) LocalService() string
- func (nc *PacketConn) ReadFrom(p []byte) (n int, addr net.Addr, err error)
- func (nc *PacketConn) SetDeadline(t time.Time) error
- func (nc *PacketConn) SetReadDeadline(t time.Time) error
- func (nc *PacketConn) SetWriteDeadline(t time.Time) error
- func (nc *PacketConn) WriteTo(p []byte, addr net.Addr) (n int, err error)
- type ServiceAdvertisement
- type Status
- type TLSClientCfg
- type TLSServerCfg
- type TimeoutError
Constants ¶
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 )
const MTU = 16384
MTU is the largest message sendable over the Netecptor network
const RouteUpdateTime = 10 * time.Second
RouteUpdateTime is the interval at which regular route updates will be sent
const SeenUpdateExpireTime = 1 * time.Hour
SeenUpdateExpireTime is the age after which routing update IDs can be discarded
const ServiceAdTime = 60 * time.Second
ServiceAdTime is the interval at which regular service advertisements will be sent
Variables ¶
var ErrTimeout error = &TimeoutError{}
ErrTimeout is returned for an expired deadline.
Functions ¶
func BackendCount ¶
func BackendCount() int32
BackendCount returns the number of backends that ever registered
func DoneBackend ¶
func DoneBackend()
DoneBackend signals to the wait group that the backend is done
func GetClientTLSConfig ¶
GetClientTLSConfig 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
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 ¶
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) RemoteAddr ¶
RemoteAddr returns the remote address of this connection
func (*Conn) SetDeadline ¶
SetDeadline sets both read and write deadlines
func (*Conn) SetReadDeadline ¶
SetReadDeadline sets the read deadline
func (*Conn) SetWriteDeadline ¶
SetWriteDeadline sets the write deadline
type ConnStatus ¶
ConnStatus holds information about a single connection in the Status struct.
type ErrorFunc ¶
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
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 (*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 ¶
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) RunBackend ¶
RunBackend runs the Netceptor protocol on a backend object
type PacketConn ¶
type PacketConn struct {
// contains filtered or unexported fields
}
PacketConn implements the net.PacketConn interface via the Receptor network
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 ¶
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.
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.