p2p

package
v1.2.4 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2020 License: MIT Imports: 13 Imported by: 1

Documentation

Overview

Package p2p is a generated GoMock package.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNewStream    = errors.New("[HOST]: new stream error")
	ErrMsgWrite     = errors.New("[HOST]: send message write error")
	ErrAddProtocols = errors.New("[HOST]: cannot add protocols")
)

Error of host package

Functions

This section is empty.

Types

type Backoff

type Backoff interface {
	Reset()
	Sleep()
	Backoff()
}

Backoff is a backoff sleeper.

type BackoffBase

type BackoffBase struct {
	Min, Cur, Max time.Duration
}

BackoffBase is the base implementation of backoff sleeper. It handles the minimum/current/maximum backoff logic. If maximum backoff is 0, there is no maximum.

func NewBackoffBase

func NewBackoffBase(min, max time.Duration) *BackoffBase

NewBackoffBase creates a new BackOffBase structure

func (*BackoffBase) Backoff

func (b *BackoffBase) Backoff()

Backoff adjusts the duration. Subtypes shall implement this.

func (*BackoffBase) Reset

func (b *BackoffBase) Reset()

Reset the current sleep duration to its minimum value.

func (*BackoffBase) Sleep

func (b *BackoffBase) Sleep()

Sleep for the current duration, then adjust the duration.

type ExpBackoff

type ExpBackoff struct {
	BackoffBase
	Factor float64
}

ExpBackoff is an exponential backoff data structure.

func NewExpBackoff

func NewExpBackoff(min, max time.Duration, factor float64) *ExpBackoff

NewExpBackoff creates a new ExpBackOff structure

func (*ExpBackoff) Backoff

func (b *ExpBackoff) Backoff()

Backoff implements the exponential backoff

type GroupReceiver

type GroupReceiver interface {
	// Close closes this receiver.
	io.Closer

	// Receive a message.
	Receive(ctx context.Context) (msg []byte, sender libp2p_peer.ID, err error)
}

GroupReceiver is a multicast group message receiver interface.

type Host

type Host interface {
	GetSelfPeer() Peer
	Close() error
	AddPeer(*Peer) error
	GetID() libp2p_peer.ID
	GetP2PHost() libp2p_host.Host
	GetPeerCount() int

	//AddIncomingPeer(Peer)
	//AddOutgoingPeer(Peer)
	ConnectHostPeer(Peer)

	// SendMessageToGroups sends a message to one or more multicast groups.
	SendMessageToGroups(groups []nodeconfig.GroupID, msg []byte) error

	// GroupReceiver returns a receiver of messages sent to a multicast group.
	// Each call creates a new receiver.
	// If multiple receivers are created for the same group,
	// a message sent to the group will be delivered to all of the receivers.
	GroupReceiver(nodeconfig.GroupID) (receiver GroupReceiver, err error)
}

Host is the client + server in p2p network.

type MockStream

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

MockStream is a mock of Stream interface

func NewMockStream

func NewMockStream(ctrl *gomock.Controller) *MockStream

NewMockStream creates a new mock instance

func (*MockStream) Close

func (m *MockStream) Close() error

Close mocks base method

func (*MockStream) EXPECT

func (m *MockStream) EXPECT() *MockStreamMockRecorder

EXPECT returns an object that allows the caller to indicate expected use

func (*MockStream) Read

func (m *MockStream) Read(arg0 []byte) (int, error)

Read mocks base method

func (*MockStream) SetReadDeadline

func (m *MockStream) SetReadDeadline(arg0 time.Time) error

SetReadDeadline mocks base method

func (*MockStream) Write

func (m *MockStream) Write(arg0 []byte) (int, error)

Write mocks base method

type MockStreamMockRecorder

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

MockStreamMockRecorder is the mock recorder for MockStream

func (*MockStreamMockRecorder) Close

func (mr *MockStreamMockRecorder) Close() *gomock.Call

Close indicates an expected call of Close

func (*MockStreamMockRecorder) Read

func (mr *MockStreamMockRecorder) Read(arg0 interface{}) *gomock.Call

Read indicates an expected call of Read

func (*MockStreamMockRecorder) SetReadDeadline

func (mr *MockStreamMockRecorder) SetReadDeadline(arg0 interface{}) *gomock.Call

SetReadDeadline indicates an expected call of SetReadDeadline

func (*MockStreamMockRecorder) Write

func (mr *MockStreamMockRecorder) Write(arg0 interface{}) *gomock.Call

Write indicates an expected call of Write

type Peer

type Peer struct {
	IP              string         // IP address of the peer
	Port            string         // Port number of the peer
	ConsensusPubKey *bls.PublicKey // Public key of the peer, used for consensus signing
	Addrs           []ma.Multiaddr // MultiAddress of the peer
	PeerID          libp2p_peer.ID // PeerID, the pubkey for communication
}

Peer is the object for a p2p peer (node)

func (Peer) String

func (p Peer) String() string

type Stream

type Stream interface {
	Read([]byte) (int, error)
	Write([]byte) (int, error)
	Close() error
	SetReadDeadline(time.Time) error
}

Stream is abstract p2p stream from where we read message

type StreamHandler

type StreamHandler func(Stream)

StreamHandler handles incoming p2p message.

Directories

Path Synopsis
mock
Package mock_p2p is a generated GoMock package.
Package mock_p2p is a generated GoMock package.

Jump to

Keyboard shortcuts

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