prysm-pulse/beacon-chain/p2p/peers/store.go
Victor Farazdagi 568238009e
Extracts peer data store in p2p/peers status (#6639)
* introduces peer data store to p2p/peers
* Merge refs/heads/master into p2p-extract-data-store
* Merge refs/heads/master into p2p-extract-data-store
* refactores status service
* Merge branch 'p2p-extract-data-store' of github.com:prysmaticlabs/prysm into p2p-extract-data-store
* updates tests
* gofmt
* rever decay test
2020-07-19 03:45:08 +00:00

50 lines
1.4 KiB
Go

package peers
import (
"context"
"sync"
"time"
"github.com/ethereum/go-ethereum/p2p/enr"
"github.com/libp2p/go-libp2p-core/network"
"github.com/libp2p/go-libp2p-core/peer"
ma "github.com/multiformats/go-multiaddr"
pb "github.com/prysmaticlabs/prysm/proto/beacon/p2p/v1"
)
// peerDataStore is a container for various peer related data (both protocol and app level).
// Container implements RWMutex, so data access can be restricted on the container level. This allows
// different components rely on the very same peer map container.
type peerDataStore struct {
sync.RWMutex
ctx context.Context
config *peerDataStoreConfig
peers map[peer.ID]*peerData
}
// peerDataStoreConfig holds peer store parameters.
type peerDataStoreConfig struct {
maxPeers int
}
// peerData aggregates protocol and application level info about a single peer.
type peerData struct {
address ma.Multiaddr
direction network.Direction
connState PeerConnectionState
chainState *pb.Status
enr *enr.Record
metaData *pb.MetaData
chainStateLastUpdated time.Time
badResponsesCount int
}
// newPeerDataStore creates peer store.
func newPeerDataStore(ctx context.Context, config *peerDataStoreConfig) *peerDataStore {
return &peerDataStore{
ctx: ctx,
config: config,
peers: make(map[peer.ID]*peerData),
}
}