Sort peers for crdt consensus.Peers
This commit is contained in:
parent
e6d183fd70
commit
c109a01343
11
cluster.go
11
cluster.go
|
@ -723,10 +723,12 @@ func (c *Cluster) ID(ctx context.Context) *api.ID {
|
|||
}
|
||||
|
||||
var addrs []api.Multiaddr
|
||||
mAddrs, _ := peer.AddrInfoToP2pAddrs(&peer.AddrInfo{ID: c.id, Addrs: c.host.Addrs()})
|
||||
mAddrs, err := peer.AddrInfoToP2pAddrs(&peer.AddrInfo{ID: c.id, Addrs: c.host.Addrs()})
|
||||
if err == nil {
|
||||
for _, mAddr := range mAddrs {
|
||||
addrs = append(addrs, api.NewMultiaddrWithValue(mAddr))
|
||||
}
|
||||
}
|
||||
|
||||
peers := []peer.ID{}
|
||||
// This method might get called very early by a remote peer
|
||||
|
@ -747,7 +749,7 @@ func (c *Cluster) ID(ctx context.Context) *api.ID {
|
|||
}
|
||||
}
|
||||
|
||||
return &api.ID{
|
||||
id := &api.ID{
|
||||
ID: c.id,
|
||||
//PublicKey: c.host.Peerstore().PubKey(c.id),
|
||||
Addresses: addrs,
|
||||
|
@ -758,6 +760,11 @@ func (c *Cluster) ID(ctx context.Context) *api.ID {
|
|||
IPFS: ipfsID,
|
||||
Peername: c.config.Peername,
|
||||
}
|
||||
if err != nil {
|
||||
id.Error = err.Error()
|
||||
}
|
||||
|
||||
return id
|
||||
}
|
||||
|
||||
// PeerAdd adds a new peer to this Cluster.
|
||||
|
|
|
@ -3,6 +3,7 @@ package crdt
|
|||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"sort"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
|
@ -399,6 +400,8 @@ func (css *Consensus) Peers(ctx context.Context) ([]peer.ID, error) {
|
|||
peers = append(peers, css.host.ID())
|
||||
}
|
||||
|
||||
sort.Sort(peer.IDSlice(peers))
|
||||
|
||||
return peers, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user