p2p

package
v0.0.0-...-967d326 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2019 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Identity

func Identity(sk crypto.PrivKey) (libp2p.Option, error)

Identity ...

func ListenAddress

func ListenAddress(addr string) (libp2p.Option, error)

ListenAddress ...

func RandomIdentity

func RandomIdentity() libp2p.Option

RandomIdentity ...

func XORDistance

func XORDistance(a, b peer.ID) big.Int

XORDistance returns the XOR distance between two peers

Types

type BoostrappingRoutine

type BoostrappingRoutine struct {
	Host host.Host

	Wlp bnetwork.WhiteListProvider
	// contains filtered or unexported fields
}

BoostrappingRoutine embedded all the bootstrapping logic

func NewBoostrappingRoutine

func NewBoostrappingRoutine(
	ctx context.Context,
	host host.Host,

	Wlp bnetwork.WhiteListProvider,

	minConns int,
	maxConns int,

	bootstrappingPeriod time.Duration,

) *BoostrappingRoutine

NewBoostrappingRoutine construct a new BootstrappingRoutine object

func (*BoostrappingRoutine) AddConnections

func (br *BoostrappingRoutine) AddConnections() error

AddConnections add peers until the target is reached

func (*BoostrappingRoutine) Permissionize

func (br *BoostrappingRoutine) Permissionize()

Permissionize blocks remote connexions from unauthorized peers

func (*BoostrappingRoutine) PruneConnections

func (br *BoostrappingRoutine) PruneConnections() error

PruneConnections remove peers until the target is reached

func (*BoostrappingRoutine) RunBootstrap

func (br *BoostrappingRoutine) RunBootstrap() (err error)

RunBootstrap will adjust the number of connected peers

func (*BoostrappingRoutine) SetNewWhiteList

func (br *BoostrappingRoutine) SetNewWhiteList(newPeers [][]byte) error

SetNewWhiteList replace the old whitelist with the new one

func (*BoostrappingRoutine) Start

func (br *BoostrappingRoutine) Start() error

Start the bootsrapping routine

func (*BoostrappingRoutine) TrimUnlistedPeers

func (br *BoostrappingRoutine) TrimUnlistedPeers()

TrimUnlistedPeers remove peers that are not listed anymore

type Server

type Server struct {
	Host      host.Host
	PubSub    *pubsub.PubSub
	Bootstrap *BoostrappingRoutine
}

Server ...

func DefaultServer

func DefaultServer(addr string, wlp network.WhiteListProvider) (*Server, error)

DefaultServer ...

func MakeServers

func MakeServers(n int) []*Server

MakeServers returns a list of started servers

func NewServerWithID

func NewServerWithID(wlp network.WhiteListProvider, priv *identity.PrivKey, addr string) (*Server, error)

NewServerWithID returns a server object with

func (*Server) GetPeerInfo

func (s *Server) GetPeerInfo() peer.AddrInfo

GetPeerInfo returns the marshalled peer info of the server

func (*Server) GetTopic

func (s *Server) GetTopic(ctx context.Context, topic string) network.Topic

GetTopic returns a topic

func (*Server) Publish

func (s *Server) Publish(topic string, msg []byte) error

Publish sends a message in a topic

func (*Server) Start

func (s *Server) Start()

Start the server

type Topic

type Topic struct {
	Subs *pubsub.Subscription
	Name string
	// contains filtered or unexported fields
}

A Topic is a pubsub abstraction that can be subscribed and published

func (*Topic) Chan

func (t *Topic) Chan() (<-chan []byte, error)

Chan get a chan for the message Should be called only once

func (*Topic) Close

func (t *Topic) Close()

Close the subscription

func (*Topic) Publish

func (t *Topic) Publish(msg []byte) error

Publish a message in the topic

Jump to

Keyboard shortcuts

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