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

Adding some comments to P2P classes #1212

Merged
merged 40 commits into from
Dec 10, 2019
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
a219962
Adding random hashes for OnGetDataMessageReceived
vncoelho Oct 18, 2019
9efa148
Adding static readonly Random
vncoelho Oct 18, 2019
79d9c3e
Merge branch 'master' of github.com:neo-project/neo
vncoelho Nov 8, 2019
f381677
Adding some comments to Peers class
vncoelho Nov 8, 2019
1390057
Reverting change on ProtocolHandler
vncoelho Nov 8, 2019
7172645
dotnet format
vncoelho Nov 8, 2019
8c79d93
Additional comments
vncoelho Nov 8, 2019
5d7f0fd
Adding extra comments
vncoelho Nov 10, 2019
841e199
Merge branch 'master' into adding-comments-peers
vncoelho Nov 10, 2019
871f14f
Fixing typo
lock9 Nov 14, 2019
bb89d9e
Fixing typo
lock9 Nov 14, 2019
4356483
Fixing typo
lock9 Nov 14, 2019
b968d83
Merge branch 'master' into adding-comments-peers
shargon Nov 14, 2019
6d9ff9c
Merge branch 'master' into adding-comments-peers
lock9 Nov 18, 2019
9ff443a
Merge branch 'master' into adding-comments-peers
lock9 Nov 25, 2019
1653ec0
Adding more comments
vncoelho Nov 25, 2019
d6f5a24
Merge branch 'master' into adding-comments-peers
vncoelho Nov 25, 2019
caf3e0a
adding more comments
vncoelho Nov 25, 2019
1850780
Merge branch 'adding-comments-peers' of github.com:neo-project/neo in…
vncoelho Nov 25, 2019
44d25a4
Merge branch 'master' into adding-comments-peers
vncoelho Nov 28, 2019
31976ce
Merge branch 'master' into adding-comments-peers
vncoelho Nov 28, 2019
a1c8f3d
Add some comments of P2P (#1303)
ShawnYun Nov 29, 2019
6d7b0ff
dotnet format
vncoelho Nov 29, 2019
ca3df0f
Merge branch 'master' into adding-comments-peers
vncoelho Nov 29, 2019
8dff674
Minor changes
vncoelho Nov 29, 2019
0b03c83
Minor changes
vncoelho Nov 29, 2019
cf5dacd
Additional comments
vncoelho Nov 29, 2019
cc4825b
Minor changes
vncoelho Nov 29, 2019
a68e828
Reverting variable change
vncoelho Nov 29, 2019
84061b9
Merge branch 'master' into adding-comments-peers
vncoelho Dec 3, 2019
38c63f5
Merge branch 'master' into adding-comments-peers
vncoelho Dec 4, 2019
c01c70d
Merge branch 'master' into adding-comments-peers
vncoelho Dec 5, 2019
bf28f7d
Dotnet format
vncoelho Dec 5, 2019
c9d3ad1
Minor changes
vncoelho Dec 9, 2019
8e238c5
Minor changes
vncoelho Dec 9, 2019
945d0b7
Minor changes
vncoelho Dec 9, 2019
86fd901
Minor changes
vncoelho Dec 9, 2019
055b6d4
Minor changes
vncoelho Dec 9, 2019
f17af50
Merge branch 'master' into adding-comments-peers
vncoelho Dec 9, 2019
f588b22
Merge branch 'master' into adding-comments-peers
shargon Dec 10, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions neo/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ internal static IPAddress Unmap(this IPAddress address)
return address;
}

/// <summary>
/// Checks IPv4 and IPv6 formats and unmap, if necessary
/// </summary>
internal static IPEndPoint Unmap(this IPEndPoint endPoint)
Copy link
Member

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?

{
if (!endPoint.Address.IsIPv4MappedToIPv6)
Expand Down
7 changes: 7 additions & 0 deletions neo/Network/P2P/LocalNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Member

Choose a reason for hiding this comment

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

Count parameter information too

{
count = Math.Max(count, MaxCountFromSeedList);
Expand All @@ -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));
}
}
Expand Down
12 changes: 12 additions & 0 deletions neo/Network/P2P/Peer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

@lock9 lock9 Nov 14, 2019

Choose a reason for hiding this comment

The 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

Copy link
Member

Choose a reason for hiding this comment

The 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));
}
Expand All @@ -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);
Expand All @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions neo/Network/P2P/TaskManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,28 @@ private void OnNewTasks(InvPayload payload)
{
if (!sessions.TryGetValue(Sender, out TaskSession session))
return;
// Do not accept payload of type InventoryType.TX if not synced on best known top HeaderHeight
if (payload.Type == InventoryType.TX && Blockchain.Singleton.Height < Blockchain.Singleton.HeaderHeight)
{
RequestTasks(session);
return;
}
HashSet<UInt256> hashes = new HashSet<UInt256>(payload.Hashes);
// Remove all previously processed knownHashes from the list that is being requested
hashes.Remove(knownHashes);
// Add to AvailableTasks the ones, of type InventoryType.Block, that are global (already under processement by other sessions)
if (payload.Type == InventoryType.Block)
session.AvailableTasks.UnionWith(hashes.Where(p => globalTasks.ContainsKey(p)));

// Remove those that are already in processement by other sessions
hashes.Remove(globalTasks);
if (hashes.Count == 0)
{
RequestTasks(session);
return;
}

// Update globalTasks with the ones that will be requested within this current session
foreach (UInt256 hash in hashes)
{
IncrementGlobalTask(hash);
Expand Down