-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Adding some comments to P2P classes #1212
Changes from 9 commits
a219962
9efa148
79d9c3e
f381677
1390057
7172645
8c79d93
5d7f0fd
841e199
871f14f
bb89d9e
4356483
b968d83
6d9ff9c
9ff443a
1653ec0
d6f5a24
caf3e0a
1850780
44d25a4
31976ce
a1c8f3d
6d7b0ff
ca3df0f
8dff674
0b03c83
cf5dacd
cc4825b
a68e828
84061b9
38c63f5
c01c70d
bf28f7d
c9d3ad1
8e238c5
945d0b7
86fd901
055b6d4
f17af50
f588b22
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,6 +122,11 @@ public IEnumerable<IPEndPoint> GetUnconnectedPeers() | |
return UnconnectedPeers; | ||
} | ||
|
||
/// <summary> | ||
/// Override of abstract class that is triggered when UnconnectedPeers is empty | ||
/// Performs a BroadcastMessage with the command `MessageCommand.GetAddr`, which, eventually, tells all known connections | ||
/// If there are no connected peers it will try with the default, respecting MaxCountFromSeedList limit | ||
/// </summary> | ||
protected override void NeedMorePeers(int count) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Count parameter information too |
||
{ | ||
count = Math.Max(count, MaxCountFromSeedList); | ||
|
@@ -131,6 +136,8 @@ protected override void NeedMorePeers(int count) | |
} | ||
else | ||
{ | ||
// Will call AddPeers with default SeedList set on Protocol.json | ||
// trying to adding those to the list of currently uncconected ones | ||
AddPeers(GetIPEndPointsFromSeedList(count)); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,10 +62,16 @@ static Peer() | |
localAddresses.UnionWith(NetworkInterface.GetAllNetworkInterfaces().SelectMany(p => p.GetIPProperties().UnicastAddresses).Select(p => p.Address.Unmap())); | ||
} | ||
|
||
/// <summary> | ||
/// Tries to add a set ff peers to an immutable hashset of UnconnectedPeers | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is an "ff peer"? Did you mean "of"? I didn't fix because I'm not sure There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it's of i think |
||
/// </summary> | ||
/// <param name="peers">Peers that the method will try to add (union) to (with) UnconnectedPeers</param> | ||
protected void AddPeers(IEnumerable<IPEndPoint> peers) | ||
{ | ||
if (UnconnectedPeers.Count < UnconnectedMax) | ||
{ | ||
// Do not select peers to be added that are already on the ConnectedPeers | ||
// If the address is the same, the ListenerTcpPort should be different | ||
peers = peers.Where(p => (p.Port != ListenerTcpPort || !localAddresses.Contains(p.Address)) && !ConnectedPeers.Values.Contains(p)); | ||
ImmutableInterlocked.Update(ref UnconnectedPeers, p => p.Union(peers)); | ||
} | ||
|
@@ -74,6 +80,7 @@ protected void AddPeers(IEnumerable<IPEndPoint> peers) | |
protected void ConnectToPeer(IPEndPoint endPoint, bool isTrusted = false) | ||
{ | ||
endPoint = endPoint.Unmap(); | ||
// If the address is the same, the ListenerTcpPort should be different, otherwise, return | ||
if (endPoint.Port == ListenerTcpPort && localAddresses.Contains(endPoint.Address)) return; | ||
|
||
if (isTrusted) TrustedIpAddresses.Add(endPoint.Address); | ||
|
@@ -96,6 +103,11 @@ private static bool IsIntranetAddress(IPAddress address) | |
return (value & 0xff000000) == 0x0a000000 || (value & 0xff000000) == 0x7f000000 || (value & 0xfff00000) == 0xac100000 || (value & 0xffff0000) == 0xc0a80000 || (value & 0xffff0000) == 0xa9fe0000; | ||
} | ||
|
||
/// <summary> | ||
/// Abstract class for asking for more peers | ||
/// Currently triggered when UnconnectedPeers is empty | ||
/// </summary> | ||
/// <param name="count">Number of peers that are being requested</param> | ||
protected abstract void NeedMorePeers(int count); | ||
|
||
protected override void OnReceive(object message) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add the info for the parameters too?