Exemple #1
0
        /// <summary>
        /// Decode the input and update this Schedule object.
        /// </summary>
        ///
        /// <param name="input"></param>
        /// <exception cref="EncodingException">For invalid encoding.</exception>
        public void wireDecode(ByteBuffer input)
        {
            // For now, don't use WireFormat and hardcode to use TLV since the encoding
            // doesn't go out over the wire, only into the local SQL database.
            TlvDecoder decoder = new TlvDecoder(input);

            int endOffset = decoder.readNestedTlvsStart(net.named_data.jndn.encoding.tlv.Tlv.Encrypt_Schedule);

            // Decode the whiteIntervalList.
            ILOG.J2CsMapping.Collections.Collections.Clear(whiteIntervalList_);
            int listEndOffset = decoder
                                .readNestedTlvsStart(net.named_data.jndn.encoding.tlv.Tlv.Encrypt_WhiteIntervalList);

            while (decoder.getOffset() < listEndOffset)
            {
                ILOG.J2CsMapping.Collections.Collections.Add(whiteIntervalList_, decodeRepetitiveInterval(decoder));
            }
            decoder.finishNestedTlvs(listEndOffset);

            // Decode the blackIntervalList.
            ILOG.J2CsMapping.Collections.Collections.Clear(blackIntervalList_);
            listEndOffset = decoder
                            .readNestedTlvsStart(net.named_data.jndn.encoding.tlv.Tlv.Encrypt_BlackIntervalList);
            while (decoder.getOffset() < listEndOffset)
            {
                ILOG.J2CsMapping.Collections.Collections.Add(blackIntervalList_, decodeRepetitiveInterval(decoder));
            }
            decoder.finishNestedTlvs(listEndOffset);

            decoder.finishNestedTlvs(endOffset);
        }
Exemple #2
0
        /// <summary>
        /// Decode the input as an NDN-TLV RepetitiveInterval.
        /// </summary>
        ///
        /// <param name="decoder">The decoder with the input to decode.</param>
        /// <returns>A new RepetitiveInterval with the decoded result.</returns>
        private static RepetitiveInterval decodeRepetitiveInterval(
            TlvDecoder decoder)
        {
            int endOffset = decoder
                            .readNestedTlvsStart(net.named_data.jndn.encoding.tlv.Tlv.Encrypt_RepetitiveInterval);

            // Use Blob to convert UTF8 to a string.
            double startDate = fromIsoString(new Blob(
                                                 decoder.readBlobTlv(net.named_data.jndn.encoding.tlv.Tlv.Encrypt_StartDate), true).toString());
            double endDate = fromIsoString(new Blob(
                                               decoder.readBlobTlv(net.named_data.jndn.encoding.tlv.Tlv.Encrypt_EndDate), true).toString());
            int startHour = (int)decoder
                            .readNonNegativeIntegerTlv(net.named_data.jndn.encoding.tlv.Tlv.Encrypt_IntervalStartHour);
            int endHour = (int)decoder
                          .readNonNegativeIntegerTlv(net.named_data.jndn.encoding.tlv.Tlv.Encrypt_IntervalEndHour);
            int nRepeats = (int)decoder
                           .readNonNegativeIntegerTlv(net.named_data.jndn.encoding.tlv.Tlv.Encrypt_NRepeats);

            int repeatUnitCode = (int)decoder
                                 .readNonNegativeIntegerTlv(net.named_data.jndn.encoding.tlv.Tlv.Encrypt_RepeatUnit);

            RepetitiveInterval.RepeatUnit repeatUnit;
            if (repeatUnitCode == net.named_data.jndn.encrypt.RepetitiveInterval.RepeatUnit.NONE
                .getNumericType())
            {
                repeatUnit = net.named_data.jndn.encrypt.RepetitiveInterval.RepeatUnit.NONE;
            }
            else if (repeatUnitCode == net.named_data.jndn.encrypt.RepetitiveInterval.RepeatUnit.DAY
                     .getNumericType())
            {
                repeatUnit = net.named_data.jndn.encrypt.RepetitiveInterval.RepeatUnit.DAY;
            }
            else if (repeatUnitCode == net.named_data.jndn.encrypt.RepetitiveInterval.RepeatUnit.MONTH
                     .getNumericType())
            {
                repeatUnit = net.named_data.jndn.encrypt.RepetitiveInterval.RepeatUnit.MONTH;
            }
            else if (repeatUnitCode == net.named_data.jndn.encrypt.RepetitiveInterval.RepeatUnit.YEAR
                     .getNumericType())
            {
                repeatUnit = net.named_data.jndn.encrypt.RepetitiveInterval.RepeatUnit.YEAR;
            }
            else
            {
                throw new EncodingException(
                          "Unrecognized RepetitiveInterval RepeatUnit code: "
                          + repeatUnitCode);
            }

            decoder.finishNestedTlvs(endOffset);
            return(new RepetitiveInterval(startDate, endDate, startHour, endHour,
                                          nRepeats, repeatUnit));
        }
Exemple #3
0
        private static string DecodeBase64(string contentType, string payload, TlvDecoder tlvDecoder)
        {
            if (!string.IsNullOrEmpty(contentType))
            {
                if (contentType.Contains("tlv"))
                {
                    payload = tlvDecoder.DecodeTlvFromString(payload);
                }
                else
                {
                    var data = Convert.FromBase64String(payload ?? string.Empty);
                    payload = Encoding.UTF8.GetString(data);
                }
            }
            else
            {
                var data = Convert.FromBase64String(payload ?? string.Empty);
                payload = Encoding.UTF8.GetString(data);
            }

            return(payload);
        }
        wireDecode(ByteBuffer input)
        {
            clear();

            TlvDecoder decoder   = new TlvDecoder(input);
            int        endOffset = decoder.readNestedTlvsStart(ContentMetaInfo_ContentMetaInfo);

            // Set copy false since we just immediately get a string.
            Blob contentTypeText = new Blob
                                       (decoder.readBlobTlv(ContentMetaInfo_ContentType), false);

            contentType_ = contentTypeText.toString();
            timestamp_   = decoder.readNonNegativeIntegerTlv(ContentMetaInfo_Timestamp);
            hasSegments_ = decoder.readBooleanTlv
                               (ContentMetaInfo_HasSegments, endOffset);
            if (decoder.peekType(ContentMetaInfo_Other, endOffset))
            {
                other_ = new Blob(decoder.readBlobTlv(ContentMetaInfo_Other), true);
            }

            decoder.finishNestedTlvs(endOffset);
        }
Exemple #5
0
        /// <summary>
        /// Decode the input as an NDN-TLV SafeBag and update this object.
        /// </summary>
        ///
        /// <param name="input"></param>
        /// <exception cref="EncodingException">For invalid encoding.</exception>
        public void wireDecode(ByteBuffer input)
        {
            // Decode directly as TLV. We don't support the WireFormat abstraction
            // because this isn't meant to go directly on the wire.
            TlvDecoder decoder   = new TlvDecoder(input);
            int        endOffset = decoder.readNestedTlvsStart(net.named_data.jndn.encoding.tlv.Tlv.SafeBag_SafeBag);

            // Get the bytes of the certificate and decode.
            int certificateBeginOffset = decoder.getOffset();
            int certificateEndOffset   = decoder.readNestedTlvsStart(net.named_data.jndn.encoding.tlv.Tlv.Data);

            decoder.seek(certificateEndOffset);
            certificate_ = new Data();
            certificate_.wireDecode(
                decoder.getSlice(certificateBeginOffset, certificateEndOffset),
                net.named_data.jndn.encoding.TlvWireFormat.get());

            privateKeyBag_ = new Blob(
                decoder.readBlobTlv(net.named_data.jndn.encoding.tlv.Tlv.SafeBag_EncryptedKeyBag), true);

            decoder.finishNestedTlvs(endOffset);
        }
Exemple #6
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);
            }
        }
Exemple #7
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);
                    }
                }
            }
        }