fix (directchat): auto disconnect self once conn closed (#663)

When closing a connection of clientA(using the command “/disconnect”), the connection is then closed on clientA’s side. However, the connection remained open on clientB and clientB could continue sending message to clientA and clientA would receive those messages.

This PR listens for a closing connection on clientB, then also closes clientB’s connection.
This commit is contained in:
Eric Mastro 2021-12-02 23:45:55 +11:00 committed by GitHub
parent b8c54068a3
commit c19b966d23
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 2 deletions

View File

@ -79,7 +79,9 @@ proc handlePeer(c: Chat, conn: Connection) {.async.} =
c.writeStdout $conn.peerId & ": " & $str
except LPStreamEOFError:
c.writeStdout $conn.peerId & " disconnected"
defer: c.writeStdout $conn.peerId & " disconnected"
await c.conn.close()
c.connected = false
proc dialPeer(c: Chat, address: string) {.async.} =
# Parse and dial address
@ -130,7 +132,7 @@ proc readLoop(c: Chat) {.async.} =
await c.switch.stop()
c.writeStdout "quitting..."
quit(0)
return
else:
if c.connected:
await c.conn.writeLp(line)
@ -189,5 +191,6 @@ proc main() {.async.} =
await chat.readLoop()
await allFuturesThrowing(libp2pFuts)
quit(0)
waitFor(main())