Пример #1
0
        public void onReceivedElement(ByteBuffer element)
        {
            LpPacket lpPacket = null;

            if (element.get(0) == net.named_data.jndn.encoding.tlv.Tlv.LpPacket_LpPacket)
            {
                // Decode the LpPacket and replace element with the fragment.
                lpPacket = new LpPacket();
                // Set copy false so that the fragment is a slice which will be copied below.
                // The header fields are all integers and don't need to be copied.
                net.named_data.jndn.encoding.TlvWireFormat.get().decodeLpPacket(lpPacket, element, false);
                element = lpPacket.getFragmentWireEncoding().buf();
            }

            // First, decode as Interest or Data.
            Interest interest = null;
            Data     data     = null;

            if (element.get(0) == net.named_data.jndn.encoding.tlv.Tlv.Interest || element.get(0) == net.named_data.jndn.encoding.tlv.Tlv.Data)
            {
                TlvDecoder decoder = new TlvDecoder(element);
                if (decoder.peekType(net.named_data.jndn.encoding.tlv.Tlv.Interest, element.remaining()))
                {
                    interest = new Interest();
                    interest.wireDecode(element, net.named_data.jndn.encoding.TlvWireFormat.get());

                    if (lpPacket != null)
                    {
                        interest.setLpPacket(lpPacket);
                    }
                }
                else if (decoder.peekType(net.named_data.jndn.encoding.tlv.Tlv.Data, element.remaining()))
                {
                    data = new Data();
                    data.wireDecode(element, net.named_data.jndn.encoding.TlvWireFormat.get());

                    if (lpPacket != null)
                    {
                        data.setLpPacket(lpPacket);
                    }
                }
            }

            if (lpPacket != null)
            {
                // We have decoded the fragment, so remove the wire encoding to save memory.
                lpPacket.setFragmentWireEncoding(new Blob());

                NetworkNack networkNack = net.named_data.jndn.NetworkNack.getFirstHeader(lpPacket);
                if (networkNack != null)
                {
                    if (interest == null)
                    {
                        // We got a Nack but not for an Interest, so drop the packet.
                        return;
                    }

                    ArrayList <PendingInterestTable.Entry> pitEntries = new ArrayList <PendingInterestTable.Entry>();
                    pendingInterestTable_.extractEntriesForNackInterest(interest,
                                                                        pitEntries);
                    for (int i = 0; i < pitEntries.Count; ++i)
                    {
                        PendingInterestTable.Entry pendingInterest = pitEntries[i];
                        try {
                            pendingInterest.getOnNetworkNack().onNetworkNack(
                                pendingInterest.getInterest(), networkNack);
                        } catch (Exception ex) {
                            logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onNack", ex);
                        }
                    }

                    // We have processed the network Nack packet.
                    return;
                }
            }

            // Now process as Interest or Data.
            if (interest != null)
            {
                dispatchInterest(interest);
            }
            else if (data != null)
            {
                satisfyPendingInterests(data);
            }
        }
Пример #2
0
        public void onReceivedElement(ByteBuffer element)
        {
            LpPacket lpPacket = null;

            if (element.get(0) == net.named_data.jndn.encoding.tlv.Tlv.LpPacket_LpPacket)
            {
                // Decode the LpPacket and replace element with the fragment.
                lpPacket = new LpPacket();
                net.named_data.jndn.encoding.TlvWireFormat.get().decodeLpPacket(lpPacket, element);
                element = lpPacket.getFragmentWireEncoding().buf();
            }

            // First, decode as Interest or Data.
            Interest interest = null;
            Data     data     = null;

            if (element.get(0) == net.named_data.jndn.encoding.tlv.Tlv.Interest || element.get(0) == net.named_data.jndn.encoding.tlv.Tlv.Data)
            {
                TlvDecoder decoder = new TlvDecoder(element);
                if (decoder.peekType(net.named_data.jndn.encoding.tlv.Tlv.Interest, element.remaining()))
                {
                    interest = new Interest();
                    interest.wireDecode(element, net.named_data.jndn.encoding.TlvWireFormat.get());

                    if (lpPacket != null)
                    {
                        interest.setLpPacket(lpPacket);
                    }
                }
                else if (decoder.peekType(net.named_data.jndn.encoding.tlv.Tlv.Data, element.remaining()))
                {
                    data = new Data();
                    data.wireDecode(element, net.named_data.jndn.encoding.TlvWireFormat.get());

                    if (lpPacket != null)
                    {
                        data.setLpPacket(lpPacket);
                    }
                }
            }

            if (lpPacket != null)
            {
                // We have decoded the fragment, so remove the wire encoding to save memory.
                lpPacket.setFragmentWireEncoding(new Blob());

                NetworkNack networkNack = net.named_data.jndn.NetworkNack.getFirstHeader(lpPacket);
                if (networkNack != null)
                {
                    if (interest == null)
                    {
                        // We got a Nack but not for an Interest, so drop the packet.
                        return;
                    }

                    ArrayList <PendingInterestTable.Entry> pitEntries = new ArrayList <PendingInterestTable.Entry>();
                    pendingInterestTable_.extractEntriesForNackInterest(interest,
                                                                        pitEntries);
                    for (int i = 0; i < pitEntries.Count; ++i)
                    {
                        PendingInterestTable.Entry pendingInterest = pitEntries[i];
                        try {
                            pendingInterest.getOnNetworkNack().onNetworkNack(
                                pendingInterest.getInterest(), networkNack);
                        } catch (Exception ex) {
                            logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onNack", ex);
                        }
                    }

                    // We have process the network Nack packet.
                    return;
                }
            }

            // Now process as Interest or Data.
            if (interest != null)
            {
                // Quickly lock and get all interest filter callbacks which match.
                ArrayList matchedFilters = new ArrayList();
                interestFilterTable_.getMatchedFilters(interest, matchedFilters);

                // The lock on interestFilterTable_ is released, so call the callbacks.
                for (int i_0 = 0; i_0 < matchedFilters.Count; ++i_0)
                {
                    InterestFilterTable.Entry entry = (InterestFilterTable.Entry)matchedFilters[i_0];
                    try {
                        entry.getOnInterest().onInterest(
                            entry.getFilter().getPrefix(), interest,
                            entry.getFace(), entry.getInterestFilterId(),
                            entry.getFilter());
                    } catch (Exception ex_1) {
                        logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onInterest", ex_1);
                    }
                }
            }
            else if (data != null)
            {
                ArrayList <PendingInterestTable.Entry> pitEntries_2 = new ArrayList <PendingInterestTable.Entry>();
                pendingInterestTable_.extractEntriesForExpressedInterest(
                    data.getName(), pitEntries_2);
                for (int i_3 = 0; i_3 < pitEntries_2.Count; ++i_3)
                {
                    PendingInterestTable.Entry pendingInterest_4 = pitEntries_2[i_3];
                    try {
                        pendingInterest_4.getOnData().onData(
                            pendingInterest_4.getInterest(), data);
                    } catch (Exception ex_5) {
                        logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onData", ex_5);
                    }
                }
            }
        }