noise: github.com/perlin-network/noise Index | Files | Directories

package noise

import "github.com/perlin-network/noise"

Index

Package Files

callbacks.go empty.go init.go msg.go node.go opcode.go params.go peer.go

func DebugOpcodes Uses

func DebugOpcodes()

DebugOpcodes prints out all opcodes registered to Noise thus far.

func DefaultParams Uses

func DefaultParams() parameters

type AfterMessageEncodedCallback Uses

type AfterMessageEncodedCallback func(node *Node, peer *Peer, header, msg []byte) ([]byte, error)

type AfterMessageReceivedCallback Uses

type AfterMessageReceivedCallback func(node *Node, peer *Peer) error

type AfterMessageSentCallback Uses

type AfterMessageSentCallback func(node *Node, peer *Peer) error

type BeforeMessageReceivedCallback Uses

type BeforeMessageReceivedCallback func(node *Node, peer *Peer, msg []byte) ([]byte, error)

type BeforeMessageSentCallback Uses

type BeforeMessageSentCallback func(node *Node, peer *Peer, msg []byte) ([]byte, error)

type EmptyMessage Uses

type EmptyMessage struct{}

func (EmptyMessage) Read Uses

func (EmptyMessage) Read(reader payload.Reader) (Message, error)

func (EmptyMessage) Write Uses

func (EmptyMessage) Write() []byte

type Message Uses

type Message interface {
    Read(reader payload.Reader) (Message, error)
    Write() []byte
}

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 Uses

func MessageFromOpcode(opcode Opcode) (Message, error)

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 Uses

type Node struct {
    Keys identity.Keypair
    // contains filtered or unexported fields
}

func NewNode Uses

func NewNode(params parameters) (*Node, error)

func (*Node) Delete Uses

func (n *Node) Delete(key string)

func (*Node) Dial Uses

func (n *Node) Dial(address string) (*Peer, error)

Dial has our node attempt to dial and establish a connection with a remote peer.

func (*Node) ExternalAddress Uses

func (n *Node) ExternalAddress() string

func (*Node) ExternalPort Uses

func (n *Node) ExternalPort() uint16

func (*Node) Fence Uses

func (n *Node) Fence()

Fence blocks the current goroutine until the node stops listening for peers.

func (*Node) Get Uses

func (n *Node) Get(key string) interface{}

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) Has Uses

func (n *Node) Has(key string) bool

func (*Node) InternalPort Uses

func (n *Node) InternalPort() uint16

func (*Node) Kill Uses

func (n *Node) Kill()

func (*Node) Listen Uses

func (n *Node) Listen()

Listen makes our node start listening for peers.

func (*Node) LoadOrStore Uses

func (n *Node) LoadOrStore(key string, val interface{}) interface{}

func (*Node) OnListenerError Uses

func (n *Node) OnListenerError(c OnErrorCallback)

OnListenerError registers a callback for whenever our nodes listener fails to accept an incoming peer.

func (*Node) OnPeerConnected Uses

func (n *Node) OnPeerConnected(c OnPeerInitCallback)

OnPeerConnected registers a callback for whenever a peer has successfully been accepted by our node.

func (*Node) OnPeerDialed Uses

func (n *Node) OnPeerDialed(c OnPeerInitCallback)

OnPeerDialed registers a callback for whenever a peer has been successfully dialed.

func (*Node) OnPeerDisconnected Uses

func (n *Node) OnPeerDisconnected(srcCallbacks ...OnPeerDisconnectCallback)

OnPeerDisconnected registers a callback whenever a peer has been disconnected.

func (*Node) OnPeerInit Uses

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.

func (*Node) Set Uses

func (n *Node) Set(key string, val interface{})

Set sets a metadata entry given a key-value pair on our node.

type OnErrorCallback Uses

type OnErrorCallback func(node *Node, err error) error

type OnMessageReceivedCallback Uses

type OnMessageReceivedCallback func(node *Node, opcode Opcode, peer *Peer, message Message) error

type OnPeerDecodeFooterCallback Uses

type OnPeerDecodeFooterCallback func(node *Node, peer *Peer, msg []byte, reader payload.Reader) error

type OnPeerDecodeHeaderCallback Uses

type OnPeerDecodeHeaderCallback func(node *Node, peer *Peer, reader payload.Reader) error

type OnPeerDisconnectCallback Uses

type OnPeerDisconnectCallback func(node *Node, peer *Peer) error

type OnPeerErrorCallback Uses

type OnPeerErrorCallback func(node *Node, peer *Peer, err error) error

type OnPeerInitCallback Uses

type OnPeerInitCallback func(node *Node, peer *Peer) error

type Opcode Uses

type Opcode byte
const (
    OpcodeNil Opcode = 0
)

func NextAvailableOpcode Uses

func NextAvailableOpcode() Opcode

NextAvailableOpcode returns the next available unregistered message opcode registered to Noise.

func OpcodeFromMessage Uses

func OpcodeFromMessage(msg Message) (Opcode, error)

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 Uses

func RegisterMessage(o Opcode, m interface{}) Opcode

func (Opcode) Bytes Uses

func (o Opcode) Bytes() (buf [1]byte)

Bytes returns this opcodes' byte representation.

type Peer Uses

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

func (*Peer) AfterMessageReceived Uses

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 Uses

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 Uses

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 Uses

func (p *Peer) BeforeMessageSent(c BeforeMessageSentCallback)

BeforeMessageSent registers a callback to be called before a message is sent to a specified peer.

func (*Peer) DecodeMessage Uses

func (p *Peer) DecodeMessage(buf []byte) (Opcode, Message, error)

func (*Peer) Delete Uses

func (p *Peer) Delete(key string)

func (*Peer) Disconnect Uses

func (p *Peer) Disconnect()

func (*Peer) DisconnectAsync Uses

func (p *Peer) DisconnectAsync() <-chan struct{}

func (*Peer) EncodeMessage Uses

func (p *Peer) EncodeMessage(message Message) ([]byte, error)

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 Uses

func (p *Peer) Get(key string) interface{}

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) Has Uses

func (p *Peer) Has(key string) bool

func (*Peer) LoadOrStore Uses

func (p *Peer) LoadOrStore(key string, val interface{}) interface{}

func (*Peer) LocalIP Uses

func (p *Peer) LocalIP() net.IP

func (*Peer) LocalPort Uses

func (p *Peer) LocalPort() uint16

func (*Peer) LockOnReceive Uses

func (p *Peer) LockOnReceive(opcode Opcode) receiveHandle

func (*Peer) Node Uses

func (p *Peer) Node() *Node

func (*Peer) OnConnError Uses

func (p *Peer) OnConnError(c OnPeerErrorCallback)

OnConnError registers a callback for whenever something goes wrong with the connection to our peer.

func (*Peer) OnDecodeFooter Uses

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 Uses

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 Uses

func (p *Peer) OnDisconnect(srcCallbacks ...OnPeerDisconnectCallback)

OnDisconnect registers a callback for whenever the peer disconnects.

func (*Peer) OnEncodeFooter Uses

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 Uses

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) Receive Uses

func (p *Peer) Receive(o Opcode) <-chan Message

func (*Peer) RemoteIP Uses

func (p *Peer) RemoteIP() net.IP

func (*Peer) RemotePort Uses

func (p *Peer) RemotePort() uint16

func (*Peer) SendMessage Uses

func (p *Peer) SendMessage(message Message) error

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 Uses

func (p *Peer) SendMessageAsync(message Message) <-chan error

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.

func (*Peer) Set Uses

func (p *Peer) Set(key string, val interface{})

Set sets a metadata entry given a key-value pair on our node.

func (*Peer) SetNode Uses

func (p *Peer) SetNode(node *Node)

Directories

PathSynopsis
callbacks
cipher/aead
examples/benchmark
examples/chat
examples/e2e
handshake/ecdh
identity
identity/ed25519
internal/bufconnPackage bufconn provides a net.Conn implemented by a buffer and related dialing and listening functionality.
internal/edwards25519Package ed25519 implements the Ed25519 signature algorithm.
log
nat
payload
protocol
signature
signature/eddsa
skademlia
transport

Package noise imports 18 packages (graph) and is imported by 8 packages. Updated 2019-03-05. Refresh now. Tools for package owners.