private void SessionDisconnected(object sender, DisconnectEventArgs e) { ISession session = (ISession)sender; session.Initialized -= SessionInitialized; session.Disconnected -= SessionDisconnected; if (_syncPeers.ContainsKey(session.SessionId)) { ISyncPeer syncPeer = _syncPeers[session.SessionId]; _syncPool.RemovePeer(syncPeer); _txPool.RemovePeer(syncPeer.Node.Id); if (session.BestStateReached == SessionState.Initialized) { if (_logger.IsDebug) { _logger.Debug($"{session.Direction} {session.Node:s} disconnected {e.DisconnectType} {e.DisconnectReason} {e.Details}"); } } _syncPeers.TryRemove(session.SessionId, out _); } _sessions.TryRemove(session.SessionId, out session); }
private void SessionDisconnected(object sender, DisconnectEventArgs e) { ISession session = (ISession)sender; session.Initialized -= SessionInitialized; session.Disconnected -= SessionDisconnected; if (_syncPeers.ContainsKey(session.SessionId)) { ISyncPeer syncPeer = _syncPeers[session.SessionId]; _syncPool.RemovePeer(syncPeer, EthSyncPeerPool.PeerRemoveReason.SessionDisconnected); _txPool.RemovePeer(syncPeer.Node.Id); if (_logger.IsInfo) { _logger.Info($"{session.Direction} {session.Node:s} disconnected {e.DisconnectType} {e.DisconnectReason}"); } } _sessions.TryRemove(session.SessionId, out session); }
public async Task Cannot_remove_when_stopped() { _pool.Start(); ISyncPeer[] syncPeers = new ISyncPeer[3]; for (int i = 0; i < 3; i++) { syncPeers[i] = new SimpleSyncPeerMock(TestItem.PublicKeys[i]); _pool.AddPeer(syncPeers[i]); } await _pool.StopAsync(); for (int i = 3; i > 0; i--) { Assert.AreEqual(3, _pool.PeerCount, $"Remove {i}"); _pool.RemovePeer(syncPeers[i - 1]); } }