CRDT: Fix protecting of nodes before loading the peerstore

Addresses comments from review #792
This commit is contained in:
Hector Sanjuan 2019-05-27 13:59:01 +02:00
parent 99be078548
commit 2a2f8c0309
2 changed files with 12 additions and 7 deletions

View File

@ -102,12 +102,6 @@ func New(
readyCh: make(chan struct{}, 1),
}
// Set up a fast-lookup trusted peers cache.
// Protect these peers in the ConnMgr
for _, p := range css.config.TrustedPeers {
css.Trust(ctx, p)
}
go css.setup()
return css, nil
}
@ -119,6 +113,12 @@ func (css *Consensus) setup() {
case <-css.rpcReady:
}
// Set up a fast-lookup trusted peers cache.
// Protect these peers in the ConnMgr
for _, p := range css.config.TrustedPeers {
css.Trust(css.ctx, p)
}
// Hash the cluster name and produce the topic name from there
// as a way to avoid pubsub topic collisions with other
// pubsub applications potentially when both potentially use

View File

@ -256,7 +256,7 @@ func (pm *Manager) SavePeerstoreForPeers(peers []peer.ID) {
// Bootstrap attempts to get as much as count connected peers by selecting
// randomly from those in the libp2p host peerstore. It returns the number
// if peers it sucessfully connected to.
// of peers it successfully connected to.
func (pm *Manager) Bootstrap(count int) int {
knownPeers := pm.host.Peerstore().PeersWithAddrs()
toSort := &peerSort{
@ -296,6 +296,11 @@ func (pm *Manager) SetPriority(pid peer.ID, prio int) error {
return pm.host.Peerstore().Put(pid, PriorityTag, prio)
}
// peerSort is used to sort a slice of PinInfos given the PriorityTag in the
// peerstore, from the lowest tag value (0 is the highest priority) to the
// highest, Peers without a valid priority tag are considered as having a tag
// with value 0, so they will be among the first elements in the resulting
// slice.
type peerSort struct {
pinfos []peerstore.PeerInfo
pstore peerstore.Peerstore