Esempio n. 1
0
 /// <summary>
 /// Set this interest to use a copy of the given DelegationSet object as the
 /// forwarding hint.
 /// </summary>
 ///
 /// @note You can also call getForwardingHint and change the forwarding hint
 /// directly.
 /// <param name="forwardingHint">set to a new default DelegationSet() with no entries.</param>
 /// <returns>This Interest so that you can chain calls to update values.</returns>
 public Interest setForwardingHint(DelegationSet forwardingHint)
 {
     forwardingHint_.set((forwardingHint == null) ? new DelegationSet()
                                 : new DelegationSet(forwardingHint));
     ++changeCount_;
     return(this);
 }
Esempio n. 2
0
        /// <summary>
        /// Create a Link with the given name and default values and where the list of
        /// delegations is empty and the meta info type is LINK.
        /// </summary>
        ///
        /// <param name="name">The name which is copied.</param>
        public Link(Name name)
            : base(name)
        {
            this.delegations_ = new DelegationSet();

            getMetaInfo().setType(net.named_data.jndn.ContentType.LINK);
        }
Esempio n. 3
0
        /// <summary>
        /// Create a Link, copying values from the other Data object. If the content
        /// can be decoded using the default wire encoding, then update the list
        /// of delegations.
        /// </summary>
        ///
        /// <param name="data">The Data object to copy values from.</param>
        public Link(Data data)
            : base(data)
        {
            this.delegations_ = new DelegationSet();

            if (!getContent().isNull()) {
                try {
                    delegations_.wireDecode(getContent());
                    getMetaInfo().setType(net.named_data.jndn.ContentType.LINK);
                } catch (EncodingException ex) {
                    delegations_.clear();
                }
            }
        }
Esempio n. 4
0
 /// <summary>
 /// Create a DelegationSet, copying values from the other DelegationSet.
 /// </summary>
 ///
 /// <param name="delegationSet">The DelegationSet to copy values from.</param>
 public DelegationSet(DelegationSet delegationSet)
 {
     this.delegations_ = new ArrayList <Delegation>();
     this.changeCount_ = 0;
     delegations_.AddRange(delegationSet.delegations_);
 }
Esempio n. 5
0
 /// <summary>
 /// Create a DelegationSet, copying values from the other DelegationSet.
 /// </summary>
 ///
 /// <param name="delegationSet">The DelegationSet to copy values from.</param>
 public DelegationSet(DelegationSet delegationSet)
 {
     this.delegations_ = new ArrayList<Delegation>();
     delegations_.AddRange(delegationSet.delegations_);
 }
Esempio n. 6
0
            /// <summary>
            /// Compare this Delegation with other according to the ordering, based first
            /// on the preference number, then on the delegation name.
            /// </summary>
            ///
            /// <param name="other">The other Delegation to compare with.</param>
            /// <returns>0 If they compare equal, -1 if this Delegation comes before other
            /// in the ordering, or 1 if this Delegation comes after.</returns>
            public int compare(DelegationSet.Delegation  other)
            {
                if (preference_ < other.preference_)
                    return -1;
                if (preference_ > other.preference_)
                    return 1;

                return name_.compare(other.name_);
            }
Esempio n. 7
0
        /// <summary>
        /// Encode delegationSet as a sequence of NDN-TLV Delegation, and return the
        /// encoding. Note that the sequence of Delegation does not have an outer TLV
        /// type and length because it is intended to use the type and length of a Data
        /// packet's Content.
        /// </summary>
        ///
        /// <param name="delegationSet">The DelegationSet object to encode.</param>
        /// <returns>A Blob containing the encoding.</returns>
        public override Blob encodeDelegationSet(DelegationSet delegationSet)
        {
            TlvEncoder encoder = new TlvEncoder(256);

            // Encode backwards.
            for (int i = delegationSet.size() - 1; i >= 0; --i) {
                int saveLength = encoder.getLength();

                encodeName(delegationSet.get(i).getName(), new int[1], new int[1],
                        encoder);
                encoder.writeNonNegativeIntegerTlv(net.named_data.jndn.encoding.tlv.Tlv.Link_Preference,
                        delegationSet.get(i).getPreference());

                encoder.writeTypeAndLength(net.named_data.jndn.encoding.tlv.Tlv.Link_Delegation, encoder.getLength()
                        - saveLength);
            }

            return new Blob(encoder.getOutput(), false);
        }
Esempio n. 8
0
        /// <summary>
        /// Decode input as a sequence of NDN-TLV Delegation and set the fields of the
        /// delegationSet object. Note that the sequence of Delegation does not have an
        /// outer TLV type and length because it is intended to use the type and length
        /// of a Data packet's Content. This ignores any elements after the sequence
        /// of Delegation and before input.limit().
        /// </summary>
        ///
        /// <param name="delegationSet">The DelegationSet object whose fields are updated.</param>
        /// <param name="input"></param>
        /// <param name="copy">unchanged while the Blob values are used.</param>
        /// <exception cref="EncodingException">For invalid encoding.</exception>
        public override void decodeDelegationSet(DelegationSet delegationSet,
				ByteBuffer input, bool copy)
        {
            TlvDecoder decoder = new TlvDecoder(input);
            int endOffset = input.limit();

            delegationSet.clear();
            while (decoder.getOffset() < endOffset) {
                decoder.readTypeAndLength(net.named_data.jndn.encoding.tlv.Tlv.Link_Delegation);
                int preference = (int) decoder
                        .readNonNegativeIntegerTlv(net.named_data.jndn.encoding.tlv.Tlv.Link_Preference);
                Name name = new Name();
                decodeName(name, new int[1], new int[1], decoder, copy);

                // Add unsorted to preserve the order so that Interest selected delegation
                // index will work.
                delegationSet.addUnsorted(preference, name);
            }
        }
Esempio n. 9
0
 /// <summary>
 /// Encode delegationSet and return the encoding.
 /// Your derived class should override.
 /// </summary>
 ///
 /// <param name="delegationSet">The DelegationSet object to encode.</param>
 /// <returns>A Blob containing the encoding.</returns>
 /// <exception cref="System.NotSupportedException">for unimplemented if the derivedclass does not override.</exception>
 public virtual Blob encodeDelegationSet(DelegationSet delegationSet)
 {
     throw new NotSupportedException(
             "encodeDelegationSet is not implemented");
 }
Esempio n. 10
0
        /// <summary>
        /// Decode input as a delegation set and set the fields of the
        /// delegationSet object. Copy from the input when making new Blob values. Your
        /// derived class should override.
        /// </summary>
        ///
        /// <param name="delegationSet">The DelegationSet object whose fields are updated.</param>
        /// <param name="input"></param>
        /// <exception cref="System.NotSupportedException">for unimplemented if the derivedclass does not override.</exception>
        /// <exception cref="EncodingException">For invalid encoding.</exception>
        public void decodeDelegationSet(DelegationSet delegationSet,
				ByteBuffer input)
        {
            decodeDelegationSet(delegationSet, input, true);
        }
Esempio n. 11
0
        /// <summary>
        /// Decode input as a delegation set and set the fields of the
        /// delegationSet object.  Your derived class should override.
        /// </summary>
        ///
        /// <param name="delegationSet">The DelegationSet object whose fields are updated.</param>
        /// <param name="input"></param>
        /// <param name="copy">unchanged while the Blob values are used.</param>
        /// <exception cref="System.NotSupportedException">for unimplemented if the derivedclass does not override.</exception>
        /// <exception cref="EncodingException">For invalid encoding.</exception>
        public virtual void decodeDelegationSet(DelegationSet delegationSet,
				ByteBuffer input, bool copy)
        {
            throw new NotSupportedException(
                    "decodeDelegationSet is not implemented");
        }