sprawl: github.com/sprawl/sprawl/p2p Index | Files

package p2p

import "github.com/sprawl/sprawl/p2p"


Package Files

data.go options.go p2p.go stream.go sync.go

type Option Uses

type Option func(*P2p) error

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

func Logger Uses

func Logger(logger interfaces.Logger) Option

Logger is an interface to a logger for the p2p package

func Receiver Uses

func Receiver(receiver interfaces.Receiver) Option

Receiver receives all data that other peers send on pubsub channels

func Storage Uses

func Storage(storage interfaces.Storage) Option

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

type Options Uses

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

Options for this p2p package, unrelated to libp2pConfig.Option

type P2p Uses

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 Uses

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 Uses

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

AddReceiver registers a data receiver function with p2p

func (*P2p) BlacklistPeer Uses

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

BlacklistPeer blacklists a peer from connecting to this node

func (*P2p) Close Uses

func (p2p *P2p) Close()

Close closes the underlying libp2p host

func (*P2p) CloseStream Uses

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

CloseStream removes and closes a stream

func (*P2p) ConstructAddrInfo Uses

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 Uses

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

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

func (*P2p) GetAddrInfo Uses

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

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

func (*P2p) GetAllPeers Uses

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

GetAllPeers returns all peers that we are currently connected to

func (*P2p) GetHostID Uses

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

GetHostID returns the underlying libp2p host's peer.ID

func (*P2p) GetHostIDString Uses

func (p2p *P2p) GetHostIDString() string

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

func (*P2p) InitHost Uses

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

InitHost creates a libp2p host with given options

func (*P2p) OpenStream Uses

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

OpenStream opens a stream with another Sprawl peer

func (*P2p) Run Uses

func (p2p *P2p) Run()

Run runs the p2p network

func (*P2p) Send Uses

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

Send queues a message for sending to other peers

func (*P2p) Subscribe Uses

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

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

func (*P2p) Unsubscribe Uses

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

Unsubscribe sends a quit signal to a channel goroutine

type Stream Uses

type Stream struct {
    // contains filtered or unexported fields

Stream is a single streaming connection between two peers

func (*Stream) WriteToStream Uses

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

WriteToStream writes data as bytes to specified stream

Package p2p imports 21 packages (graph) and is imported by 2 packages. Updated 2020-07-10. Refresh now. Tools for package owners.