Beispiel #1
0
 private void Close(int disconnectReason)
 {
     if (Logger.IsTrace)
     {
         Logger.Trace($"{P2PSession.RemoteNodeId} P2P received disconnect on {P2PSession.RemotePort} ({RemoteClientId}) [{disconnectReason}]");
     }
     // Received disconnect message, triggering direct TCP disconnection
     P2PSession.DisconnectAsync((DisconnectReason)disconnectReason, DisconnectType.Remote);
 }
Beispiel #2
0
        protected void Send <T>(T message) where T : P2PMessage
        {
            if (Logger.IsTrace)
            {
                Logger.Trace($"Sending {typeof(T).Name}");
            }
            Packet packet = new Packet(message.Protocol, message.PacketType, _serializer.Serialize(message));

            P2PSession.DeliverMessage(packet);
        }
Beispiel #3
0
        protected async Task CheckProtocolInitTimeout()
        {
            var receivedInitMsgTask = _initCompletionSource.Task;
            var firstTask           = await Task.WhenAny(receivedInitMsgTask, Task.Delay(InitTimeout));

            if (firstTask != receivedInitMsgTask)
            {
                if (Logger.IsTrace)
                {
                    Logger.Trace($"Disconnecting due to timeout for protocol init message ({GetType().Name}): {P2PSession.RemoteNodeId}");
                }

                await P2PSession.InitiateDisconnectAsync(DisconnectReason.ReceiveMessageTimeout);
            }
        }
        private void Close(int disconnectReasonId)
        {
            DisconnectReason disconnectReason = (DisconnectReason)disconnectReasonId;

            if (disconnectReason != DisconnectReason.TooManyPeers && disconnectReason != DisconnectReason.Other && disconnectReason != DisconnectReason.DisconnectRequested)
            {
                if (Logger.IsDebug)
                {
                    Logger.Debug($"{P2PSession.RemoteNodeId} P2P received disconnect on {P2PSession.RemotePort} ({RemoteClientId}) [{disconnectReason}]");
                }
            }
            else
            {
                if (Logger.IsTrace)
                {
                    Logger.Trace($"{P2PSession.RemoteNodeId} P2P received disconnect on {P2PSession.RemotePort} ({RemoteClientId}) [{disconnectReason}]");
                }
            }

            switch (disconnectReason)
            {
            case DisconnectReason.BreachOfProtocol:
                Metrics.BreachOfProtocolDisconnects++;
                break;

            case DisconnectReason.UselessPeer:
                Metrics.UselessPeerDisconnects++;
                break;

            case DisconnectReason.TooManyPeers:
                Metrics.TooManyPeersDisconnects++;
                break;

            case DisconnectReason.AlreadyConnected:
                Metrics.AlreadyConnectedDisconnects++;
                break;

            case DisconnectReason.IncompatibleP2PVersion:
                Metrics.IncompatibleP2PDisconnects++;
                break;

            case DisconnectReason.NullNodeIdentityReceived:
                Metrics.NullNodeIdentityDisconnects++;
                break;

            case DisconnectReason.ClientQuitting:
                Metrics.ClientQuittingDisconnects++;
                break;

            case DisconnectReason.UnexpectedIdentity:
                Metrics.UnexpectedIdentityDisconnects++;
                break;

            case DisconnectReason.ReceiveMessageTimeout:
                Metrics.ReceiveMessageTimeoutDisconnects++;
                break;

            case DisconnectReason.DisconnectRequested:
                Metrics.DisconnectRequestedDisconnects++;
                break;

            case DisconnectReason.IdentitySameAsSelf:
                Metrics.SameAsSelfDisconnects++;
                break;

            case DisconnectReason.TcpSubSystemError:
                Metrics.TcpSubsystemErrorDisconnects++;
                break;

            default:
                Metrics.OtherDisconnects++;
                break;
            }

            // Received disconnect message, triggering direct TCP disconnection
            P2PSession.DisconnectAsync(disconnectReason, DisconnectType.Remote);
        }