Skip to content

Commit

Permalink
Identify Update
Browse files Browse the repository at this point in the history
  • Loading branch information
erwin-kok committed Sep 6, 2023
1 parent 89a7d2c commit ac7301a
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,22 @@ class NetworkPeer(
statistics.direction = direction
statistics.opened = Instant.now()
connections.withLock {
val connection = SwarmConnection(scope, transportConnection, swarm, resourceManager, streamHandler, nextConnectionId())
val connection = SwarmConnection(scope, transportConnection, resourceManager, streamHandler, nextConnectionId()) {
swarm.removeConnection(it)
}
connections.add(connection)
return Ok(connection)
}
}

fun removeConnection(connection: SwarmConnection) {
connections.remove(connection)
connections.withLock {
connections.remove(connection)
}
}

fun connections(): List<SwarmConnection> {
return connections.toList()
return connections.withLock { connections.toList() }
}

fun connectedness(): Connectedness {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,6 @@ class Swarm(
_context.complete()
}

internal fun removeConnection(swarmConnection: SwarmConnection) {
getPeer(swarmConnection.remoteIdentity.peerId)?.removeConnection(swarmConnection)
notifyAll { subscriber -> subscriber.disconnected(this, swarmConnection) }
}

private fun bestConnectionToPeer(peerId: PeerId): SwarmConnection? {
return getPeer(peerId)?.bestConnectionToPeer()
}
Expand Down Expand Up @@ -204,6 +199,11 @@ class Swarm(
}
}

internal fun removeConnection(swarmConnection: SwarmConnection) {
getPeer(swarmConnection.remoteIdentity.peerId)?.removeConnection(swarmConnection)
notifyAll { subscriber -> subscriber.disconnected(this, swarmConnection) }
}

internal fun notifyAll(notify: (Subscriber) -> Unit) {
subscribersLock.withLock {
subscribers.toList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ private val logger = KotlinLogging.logger {}
class SwarmConnection(
scope: CoroutineScope,
private val transportConnection: TransportConnection,
private val swarm: Swarm,
private val resourceManager: ResourceManager,
private val streamHandler: StreamHandler?,
private val identifier: Long,
private val onClose: (SwarmConnection) -> Unit,
) : AwaitableClosable, NetworkConnection {
private val _context = Job()
private val _streams = closableLockedList<SwarmStream>()
Expand Down Expand Up @@ -136,7 +136,7 @@ class SwarmConnection(
transportConnection.close()
streams.forEach { it.reset() }
_context.complete()
swarm.removeConnection(this)
onClose(this)
}

private fun addStream(muxedStream: MuxedStream, direction: Direction, streamScope: StreamManagementScope): Result<Stream> {
Expand Down
2 changes: 1 addition & 1 deletion test-plans/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
</appender>

<!-- LOG everything at INFO level -->
<root level="debug">
<root level="info">
<appender-ref ref="Console"/>
</root>
</configuration>

0 comments on commit ac7301a

Please sign in to comment.