private async void OnPeerDisconnected(object sender, DisconnectEventArgs e) { var peer = (IP2PSession)sender; peer.PeerDisconnected -= OnPeerDisconnected; if (_activePeers.TryRemove(peer.RemoteNodeId, out var removedPeer)) { removedPeer.NodeStats.AddNodeStatsDisconnectEvent(e.DisconnectType, e.DisconnectReason); if (removedPeer.SynchronizationPeer != null) { _synchronizationManager.RemovePeer(removedPeer.SynchronizationPeer); } if (_logger.IsInfoEnabled) { _logger.Info($"Removing Active Peer on disconnect {peer.RemoteNodeId.ToString(false)}"); } if (_isInitialized) { await RunPeerUpdate(); } } if (_newPeers.TryRemove(peer.RemoteNodeId, out removedPeer)) { removedPeer.NodeStats.AddNodeStatsDisconnectEvent(e.DisconnectType, e.DisconnectReason); if (_logger.IsInfoEnabled) { _logger.Info($"Removing New Peer on disconnect {peer.RemoteNodeId.ToString(false)}"); } } }
private void SessionDisconnected(object sender, DisconnectEventArgs e) { ISession session = (ISession)sender; session.Initialized -= SessionInitialized; session.Disconnected -= SessionDisconnected; if (_syncPeers.ContainsKey(session.SessionId)) { ISynchronizationPeer syncPeer = _syncPeers[session.SessionId]; _syncManager.RemovePeer(syncPeer); _transactionPool.RemovePeer(syncPeer.Node.Id); } _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)) { ISynchronizationPeer syncPeer = _syncPeers[session.SessionId]; _syncManager.RemovePeer(syncPeer); _transactionPool.RemovePeer(syncPeer.Node.Id); if (_logger.IsDebug) { _logger.Debug($"{session.Node.ClientId} sync peer {session} disconnected {e.DisconnectType} {e.DisconnectReason}"); } } _sessions.TryRemove(session.SessionId, out session); }
private async Task OnPeerDisconnected(object sender, DisconnectEventArgs e) { var peer = (IP2PSession)sender; if (_logger.IsInfoEnabled) { _logger.Info($"Peer disconnected event in PeerManager: {peer.RemoteNodeId}, disconnectReason: {e.DisconnectReason}, disconnectType: {e.DisconnectType}"); } if (_activePeers.TryGetValue(peer.RemoteNodeId, out var activePeer)) { if (activePeer.Session.SessionId != e.SessionId) { if (_logger.IsInfoEnabled) { _logger.Info($"Received disconnect on a different session than the active peer runs. Ignoring. Id: {activePeer.Node.Id}"); } //TODO verify we do not want to change reputation here return; } _activePeers.TryRemove(peer.RemoteNodeId, out _); activePeer.NodeStats.AddNodeStatsDisconnectEvent(e.DisconnectType, e.DisconnectReason); if (activePeer.SynchronizationPeer != null) { _synchronizationManager.RemovePeer(activePeer.SynchronizationPeer); } if (_logger.IsInfoEnabled) { _logger.Info($"Removing Active Peer on disconnect {peer.RemoteNodeId}"); } if (_isInitialized) { await RunPeerUpdate(); } } }