Skip to content

Commit

Permalink
fix: nph
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-ramos committed Feb 19, 2025
1 parent 63c2533 commit 1456bcf
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
11 changes: 8 additions & 3 deletions libp2p/daemon/daemonapi.nim
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ type
): Future[bool] {.gcsafe, raises: [CatchableError].}
P2PPubSubCallback2* = proc(
api: DaemonAPI, ticket: PubsubTicket, message: PubSubMessage
): Future[bool] {.async:(raises: [CatchableError]).}
): Future[bool] {.async: (raises: [CatchableError]).}
DaemonError* = object of LPError
DaemonRemoteError* = object of DaemonError
DaemonLocalError* = object of DaemonError
Expand Down Expand Up @@ -1512,9 +1512,14 @@ proc pubsubSubscribe*(

proc pubsubSubscribe*(
api: DaemonAPI, topic: string, handler: P2PPubSubCallback
): Future[PubsubTicket] {.async: (raises: [CatchableError]), deprecated: "Use P2PPubSubCallback2 instead".} =
proc wrap(api: DaemonAPI, ticket: PubsubTicket, message: PubSubMessage): Future[bool] {.async:(raises: [CatchableError]).} =
): Future[PubsubTicket] {.
async: (raises: [CatchableError]), deprecated: "Use P2PPubSubCallback2 instead"
.} =
proc wrap(
api: DaemonAPI, ticket: PubsubTicket, message: PubSubMessage
): Future[bool] {.async: (raises: [CatchableError]).} =
await handler(api, ticket, message)

await pubsubSubscribe(api, topic, wrap)

proc shortLog*(pinfo: PeerInfo): string =
Expand Down
4 changes: 3 additions & 1 deletion libp2p/protocols/pubsub/pubsub.nim
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,9 @@ method getOrCreatePeer*(
peer[].codec = protoNegotiated
return peer[]

proc getConn(): Future[Connection] {.async: (raises: [CancelledError, GetConnDialError]).} =
proc getConn(): Future[Connection] {.
async: (raises: [CancelledError, GetConnDialError])
.} =
try:
return await p.switch.dial(peerId, protosToDial)
except CancelledError as exc:
Expand Down
8 changes: 4 additions & 4 deletions libp2p/protocols/pubsub/pubsubpeer.nim
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ type
PubSubPeerEvent* = object
kind*: PubSubPeerEventKind

GetConn* = proc(): Future[Connection] {.async: (raises: [CancelledError, GetConnDialError]).}
GetConn* =
proc(): Future[Connection] {.async: (raises: [CancelledError, GetConnDialError]).}
DropConn* = proc(peer: PubSubPeer) {.gcsafe, raises: [].}
# have to pass peer as it's unknown during init
OnEvent* = proc(peer: PubSubPeer, event: PubSubPeerEvent) {.gcsafe, raises: [].}
Expand Down Expand Up @@ -123,9 +124,8 @@ type
# The max number of elements allowed in the non-priority queue.
disconnected: bool

RPCHandler* = proc(peer: PubSubPeer, data: seq[byte]): Future[void] {.
async: (raises: [])
.}
RPCHandler* =
proc(peer: PubSubPeer, data: seq[byte]): Future[void] {.async: (raises: []).}

when defined(libp2p_agents_metrics):
func shortAgent*(p: PubSubPeer): string =
Expand Down
6 changes: 4 additions & 2 deletions tests/pubsub/utils.nim
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ randomize()
type TestGossipSub* = ref object of GossipSub

proc getPubSubPeer*(p: TestGossipSub, peerId: PeerId): PubSubPeer =
proc getConn(): Future[Connection] {.async: (raises: [CancelledError, GetConnDialError]).} =
try:
proc getConn(): Future[Connection] {.
async: (raises: [CancelledError, GetConnDialError])
.} =
try:
return await p.switch.dial(peerId, GossipSubCodec_12)
except CancelledError as exc:
raise exc
Expand Down

0 comments on commit 1456bcf

Please sign in to comment.