mirror of
https://github.com/status-im/nim-eth-p2p.git
synced 2025-01-28 23:55:02 +00:00
Add newNode(ENode).
Change newDiscoveryProtocol to use not strings, but ENode.
This commit is contained in:
parent
eda7fd5816
commit
da30ba61eb
@ -162,7 +162,7 @@ proc sendNeighbours*(d: DiscoveryProtocol, node: Node, neighbours: seq[Node]) =
|
||||
|
||||
if nodes.len != 0: flush()
|
||||
|
||||
proc newDiscoveryProtocol*(privKey: PrivateKey, address: Address, bootstrapNodes: openarray[string]): DiscoveryProtocol =
|
||||
proc newDiscoveryProtocol*(privKey: PrivateKey, address: Address, bootstrapNodes: openarray[ENode]): DiscoveryProtocol =
|
||||
result.new()
|
||||
result.privKey = privKey
|
||||
result.address = address
|
||||
@ -312,12 +312,16 @@ when isMainModule:
|
||||
# let (remotePubkey, cmdId, payload) = unpack(m)
|
||||
# assert(remotePubkey.raw_key.toHex == privKey.public_key.raw_key.toHex)
|
||||
|
||||
var bootnodes = newSeq[ENode]()
|
||||
for item in LOCAL_BOOTNODES:
|
||||
bootnodes.add(initENode(item))
|
||||
|
||||
let listenPort = Port(30310)
|
||||
var address = Address(udpPort: listenPort, tcpPort: listenPort)
|
||||
address.ip.family = IpAddressFamily.IPv4
|
||||
let discovery = newDiscoveryProtocol(privkey, address, LOCAL_BOOTNODES)
|
||||
let discovery = newDiscoveryProtocol(privkey, address, bootnodes)
|
||||
|
||||
echo discovery.thisNode.pubkey
|
||||
echo discovery.thisNode.node.pubkey
|
||||
echo "this_node.id: ", discovery.thisNode.id.toHex()
|
||||
|
||||
discovery.open()
|
||||
|
@ -61,6 +61,11 @@ proc newNode*(uriString: string): Node =
|
||||
result.node = initENode(uriString)
|
||||
result.id = result.node.pubkey.toNodeId()
|
||||
|
||||
proc newNode*(enode: ENode): Node =
|
||||
result.new()
|
||||
result.node = enode
|
||||
result.id = result.node.pubkey.toNodeId()
|
||||
|
||||
proc distanceTo(n: Node, id: NodeId): UInt256 = n.id xor id
|
||||
|
||||
proc `$`*(n: Node): string =
|
||||
|
Loading…
x
Reference in New Issue
Block a user