Documentation ¶
Index ¶
- func DebugOpcodes()
- func DefaultParams() parameters
- type AfterMessageEncodedCallback
- type AfterMessageReceivedCallback
- type AfterMessageSentCallback
- type BeforeMessageReceivedCallback
- type BeforeMessageSentCallback
- type EmptyMessage
- type Message
- type Node
- func (n *Node) Delete(key string)
- func (n *Node) Dial(address string) (*Peer, error)
- func (n *Node) ExternalAddress() string
- func (n *Node) ExternalPort() uint16
- func (n *Node) Fence()
- func (n *Node) Get(key string) interface{}
- func (n *Node) Has(key string) bool
- func (n *Node) InternalPort() uint16
- func (n *Node) Kill()
- func (n *Node) Listen()
- func (n *Node) LoadOrStore(key string, val interface{}) interface{}
- func (n *Node) OnListenerError(c OnErrorCallback)
- func (n *Node) OnPeerConnected(c OnPeerInitCallback)
- func (n *Node) OnPeerDialed(c OnPeerInitCallback)
- func (n *Node) OnPeerDisconnected(srcCallbacks ...OnPeerDisconnectCallback)
- func (n *Node) OnPeerInit(srcCallbacks ...OnPeerInitCallback)
- func (n *Node) Set(key string, val interface{})
- type OnErrorCallback
- type OnMessageReceivedCallback
- type OnPeerDecodeFooterCallback
- type OnPeerDecodeHeaderCallback
- type OnPeerDisconnectCallback
- type OnPeerErrorCallback
- type OnPeerInitCallback
- type Opcode
- type Peer
- func (p *Peer) AfterMessageReceived(c AfterMessageReceivedCallback)
- func (p *Peer) AfterMessageSent(c AfterMessageSentCallback)
- func (p *Peer) BeforeMessageReceived(c BeforeMessageReceivedCallback)
- func (p *Peer) BeforeMessageSent(c BeforeMessageSentCallback)
- func (p *Peer) DecodeMessage(buf []byte) (Opcode, Message, error)
- func (p *Peer) Delete(key string)
- func (p *Peer) Disconnect()
- func (p *Peer) DisconnectAsync() <-chan struct{}
- func (p *Peer) EncodeMessage(message Message) ([]byte, error)
- func (p *Peer) Get(key string) interface{}
- func (p *Peer) Has(key string) bool
- func (p *Peer) LoadOrStore(key string, val interface{}) interface{}
- func (p *Peer) LocalIP() net.IP
- func (p *Peer) LocalPort() uint16
- func (p *Peer) LockOnReceive(opcode Opcode) receiveHandle
- func (p *Peer) Node() *Node
- func (p *Peer) OnConnError(c OnPeerErrorCallback)
- func (p *Peer) OnDecodeFooter(c OnPeerDecodeFooterCallback)
- func (p *Peer) OnDecodeHeader(c OnPeerDecodeHeaderCallback)
- func (p *Peer) OnDisconnect(srcCallbacks ...OnPeerDisconnectCallback)
- func (p *Peer) OnEncodeFooter(c AfterMessageEncodedCallback)
- func (p *Peer) OnEncodeHeader(c AfterMessageEncodedCallback)
- func (p *Peer) Receive(o Opcode) <-chan Message
- func (p *Peer) RemoteIP() net.IP
- func (p *Peer) RemotePort() uint16
- func (p *Peer) SendMessage(message Message) error
- func (p *Peer) SendMessageAsync(message Message) <-chan error
- func (p *Peer) Set(key string, val interface{})
- func (p *Peer) SetNode(node *Node)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DebugOpcodes ¶
func DebugOpcodes()
DebugOpcodes prints out all opcodes registered to Noise thus far.
func DefaultParams ¶
func DefaultParams() parameters
Types ¶
type EmptyMessage ¶
type EmptyMessage struct{}
func (EmptyMessage) Write ¶
func (EmptyMessage) Write() []byte
type Message ¶
To have Noise send/receive messages of a given type, said type must implement the following Message interface.
Noise by default encodes messages as bytes in little-endian order, and provides utility classes to assist with serializing/deserializing arbitrary Go types into bytes efficiently.
By exposing raw network packets as bytes to users, any additional form of serialization or message packing or compression scheme or cipher scheme may be bootstrapped on top of any particular message type registered to Noise.
func MessageFromOpcode ¶
MessageFromOpcode returns an empty message representation associated to a registered message opcode.
It errors if the specified message opcode is not registered to Noise.
type Node ¶
func (*Node) Dial ¶
Dial has our node attempt to dial and establish a connection with a remote peer.
func (*Node) ExternalAddress ¶
func (*Node) ExternalPort ¶
func (*Node) Fence ¶
func (n *Node) Fence()
Fence blocks the current goroutine until the node stops listening for peers.
func (*Node) Get ¶
Get returns the value to a metadata key from our node, or otherwise returns nil should there be no corresponding value to a provided key.
func (*Node) InternalPort ¶
func (*Node) LoadOrStore ¶
func (*Node) OnListenerError ¶
func (n *Node) OnListenerError(c OnErrorCallback)
OnListenerError registers a callback for whenever our nodes listener fails to accept an incoming peer.
func (*Node) OnPeerConnected ¶
func (n *Node) OnPeerConnected(c OnPeerInitCallback)
OnPeerConnected registers a callback for whenever a peer has successfully been accepted by our node.
func (*Node) OnPeerDialed ¶
func (n *Node) OnPeerDialed(c OnPeerInitCallback)
OnPeerDialed registers a callback for whenever a peer has been successfully dialed.
func (*Node) OnPeerDisconnected ¶
func (n *Node) OnPeerDisconnected(srcCallbacks ...OnPeerDisconnectCallback)
OnPeerDisconnected registers a callback whenever a peer has been disconnected.
func (*Node) OnPeerInit ¶
func (n *Node) OnPeerInit(srcCallbacks ...OnPeerInitCallback)
OnPeerInit registers a callback for whenever a peer has either been successfully dialed, or otherwise accepted by our node.
In essence a helper function that registers callbacks for both `OnPeerConnected` and `OnPeerDialed` at once.
type OnErrorCallback ¶
type OnPeerInitCallback ¶
type Opcode ¶
type Opcode byte
const (
OpcodeNil Opcode = 0
)
func NextAvailableOpcode ¶
func NextAvailableOpcode() Opcode
NextAvailableOpcode returns the next available unregistered message opcode registered to Noise.
func OpcodeFromMessage ¶
OpcodeFromMessage uses reflection to extract and return the opcode associated to a message value type.
It errors if the specified message value type is not registered to Noise.
func RegisterMessage ¶
type Peer ¶
type Peer struct {
// contains filtered or unexported fields
}
func (*Peer) AfterMessageReceived ¶
func (p *Peer) AfterMessageReceived(c AfterMessageReceivedCallback)
AfterMessageReceived registers a callback to be called after a message is to be received from a specified peer.
func (*Peer) AfterMessageSent ¶
func (p *Peer) AfterMessageSent(c AfterMessageSentCallback)
AfterMessageSent registers a callback to be called after a message is sent to a specified peer.
func (*Peer) BeforeMessageReceived ¶
func (p *Peer) BeforeMessageReceived(c BeforeMessageReceivedCallback)
BeforeMessageReceived registers a callback to be called before a message is to be received from a specified peer.
func (*Peer) BeforeMessageSent ¶
func (p *Peer) BeforeMessageSent(c BeforeMessageSentCallback)
BeforeMessageSent registers a callback to be called before a message is sent to a specified peer.
func (*Peer) Disconnect ¶
func (p *Peer) Disconnect()
func (*Peer) DisconnectAsync ¶
func (p *Peer) DisconnectAsync() <-chan struct{}
func (*Peer) EncodeMessage ¶
EncodeMessage serializes a message body into its byte representation, and prefixes said byte representation with the messages opcode for the purpose of sending said bytes over the wire.
Additional header/footer bytes is prepended/appended accordingly.
Refer to the functions `OnEncodeHeader` and `OnEncodeFooter` available in `noise.Peer` to prepend/append additional information on every single message sent over the wire.
func (*Peer) Get ¶
Get returns the value to a metadata key from our node, or otherwise returns nil should there be no corresponding value to a provided key.
func (*Peer) LoadOrStore ¶
func (*Peer) LockOnReceive ¶
func (*Peer) OnConnError ¶
func (p *Peer) OnConnError(c OnPeerErrorCallback)
OnConnError registers a callback for whenever something goes wrong with the connection to our peer.
func (*Peer) OnDecodeFooter ¶
func (p *Peer) OnDecodeFooter(c OnPeerDecodeFooterCallback)
OnDecodeFooter registers a callback that is fed in the contents of the footer portion of an incoming message from a specified peer.
func (*Peer) OnDecodeHeader ¶
func (p *Peer) OnDecodeHeader(c OnPeerDecodeHeaderCallback)
OnDecodeHeader registers a callback that is fed in the contents of the header portion of an incoming message from a specified peer.
func (*Peer) OnDisconnect ¶
func (p *Peer) OnDisconnect(srcCallbacks ...OnPeerDisconnectCallback)
OnDisconnect registers a callback for whenever the peer disconnects.
func (*Peer) OnEncodeFooter ¶
func (p *Peer) OnEncodeFooter(c AfterMessageEncodedCallback)
OnEncodeFooter registers a callback that is fed in the raw contents of a message to be sent, which then outputs bytes that are to be appended to the footer of an outgoing message.
func (*Peer) OnEncodeHeader ¶
func (p *Peer) OnEncodeHeader(c AfterMessageEncodedCallback)
OnEncodeHeader registers a callback that is fed in the raw contents of a message to be sent, which then outputs bytes that are to be appended to the header of an outgoing message.
func (*Peer) RemotePort ¶
func (*Peer) SendMessage ¶
SendMessage sends a message whose type is registered with Noise to a specified peer. Calling this function will block the current goroutine until the message is successfully sent. In order to not block, refer to `SendMessageAsync(message Message) <-chan error`.
It is guaranteed that all messages are sent in a linearized order.
It returns an error should it take too long to send a message, the message is not registered with Noise, or there are message that are blocking the peers send worker.
func (*Peer) SendMessageAsync ¶
SendMessageAsync sends a message whose type is registered with Noise to a specified peer. Calling this function will not block the current goroutine until the message is successfully sent. In order to block, refer to `SendMessage(message Message) error`.
It is guaranteed that all messages are sent in a linearized order.
It returns an error should the message not be registered with Noise, or there are message that are blocking the peers send worker.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
cipher
|
|
examples
|
|
handshake
|
|
internal
|
|
bufconn
Package bufconn provides a net.Conn implemented by a buffer and related dialing and listening functionality.
|
Package bufconn provides a net.Conn implemented by a buffer and related dialing and listening functionality. |
edwards25519
Package ed25519 implements the Ed25519 signature algorithm.
|
Package ed25519 implements the Ed25519 signature algorithm. |