-
Notifications
You must be signed in to change notification settings - Fork 434
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Feed ENR dns to discovery appp * Missed a file * Unit tests * Fixed misconfiguration
- Loading branch information
Showing
5 changed files
with
81 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/Nethermind/Nethermind.Network.Discovery.Test/NodeSourceToDiscV4Feeder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
using Nethermind.Core.Test.Builders; | ||
using Nethermind.Stats.Model; | ||
using NSubstitute; | ||
using NUnit.Framework; | ||
|
||
namespace Nethermind.Network.Discovery.Test; | ||
|
||
public class NodeSourceToDiscV4FeederTests | ||
{ | ||
[Test] | ||
public void Test_ShouldAddNodeToDiscover() | ||
{ | ||
INodeSource source = Substitute.For<INodeSource>(); | ||
IDiscoveryApp discoveryApp = Substitute.For<IDiscoveryApp>(); | ||
using NodeSourceToDiscV4Feeder feeder = new(source, discoveryApp, 10); | ||
source.NodeAdded += Raise.EventWith(new NodeEventArgs(new Node(TestItem.PublicKeyA, TestItem.IPEndPointA))); | ||
|
||
discoveryApp.Received().AddNodeToDiscovery(Arg.Any<Node>()); | ||
} | ||
|
||
[Test] | ||
public void Test_ShouldLimitAddedNode() | ||
{ | ||
INodeSource source = Substitute.For<INodeSource>(); | ||
IDiscoveryApp discoveryApp = Substitute.For<IDiscoveryApp>(); | ||
using NodeSourceToDiscV4Feeder feeder = new(source, discoveryApp, 10); | ||
|
||
for (int i = 0; i < 20; i++) | ||
{ | ||
source.NodeAdded += Raise.EventWith(new NodeEventArgs(new Node(TestItem.PublicKeyA, TestItem.IPEndPointA))); | ||
} | ||
|
||
discoveryApp.Received(10).AddNodeToDiscovery(Arg.Any<Node>()); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/Nethermind/Nethermind.Network.Discovery/NodeSourceToDiscV4Feeder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// SPDX-FileCopyrightText: 2023 Demerzel Solutions Limited | ||
// SPDX-License-Identifier: LGPL-3.0-only | ||
|
||
namespace Nethermind.Network.Discovery; | ||
|
||
public class NodeSourceToDiscV4Feeder : IDisposable | ||
{ | ||
private readonly INodeSource _nodeSource; | ||
private readonly IDiscoveryApp _discoveryApp; | ||
private readonly int _maxNodes; | ||
private int _addedNodes = 0; | ||
|
||
public NodeSourceToDiscV4Feeder(INodeSource nodeSource, IDiscoveryApp discoveryApp, int maxNodes) | ||
{ | ||
nodeSource.NodeAdded += AddToDiscoveryApp; | ||
_nodeSource = nodeSource; | ||
_discoveryApp = discoveryApp; | ||
_maxNodes = maxNodes; | ||
} | ||
|
||
private void AddToDiscoveryApp(object? sender, NodeEventArgs e) | ||
{ | ||
if (_addedNodes >= _maxNodes) return; | ||
_addedNodes++; | ||
_discoveryApp.AddNodeToDiscovery(e.Node); | ||
} | ||
|
||
public void Dispose() | ||
{ | ||
_nodeSource.NodeAdded -= AddToDiscoveryApp; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters