eth2peerstore

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2022 License: MIT Imports: 9 Imported by: 0

README

go-eth2-peerstore

go get github.com/protolambda/go-eth2-peerstore

This extends the Libp2p peerstore, adding:

  • Address conversion utils in addrutil
  • Eth2 Status, Metadata (with seqnr handling) support, building on ZRNT types
  • Eth2 ENR support
  • Interface to access the libp2p Identify info (default libp2p does not expose it)
  • List function to get a collection of detailed info of a peer, to not have to query all separate peerstore components.
  • Everything can be persisted, with the same datastore abstraction as the native libp2p peerstore uses.
  • Peerstore tee: sync any changes made to the libp2p keystore with an external source. Logging and CSV tee types included as examples.

Getting started

import (
    "fmt"
    ds "github.com/ipfs/go-datastore"
    "github.com/ipfs/go-datastore/sync"
    "github.com/libp2p/go-libp2p-peerstore/pstoreds"
    "github.com/protolambda/go-eth2-peerstore/dstrack"
)

func main() {
    store := sync.MutexWrap(ds.NewMapDatastore())  // or your favorite persisted libp2p datastore (Leveldb, badger, etc.)
    peerstore, err := dstrack.NewExtendedPeerstore(context.Background(), store, pstoreds.DefaultOpts())
    if err != nil {
        panic(err)
    }
    data, err := peerstore.GetAllData("peerid.....")
    if err != nil {
        panic(err)
    }
    fmt.Println(data)
}

License

MIT. See LICENSE file.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AllDataGetter

type AllDataGetter interface {
	GetAllData(ctx context.Context, id peer.ID) (*PeerAllData, error)
}

type ENRBook

type ENRBook interface {
	// Updates the ENR, if it is has a higher sequence number
	UpdateENRMaybe(ctx context.Context, id peer.ID, n *enode.Node) (updated bool, err error)

	// find the latest enr for the given peer.
	LatestENR(ctx context.Context, id peer.ID) (n *enode.Node, err error)
}

type IdentifyBook

type IdentifyBook interface {
	ProtocolVersion(ctx context.Context, id peer.ID) (string, error)
	UserAgent(ctx context.Context, id peer.ID) (string, error)
}

IdentifyBook exposes the peer libp2p-identify info. Libp2p stores this data in the misc-data book

type MetadataBook

type MetadataBook interface {
	Metadata(context.Context, peer.ID) (*common.MetaData, error)
	ClaimedSeq(context.Context, peer.ID) (seq common.SeqNr, err error)
	RegisterSeqClaim(ctx context.Context, id peer.ID, seq common.SeqNr) (newer bool, err error)
	RegisterMetaFetch(context.Context, peer.ID) (uint64, error)
	RegisterMetadata(ctx context.Context, id peer.ID, md common.MetaData) (newer bool, err error)
}

type PeerAllData

type PeerAllData struct {
	PeerID peer.ID  `json:"peer_id"`
	NodeID enode.ID `json:"node_id"`
	Pubkey string   `json:"pubkey"`

	Addrs     []string `json:"addrs,omitempty"`
	Protocols []string `json:"protocols,omitempty"`

	Latency time.Duration `json:"latency,omitempty"`

	UserAgent       string `json:"user_agent,omitempty"`
	ProtocolVersion string `json:"protocol_version,omitempty"`

	ForkDigest      *common.ForkDigest `json:"enr_fork_digest,omitempty"`
	NextForkVersion *common.Version    `json:"enr_next_fork_version,omitempty"`
	NextForkEpoch   *common.Epoch      `json:"enr_next_fork_epoch,omitempty"`

	Attnets *common.AttnetBits `json:"enr_attnets,omitempty"`

	// Metadata with highest sequence number
	MetaData *common.MetaData `json:"metadata,omitempty"`
	// Highest claimed seq nr, we may not have the actual corresponding metadata yet.
	ClaimedSeq common.SeqNr `json:"claimed_seq,omitempty"`
	// Latest status
	Status *common.Status `json:"status,omitempty"`
	// Latest ENR
	ENR *enode.Node `json:"enr,omitempty"`
}

func (*PeerAllData) String

func (p *PeerAllData) String() string

type StatusBook

type StatusBook interface {
	// Status retrieves the peer status, and may be nil if there is no status
	Status(context.Context, peer.ID) (*common.Status, error)
	// RegisterStatus updates the status of the peer
	RegisterStatus(context.Context, peer.ID, common.Status) error
}

type TeedDatastore

type TeedDatastore interface {
	// AddTee registers a tee, and returns true if it was already registered
	AddTee(tee dstee.Tee) (exists bool)
	// RmTee registers a tee, and returns true if it was registered before unregistering it
	RmTee(tee dstee.Tee) (exists bool)
	// ListTees lists all the tees
	ListTees() (out []dstee.Tee)
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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