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

Discvv5.1 - the latest spec updates #76

Merged
merged 99 commits into from
Oct 13, 2020
Merged
Show file tree
Hide file tree
Changes from 94 commits
Commits
Show all changes
99 commits
Select commit Hold shift + click to select a range
83c5da3
Initial set of packet classes for 5.1 version
Nashatyrev Sep 16, 2020
e73d9d1
Refactor packet classes, add test vectors unit test
Nashatyrev Sep 17, 2020
65dbad8
Packet encode/decode passed initial test vectors
Nashatyrev Sep 18, 2020
8fd0787
Integrate new packet classes and update handshake to 5.1
Nashatyrev Sep 22, 2020
eeab34e
Rename old and new packet packages
Nashatyrev Sep 22, 2020
90a25be
Apply spotless
Nashatyrev Sep 22, 2020
8e3e415
Update FindNode message for multiple distances
Nashatyrev Sep 23, 2020
0055968
Minor updates
Nashatyrev Sep 23, 2020
47dbb52
Distinguish DecodeException and DecryptException.
Nashatyrev Sep 23, 2020
91ed52e
Refactor unit tests to new Packet classes
Nashatyrev Sep 23, 2020
04bfd6b
Add OrdinaryMessagePacketTest unit tests
Nashatyrev Sep 24, 2020
7701748
Add WhoAreYouPacketTest
Nashatyrev Sep 24, 2020
2d03656
Add HandshakePacketTest, add dedicated validate() method to all packets
Nashatyrev Sep 24, 2020
dfa6ad7
Remove old packet classes and obsolete tests
Nashatyrev Sep 24, 2020
883cda8
Apply spotless
Nashatyrev Sep 24, 2020
9966bea
Fix warns and licences
Nashatyrev Sep 24, 2020
0405c2f
Fix the test
Nashatyrev Sep 24, 2020
81c7a54
Fix the test
Nashatyrev Sep 24, 2020
2756f88
Draft commit
Nashatyrev Sep 24, 2020
df99cf7
Add some javadoc
Nashatyrev Sep 24, 2020
d6c667e
Process the case when in AUTHORIZED session state inbound message cou…
Nashatyrev Sep 25, 2020
8601f95
Handle malformed remote peer behaviour
Nashatyrev Sep 25, 2020
d21af5d
Remove test-only methods from production interfaces
Nashatyrev Sep 25, 2020
12c4a7a
Rename the class
Nashatyrev Sep 25, 2020
af42f90
Apply spotless
Nashatyrev Sep 25, 2020
5913f5d
Check distances arg to be non-empty
Nashatyrev Sep 29, 2020
784c3f3
Deduplicate distances in incoming FindNodes message
Nashatyrev Sep 29, 2020
c2427b0
Use explicit Flag codes
Nashatyrev Sep 29, 2020
6221320
The Nodes.total field should contain the total number of packets but …
Nashatyrev Sep 29, 2020
12cfd65
Assign the method with more explanatory name
Nashatyrev Sep 29, 2020
bd2f54d
Fix typo in class name
Nashatyrev Sep 29, 2020
10fa187
Fix param name srcNodeId -> destNodeId. Name params more explicitly (…
Nashatyrev Sep 29, 2020
d65bcdf
Narrow compareBytes() param type from Bytes to Bytes32 to avoid incor…
Nashatyrev Sep 29, 2020
091a919
Apply spotless
Nashatyrev Sep 29, 2020
a77ff29
Reduce the number of static factory methods in 5.1 Packet interfaces.…
Nashatyrev Sep 29, 2020
0bb80a7
Fix the test: empty FindNode distances list is not allowed
Nashatyrev Sep 29, 2020
7d627af
Apply spotless
Nashatyrev Sep 29, 2020
84a8118
Increase retryTimeout for slow machines (like CircleCI docker)
Nashatyrev Sep 29, 2020
91d7e4d
Increase also life check interval
Nashatyrev Sep 29, 2020
640b118
Check outgoing packet against max size. Just drop it if too large
Nashatyrev Sep 29, 2020
0aaee3a
Apply spotless
Nashatyrev Sep 29, 2020
3e7ee9a
Fix wording
Nashatyrev Sep 30, 2020
50748e4
Large outbound packet size is rather the error
Nashatyrev Sep 30, 2020
69e5ee9
Limit the total number of returned ENRs for a single FindNode request
Nashatyrev Sep 30, 2020
c7b5611
Limit the total number of returned ENRs for a single FindNode request
Nashatyrev Sep 30, 2020
7f648c5
Merge remote-tracking branch 'origin/feature/disc-v5.1' into feature/…
Nashatyrev Sep 30, 2020
f1b879c
Apply spotless
Nashatyrev Sep 30, 2020
3b62935
Merge branch 'feature/disc-v5.1' into feature/talk-support
Nashatyrev Sep 30, 2020
2e46963
Merge remote-tracking branch 'Pegasys/master' into feature/talk-support
Nashatyrev Sep 30, 2020
eef00f1
Add some more RLP decode validations
Nashatyrev Sep 30, 2020
fe9263a
Add TALKREQ handling
Nashatyrev Sep 30, 2020
737b921
Fix failing tests: request-id is now limited with 8 bytes
Nashatyrev Sep 30, 2020
05ca4cd
Fix bug in validation
Nashatyrev Sep 30, 2020
e59a075
Refactor task handling. Remove unnecessary intermediate classes. Make…
Nashatyrev Oct 1, 2020
470716d
Generify Response
Nashatyrev Oct 1, 2020
9c9675a
Implement TALKREQ
Nashatyrev Oct 1, 2020
bdf7111
Fix warns
Nashatyrev Oct 1, 2020
dba8915
Require sending record when enr-seq == 0
Nashatyrev Oct 1, 2020
e9f0671
Add destination ID into id-sig-input
Nashatyrev Oct 1, 2020
f6afe20
Put version into protocol-id
Nashatyrev Oct 1, 2020
f2899f9
Rename 'iv' to 'maskingIV' according to spec changes
Nashatyrev Oct 2, 2020
125159c
Check min packet size
Nashatyrev Oct 2, 2020
53851ac
TALKRESP protocol is Bytes not the String by the spec.
Nashatyrev Oct 5, 2020
e362b3b
Remove obsolete class
Nashatyrev Oct 5, 2020
1c83b49
Add FindNodeHandler unit test
Nashatyrev Oct 5, 2020
1ff8979
Rename create() to a more appropriate decode()
Nashatyrev Oct 5, 2020
79a82d3
Remove confusing DiscoveryV5Message wrapper and add DiscoveryMessageD…
Nashatyrev Oct 5, 2020
cf02712
Do not wrap DecryptException into DecodeException
Nashatyrev Oct 5, 2020
8db508c
Apply spotless
Nashatyrev Oct 5, 2020
e263e65
Initial refactor to reflect the latest Discv5.1 spec changes:
Nashatyrev Oct 6, 2020
8d3ba7b
Merge branch 'feature/talk-support' into feature/v5.1-last-updates-1
Nashatyrev Oct 6, 2020
228f691
Add test vectors (passing)
Nashatyrev Oct 6, 2020
20e1f0e
Adjust tests to the new reality
Nashatyrev Oct 6, 2020
ce90f4e
Apply spotless. Fix warnings
Nashatyrev Oct 6, 2020
38ad5ef
Merge remote-tracking branch 'Pegasys/master' into feature/v5.1-last-…
Nashatyrev Oct 6, 2020
f77c373
No need to generate and put MASKING_IV here
Nashatyrev Oct 6, 2020
1c03fb4
Use dedicated method to generate MASKING_IV
Nashatyrev Oct 6, 2020
9c3cac3
More type safety for Envelope
Nashatyrev Oct 6, 2020
0dbbe5c
Fix warnings
Nashatyrev Oct 6, 2020
874fcc1
Add Discovery test server
Nashatyrev Oct 7, 2020
229765e
Gradle: no need for 'application' plugin
Nashatyrev Oct 7, 2020
a8c86eb
Sptoless apply
Nashatyrev Oct 7, 2020
aa7f492
Get rid of 'import' which is highlighted by IDEA as ERROR
Nashatyrev Oct 7, 2020
bb70bfe
Create DiscoveryServer outside of DiscoveryManagerImpl
Nashatyrev Oct 8, 2020
01b1df2
Add Field names for better debugging and logging
Nashatyrev Oct 8, 2020
6306c38
Calling a discovery method with NodeRecord should work even this node…
Nashatyrev Oct 8, 2020
1255546
Remove obsolete tests
Nashatyrev Oct 8, 2020
5515c10
Add DiscoveryManager tests and test helpers to simulate and control n…
Nashatyrev Oct 8, 2020
2891f5c
If another ordinary message received after WhoAreYou packet was sent,…
Nashatyrev Oct 8, 2020
d8f1bd6
If a session was dropped on remote host we are sending packets instea…
Nashatyrev Oct 8, 2020
e3bd4e6
Sptoless apply
Nashatyrev Oct 8, 2020
8d03dac
Fix the test
Nashatyrev Oct 8, 2020
362703d
Sptoless apply
Nashatyrev Oct 8, 2020
a0434fb
Add missing field to StaticHeader.toString()
Nashatyrev Oct 12, 2020
d0d3cc8
Handshake ephemeral public key should be in compressed form
Nashatyrev Oct 13, 2020
df8b742
Spotless apply
Nashatyrev Oct 13, 2020
4c9e1c4
Fix outdated StaticHeader javadoc
Nashatyrev Oct 13, 2020
35c192f
Spotless apply
Nashatyrev Oct 13, 2020
94ea4e8
Add sleep() to DiscoveryTestServer to not eat 1 CPU when running
Nashatyrev Oct 13, 2020
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
24 changes: 14 additions & 10 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import net.ltgt.gradle.errorprone.*

//discovery v5

plugins {
Expand Down Expand Up @@ -90,23 +88,23 @@ tasks.withType(JavaCompile) {
options.errorprone {
disableWarningsInGeneratedCode
// Our equals need to be symmetric, this checker doesn't respect that.
check('EqualsGetClass', CheckSeverity.OFF)
check('EqualsGetClass', net.ltgt.gradle.errorprone.CheckSeverity.OFF)
// We like to use futures with no return values.
check('FutureReturnValueIgnored', CheckSeverity.OFF)
check('FutureReturnValueIgnored', net.ltgt.gradle.errorprone.CheckSeverity.OFF)
// We use the JSR-305 annotations instead of the Google annotations.
check('ImmutableEnumChecker', CheckSeverity.OFF)
check('ImmutableEnumChecker', net.ltgt.gradle.errorprone.CheckSeverity.OFF)

check('FieldCanBeFinal', CheckSeverity.OFF)
check('InsecureCryptoUsage', CheckSeverity.WARN)
check('WildcardImport', CheckSeverity.WARN)
check('FieldCanBeFinal', net.ltgt.gradle.errorprone.CheckSeverity.OFF)
check('InsecureCryptoUsage', net.ltgt.gradle.errorprone.CheckSeverity.WARN)
check('WildcardImport', net.ltgt.gradle.errorprone.CheckSeverity.WARN)

// This check is broken in Java 12. See https://github.com/google/error-prone/issues/1257
if (JavaVersion.current() == JavaVersion.VERSION_12) {
check('Finally', CheckSeverity.OFF)
check('Finally', net.ltgt.gradle.errorprone.CheckSeverity.OFF)
}
// This check is broken after Java 12. See https://github.com/google/error-prone/issues/1352
if (JavaVersion.current() > JavaVersion.VERSION_12) {
check('TypeParameterUnusedInFormals', CheckSeverity.OFF)
check('TypeParameterUnusedInFormals', net.ltgt.gradle.errorprone.CheckSeverity.OFF)
}
}
options.encoding = 'UTF-8'
Expand Down Expand Up @@ -147,6 +145,12 @@ task sourcesJar(type: Jar, dependsOn: classes) {
from sourceSets.main.allSource
}

task runTestDiscovery(type:JavaExec) {
main = 'org.ethereum.beacon.discovery.app.DiscoveryTestServer'
classpath = sourceSets.main.runtimeClasspath + sourceSets.test.runtimeClasspath
systemProperty "log4j.configurationFile", "log4j2-test-discovery.xml"
}

def resolvedVersion = calculateVersion()
def bintrayUser = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('BINTRAY_USER')
def bintrayKey = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('BINTRAY_KEY')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,7 @@
package org.ethereum.beacon.discovery;

import com.google.common.annotations.VisibleForTesting;
import java.net.InetSocketAddress;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand All @@ -18,7 +16,6 @@
import org.ethereum.beacon.discovery.network.DiscoveryClient;
import org.ethereum.beacon.discovery.network.NettyDiscoveryClientImpl;
import org.ethereum.beacon.discovery.network.NettyDiscoveryServer;
import org.ethereum.beacon.discovery.network.NettyDiscoveryServerImpl;
import org.ethereum.beacon.discovery.network.NetworkParcel;
import org.ethereum.beacon.discovery.pipeline.Envelope;
import org.ethereum.beacon.discovery.pipeline.Field;
Expand All @@ -38,17 +35,19 @@
import org.ethereum.beacon.discovery.pipeline.handler.UnauthorizedMessagePacketHandler;
import org.ethereum.beacon.discovery.pipeline.handler.UnknownPacketTagToSender;
import org.ethereum.beacon.discovery.pipeline.handler.WhoAreYouPacketHandler;
import org.ethereum.beacon.discovery.pipeline.handler.WhoAreYouSessionResolver;
import org.ethereum.beacon.discovery.pipeline.info.FindNodeResponseHandler;
import org.ethereum.beacon.discovery.pipeline.info.MultiPacketResponseHandler;
import org.ethereum.beacon.discovery.pipeline.info.Request;
import org.ethereum.beacon.discovery.scheduler.ExpirationSchedulerFactory;
import org.ethereum.beacon.discovery.scheduler.Scheduler;
import org.ethereum.beacon.discovery.schema.NodeRecord;
import org.ethereum.beacon.discovery.schema.NodeRecordFactory;
import org.ethereum.beacon.discovery.storage.AuthTagRepository;
import org.ethereum.beacon.discovery.schema.NodeRecordInfo;
import org.ethereum.beacon.discovery.storage.LocalNodeRecordStore;
import org.ethereum.beacon.discovery.storage.NodeBucketStorage;
import org.ethereum.beacon.discovery.storage.NodeTable;
import org.ethereum.beacon.discovery.storage.NonceRepository;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
import reactor.core.publisher.FluxSink;
Expand All @@ -62,10 +61,11 @@ public class DiscoveryManagerImpl implements DiscoveryManager {
private final Pipeline incomingPipeline = new PipelineImpl();
private final Pipeline outgoingPipeline = new PipelineImpl();
private final LocalNodeRecordStore localNodeRecordStore;
private final NodeTable nodeTable;
private volatile DiscoveryClient discoveryClient;

public DiscoveryManagerImpl(
Optional<InetSocketAddress> listenAddress,
NettyDiscoveryServer discoveryServer,
NodeTable nodeTable,
NodeBucketStorage nodeBucketStorage,
LocalNodeRecordStore localNodeRecordStore,
Expand All @@ -74,29 +74,24 @@ public DiscoveryManagerImpl(
Scheduler taskScheduler,
ExpirationSchedulerFactory expirationSchedulerFactory,
TalkHandler talkHandler) {
this.nodeTable = nodeTable;
this.localNodeRecordStore = localNodeRecordStore;
final NodeRecord homeNodeRecord = localNodeRecordStore.getLocalNodeRecord();
AuthTagRepository authTagRepo = new AuthTagRepository();

this.discoveryServer =
new NettyDiscoveryServerImpl(
listenAddress
.or(homeNodeRecord::getUdpAddress)
.orElseThrow(
() ->
new IllegalArgumentException(
"Local node record must contain an IP and UDP port")));
NonceRepository nonceRepository = new NonceRepository();

this.discoveryServer = discoveryServer;
NodeIdToSession nodeIdToSession =
new NodeIdToSession(
localNodeRecordStore,
homeNodePrivateKey,
nodeBucketStorage,
authTagRepo,
nonceRepository,
nodeTable,
outgoingPipeline,
expirationSchedulerFactory);
incomingPipeline
.addHandler(new IncomingDataPacker(homeNodeRecord.getNodeId()))
.addHandler(new WhoAreYouSessionResolver(nonceRepository))
.addHandler(new UnknownPacketTagToSender())
.addHandler(nodeIdToSession)
.addHandler(new PacketDispatcherHandler())
Expand Down Expand Up @@ -156,8 +151,15 @@ private <T> CompletableFuture<T> executeTaskImpl(NodeRecord nodeRecord, Request<
return request.getResultPromise();
}

private void addNode(NodeRecord nodeRecord) {
if (nodeTable.getNode(nodeRecord.getNodeId()).isEmpty()) {
nodeTable.save(NodeRecordInfo.createDefault(nodeRecord));
}
}

@Override
public CompletableFuture<Void> findNodes(NodeRecord nodeRecord, List<Integer> distances) {
addNode(nodeRecord);
Request<Void> request =
new Request<>(
new CompletableFuture<>(),
Expand All @@ -168,6 +170,7 @@ public CompletableFuture<Void> findNodes(NodeRecord nodeRecord, List<Integer> di

@Override
public CompletableFuture<Void> ping(NodeRecord nodeRecord) {
addNode(nodeRecord);
Request<Void> request =
new Request<>(
new CompletableFuture<>(),
Expand All @@ -178,6 +181,7 @@ public CompletableFuture<Void> ping(NodeRecord nodeRecord) {

@Override
public CompletableFuture<Bytes> talk(NodeRecord nodeRecord, Bytes protocol, Bytes requestBytes) {
addNode(nodeRecord);
Request<Bytes> request =
new Request<>(
new CompletableFuture<>(),
Expand All @@ -190,4 +194,14 @@ public CompletableFuture<Bytes> talk(NodeRecord nodeRecord, Bytes protocol, Byte
public Publisher<NetworkParcel> getOutgoingMessages() {
return outgoingMessages;
}

@VisibleForTesting
public Pipeline getIncomingPipeline() {
return incomingPipeline;
}

@VisibleForTesting
public Pipeline getOutgoingPipeline() {
return outgoingPipeline;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

import static com.google.common.base.Preconditions.checkNotNull;
import static java.util.Arrays.asList;
import static java.util.Objects.requireNonNullElseGet;

import com.google.common.annotations.VisibleForTesting;
import com.google.common.util.concurrent.ThreadFactoryBuilder;
import java.net.InetSocketAddress;
import java.time.Duration;
Expand All @@ -18,6 +20,8 @@
import java.util.stream.Stream;
import org.apache.tuweni.bytes.Bytes;
import org.ethereum.beacon.discovery.database.Database;
import org.ethereum.beacon.discovery.network.NettyDiscoveryServer;
import org.ethereum.beacon.discovery.network.NettyDiscoveryServerImpl;
import org.ethereum.beacon.discovery.scheduler.ExpirationSchedulerFactory;
import org.ethereum.beacon.discovery.scheduler.Schedulers;
import org.ethereum.beacon.discovery.schema.NodeRecord;
Expand All @@ -34,6 +38,7 @@
import org.ethereum.beacon.discovery.task.DiscoveryTaskManager;

public class DiscoverySystemBuilder {

private static final AtomicInteger COUNTER = new AtomicInteger();
private List<NodeRecord> bootnodes = Collections.emptyList();
private Optional<InetSocketAddress> listenAddress = Optional.empty();
Expand All @@ -46,6 +51,7 @@ public class DiscoverySystemBuilder {
private Duration retryTimeout = DiscoveryTaskManager.DEFAULT_RETRY_TIMEOUT;
private Duration lifeCheckInterval = DiscoveryTaskManager.DEFAULT_LIVE_CHECK_INTERVAL;
private TalkHandler talkHandler = TalkHandler.NOOP;
private NettyDiscoveryServer discoveryServer = null;

public DiscoverySystemBuilder localNodeRecord(final NodeRecord localNodeRecord) {
this.localNodeRecord = localNodeRecord;
Expand All @@ -71,6 +77,11 @@ public DiscoverySystemBuilder bootnodes(final String... enrs) {
return this;
}

public DiscoverySystemBuilder bootnodes(final List<NodeRecord> records) {
bootnodes = records;
return this;
}

public DiscoverySystemBuilder bootnodes(final NodeRecord... records) {
bootnodes = asList(records);
return this;
Expand Down Expand Up @@ -106,42 +117,68 @@ public DiscoverySystemBuilder talkHandler(TalkHandler talkHandler) {
return this;
}

public DiscoverySystem build() {
checkNotNull(localNodeRecord, "Missing local node record");
checkNotNull(privateKey, "Missing private key");
public DiscoverySystemBuilder discoveryServer(NettyDiscoveryServer discoveryServer) {
this.discoveryServer = discoveryServer;
return this;
}

if (database == null) {
database = Database.inMemoryDB();
}
final NodeTableStorageFactory nodeTableStorageFactory = new NodeTableStorageFactoryImpl();
final NodeSerializerFactory serializerFactory = new NodeSerializerFactory(nodeRecordFactory);
final NodeTableStorage nodeTableStorage =
nodeTableStorageFactory.createTable(
database, serializerFactory, oldSeq -> localNodeRecord, () -> bootnodes);
final NodeTable nodeTable = nodeTableStorage.get();
if (schedulers == null) {
schedulers = Schedulers.createDefault();
}
final NodeBucketStorage nodeBucketStorage =
new NodeBucketStorageImpl(database, serializerFactory, localNodeRecord);
final int clientNumber = COUNTER.incrementAndGet();
final LocalNodeRecordStore localNodeRecordStore =
new LocalNodeRecordStore(localNodeRecord, privateKey, localNodeRecordListener);
final ExpirationSchedulerFactory expirationSchedulerFactory =
new ExpirationSchedulerFactory(
Executors.newSingleThreadScheduledExecutor(
new ThreadFactoryBuilder().setNameFormat("discovery-expiration-%d").build()));
final DiscoveryManager discoveryManager =
new DiscoveryManagerImpl(
listenAddress,
nodeTable,
private void createDefaults() {
database = requireNonNullElseGet(database, () -> Database.inMemoryDB());
schedulers = requireNonNullElseGet(schedulers, () -> Schedulers.createDefault());
discoveryServer =
requireNonNullElseGet(
discoveryServer,
() ->
new NettyDiscoveryServerImpl(
listenAddress
.or(localNodeRecord::getUdpAddress)
.orElseThrow(
() ->
new IllegalArgumentException(
"Local node record must contain an IP and UDP port"))));

nodeTableStorage =
requireNonNullElseGet(
nodeTableStorage,
() ->
nodeTableStorageFactory.createTable(
database, serializerFactory, oldSeq -> localNodeRecord, () -> bootnodes));
nodeTable = requireNonNullElseGet(nodeTable, () -> nodeTableStorage.get());
nodeBucketStorage =
requireNonNullElseGet(
nodeBucketStorage,
() -> new NodeBucketStorageImpl(database, serializerFactory, localNodeRecord));
localNodeRecordStore =
requireNonNullElseGet(
localNodeRecordStore,
privateKey,
nodeRecordFactory,
schedulers.newSingleThreadDaemon("discovery-client-" + clientNumber),
() -> new LocalNodeRecordStore(localNodeRecord, privateKey, localNodeRecordListener));
expirationSchedulerFactory =
requireNonNullElseGet(
expirationSchedulerFactory,
talkHandler);
() ->
new ExpirationSchedulerFactory(
Executors.newSingleThreadScheduledExecutor(
new ThreadFactoryBuilder()
.setNameFormat("discovery-expiration-%d")
.build())));
}

final NodeTableStorageFactory nodeTableStorageFactory = new NodeTableStorageFactoryImpl();
final NodeSerializerFactory serializerFactory = new NodeSerializerFactory(nodeRecordFactory);
final int clientNumber = COUNTER.incrementAndGet();

NodeTableStorage nodeTableStorage;
NodeTable nodeTable;
NodeBucketStorage nodeBucketStorage;
LocalNodeRecordStore localNodeRecordStore;
ExpirationSchedulerFactory expirationSchedulerFactory;

public DiscoverySystem build() {
checkNotNull(localNodeRecord, "Missing local node record");
checkNotNull(privateKey, "Missing private key");
createDefaults();

final DiscoveryManager discoveryManager = buildDiscoveryManager();

final DiscoveryTaskManager discoveryTaskManager =
new DiscoveryTaskManager(
Expand All @@ -158,4 +195,19 @@ public DiscoverySystem build() {
return new DiscoverySystem(
discoveryManager, discoveryTaskManager, expirationSchedulerFactory, nodeTable, bootnodes);
}

@VisibleForTesting
DiscoveryManagerImpl buildDiscoveryManager() {
createDefaults();
return new DiscoveryManagerImpl(
discoveryServer,
nodeTable,
nodeBucketStorage,
localNodeRecordStore,
privateKey,
nodeRecordFactory,
schedulers.newSingleThreadDaemon("discovery-client-" + clientNumber),
expirationSchedulerFactory,
talkHandler);
}
}
17 changes: 1 addition & 16 deletions src/main/java/org/ethereum/beacon/discovery/packet/AuthData.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,5 @@
*/
package org.ethereum.beacon.discovery.packet;

import org.ethereum.beacon.discovery.type.Bytes12;
import org.ethereum.beacon.discovery.util.DecodeException;

/** AuthData part of any {@link Packet}'s {@link Header} */
public interface AuthData extends BytesSerializable {

Bytes12 getAesGcmNonce();

@Override
default void validate() throws DecodeException {
DecodeException.wrap(
() -> "Couldn't decode AuthData nonce: " + getBytes(),
() -> {
getAesGcmNonce();
});
}
}
public interface AuthData extends BytesSerializable {}
Loading