private bool DecodeHeader(AlternativeCompositeByteBuf buffer, IPEndPoint recipient, IPEndPoint sender) { if (Message == null) { if (buffer.ReadableBytes < MessageHeaderCodec.HeaderSize) { // we don't have the header yet, we need the full header first // wait for more data return(false); } Message = MessageHeaderCodec.DecodeHeader(buffer, recipient, sender); // we have set the content types already Message.SetPresetContentTypes(true); foreach (var content in Message.ContentTypes) { if (content == Message.Content.Empty) { break; } if (content == Message.Content.PublicKeySignature) { Message.SetHintSign(); } _contentTypes.Enqueue(content); } Logger.Debug("Parsed message {0}.", Message); return(true); } return(false); }
public bool Write(AlternativeCompositeByteBuf buffer, Message message, ISignatureCodec signatureCodec) { Message = message; Logger.Debug("Message for outbound {0}.", message); if (!_header) { MessageHeaderCodec.EncodeHeader(buffer, message); _header = true; } else { Logger.Debug("Send a follow-up message {0}.", message); _resume = true; } bool done = Loop(buffer); Logger.Debug("Message encoded {0}.", message); // write out what we have if (buffer.IsReadable && done) { // check if message needs to be signed if (message.IsSign) { // we sign if we did not provide a signature already if (signatureCodec == null) { signatureCodec = _signatureFactory.Sign(message.PrivateKey, buffer); } // in case of relay, we have a signature, so we need to resuse this signatureCodec.Write(buffer); } } return(done); }