mirror of
https://github.com/vacp2p/nim-libp2p-experimental.git
synced 2025-02-05 06:44:12 +00:00
better
This commit is contained in:
parent
6b19ff15dd
commit
0f73ce0ea9
@ -174,7 +174,7 @@ proc connectOnce(p: PubSubPeer): Future[void] {.async.} =
|
|||||||
try:
|
try:
|
||||||
if p.connectedFut.finished:
|
if p.connectedFut.finished:
|
||||||
p.connectedFut = newFuture[void]()
|
p.connectedFut = newFuture[void]()
|
||||||
let newConn = await p.getConn().withTimeout(5.seconds)
|
let newConn = await p.getConn().wait(5.seconds)
|
||||||
if newConn.isNil:
|
if newConn.isNil:
|
||||||
raise (ref LPError)(msg: "Cannot establish send connection")
|
raise (ref LPError)(msg: "Cannot establish send connection")
|
||||||
|
|
||||||
@ -201,6 +201,9 @@ proc connectOnce(p: PubSubPeer): Future[void] {.async.} =
|
|||||||
await p.sendConn.close()
|
await p.sendConn.close()
|
||||||
p.sendConn = nil
|
p.sendConn = nil
|
||||||
|
|
||||||
|
if not p.connectedFut.finished:
|
||||||
|
p.connectedFut.complete()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if p.onEvent != nil:
|
if p.onEvent != nil:
|
||||||
p.onEvent(p, PubSubPeerEvent(kind: PubSubPeerEventKind.Disconnected))
|
p.onEvent(p, PubSubPeerEvent(kind: PubSubPeerEventKind.Disconnected))
|
||||||
@ -249,11 +252,13 @@ proc sendEncoded*(p: PubSubPeer, msg: seq[byte]) {.raises: [Defect], async.} =
|
|||||||
return
|
return
|
||||||
|
|
||||||
if p.sendConn == nil:
|
if p.sendConn == nil:
|
||||||
discard await p.connectedFut.withTimeout(1.seconds)
|
# Wait for a send conn to be setup. `connectOnce` will
|
||||||
|
# complete this even if the sendConn setup failed
|
||||||
|
await p.connectedFut
|
||||||
|
|
||||||
var conn = p.sendConn
|
var conn = p.sendConn
|
||||||
if conn == nil or conn.closed():
|
if conn == nil or conn.closed():
|
||||||
debug "No send connection, skipping message", p, msg = shortLog(msg)
|
debug "No send connection", p, msg = shortLog(msg)
|
||||||
return
|
return
|
||||||
|
|
||||||
trace "sending encoded msgs to peer", conn, encoded = shortLog(msg)
|
trace "sending encoded msgs to peer", conn, encoded = shortLog(msg)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user