private bool Validate(Packet packet) { int requestLength = 2 + connectKeyValidator.KeyLength; if (packet.length < requestLength) { return(false); } // todo do security stuff here: // - connect request // - simple key/phrase send from client with first message // - hashcash?? // - white/black list for endpoint? if (packet.type != PacketType.Command) { return(false); } if (packet.command != Commands.ConnectRequest) { return(false); } if (!connectKeyValidator.Validate(packet.buffer.array)) { return(false); } //if (!hashCashValidator.Validate(packet)) // return false; return(true); }
private void HandleNewConnection(IEndPoint endPoint, Packet packet) { // if invalid, then reject without reason if (!Validate(packet)) { return; } if (!_connectKeyValidator.Validate(packet.Buffer.array)) { RejectConnectionWithReason(endPoint, RejectReason.KeyInvalid); } else if (AtMaxConnections()) { RejectConnectionWithReason(endPoint, RejectReason.ServerFull); } // todo do other security stuff here: // - white/black list for endpoint? // (maybe a callback for developers to use?) else { AcceptNewConnection(endPoint); } }