mirror of https://github.com/status-im/nim-eth.git
Minor adjustments in utp_discv5_protocol (#459)
- Move SocketConfig parameter location - Reuse rng from disc5 protocol - add exports - Some whitespace clean-up
This commit is contained in:
parent
0f18272315
commit
26ab9b078e
|
@ -13,7 +13,7 @@ import
|
||||||
./utp_router,
|
./utp_router,
|
||||||
../keys
|
../keys
|
||||||
|
|
||||||
export utp_router
|
export utp_router, protocol
|
||||||
|
|
||||||
type UtpDiscv5Protocol* = ref object of TalkProtocol
|
type UtpDiscv5Protocol* = ref object of TalkProtocol
|
||||||
prot: protocol.Protocol
|
prot: protocol.Protocol
|
||||||
|
@ -66,16 +66,15 @@ proc new*(
|
||||||
p: protocol.Protocol,
|
p: protocol.Protocol,
|
||||||
subProtocolName: seq[byte],
|
subProtocolName: seq[byte],
|
||||||
acceptConnectionCb: AcceptConnectionCallback[Node],
|
acceptConnectionCb: AcceptConnectionCallback[Node],
|
||||||
socketConfig: SocketConfig = SocketConfig.init(),
|
|
||||||
allowConnectionCb: AllowConnectionCallback[Node] = nil,
|
allowConnectionCb: AllowConnectionCallback[Node] = nil,
|
||||||
rng = newRng()): UtpDiscv5Protocol =
|
socketConfig: SocketConfig = SocketConfig.init()): UtpDiscv5Protocol =
|
||||||
doAssert(not(isNil(acceptConnectionCb)))
|
doAssert(not(isNil(acceptConnectionCb)))
|
||||||
|
|
||||||
let router = UtpRouter[Node].new(
|
let router = UtpRouter[Node].new(
|
||||||
acceptConnectionCb,
|
acceptConnectionCb,
|
||||||
allowConnectionCb,
|
allowConnectionCb,
|
||||||
socketConfig,
|
socketConfig,
|
||||||
rng
|
p.rng
|
||||||
)
|
)
|
||||||
router.sendCb = initSendCallback(p, subProtocolName)
|
router.sendCb = initSendCallback(p, subProtocolName)
|
||||||
|
|
||||||
|
|
|
@ -113,8 +113,8 @@ proc new*[A](
|
||||||
rng = newRng()): UtpRouter[A] =
|
rng = newRng()): UtpRouter[A] =
|
||||||
UtpRouter[A].new(acceptConnectionCb, nil, socketConfig, rng)
|
UtpRouter[A].new(acceptConnectionCb, nil, socketConfig, rng)
|
||||||
|
|
||||||
# There are different possiblites how connection was established, and we need to
|
# There are different possibilities on how the connection got established, need
|
||||||
# check every case
|
# to check every case.
|
||||||
proc getSocketOnReset[A](r: UtpRouter[A], sender: A, id: uint16): Option[UtpSocket[A]] =
|
proc getSocketOnReset[A](r: UtpRouter[A], sender: A, id: uint16): Option[UtpSocket[A]] =
|
||||||
# id is our recv id
|
# id is our recv id
|
||||||
let recvKey = UtpSocketKey[A].init(sender, id)
|
let recvKey = UtpSocketKey[A].init(sender, id)
|
||||||
|
|
|
@ -145,14 +145,14 @@ procSuite "Utp protocol over discovery v5 tests":
|
||||||
node1,
|
node1,
|
||||||
utpProtId,
|
utpProtId,
|
||||||
registerIncomingSocketCallback(queue),
|
registerIncomingSocketCallback(queue),
|
||||||
SocketConfig.init(lowSynTimeout))
|
socketConfig = SocketConfig.init(lowSynTimeout))
|
||||||
utp2 =
|
utp2 =
|
||||||
UtpDiscv5Protocol.new(
|
UtpDiscv5Protocol.new(
|
||||||
node2,
|
node2,
|
||||||
utpProtId,
|
utpProtId,
|
||||||
registerIncomingSocketCallback(queue),
|
registerIncomingSocketCallback(queue),
|
||||||
SocketConfig.init(),
|
allowOneIdCallback(allowedId),
|
||||||
allowOneIdCallback(allowedId))
|
SocketConfig.init())
|
||||||
|
|
||||||
# nodes must know about each other
|
# nodes must know about each other
|
||||||
check:
|
check:
|
||||||
|
@ -191,7 +191,7 @@ procSuite "Utp protocol over discovery v5 tests":
|
||||||
node2,
|
node2,
|
||||||
utpProtId,
|
utpProtId,
|
||||||
registerIncomingSocketCallback(queue),
|
registerIncomingSocketCallback(queue),
|
||||||
SocketConfig.init(incomingSocketReceiveTimeout = none[Duration]())
|
socketConfig = SocketConfig.init(incomingSocketReceiveTimeout = none[Duration]())
|
||||||
)
|
)
|
||||||
|
|
||||||
# nodes must know about each other
|
# nodes must know about each other
|
||||||
|
|
Loading…
Reference in New Issue