Skip to content

Commit

Permalink
ConnectionManager: Actually keep track of outputStreams and use Conso…
Browse files Browse the repository at this point in the history
…le.err.println
  • Loading branch information
ckuessner committed Jul 4, 2024
1 parent 9fb1e8a commit a43ff05
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class ConnectionManager[MSG](
case Failure(exception) =>
exception.printStackTrace()
running = false
sys.error("Stopping listener")
Console.err.println("Stopping listener")
case Success((socket, peerIdentity)) =>
if peerIdentity == localPublicId
then // We don't want to connect to ourselves.
Expand Down Expand Up @@ -135,7 +135,7 @@ class ConnectionManager[MSG](
if expectedUser == peerId
then connectionEstablished(socket, peerId, establishedByRemote = false)
else {
sys.error(s"Expecting $expectedUser at $host:$port but connected to $peerId. Closing socket.")
Console.err.println(s"Expecting $expectedUser at $host:$port but connected to $peerId. Closing socket.")
try {
socket.close()
} catch
Expand Down Expand Up @@ -166,6 +166,7 @@ class ConnectionManager[MSG](
|| !establishedByRemote && peerIdentity.id < localPublicId.id
then
connections = connections.updated(peerIdentity, socket)
outputStreams = outputStreams.updated(peerIdentity, DataOutputStream(socket.getOutputStream))
try {
existingConnection.close()
messageHandler.connectionShutdown(peerIdentity)
Expand All @@ -178,6 +179,7 @@ class ConnectionManager[MSG](
} catch { case e: IOException => }
case None =>
connections = connections.updated(peerIdentity, socket)
outputStreams = outputStreams.updated(peerIdentity, DataOutputStream(socket.getOutputStream))
receiveFrom(peerIdentity, socket)
}
}
Expand Down Expand Up @@ -207,6 +209,7 @@ class ConnectionManager[MSG](
if storedSocket eq socket // Only remove and notify if this socket wasn't already replaced
then
connections = connections.removed(peerIdentity)
outputStreams = outputStreams.removed(peerIdentity)
messageHandler.connectionShutdown(peerIdentity)
case None =>
}
Expand Down

0 comments on commit a43ff05

Please sign in to comment.