Documentation ¶
Index ¶
- Constants
- Variables
- func NodeIDFromPublicKeyBytes(pubKey []byte) (peer.ID, error)
- type LibP2PNetwork
- type Peer
- func (p *Peer) BootstrapNodes() []peer.AddrInfo
- func (p *Peer) Close() error
- func (p *Peer) Configuration() *PeerConfiguration
- func (p *Peer) CreateStream(ctx context.Context, peerID peer.ID, protocolID string) (network.Stream, error)
- func (p *Peer) FilterValidators(exclude peer.ID) []peer.ID
- func (p *Peer) GetRandomPeerID() peer.ID
- func (p *Peer) ID() peer.ID
- func (p *Peer) MultiAddresses() []ma.Multiaddr
- func (p *Peer) Network() network.Network
- func (p *Peer) PublicKey() (crypto.PubKey, error)
- func (p *Peer) RegisterProtocolHandler(protocolID string, handler network.StreamHandler)
- func (p *Peer) RemoveProtocolHandler(protocolID string)
- func (p *Peer) String() string
- func (p *Peer) Validators() []peer.ID
- type PeerConfiguration
- type PeerKeyPair
- type ValidatorNetOptions
Constants ¶
const ( ProtocolBlockProposal = "/ab/block-proposal/0.0.1" ProtocolUnicityCertificates = "/ab/certificates/0.0.1" ProtocolBlockCertification = "/ab/block-certification/0.0.1" ProtocolInputForward = "/ab/input-forward/0.0.1" ProtocolLedgerReplicationReq = "/ab/replication-req/0.0.1" ProtocolLedgerReplicationResp = "/ab/replication-resp/0.0.1" ProtocolHandshake = "/ab/handshake/0.0.1" )
Variables ¶
var DefaultValidatorNetOptions = ValidatorNetOptions{ ResponseChannelCapacity: 1000, ForwarderTimeout: 300 * time.Millisecond, BlockCertificationTimeout: 300 * time.Millisecond, BlockProposalTimeout: 300 * time.Millisecond, LedgerReplicationRequestTimeout: 300 * time.Millisecond, LedgerReplicationResponseTimeout: 300 * time.Millisecond, HandshakeTimeout: 300 * time.Millisecond, }
var (
ErrPeerConfigurationIsNil = errors.New("peer configuration is nil")
)
Functions ¶
Types ¶
type LibP2PNetwork ¶
type LibP2PNetwork struct {
// contains filtered or unexported fields
}
LibP2PNetwork implements "alphabill network" using libp2p.
Zero value is not useable, use one of the constructors to create network!
func NewLibP2PValidatorNetwork ¶
func NewLibP2PValidatorNetwork(self *Peer, opts ValidatorNetOptions) (*LibP2PNetwork, error)
NewLibP2PValidatorNetwork creates a new libp2p for a validator.
func (*LibP2PNetwork) ReceivedChannel ¶
func (n *LibP2PNetwork) ReceivedChannel() <-chan any
type Peer ¶
type Peer struct {
// contains filtered or unexported fields
}
Peer represents a single node in p2p network. It is a wrapper around the libp2p host.Host.
func NewPeer ¶
func NewPeer(ctx context.Context, conf *PeerConfiguration) (*Peer, error)
NewPeer constructs a new peer node with given configuration. If no peer key is provided, it generates a random Secp256k1 key-pair and derives a new identity from it. If no transport and listen addresses are provided, the node listens to the multiaddresses "/ip4/0.0.0.0/tcp/0".
func (*Peer) BootstrapNodes ¶ added in v0.2.0
func (*Peer) Configuration ¶
func (p *Peer) Configuration() *PeerConfiguration
Configuration returns peer configuration
func (*Peer) CreateStream ¶
func (p *Peer) CreateStream(ctx context.Context, peerID peer.ID, protocolID string) (network.Stream, error)
CreateStream opens a new stream to given peer p, and writes a libp2p protocol header with given ProtocolID.
func (*Peer) FilterValidators ¶ added in v0.2.0
func (*Peer) GetRandomPeerID ¶
GetRandomPeerID returns a random peer.ID from the peerstore.
func (*Peer) MultiAddresses ¶
MultiAddresses the address associated with this Peer.
func (*Peer) RegisterProtocolHandler ¶
func (p *Peer) RegisterProtocolHandler(protocolID string, handler network.StreamHandler)
RegisterProtocolHandler sets the protocol stream handler for given protocol.
func (*Peer) RemoveProtocolHandler ¶
RemoveProtocolHandler removes the given protocol handler.
func (*Peer) Validators ¶
type PeerConfiguration ¶
type PeerConfiguration struct { Address string // address to listen for incoming connections. Uses libp2p multiaddress format. KeyPair *PeerKeyPair // keypair for the peer. BootstrapPeers []peer.AddrInfo // a list of seed peers to connect to. Validators []peer.ID // a list of known peers (in case of partition node this list must contain all validators). }
PeerConfiguration includes single peer configuration values.
type PeerKeyPair ¶
PeerKeyPair contains node's public and private key.
type ValidatorNetOptions ¶
type ValidatorNetOptions struct { // How many messages will be buffered (ReceivedChannel) in case of slow consumer. // Once buffer is full messages will be dropped (ie not processed) // until consumer catches up. ResponseChannelCapacity uint ForwarderTimeout time.Duration BlockCertificationTimeout time.Duration BlockProposalTimeout time.Duration LedgerReplicationRequestTimeout time.Duration LedgerReplicationResponseTimeout time.Duration HandshakeTimeout time.Duration }