net

package
v0.0.0-...-e4becd7 Latest Latest
Warning

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

Go to latest
Published: Jun 18, 2020 License: MPL-2.0 Imports: 27 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// LogName identifies the log of this module
	LogName = "nahs/net"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Contacts

type Contacts map[peer.ID]Services

Contacts of peer: the nodes that have announced services

type ErrHandleEvent

type ErrHandleEvent struct {
	ID     string
	Reason string
}

ErrHandleEvent is returned when handling events and sent as a response

func (ErrHandleEvent) Error

func (e ErrHandleEvent) Error() string

type Node

type Node struct {

	// Contacts of the Node
	Contacts Contacts

	// OpenInstances maps instance keys to peer.IDs to
	// verify that the node sending the event is the one
	// who created it
	OpenInstances map[string]peer.ID
	// contains filtered or unexported fields
}

Node represents a single NaHS peer.

func LocalNode

func LocalNode(reasoner bspl.Reasoner, options ...libp2p.Option) *Node

LocalNode returns a new node without settings up the discovery protocols. This is useful for testing without connection or wasting time.

func NewNode

func NewNode(reasoner bspl.Reasoner, options ...libp2p.Option) *Node

NewNode is the default constructor for Node.

func NodeFromPrivKey

func NodeFromPrivKey(reasoner bspl.Reasoner, sk crypto.PrivKey, options ...libp2p.Option) *Node

NodeFromPrivKey is a newNode wrapper to create a new Node with the specified private key. Additional options may be provided.

func (*Node) AddContact

func (n *Node) AddContact(id peer.ID, services ...Service)

AddContact adds a new contact to the Node

func (*Node) AddProtocol

func (n *Node) AddProtocol(p bspl.Protocol, roles ...bspl.Role)

AddProtocol adds a protocol to the node and establishes what roles the node plays in that protocol. If the protocol was already added, the roles that weren't already established are added.

func (*Node) AddServices

func (n *Node) AddServices(id peer.ID, services ...Service)

AddServices is functionally the same as AddContact for now.

func (Node) Addrs

func (n Node) Addrs() []multiaddr.Multiaddr

Addrs returns the multiaddr of the libp2p host of the Node

func (*Node) Announce

func (n *Node) Announce()

Announce self in network

func (*Node) ExportKey

func (n *Node) ExportKey() []byte

ExportKey returns the marshaled private key of the Node

func (*Node) FindContact

func (n *Node) FindContact(protocolKey string, role bspl.Role) []peer.ID

FindContact finds a contact that offers a service and plays a role in that service. A slice of the peer.ID of those contacts is returned.

func (*Node) FindNodes

func (n *Node) FindNodes()

FindNodes searches for other NaHS nodes in the network

func (Node) ID

func (n Node) ID() peer.ID

ID of the libp2p host of the Node

func (*Node) Peerstore

func (n *Node) Peerstore() peerstore.Peerstore

Peerstore returns the Peerstore of the Host of the Node

func (*Node) Reasoner

func (n *Node) Reasoner() bspl.Reasoner

Reasoner returns the reasoner of the Node

func (*Node) SendEvent

func (n *Node) SendEvent(target peer.ID, event events.Event) (bool, error)

SendEvent sends an events.Event to the target node. If the node is unreachable, the address is not known or some error occurs the error is returned. If the event was invalid, false is returned. If it was registered correctly, true is returned.

type Service

type Service struct {
	Roles    []bspl.Role
	Protocol bspl.Protocol
}

Service contains a protocol describing the service and the roles the announcing node plays

type Services

type Services map[string]Service

Services maps protocol keys to a Service with the protocol the key belongs to

Jump to

Keyboard shortcuts

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