public void ReadFrom(ref SpanBufferReader bufferReader)
 {
     UserId    = bufferReader.ReadString();
     UserName  = bufferReader.ReadString();
     Random    = bufferReader.ReadBytes(32).ToArray();
     PublicKey = bufferReader.ReadVarBytes().ToArray();
     Secret    = bufferReader.ReadString();
     Code      = bufferReader.ReadString();
     Password  = bufferReader.ReadString();
     UseRelay  = bufferReader.ReadBool();
 }
        public void Signal(ISession session, ReadOnlySpan <byte> buffer)
        {
            var      bufferReader = new SpanBufferReader(buffer);
            IMessage message;

            try
            {
                var isEncrypted = bufferReader.ReadBool();
                if (isEncrypted)
                {
                    if (session.EncryptionParameters is null)
                    {
                        _logger.Warning(
                            "Received an encrypted messsage before any " +
                            "encryption parameters were established " +
                            $"(EndPoint='{session.EndPoint}')."
                            );
                        return;
                    }
                    message = _encryptedMessageReader.ReadFrom(
                        ref bufferReader,
                        session.EncryptionParameters.ReceiveKey,
                        session.EncryptionParameters.ReceiveMac,
                        PacketProperty
                        );
                }
                else
                {
                    message = _messageReader.ReadFrom(ref bufferReader, PacketProperty);
                }
            }
            catch (Exception e)
            {
                _logger.Warning(e, $"Failed to read message (EndPoint='{session.EndPoint}').");
                return;
            }
            Signal(session, message);
        }
Ejemplo n.º 3
0
 public void ReadFrom(ref SpanBufferReader bufferReader)
 {
     MessageHandled = bufferReader.ReadBool();
 }