v0.0.4 Latest Latest

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

Go to latest
Published: Feb 7, 2020 License: MIT Imports: 20 Imported by: 0




This section is empty.


This section is empty.


This section is empty.


type Option

type Option func(*P2p) error

Option type that allows us to have many underlying types of options.

func Logger

func Logger(logger interfaces.Logger) Option

Logger is an interface to a logger for the p2p package

func Receiver

func Receiver(receiver interfaces.Receiver) Option

Receiver receives all data that other peers send on pubsub channels

func Storage

func Storage(storage interfaces.Storage) Option

Storage is an interface to a data store for the p2p package

type Options

type Options struct {
	Logger  interfaces.Logger
	Storage interfaces.Storage

Options for this p2p package, unrelated to libp2pConfig.Option

type P2p

type P2p struct {
	Config interfaces.Config

	Logger interfaces.Logger

	Receiver interfaces.Receiver
	// contains filtered or unexported fields

P2p stores all things required to converse with other peers in the Sprawl network and save data locally

func NewP2p

func NewP2p(config interfaces.Config, privateKey crypto.PrivKey, publicKey crypto.PubKey, opts ...Option) (p2p *P2p)

NewP2p returns a P2p struct with an input channel

func (*P2p) AddReceiver

func (p2p *P2p) AddReceiver(receiver interfaces.Receiver)

AddReceiver registers a data receiver function with p2p

func (*P2p) BlacklistPeer

func (p2p *P2p) BlacklistPeer(pbPeer *pb.Peer)

BlacklistPeer blacklists a peer from connecting to this node

func (*P2p) Close

func (p2p *P2p) Close()

Close closes the underlying libp2p host

func (*P2p) CloseStream

func (p2p *P2p) CloseStream(peerID peer.ID) error

CloseStream removes and closes a stream

func (*P2p) ConstructAddrInfo

func (p2p *P2p) ConstructAddrInfo(id peer.ID, addrs []ma.Multiaddr) peer.AddrInfo

ConstructAddrInfo is used to construct peer.AddrInfo especially in tests

func (*P2p) CreateOptions

func (p2p *P2p) CreateOptions() []libp2pConfig.Option

CreateOptions queries p2p.Config for any user-submitted options and assigns defaults

func (*P2p) GetAddrInfo

func (p2p *P2p) GetAddrInfo() peer.AddrInfo

GetAddrInfo uses p2p.ConstructAddrInfo to get this peer's own AddrInfo

func (*P2p) GetAllPeers

func (p2p *P2p) GetAllPeers() []peer.ID

GetAllPeers returns all peers that we are currently connected to

func (*P2p) GetHostID

func (p2p *P2p) GetHostID() peer.ID

GetHostID returns the underlying libp2p host's peer.ID

func (*P2p) GetHostIDString

func (p2p *P2p) GetHostIDString() string

GetHostIDString returns the underlying libp2p host's peer.ID as a string

func (*P2p) InitHost

func (p2p *P2p) InitHost(options ...libp2pConfig.Option)

InitHost creates a libp2p host with given options

func (*P2p) OpenStream

func (p2p *P2p) OpenStream(peerID peer.ID) (interfaces.Stream, error)

OpenStream opens a stream with another Sprawl peer

func (*P2p) Run

func (p2p *P2p) Run()

Run runs the p2p network

func (*P2p) Send

func (p2p *P2p) Send(message *pb.WireMessage)

Send queues a message for sending to other peers

func (*P2p) Subscribe

func (p2p *P2p) Subscribe(channel *pb.Channel) (context.Context, error)

Subscribe subscribes to a libp2p pubsub channel defined with "channel"

func (*P2p) Unsubscribe

func (p2p *P2p) Unsubscribe(channel *pb.Channel)

Unsubscribe sends a quit signal to a channel goroutine

type Stream

type Stream struct {
	// contains filtered or unexported fields

Stream is a single streaming connection between two peers

func (*Stream) WriteToStream

func (stream *Stream) WriteToStream(data []byte) error

WriteToStream writes data as bytes to specified stream

Jump to

Keyboard shortcuts

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