Skip to content

Commit

Permalink
Fix peerstore and a test
Browse files Browse the repository at this point in the history
  • Loading branch information
flcl42 committed Oct 16, 2024
1 parent 8450958 commit 1d1f01f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/libp2p/Libp2p.Core/Discovery/PeerStore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ public void Discover(Multiaddress[] addrs)

if (peerId is not null)
{
PeerInfo peerInfo = store.GetOrAdd(peerId, new PeerInfo { Addrs = [.. addrs] });
if(peerInfo.Addrs is not null && peerInfo.Addrs.Count == addrs.Length && addrs.All(peerInfo.Addrs.Contains))
PeerInfo? newOne = null;
PeerInfo peerInfo = store.GetOrAdd(peerId, (id) => newOne = new PeerInfo { Addrs = [.. addrs] });
if(peerInfo != newOne && peerInfo.Addrs is not null && peerInfo.Addrs.Count == addrs.Length && addrs.All(peerInfo.Addrs.Contains))
{
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public async Task Test_New_messages_are_sent_to_mesh_only()
PubsubRouter router = new(peerStore);
Settings settings = new() { HeartbeatInterval = int.MaxValue };
IRoutingStateContainer state = router;
int peerCount = Settings.Default.Degree * 2;
int peerCount = Settings.Default.HighestDegree + 1;
const string commonTopic = "topic1";

ILocalPeer peer = new LocalPeerStub();
Expand Down Expand Up @@ -47,7 +47,7 @@ public async Task Test_New_messages_are_sent_to_mesh_only()
Assert.Multiple(() =>
{
Assert.That(state.GossipsubPeers[commonTopic], Has.Count.EqualTo(peerCount));
Assert.That(state.Mesh[commonTopic], Has.Count.EqualTo(Settings.Default.HighestDegree));
Assert.That(state.Mesh[commonTopic], Has.Count.EqualTo(Settings.Default.Degree));
});

tcs.SetResult();
Expand Down

0 comments on commit 1d1f01f

Please sign in to comment.