Skip to content

Commit 4cc54d4

Browse files
committed
add clean constructor for discv5
1 parent 9a44ea4 commit 4cc54d4

File tree

2 files changed

+49
-6
lines changed

2 files changed

+49
-6
lines changed

execution_chain/networking/discoveryv5.nim

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,51 @@
99

1010
{.push raises: [].}
1111

12-
include
13-
eth/p2p/discoveryv5/protocol
12+
import
13+
std/[options],
14+
chronos,
15+
chronicles,
16+
results,
17+
metrics,
18+
eth/common/keys,
19+
eth/p2p/discoveryv5/[protocol, encoding, messages_encoding, enr, node, sessions]
20+
21+
export
22+
# Core types only
23+
protocol.Protocol,
24+
node.Node,
25+
node.Address,
26+
enr.Record
27+
28+
# Type aliases for cleaner API
29+
type
30+
DiscoveryV5* = protocol.Protocol
31+
NodeV5* = node.Node
32+
AddressV5* = node.Address
33+
34+
proc newDiscoveryV5*(
35+
privKey: PrivateKey,
36+
enrIp: Opt[IpAddress],
37+
enrTcpPort: Opt[Port],
38+
enrUdpPort: Opt[Port],
39+
bootstrapRecords: openArray[enr.Record] = [],
40+
bindPort: Port,
41+
bindIp = IPv6_any(),
42+
enrAutoUpdate = true,
43+
rng = newRng(),
44+
): DiscoveryV5 =
45+
## Create a new Discovery v5 protocol instance
46+
protocol.newProtocol(
47+
privKey = privKey,
48+
enrIp = enrIp,
49+
enrTcpPort = enrTcpPort,
50+
enrUdpPort = enrUdpPort,
51+
bootstrapRecords = bootstrapRecords,
52+
bindPort = bindPort,
53+
bindIp = bindIp,
54+
enrAutoUpdate = enrAutoUpdate,
55+
rng = rng
56+
)
1457

1558
proc receiveV5*(d: Protocol, a: Address, packet: openArray[byte]): Result[void, cstring] =
1659
discv5_network_bytes.inc(packet.len.int64, labelValues = [$Direction.In])

execution_chain/networking/eth1_discovery.nim

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ logScope:
2929

3030
type
3131
DiscV4 = discoveryv4.DiscoveryV4
32-
DiscV5 = discoveryv5.Protocol
32+
DiscV5 = discoveryv5.DiscoveryV5
3333

3434
NodeV4 = discoveryv4.Node
35-
NodeV5 = discoveryv5.Node
35+
NodeV5 = discoveryv5.NodeV5
3636

3737
AddressV4 = discoveryv4.Address
38-
AddressV5 = discoveryv5.Address
38+
AddressV5 = discoveryv5.AddressV5
3939

4040
Eth1Discovery* = ref object
4141
discv4: DiscV4
@@ -110,7 +110,7 @@ proc new*(
110110
bindIp = bindIp,
111111
rng = rng
112112
),
113-
discv5: discoveryv5.newProtocol(
113+
discv5: discoveryv5.newDiscoveryV5(
114114
privKey = privKey,
115115
enrIp = Opt.some(address.ip),
116116
enrTcpPort = Opt.some(address.tcpPort),

0 commit comments

Comments
 (0)