Search in sources :

Example 1 with EnrField

use of org.ethereum.beacon.discovery.schema.EnrField in project xdagj by XDagger.

the class Libp2pUtilsTest method createNodeRecord.

private NodeRecord createNodeRecord(final EnrField... fields) {
    final ArrayList<EnrField> fieldList = new ArrayList<>(Arrays.asList(fields));
    fieldList.add(new EnrField(EnrField.ID, IdentitySchema.V4));
    fieldList.add(new EnrField(EnrField.PKEY_SECP256K1, PUB_KEY));
    return NodeRecordFactory.DEFAULT.createFromValues(UInt64.ZERO, fieldList);
}
Also used : EnrField(org.ethereum.beacon.discovery.schema.EnrField) ArrayList(java.util.ArrayList)

Example 2 with EnrField

use of org.ethereum.beacon.discovery.schema.EnrField in project teku by ConsenSys.

the class NodeRecordConverterTest method shouldConvertAttnets.

@Test
public void shouldConvertAttnets() {
    SszBitvector persistentSubnets = ATT_SUBNET_SCHEMA.ofBits(1, 8, 14, 32);
    Bytes encodedPersistentSubnets = persistentSubnets.sszSerialize();
    final Optional<DiscoveryPeer> result = convertNodeRecordWithFields(new EnrField(EnrField.IP_V6, IPV6_LOCALHOST), new EnrField(EnrField.TCP_V6, 1234), new EnrField(ATTESTATION_SUBNET_ENR_FIELD, encodedPersistentSubnets));
    assertThat(result).contains(new DiscoveryPeer(PUB_KEY, new InetSocketAddress("::1", 1234), ENR_FORK_ID, persistentSubnets, SYNCNETS));
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) DiscoveryPeer(tech.pegasys.teku.networking.p2p.discovery.DiscoveryPeer) EnrField(org.ethereum.beacon.discovery.schema.EnrField) InetSocketAddress(java.net.InetSocketAddress) SszBitvector(tech.pegasys.teku.infrastructure.ssz.collections.SszBitvector) Test(org.junit.jupiter.api.Test)

Example 3 with EnrField

use of org.ethereum.beacon.discovery.schema.EnrField in project teku by ConsenSys.

the class NodeRecordConverterTest method shouldConvertIpV6Record.

@Test
public void shouldConvertIpV6Record() {
    final Optional<DiscoveryPeer> result = convertNodeRecordWithFields(new EnrField(EnrField.IP_V6, IPV6_LOCALHOST), new EnrField(EnrField.TCP_V6, 1234));
    assertThat(result).contains(new DiscoveryPeer(PUB_KEY, new InetSocketAddress("::1", 1234), ENR_FORK_ID, ATTNETS, SYNCNETS));
}
Also used : DiscoveryPeer(tech.pegasys.teku.networking.p2p.discovery.DiscoveryPeer) EnrField(org.ethereum.beacon.discovery.schema.EnrField) InetSocketAddress(java.net.InetSocketAddress) Test(org.junit.jupiter.api.Test)

Example 4 with EnrField

use of org.ethereum.beacon.discovery.schema.EnrField in project teku by ConsenSys.

the class NodeRecordConverterTest method shouldConvertIpV4Record.

@Test
public void shouldConvertIpV4Record() {
    // IP address bytes are unsigned. Make sure we handle that correctly.
    final Optional<DiscoveryPeer> result = convertNodeRecordWithFields(new EnrField(EnrField.IP_V4, Bytes.wrap(new byte[] { -127, 24, 31, 22 })), new EnrField(EnrField.TCP, 1234));
    assertThat(result).contains(new DiscoveryPeer(PUB_KEY, new InetSocketAddress("129.24.31.22", 1234), ENR_FORK_ID, ATTNETS, SYNCNETS));
}
Also used : DiscoveryPeer(tech.pegasys.teku.networking.p2p.discovery.DiscoveryPeer) EnrField(org.ethereum.beacon.discovery.schema.EnrField) InetSocketAddress(java.net.InetSocketAddress) Test(org.junit.jupiter.api.Test)

Example 5 with EnrField

use of org.ethereum.beacon.discovery.schema.EnrField in project teku by ConsenSys.

the class NodeRecordConverterTest method shouldConvertEnrForkId.

@Test
public void shouldConvertEnrForkId() {
    EnrForkId enrForkId = new DataStructureUtil().randomEnrForkId();
    Bytes encodedForkId = enrForkId.sszSerialize();
    final Optional<DiscoveryPeer> result = convertNodeRecordWithFields(new EnrField(EnrField.IP_V6, IPV6_LOCALHOST), new EnrField(EnrField.TCP_V6, 1234), new EnrField(ETH2_ENR_FIELD, encodedForkId));
    assertThat(result).contains(new DiscoveryPeer(PUB_KEY, new InetSocketAddress("::1", 1234), Optional.of(enrForkId), ATTNETS, SYNCNETS));
}
Also used : Bytes(org.apache.tuweni.bytes.Bytes) DiscoveryPeer(tech.pegasys.teku.networking.p2p.discovery.DiscoveryPeer) EnrField(org.ethereum.beacon.discovery.schema.EnrField) InetSocketAddress(java.net.InetSocketAddress) EnrForkId(tech.pegasys.teku.spec.datastructures.networking.libp2p.rpc.EnrForkId) DataStructureUtil(tech.pegasys.teku.spec.util.DataStructureUtil) Test(org.junit.jupiter.api.Test)

Aggregations

EnrField (org.ethereum.beacon.discovery.schema.EnrField)18 Bytes (org.apache.tuweni.bytes.Bytes)12 InetSocketAddress (java.net.InetSocketAddress)11 Test (org.junit.jupiter.api.Test)8 DiscoveryPeer (tech.pegasys.teku.networking.p2p.discovery.DiscoveryPeer)8 Test (org.junit.Test)7 NodeRecord (org.ethereum.beacon.discovery.schema.NodeRecord)6 BytesValueRLPOutput (org.hyperledger.besu.ethereum.rlp.BytesValueRLPOutput)4 SszBitvector (tech.pegasys.teku.infrastructure.ssz.collections.SszBitvector)4 Libp2pUtils.convertToDiscoveryPeer (io.xdag.net.libp2p.Libp2pUtils.convertToDiscoveryPeer)2 DiscoveryPeer (io.xdag.net.libp2p.discovery.DiscoveryPeer)2 ArrayList (java.util.ArrayList)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 Suppliers (com.google.common.base.Suppliers)1 InetAddresses (com.google.common.net.InetAddresses)1 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)1 Collections (java.util.Collections)1 List (java.util.List)1