p2p

package
v0.0.0-...-fe73bcc Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2018 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package p2p implements a TCP based perfect peer-to-peer link.

Index

Constants

This section is empty.

Variables

View Source
var WithDefault = func(n *Node) {
	n.Node = node.New(node.WithDefault)
}

WithDefault can be used to instantiate a new node with default options.

Functions

func WithChannel

func WithChannel(channel string) func(*Node)

WithChannel sets the RPC channel name when instantiating a new p2p node.

func WithKeepAlive

func WithKeepAlive(keepAlive time.Duration) func(*Node)

WithKeepAlive sets the TCP keepalive when instantiating a new p2p node (e.g. New(WithKeepAlive(1 * time.Seconds), ...)).

func WithNode

func WithNode(node link.Node) func(*Node)

WithNode sets the node when instantiating a new p2p node (e.g. New(WithNode(n), ...)).

Types

type Node

type Node struct {
	link.Node
	// contains filtered or unexported fields
}

Node implements perfect peer-to-peer link.

func New

func New(configs ...func(*Node)) *Node

New instantiates a new TCP based perfect peer-to-peer link.

func (*Node) Deliver

func (n *Node) Deliver(f func(p link.Peer, m link.Message))

Deliver registers the deliver handler.

func (*Node) Send

func (n *Node) Send(q link.Peer, m link.Message) error

Send requests to send message m to process q.

type Payload

type Payload struct {
	ID      string
	Addr    net.Addr
	Message link.Message
}

Payload wraps the message and the ID of the sender.

Jump to

Keyboard shortcuts

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