Skip to content

Commit

Permalink
Replace outdated peer.
Browse files Browse the repository at this point in the history
  • Loading branch information
longfin committed Apr 25, 2019
1 parent 73ff997 commit 191beee
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions Libplanet/Net/Swarm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1288,6 +1288,7 @@ CancellationToken cancellationToken

if (IsUnknownPeer(sender))
{
_logger.Debug("The sender of delta is unknown.");
if (IsDifferentProtocolVersion(sender))
{
var args = new DifferentProtocolVersionEventArgs
Expand Down Expand Up @@ -1336,13 +1337,20 @@ CancellationToken cancellationToken

private bool IsUnknownPeer(Peer sender)
{
if (_peers.Keys.All(p => !sender.PublicKey.Equals(p.PublicKey)))
Peer existing = _peers.Keys
.FirstOrDefault(p => sender.PublicKey.Equals(p.PublicKey));

if (existing is null)
{
return true;
}

if (_dealers.Keys.All(a => !sender.Address.Equals(a)))
if (!existing.EndPoint.Equals(sender.EndPoint))
{
// Clear outdated existing peer.
_peers.Remove(existing);
CloseDealer(existing);

return true;
}

Expand Down

0 comments on commit 191beee

Please sign in to comment.