Beispiel #1
0
 static void Validated(BaseWebSocketConnection baseConnection)
 {
     lock (baseConnection)
     {
         Global.ExtensionsManager.ConnectionValidated(baseConnection);
         var connection = (AlphaWebSocketConnection)baseConnection;
         AddConnection(connection);
     }
 }
Beispiel #2
0
        private void ExtensionsManager_OnConnectionValidated(BaseWebSocketConnection connection)
        {
            var currentDate = DateTime.UtcNow;

            if (BanCandidatesManager.RegisterViolation(connection.ClientPubKey?.ToString()))
            {
                BannedClientsManager.RegisterBan(connection.Ip, currentDate);
                BannedClientsManager.RegisterBan(connection.ClientPubKey?.ToString(), currentDate);
                throw new ConnectionCloseException(WebSocketCloseStatus.PolicyViolation, "Too many connections.");
            }
            else if (BannedClientsManager.IsClientBanned(connection.Ip, currentDate) ||
                     BannedClientsManager.IsClientBanned(connection.ClientPubKey?.ToString(), currentDate))
            {
                throw new ConnectionCloseException(WebSocketCloseStatus.PolicyViolation, "This client is banned.");
            }
        }
Beispiel #3
0
        private void ExtensionsManager_OnHandleMessageFailed(BaseWebSocketConnection connection, MessageEnvelope envelope, Exception exception)
        {
            var currentDate = DateTime.UtcNow;

            if (exception is BaseClientException && //bad requests, forbidden, too many requests etc.
                BanCandidatesManager.RegisterViolation(connection.Ip, connection.ClientPubKey?.ToString()))    //riched max allowed violation count
            {
                BannedClientsManager.RegisterBan(connection.Ip, currentDate);
                BannedClientsManager.RegisterBan(connection.ClientPubKey?.ToString(), currentDate);
                throw new ConnectionCloseException(WebSocketCloseStatus.PolicyViolation, "Too many invalid messages.");
            }
            else if (BannedClientsManager.IsClientBanned(connection.Ip, currentDate) ||
                     BannedClientsManager.IsClientBanned(connection.ClientPubKey?.ToString(), currentDate))
            {
                throw new ConnectionCloseException(WebSocketCloseStatus.PolicyViolation, "This client is banned.");
            }
        }
 /// <summary>
 /// Handles message
 /// </summary>
 /// <param name="messageEnvelope">The current message envelope</param>
 /// <returns>Handle result</returns>
 public abstract Task HandleMessage(BaseWebSocketConnection connection, IncomingMessage message);
 /// <summary>
 /// Validates authentication, connection state and message.
 /// </summary>
 /// <param name="envelope">The current message envelope</param>
 public abstract Task Validate(BaseWebSocketConnection connection, IncomingMessage message);
Beispiel #6
0
 public void BeforeConnectionClose(BaseWebSocketConnection args)
 {
     OnBeforeConnectionClose?.Invoke(args);
 }
Beispiel #7
0
 public void SendMessageFailed(BaseWebSocketConnection connection, MessageEnvelope message, Exception exception)
 {
     OnSendMessageFailed?.Invoke(connection, message, exception);
 }
Beispiel #8
0
 public void AfterSendMessage(BaseWebSocketConnection connection, MessageEnvelope message)
 {
     OnAfterSendMessage?.Invoke(connection, message);
 }
Beispiel #9
0
 public void ConnectionValidated(BaseWebSocketConnection args)
 {
     OnConnectionValidated?.Invoke(args);
 }
Beispiel #10
0
 public void BeforeHandleMessage(BaseWebSocketConnection connection, MessageEnvelope message)
 {
     OnBeforeHandleMessage?.Invoke(connection, message);
 }