Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guarantee at least 10 peers to broadcast #767

Merged
merged 5 commits into from
Jan 23, 2020

Conversation

limebell
Copy link
Member

@limebell limebell commented Jan 20, 2020

If the number of total peers in routing table is less then 10, broadcast messages to all peers.
If not, pick one from each bucket, and pick additional peers which were not selected in first step until total peers count reach 10.

Closes #765.

@limebell limebell added the network Related to networking (Libplanet.Net) label Jan 20, 2020
@limebell limebell self-assigned this Jan 20, 2020
earlbread
earlbread previously approved these changes Jan 20, 2020
@codecov
Copy link

codecov bot commented Jan 22, 2020

Codecov Report

Merging #767 into master will increase coverage by 0.18%.
The diff coverage is 98.9%.

@@            Coverage Diff             @@
##           master     #767      +/-   ##
==========================================
+ Coverage    86.3%   86.48%   +0.18%     
==========================================
  Files         225      225              
  Lines       19280    19363      +83     
==========================================
+ Hits        16640    16747     +107     
+ Misses       1438     1413      -25     
- Partials     1202     1203       +1
Impacted Files Coverage Δ
Libplanet.Tests/Net/Protocols/ProtocolTest.cs 100% <100%> (ø) ⬆️
Libplanet/Net/Protocols/RoutingTable.cs 88.33% <100%> (+3.51%) ⬆️
Libplanet.Tests/Net/Protocols/TestTransport.cs 76.58% <93.33%> (+1.01%) ⬆️
Libplanet/Net/Swarm.cs 84.29% <0%> (+0.41%) ⬆️
Libplanet/Net/Protocols/KademliaProtocol.cs 66.93% <0%> (+3%) ⬆️

@limebell limebell requested a review from longfin January 23, 2020 03:52
@limebell limebell merged commit 6ab954b into planetarium:master Jan 23, 2020
- If there are less than 10 peers in the routing table, select all peers.
- If there are more than 10 peers in the routing table,
choose one from each bucket, and if the number is less than 10,
then select an additional peers so that the total is 10.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it's not a manual or docs, rather than explaining its behavioral details, we'd better to write a short descriptive guarantee and its intention.

@@ -248,10 +252,14 @@ public void BroadcastTestMessage(Address? except, string data)
public void BroadcastMessage(Address? except, Message message)
{
var peers = Protocol.PeersToBroadcast(except).ToList();
var peersString = peers.Aggregate(
new StringBuilder(),
(builder, peer) => builder.Append($"{peer.Address.ToHex()}, ")).ToString();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't the same thing be easily achieved using string.Join() method?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
network Related to networking (Libplanet.Net)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Guarantee minimum amount of peer to broadcast
5 participants