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:
Kim De Mey 2022-01-10 13:49:36 +01:00 committed by GitHub
parent 0f18272315
commit 26ab9b078e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 23 additions and 24 deletions

View File

@ -13,7 +13,7 @@ import
./utp_router,
../keys
export utp_router
export utp_router, protocol
type UtpDiscv5Protocol* = ref object of TalkProtocol
prot: protocol.Protocol
@ -66,16 +66,15 @@ proc new*(
p: protocol.Protocol,
subProtocolName: seq[byte],
acceptConnectionCb: AcceptConnectionCallback[Node],
socketConfig: SocketConfig = SocketConfig.init(),
allowConnectionCb: AllowConnectionCallback[Node] = nil,
rng = newRng()): UtpDiscv5Protocol =
socketConfig: SocketConfig = SocketConfig.init()): UtpDiscv5Protocol =
doAssert(not(isNil(acceptConnectionCb)))
let router = UtpRouter[Node].new(
acceptConnectionCb,
allowConnectionCb,
socketConfig,
rng
p.rng
)
router.sendCb = initSendCallback(p, subProtocolName)

View File

@ -113,8 +113,8 @@ proc new*[A](
rng = newRng()): UtpRouter[A] =
UtpRouter[A].new(acceptConnectionCb, nil, socketConfig, rng)
# There are different possiblites how connection was established, and we need to
# check every case
# There are different possibilities on how the connection got established, need
# to check every case.
proc getSocketOnReset[A](r: UtpRouter[A], sender: A, id: uint16): Option[UtpSocket[A]] =
# id is our recv id
let recvKey = UtpSocketKey[A].init(sender, id)

View File

@ -145,14 +145,14 @@ procSuite "Utp protocol over discovery v5 tests":
node1,
utpProtId,
registerIncomingSocketCallback(queue),
SocketConfig.init(lowSynTimeout))
socketConfig = SocketConfig.init(lowSynTimeout))
utp2 =
UtpDiscv5Protocol.new(
node2,
utpProtId,
registerIncomingSocketCallback(queue),
SocketConfig.init(),
allowOneIdCallback(allowedId))
allowOneIdCallback(allowedId),
SocketConfig.init())
# nodes must know about each other
check:
@ -191,7 +191,7 @@ procSuite "Utp protocol over discovery v5 tests":
node2,
utpProtId,
registerIncomingSocketCallback(queue),
SocketConfig.init(incomingSocketReceiveTimeout = none[Duration]())
socketConfig = SocketConfig.init(incomingSocketReceiveTimeout = none[Duration]())
)
# nodes must know about each other