static void Validated(BaseWebSocketConnection baseConnection) { lock (baseConnection) { Global.ExtensionsManager.ConnectionValidated(baseConnection); var connection = (AlphaWebSocketConnection)baseConnection; AddConnection(connection); } }
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."); } }
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);
public void BeforeConnectionClose(BaseWebSocketConnection args) { OnBeforeConnectionClose?.Invoke(args); }
public void SendMessageFailed(BaseWebSocketConnection connection, MessageEnvelope message, Exception exception) { OnSendMessageFailed?.Invoke(connection, message, exception); }
public void AfterSendMessage(BaseWebSocketConnection connection, MessageEnvelope message) { OnAfterSendMessage?.Invoke(connection, message); }
public void ConnectionValidated(BaseWebSocketConnection args) { OnConnectionValidated?.Invoke(args); }
public void BeforeHandleMessage(BaseWebSocketConnection connection, MessageEnvelope message) { OnBeforeHandleMessage?.Invoke(connection, message); }