Ejemplo n.º 1
0
        public bool Decode(ChannelHandlerContext ctx, AlternativeCompositeByteBuf buffer, IPEndPoint recipient, IPEndPoint sender)
        {
            Logger.Debug("Decoding of TomP2P starts now. Readable: {0}.", buffer.ReadableBytes);

            try
            {
                long readerBefore = buffer.ReaderIndex;
                // set the sender of this message for handling timeout
                var attrInetAddr = ctx.Attr(InetAddressKey);
                attrInetAddr.Set(sender);

                if (Message == null)
                {
                    bool doneHeader = DecodeHeader(buffer, recipient, sender);
                    if (doneHeader)
                    {
                        // store the sender as an attribute
                        var attrPeerAddr = ctx.Attr(PeerAddressKey);
                        attrPeerAddr.Set(Message.Sender);

                        Message.SetIsUdp(ctx.Channel.IsUdp);
                        if (Message.IsFireAndForget() && Message.IsUdp)
                        {
                            TimeoutFactory.RemoveTimeout(ctx);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }

                bool donePayload = DecodePayload(buffer);
                //DecodeSignature(buffer, readerBefore, donePayload);

                // TODO discardSomeReadBytes -> performance improvement
                return(donePayload);
            }
            catch (Exception ex)
            {
                ctx.FireExceptionCaught(ex);
                Console.WriteLine(ex.ToString());
                return(true);
            }
        }