p2pnet

package module
v0.0.0-...-93674d3 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2019 License: MIT Imports: 21 Imported by: 0

README

p2pnet

Codacy Badge Go Report Card GoDoc

A simple Wrapper for go-libp2p. This can be used as network layer for p2p apps.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	//RendezvousString is a unique string to identify group of nodes
	RendezvousString string

	//ListenHost is the host IP address network listens on.
	//Use 0.0.0.0 for listening on all interfaces
	ListenHost string

	//ListenPort is the host port to listens on.
	ListenPort int

	//BootstrapPeer is the multiaddress of bootstrap peer if there is any
	BootstrapPeers []multiaddr.Multiaddr

	//File to save and read key file
	KeyFile string

	//Enable/Disable circuit relay, enable if you are willing to volunteer as a relay point
	EnableRelay bool
}

Config for the network

type Network

type Network struct {

	//ID of this Host
	UUID string

	//Stream manager
	StreamMgr *StreamMgr

	//RPC object of network
	RPC *RPC

	//Router object of network
	Router *Router

	//libp2p host handle. We dont need this mostly
	Host host.Host
	// contains filtered or unexported fields
}

Network represents libp2p network layer.

func NewNetwork

func NewNetwork(cfg *Config) (*Network, error)

NewNetwork creates a network handle

func (*Network) Addrs

func (net *Network) Addrs() []multiaddr.Multiaddr

Addrs returns list of multi addresses we listen on

func (*Network) Close

func (net *Network) Close() error

Close shut down the network and services

func (*Network) Connect

func (net *Network) Connect(ctx context.Context, peer pstore.PeerInfo) error

Connect ensures a connection to remote peer

func (*Network) Context

func (net *Network) Context() context.Context

Context returns parent context of Network

func (*Network) HandlePeerFound

func (net *Network) HandlePeerFound(peer pstore.PeerInfo)

HandlePeerFound is the Notifee interface for mdns discovery. It can be also called to update the peer info found via other ways

func (*Network) InitMDNS

func (net *Network) InitMDNS() error

InitMDNS initializes the MDNS discovery in the network

func (*Network) WaitForBootstrap

func (net *Network) WaitForBootstrap()

WaitForBootstrap blocks untill local peer is bootstrapped

type RPC

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

RPC represents a RPC object of a host. It represents both server and client

func (*RPC) Call

func (rpc *RPC) Call(ctx context.Context, dest peer.ID,
	service, method string,
	args, reply interface{}) error

Call performs an RPC call to a registered Server service and blocks until completed.

func (*RPC) Register

func (rpc *RPC) Register(service interface{}) error

Register publishes in the server the set of methods of the service interface that satisfy the following conditions:

- exported method of exported type - two arguments, both of exported type - the second argument is a pointer - one return value, of type error

type Router

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

Router handles service advertising and discovery.

func (*Router) Advertise

func (r *Router) Advertise(ctx context.Context, service string)

Advertise a service to DHT

func (*Router) FindPeers

func (r *Router) FindPeers(ctx context.Context, service string) (<-chan pstore.PeerInfo, error)

FindPeers using DHT. Note that channel is not long standing. It will get closed after each peer search

type Stream

type Stream interface {
	io.ReadWriter

	// Close closes the stream for writing. Reading will still work (that
	// is, the remote side can still write).
	io.Closer

	// Reset closes both ends of the stream. Use this to tell the remote
	// side to hang up and go away.
	Reset() error
}

Stream represents a bidirectional channel between two agents

type StreamHandler

type StreamHandler func(Stream)

StreamHandler is the type of function used to listen for streams opened by the remote side.

type StreamMgr

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

StreamMgr handles connections of network

func (*StreamMgr) NewStream

func (mgr *StreamMgr) NewStream(ctx context.Context, peer peer.ID, pid protocol.ID) (Stream, error)

NewStream opens a new stream to given peer

func (*StreamMgr) RemoveHandler

func (mgr *StreamMgr) RemoveHandler(pid protocol.ID)

RemoveHandler removes the protocol handler

func (*StreamMgr) SetHandler

func (mgr *StreamMgr) SetHandler(pid protocol.ID, handler StreamHandler)

SetHandler sets the protocol handler on host.

Jump to

Keyboard shortcuts

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