nnet

package module
v0.0.0-...-f3d5c14 Latest Latest
Warning

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

Go to latest
Published: May 24, 2024 License: Apache-2.0 Imports: 10 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func SetLogger

func SetLogger(logger log.Logger) error

SetLogger sets the global logger

Types

type Config

type Config config.Config

Config is an alias of config.Config for simpler usage

type NNet

type NNet struct {
	overlay.Network
}

NNet is is a peer to peer network

func NewNNet

func NewNNet(id []byte, conf *Config) (*NNet, error)

NewNNet creates a new nnet using the local node id and configuration provided. If id is nil, a random id will be generated. Empty fields in conf will be filled with the default config.

func (*NNet) ApplyMiddleware

func (nn *NNet) ApplyMiddleware(mw interface{}) error

ApplyMiddleware add a middleware to node, network, router, etc. If multiple middleware of the same type are applied, they will be called in the order of being added.

func (*NNet) GetConfig

func (nn *NNet) GetConfig() *Config

GetConfig returns the config of nnet

func (*NNet) MustApplyMiddleware

func (nn *NNet) MustApplyMiddleware(mw interface{})

MustApplyMiddleware is the same as ApplyMiddleware, but will panic if an error occurs. This is a convenient shortcut if ApplyMiddleware is not expected to fail.

func (*NNet) NewBroadcastBytesMessage

func (nn *NNet) NewBroadcastBytesMessage(data, srcID []byte, routingType protobuf.RoutingType) (*protobuf.Message, error)

NewBroadcastBytesMessage creates a BYTES message that send arbitrary bytes to EVERY remote node in the network (not just neighbors)

func (*NNet) NewDirectBytesMessage

func (nn *NNet) NewDirectBytesMessage(data []byte) (*protobuf.Message, error)

NewDirectBytesMessage creates a BYTES message that send arbitrary bytes to a given remote node

func (*NNet) NewRelayBytesMessage

func (nn *NNet) NewRelayBytesMessage(data, srcID, key []byte) (*protobuf.Message, error)

NewRelayBytesMessage creates a BYTES message that send arbitrary bytes to the remote node that has the smallest distance to a given key

func (*NNet) SendBytesBroadcastAsync

func (nn *NNet) SendBytesBroadcastAsync(data []byte, routingType protobuf.RoutingType) (bool, error)

SendBytesBroadcastAsync sends bytes data to EVERY remote node in the network (not just neighbors), returns if send success (which is true if successfully send message to at least one next hop), and aggregated error during message sending

func (*NNet) SendBytesBroadcastReply

func (nn *NNet) SendBytesBroadcastReply(replyToID, data []byte, routingType protobuf.RoutingType) (bool, error)

SendBytesBroadcastReply is the same as SendBytesBroadcastAsync but with the replyToId field of the message set. Broadcast msg reply should be handled VERY carefully with some sort of sender identity verification, otherwise it may be used to DDoS attack sender with HUGE amplification factor. This should NOT be used unless msg src id is unknown.

func (*NNet) SendBytesBroadcastSync

func (nn *NNet) SendBytesBroadcastSync(data []byte, routingType protobuf.RoutingType) ([]byte, []byte, error)

SendBytesBroadcastSync is the same as SendBytesBroadcastSyncTimeout but use default reply timeout in config.

func (*NNet) SendBytesBroadcastSyncWithTimeout

func (nn *NNet) SendBytesBroadcastSyncWithTimeout(data []byte, routingType protobuf.RoutingType, replyTimeout time.Duration) ([]byte, []byte, error)

SendBytesBroadcastSyncWithTimeout sends bytes data to EVERY remote node in the network (not just neighbors), returns reply message, node ID who sends the reply, and aggregated error during message sending, will also returns error if doesn't receive any reply before timeout. Broadcast msg reply should be handled VERY carefully with some sort of sender identity verification, otherwise it may be used to DDoS attack sender with HUGE amplification factor.

func (*NNet) SendBytesDirectAsync

func (nn *NNet) SendBytesDirectAsync(data []byte, remoteNode *node.RemoteNode) error

SendBytesDirectAsync sends bytes data to a remote node

func (*NNet) SendBytesDirectReply

func (nn *NNet) SendBytesDirectReply(replyToID, data []byte, remoteNode *node.RemoteNode) error

SendBytesDirectReply is the same as SendBytesDirectAsync but with the replyToId field of the message set

func (*NNet) SendBytesDirectSync

func (nn *NNet) SendBytesDirectSync(data []byte, remoteNode *node.RemoteNode) ([]byte, *node.RemoteNode, error)

SendBytesDirectSync is the same as SendBytesDirectSyncWithTimeout but use default reply timeout in config.

func (*NNet) SendBytesDirectSyncWithTimeout

func (nn *NNet) SendBytesDirectSyncWithTimeout(data []byte, remoteNode *node.RemoteNode, replyTimeout time.Duration) ([]byte, *node.RemoteNode, error)

SendBytesDirectSyncWithTimeout sends bytes data to a remote node, returns reply message, RemoteNode that sends the reply and error. Will also returns an error if doesn't receive a reply before timeout.

func (*NNet) SendBytesRelayAsync

func (nn *NNet) SendBytesRelayAsync(data, key []byte) (bool, error)

SendBytesRelayAsync sends bytes data to the remote node that has smallest distance to the key, returns if send success (which is true if successfully send message to at least one next hop), and aggregated error during message sending

func (*NNet) SendBytesRelayReply

func (nn *NNet) SendBytesRelayReply(replyToID, data, key []byte) (bool, error)

SendBytesRelayReply is the same as SendBytesRelayAsync but with the replyToId field of the message set

func (*NNet) SendBytesRelaySync

func (nn *NNet) SendBytesRelaySync(data, key []byte) ([]byte, []byte, error)

SendBytesRelaySync is the same as SendBytesRelaySync but use default reply timeout in config.

func (*NNet) SendBytesRelaySyncWithTimeout

func (nn *NNet) SendBytesRelaySyncWithTimeout(data, key []byte, replyTimeout time.Duration) ([]byte, []byte, error)

SendBytesRelaySyncWithTimeout sends bytes data to the remote node that has smallest distance to the key, returns reply message, node ID who sends the reply, and aggregated error during message sending and receiving, will also returns error if doesn't receive any reply before timeout

Directories

Path Synopsis
examples
basic command

Jump to

Keyboard shortcuts

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