fix: callbacks

This commit is contained in:
Richard Ramos
2025-08-06 16:40:17 -04:00
parent 5847afa996
commit d2ed0556c0
2 changed files with 25 additions and 18 deletions

View File

@@ -109,6 +109,16 @@ proc oneNode(node: Node) {.async.} =
await sleepAsync(1000.milliseconds)
await node.switch.stop()
proc makeMixConnCb(mixProto: MixProtocol): CustomConnCreationProc =
return proc(
destAddr: Option[MultiAddress], destPeerId: PeerId, codec: string
): Connection {.gcsafe, raises: [].} =
try:
return mixProto.toConnection(destPeerId, Opt.none(MultiAddress), codec)
except CatchableError as e:
error "Error during execution of MixEntryConnection callback: ", err = e.msg
return nil
proc mixnet_gossipsub_test() {.async: (raises: [Exception]).} =
let
numberOfNodes = 5
@@ -120,14 +130,7 @@ proc mixnet_gossipsub_test() {.async: (raises: [Exception]).} =
error "Mix protocol initialization failed", err = error
return
let mixConn = proc(
destAddr: Option[MultiAddress], destPeerId: PeerId, codec: string
): Connection {.gcsafe, raises: [].} =
try:
return mixProto.toConnection(destPeerId, Opt.none(MultiAddress), codec)
except CatchableError as e:
error "Error during execution of MixEntryConnection callback: ", err = e.msg
return nil
let mixConnCb = makeMixConnCb(mixProto)
let mixPeerSelect = proc(
allPeers: HashSet[PubSubPeer],
@@ -146,7 +149,7 @@ proc mixnet_gossipsub_test() {.async: (raises: [Exception]).} =
triggerSelf = true,
customConnCallbacks = some(
CustomConnectionCallbacks(
customConnCreationCB: mixConn, customPeerSelectionCB: mixPeerSelect
customConnCreationCB: mixConnCb, customPeerSelectionCB: mixPeerSelect
)
),
)

View File

@@ -111,6 +111,17 @@ proc oneNode(node: Node, rcvdCnt: ptr Atomic[int]) {.async.} =
await sleepAsync(1000.milliseconds)
await node.switch.stop()
proc makeMixConnCb(mixProto: MixProtocol): CustomConnCreationProc =
return proc(
destAddr: Option[MultiAddress], destPeerId: PeerId, codec: string
): Connection {.gcsafe, raises: [].} =
try:
return mixProto.toConnection(destPeerId, Opt.none(MultiAddress), codec)
except CatchableError as e:
error "Error during execution of MixEntryConnection callback: ", err = e.msg
return nil
proc mixnet_gossipsub_test(): Future[int] {.async: (raises: [Exception]).} =
let
numberOfNodes = 5
@@ -124,14 +135,7 @@ proc mixnet_gossipsub_test(): Future[int] {.async: (raises: [Exception]).} =
error "Mix protocol initialization failed", err = error
return
let mixConn = proc(
destAddr: Option[MultiAddress], destPeerId: PeerId, codec: string
): Connection {.gcsafe, raises: [].} =
try:
return mixProto.toConnection(destPeerId, Opt.none(MultiAddress), codec)
except CatchableError as e:
error "Error during execution of MixEntryConnection callback: ", err = e.msg
return nil
let mixConnCb = makeMixConnCb(mixProto)
let mixPeerSelect = proc(
allPeers: HashSet[PubSubPeer],
@@ -150,7 +154,7 @@ proc mixnet_gossipsub_test(): Future[int] {.async: (raises: [Exception]).} =
triggerSelf = true,
customConnCallbacks = some(
CustomConnectionCallbacks(
customConnCreationCB: mixConn, customPeerSelectionCB: mixPeerSelect
customConnCreationCB: mixConnCb, customPeerSelectionCB: mixPeerSelect
)
),
)