Example #1
0
        private Task UpdatePeerStatistics(PeerEventBase peerEvent, CancellationToken cancellation)
        {
            PeerStatistics statistics = GetPeerStatistics(peerEvent.PeerEndPoint);

            switch (peerEvent)
            {
            case PeerConnected @event:
                statistics.Inbound = @event.Inbound;
                statistics.LogEvent($"Peer Connected");
                break;

            case PeerConnectionAttempt @event:
                statistics.Inbound = @event.Inbound;
                statistics.LogEvent($"Attempting Connection");
                break;

            case PeerConnectionAttemptFailed @event:
                statistics.Inbound = @event.Inbound;
                statistics.LogEvent($"Connection attempt FAILED. Reason: {@event.Reason}.");
                break;

            case PeerDisconnected @event:
                statistics.Inbound = @event.Inbound;
                statistics.LogEvent($"Disconnected. Reason: {@event.Reason}. Exception: {@event.Exception?.ToString()}");
                break;

            case PeerMessageReceived @event:
                statistics.ReceivedMessages++;
                statistics.BytesReceived += @event.MessageSize;
                statistics.LogEvent($"Message Received: {@event.Message.Payload.Command}");
                break;

            case PeerMessageSent @event:
                statistics.SentMessages++;
                statistics.BytesSent += @event.Size;
                statistics.LogEvent($"Message Sent: {@event.Message.Payload.Command}");
                break;

            case PeerMessageSendFailure @event:
                statistics.LogEvent($"Message Send Failure: {@event.Message?.Payload.Command}. Exception: {@event.Exception?.ToString()}");
                break;
            }

            return(Task.CompletedTask);
        }
Example #2
0
 private void EnqueuePeerEvent(PeerEventBase @event)
 {
     this.peersEventsQueue.Enqueue(@event);
 }