mirror of
https://github.com/vacp2p/nim-libp2p.git
synced 2025-03-01 16:40:32 +00:00
refactor(pubsub): do not raise exceptions on publish (#1244)
This commit is contained in:
parent
a4f0a638e7
commit
78a4344054
@ -194,7 +194,7 @@ method init*(f: FloodSub) =
|
|||||||
|
|
||||||
method publish*(
|
method publish*(
|
||||||
f: FloodSub, topic: string, data: seq[byte]
|
f: FloodSub, topic: string, data: seq[byte]
|
||||||
): Future[int] {.async: (raises: [LPError]).} =
|
): Future[int] {.async: (raises: []).} =
|
||||||
# base returns always 0
|
# base returns always 0
|
||||||
discard await procCall PubSub(f).publish(topic, data)
|
discard await procCall PubSub(f).publish(topic, data)
|
||||||
|
|
||||||
|
@ -705,7 +705,7 @@ method onTopicSubscription*(g: GossipSub, topic: string, subscribed: bool) =
|
|||||||
|
|
||||||
method publish*(
|
method publish*(
|
||||||
g: GossipSub, topic: string, data: seq[byte]
|
g: GossipSub, topic: string, data: seq[byte]
|
||||||
): Future[int] {.async: (raises: [LPError]).} =
|
): Future[int] {.async: (raises: []).} =
|
||||||
logScope:
|
logScope:
|
||||||
topic
|
topic
|
||||||
|
|
||||||
|
@ -555,7 +555,7 @@ proc subscribe*(p: PubSub, topic: string, handler: TopicHandler) {.public.} =
|
|||||||
|
|
||||||
method publish*(
|
method publish*(
|
||||||
p: PubSub, topic: string, data: seq[byte]
|
p: PubSub, topic: string, data: seq[byte]
|
||||||
): Future[int] {.base, async: (raises: [LPError]), public.} =
|
): Future[int] {.base, async: (raises: []), public.} =
|
||||||
## publish to a ``topic``
|
## publish to a ``topic``
|
||||||
##
|
##
|
||||||
## The return value is the number of neighbours that we attempted to send the
|
## The return value is the number of neighbours that we attempted to send the
|
||||||
|
@ -65,7 +65,10 @@ proc init*(
|
|||||||
topic: string,
|
topic: string,
|
||||||
seqno: Option[uint64],
|
seqno: Option[uint64],
|
||||||
sign: bool = true,
|
sign: bool = true,
|
||||||
): Message {.gcsafe, raises: [LPError].} =
|
): Message {.gcsafe, raises: [].} =
|
||||||
|
if sign and peer.isNone():
|
||||||
|
doAssert(false, "Cannot sign message without peer info")
|
||||||
|
|
||||||
var msg = Message(data: data, topic: topic)
|
var msg = Message(data: data, topic: topic)
|
||||||
|
|
||||||
# order matters, we want to include seqno in the signature
|
# order matters, we want to include seqno in the signature
|
||||||
@ -81,9 +84,6 @@ proc init*(
|
|||||||
.expect("Invalid private key!")
|
.expect("Invalid private key!")
|
||||||
.getBytes()
|
.getBytes()
|
||||||
.expect("Couldn't get public key bytes!")
|
.expect("Couldn't get public key bytes!")
|
||||||
else:
|
|
||||||
if sign:
|
|
||||||
raise (ref LPError)(msg: "Cannot sign message without peer info")
|
|
||||||
|
|
||||||
msg
|
msg
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user