p2p

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2020 License: MIT Imports: 27 Imported by: 2

Documentation

Index

Constants

View Source
const ConnectingTimeout = 20 * time.Second //todo: add to the config

ConnectingTimeout is the timeout we wait when trying to connect a neighborhood

View Source
const NoResultsInterval = 1 * time.Second

NoResultsInterval is the timeout we wait between requesting more peers repeatedly

Variables

View Source
var (
	// ErrBadFormat1 could'nt deserialize the payload
	ErrBadFormat1 = errors.New("bad msg format, could'nt deserialize 1")
	// ErrBadFormat2 could'nt deserialize the protocol message payload
	ErrBadFormat2 = errors.New("bad msg format, could'nt deserialize 2")
	// ErrOutOfSync is returned when messsage timestamp was out of sync
	ErrOutOfSync = errors.New("received out of sync msg")
	// ErrFailDecrypt session cant decrypt
	ErrFailDecrypt = errors.New("can't decrypt message payload with session key")
	// ErrNoProtocol we don't have the protocol message
	ErrNoProtocol = errors.New("received msg to an unsupported protocol")
	// ErrNoSession we don't have this session
	ErrNoSession = errors.New("connection is missing a session")
)

Functions

func Errors

func Errors(arr []error) []int

func ExtractData

func ExtractData(pm *Payload) (service.Data, error)

func New

func New(ctx context.Context, config config.Config, logger log.Log, path string) (*swarm, error)

New creates a new P2P service a.k.a `swarm` it tries to load node information from the disk.

func StringIdentifiers

func StringIdentifiers(boot ...*swarm) []string

Types

type IntegrationTestSuite

type IntegrationTestSuite struct {
	suite.Suite

	BootstrapNodesCount   int
	BootstrappedNodeCount int
	NeighborsCount        int

	BeforeHook func(idx int, s NodeTestInstance)
	AfterHook  func(idx int, s NodeTestInstance)

	Instances []*swarm
	// contains filtered or unexported fields
}

IntegrationTestSuite is a suite which bootstraps a network according to the given params and lets you run actions on this network. you must set the params before running the suite.

func (*IntegrationTestSuite) ForAll

func (its *IntegrationTestSuite) ForAll(f func(idx int, s NodeTestInstance) error, filter []int) []error

func (*IntegrationTestSuite) ForAllAsync

func (its *IntegrationTestSuite) ForAllAsync(ctx context.Context, f func(idx int, s NodeTestInstance) error) (error, []error)

func (*IntegrationTestSuite) SetupSuite

func (its *IntegrationTestSuite) SetupSuite()

func (*IntegrationTestSuite) TearDownSuite

func (its *IntegrationTestSuite) TearDownSuite()

func (*IntegrationTestSuite) WaitForGossip

func (its *IntegrationTestSuite) WaitForGossip(ctx context.Context) error

type Lookuper

type Lookuper func(key p2pcrypto.PublicKey) (*node.NodeInfo, error)

Lookuper is a service used to lookup for nodes we know already

type NodeTestInstance

type NodeTestInstance interface {
	Service
	LocalNode() node.LocalNode // this holds the keys
}

type Payload

type Payload struct {
	Payload []byte
	Wrapped *service.DataMsgWrapper
}

func CreatePayload

func CreatePayload(data service.Data) (*Payload, error)

type Peer

type Peer p2pcrypto.PublicKey

type PeerSubscriptionProvider

type PeerSubscriptionProvider interface {
	SubscribePeerEvents() (conn, disc chan p2pcrypto.PublicKey)
}

type Peers

type Peers struct {
	log.Log
	// contains filtered or unexported fields
}

func NewPeers

func NewPeers(s PeerSubscriptionProvider, lg log.Log) *Peers

func NewPeersImpl

func NewPeersImpl(snapshot *atomic.Value, exit chan struct{}, lg log.Log) *Peers

NewPeersImpl creates a Peers using specified parameters and returns it

func (Peers) Close

func (pi Peers) Close()

func (Peers) GetPeers

func (pi Peers) GetPeers() []Peer

func (Peers) PeerCount

func (pi Peers) PeerCount() uint64

type ProtocolMessage

type ProtocolMessage struct {
	Metadata *ProtocolMessageMetadata
	Payload  *Payload
}

type ProtocolMessageMetadata

type ProtocolMessageMetadata struct {
	NextProtocol  string
	ClientVersion string
	Timestamp     int64
	AuthPubkey    []byte
	NetworkID     int32
}

type Service

type Service service.Service

Service is a wrapper for service.Service to expose the Service interface to `p2p` clients

type UDPMux

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

UDPMux is a server for receiving and sending udp messages. through protocols.

func NewUDPMux

func NewUDPMux(localNode node.LocalNode, lookuper Lookuper, udpNet udpNetwork, networkid int8, logger log.Log) *UDPMux

NewUDPMux creates a new udp protocol server

func (*UDPMux) ProcessDirectProtocolMessage

func (mux *UDPMux) ProcessDirectProtocolMessage(sender p2pcrypto.PublicKey, protocol string, data service.Data, metadata service.P2PMetadata) error

ProcessDirectProtocolMessage passes a message to the protocol.

func (*UDPMux) RegisterDirectProtocolWithChannel

func (mux *UDPMux) RegisterDirectProtocolWithChannel(name string, c chan service.DirectMessage) chan service.DirectMessage

RegisterDirectProtocolWithChannel registers a protocol on a channel, should be done before `Start` was called. not thread-safe

func (*UDPMux) SendMessage

func (mux *UDPMux) SendMessage(peerPubkey p2pcrypto.PublicKey, protocol string, payload []byte) error

SendMessage is a proxy method to the sendMessageImpl.

func (*UDPMux) SendWrappedMessage

func (mux *UDPMux) SendWrappedMessage(nodeID p2pcrypto.PublicKey, protocol string, payload *service.DataMsgWrapper) error

SendWrappedMessage is a proxy method to the sendMessageImpl. it sends a wrapped message and used within MessageServer

func (*UDPMux) Shutdown

func (mux *UDPMux) Shutdown()

Shutdown closes the server

func (*UDPMux) Start

func (mux *UDPMux) Start() error

Start starts the UDPMux

Directories

Path Synopsis
Package discovery implements a Distributed Hash Table based on Kademlia protocol.
Package discovery implements a Distributed Hash Table based on Kademlia protocol.
net
wire/delimited
Package delimited implements a reader and writer for simple streams of length-delimited byte records.
Package delimited implements a reader and writer for simple streams of length-delimited byte records.

Jump to

Keyboard shortcuts

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