nim-eth-p2p/tests/tserver.nim
Zahary Karadjov 72016046fb Merge peer_pool and server into rlpx
This was done because a cycle was formed between the structures
of the three modules:

- A Peer holds a reference to its Network
- The Network holds a reference to its PeerPool
- The PeerPool keeps a table of connected Peers

I could have resolved the issue by introducing a new types module,
but it would have required all of the currently private fields to
become public (due to lack of package-level visibility in Nim).

Instead I decided to merge the modules because they were relatively
small anyway. Please note that the former `P2PServer` type is now
called `NetworkConnection`. There are slight changes in the APIs
that will be carried out in Nimbus when merging this.
2018-07-06 15:25:21 +03:00

32 lines
836 B
Nim

#
# Ethereum P2P
# (c) Copyright 2018
# Status Research & Development GmbH
#
# Licensed under either of
# Apache License, version 2.0, (LICENSE-APACHEv2)
# MIT license (LICENSE-MIT)
import sequtils
import eth_keys, asyncdispatch2
import eth_p2p/[discovery, kademlia, enode, rlpx]
const clientId = "nim-eth-p2p/0.0.1"
proc localAddress(port: int): Address =
let port = Port(port)
result = Address(udpPort: port, tcpPort: port, ip: parseIpAddress("127.0.0.1"))
proc test() {.async.} =
let kp = newKeyPair()
let address = localAddress(20301)
let s = connectToNetwork(kp, address, nil, [], clientId, 1)
let n = newNode(initENode(kp.pubKey, address))
let peer = await rlpxConnect(n, newKeyPair(), Port(1234), clientId)
doAssert(not peer.isNil)
waitFor test()