mirror of
https://github.com/status-im/nim-eth-p2p.git
synced 2025-01-14 17:04:19 +00:00
Merge pull request #12 from status-im/discv4enode2
ENode integration part 2.
This commit is contained in:
commit
7c2e8daae4
@ -8,5 +8,5 @@
|
||||
# MIT license (LICENSE-MIT)
|
||||
#
|
||||
|
||||
import ethp2p/ecies, ethp2p/auth, ethp2p/hexdump, ethp2p/enode
|
||||
export ecies, auth, enode, hexdump
|
||||
import ethp2p/[ecies, auth, hexdump, enode, rlpxcrypt, discovery, kademlia]
|
||||
export ecies, auth, enode, hexdump, rlpxcrypt, discovery, kademlia
|
||||
|
@ -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