Documentation
¶
Index ¶
- func SetLogger(logger log.Logger) error
- type Config
- type NNet
- func (nn *NNet) ApplyMiddleware(mw interface{}) error
- func (nn *NNet) GetConfig() *Config
- func (nn *NNet) MustApplyMiddleware(mw interface{})
- func (nn *NNet) NewBroadcastBytesMessage(data, srcID []byte, routingType protobuf.RoutingType) (*protobuf.Message, error)
- func (nn *NNet) NewDirectBytesMessage(data []byte) (*protobuf.Message, error)
- func (nn *NNet) NewRelayBytesMessage(data, srcID, key []byte) (*protobuf.Message, error)
- func (nn *NNet) SendBytesBroadcastAsync(data []byte, routingType protobuf.RoutingType) (bool, error)
- func (nn *NNet) SendBytesBroadcastReply(replyToID, data []byte, routingType protobuf.RoutingType) (bool, error)
- func (nn *NNet) SendBytesBroadcastSync(data []byte, routingType protobuf.RoutingType) ([]byte, []byte, error)
- func (nn *NNet) SendBytesBroadcastSyncWithTimeout(data []byte, routingType protobuf.RoutingType, replyTimeout time.Duration) ([]byte, []byte, error)
- func (nn *NNet) SendBytesDirectAsync(data []byte, remoteNode *node.RemoteNode) error
- func (nn *NNet) SendBytesDirectReply(replyToID, data []byte, remoteNode *node.RemoteNode) error
- func (nn *NNet) SendBytesDirectSync(data []byte, remoteNode *node.RemoteNode) ([]byte, *node.RemoteNode, error)
- func (nn *NNet) SendBytesDirectSyncWithTimeout(data []byte, remoteNode *node.RemoteNode, replyTimeout time.Duration) ([]byte, *node.RemoteNode, error)
- func (nn *NNet) SendBytesRelayAsync(data, key []byte) (bool, error)
- func (nn *NNet) SendBytesRelayReply(replyToID, data, key []byte) (bool, error)
- func (nn *NNet) SendBytesRelaySync(data, key []byte) ([]byte, []byte, error)
- func (nn *NNet) SendBytesRelaySyncWithTimeout(data, key []byte, replyTimeout time.Duration) ([]byte, []byte, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type NNet ¶
NNet is is a peer to peer network
func NewNNet ¶
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 ¶
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) 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 ¶
NewDirectBytesMessage creates a BYTES message that send arbitrary bytes to a given remote node
func (*NNet) NewRelayBytesMessage ¶
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 ¶
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 ¶
SendBytesRelayReply is the same as SendBytesRelayAsync but with the replyToId field of the message set
func (*NNet) SendBytesRelaySync ¶
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