Пример #1
0
 /// <summary>
 /// Create a new Interest with the given name and interest lifetime and "none"
 /// for other values.
 /// </summary>
 ///
 /// <param name="name">The name for the interest.</param>
 /// <param name="interestLifetimeMilliseconds"></param>
 public Interest(Name name, double interestLifetimeMilliseconds)
 {
     this.name_ = new ChangeCounter(new Name());
     this.minSuffixComponents_ = -1;
     this.maxSuffixComponents_ = -1;
     this.keyLocator_ = new ChangeCounter(
             new KeyLocator());
     this.exclude_ = new ChangeCounter(new Exclude());
     this.childSelector_ = -1;
     this.mustBeFresh_ = true;
     this.interestLifetimeMilliseconds_ = -1;
     this.nonce_ = new Blob();
     this.getNonceChangeCount_ = 0;
     this.lpPacket_ = null;
     this.linkWireEncoding_ = new Blob();
     this.linkWireEncodingFormat_ = null;
     this.link_ = new ChangeCounter(null);
     this.selectedDelegationIndex_ = -1;
     this.defaultWireEncoding_ = new SignedBlob();
     this.getDefaultWireEncodingChangeCount_ = 0;
     this.changeCount_ = 0;
     if (name != null)
         name_.set(new Name(name));
     interestLifetimeMilliseconds_ = interestLifetimeMilliseconds;
 }
        /// <summary>
        /// Append a timestamp component and a random value component to interest's
        /// name. This ensures that the timestamp is greater than the timestamp used in
        /// the previous call. Then use keyChain to sign the interest which appends a
        /// SignatureInfo component and a component with the signature bits. If the
        /// interest lifetime is not set, this sets it.
        /// </summary>
        ///
        /// <param name="interest">The interest whose name is append with components.</param>
        /// <param name="keyChain">The KeyChain for calling sign.</param>
        /// <param name="certificateName">The certificate name of the key to use for signing.</param>
        /// <param name="wireFormat"></param>
        public void generate(Interest interest, KeyChain keyChain,
				Name certificateName, WireFormat wireFormat)
        {
            double timestamp;
             lock (lastTimestampLock_) {
                        timestamp = Math.Round(net.named_data.jndn.util.Common.getNowMilliseconds(),MidpointRounding.AwayFromZero);
                        while (timestamp <= lastTimestamp_)
                            timestamp += 1.0d;
                        // Update the timestamp now while it is locked. In the small chance that
                        //   signing fails, it just means that we have bumped the timestamp.
                        lastTimestamp_ = timestamp;
                    }

            // The timestamp is encoded as a TLV nonNegativeInteger.
            TlvEncoder encoder = new TlvEncoder(8);
            encoder.writeNonNegativeInteger((long) timestamp);
            interest.getName().append(new Blob(encoder.getOutput(), false));

            // The random value is a TLV nonNegativeInteger too, but we know it is 8 bytes,
            //   so we don't need to call the nonNegativeInteger encoder.
            ByteBuffer randomBuffer = ILOG.J2CsMapping.NIO.ByteBuffer.allocate(8);
            // Note: SecureRandom is thread safe.
            net.named_data.jndn.util.Common.getRandom().nextBytes(randomBuffer.array());
            interest.getName().append(new Blob(randomBuffer, false));

            keyChain.sign(interest, certificateName, wireFormat);

            if (interest.getInterestLifetimeMilliseconds() < 0)
                // The caller has not set the interest lifetime, so set it here.
                interest.setInterestLifetimeMilliseconds(1000.0d);
        }
Пример #3
0
        /// <summary>
        /// Override to submit a task to use the thread pool given to the constructor.
        /// Also wrap the supplied onData, onTimeout and onNetworkNack callbacks in an
        /// outer callback which submits a task to the thread pool to call the supplied
        /// callback. See Face.expressInterest for calling details.
        /// </summary>
        ///
        public override long expressInterest(Interest interest_0, OnData onData,
				OnTimeout onTimeout, OnNetworkNack onNetworkNack,
				WireFormat wireFormat_1)
        {
            long pendingInterestId_2 = node_.getNextEntryId();

            // Wrap callbacks to submit to the thread pool.
            OnData finalOnData_3 = onData;
            OnData onDataSubmit_4 = new ThreadPoolFace.Anonymous_C14 (this, finalOnData_3);

            OnTimeout finalOnTimeout_5 = onTimeout;
            OnTimeout onTimeoutSubmit_6 = (onTimeout == null) ? null
                    : new ThreadPoolFace.Anonymous_C13 (this, finalOnTimeout_5);

            OnNetworkNack finalOnNetworkNack_7 = onNetworkNack;
            OnNetworkNack onNetworkNackSubmit_8 = (onNetworkNack == null) ? null
                    : new ThreadPoolFace.Anonymous_C12 (this, finalOnNetworkNack_7);

            // Make an interest copy as required by Node.expressInterest.
            Interest interestCopy_9 = new Interest(interest_0);
            threadPool_.submit(new ThreadPoolFace.Anonymous_C11 (this, onNetworkNackSubmit_8, onDataSubmit_4,
                    interestCopy_9, onTimeoutSubmit_6, pendingInterestId_2, wireFormat_1));

            return pendingInterestId_2;
        }
        /// <summary>
        /// Override to call onVerified.onVerifiedInterest(interest) and to indicate no
        /// further verification step.
        /// </summary>
        ///
        /// <param name="interest">The interest with the signature (to ignore).</param>
        /// <param name="stepCount"></param>
        /// <param name="onVerified">better error handling the callback should catch and properly handle any exceptions.</param>
        /// <param name="onValidationFailed">Override to ignore this.</param>
        /// <returns>null for no further step.</returns>
        public override sealed ValidationRequest checkVerificationPolicy(Interest interest,
				int stepCount, OnVerifiedInterest onVerified,
				OnInterestValidationFailed onValidationFailed, WireFormat wireFormat)
        {
            try {
                onVerified.onVerifiedInterest(interest);
            } catch (Exception ex) {
                logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onVerifiedInterest", ex);
            }
            return null;
        }
Пример #5
0
 /// <summary>
 /// The OnInterestCallback calls this to put a Data packet which satisfies an
 /// Interest.
 /// </summary>
 ///
 /// <param name="data">The Data packet which satisfies the interest.</param>
 /// <param name="wireFormat">A WireFormat object used to encode the Data packet.</param>
 /// <exception cref="System.Exception">If the encoded Data packet size exceeds getMaxNdnPacketSize().</exception>
 public void putData(Data data, WireFormat wireFormat)
 {
     node_.putData(data, wireFormat);
 }
Пример #6
0
 /// <summary>
 /// Append a timestamp component and a random value component to interest's
 /// name. Then use the keyChain and certificateName from setCommandSigningInfo
 /// to sign the interest. If the interest lifetime is not set, this sets it.
 /// </summary>
 ///
 /// <param name="interest">The interest whose name is appended with components.</param>
 /// <param name="wireFormat"></param>
 /// <exception cref="System.Security.SecurityException">If cannot find the private key for thecertificateName.</exception>
 /// @note This method is an experimental feature. See the API docs for more detail at
 /// http://named-data.net/doc/ndn-ccl-api/face.html#face-makecommandinterest-method .
 public void makeCommandInterest(Interest interest, WireFormat wireFormat)
 {
     node_.makeCommandInterest(interest, commandKeyChain_,
             commandCertificateName_, wireFormat);
 }
Пример #7
0
 /// <summary>
 /// Encode name as an Interest, using a default interest lifetime.
 /// Send the Interest through the transport, read the entire response and call
 /// onData as described below.
 /// Ignore if the interest times out.
 /// </summary>
 ///
 /// <param name="name">A Name for the interest. This copies the Name.</param>
 /// <param name="onData">expressInterest and data is the received Data object. NOTE: You must not change the interest object - if you need to change it then make a copy. NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.</param>
 /// <param name="wireFormat">A WireFormat object used to encode the message.</param>
 /// <returns>The pending interest ID which can be used with
 /// removePendingInterest.</returns>
 /// <exception cref="IOException">For I/O error in sending the interest.</exception>
 /// <exception cref="System.Exception">If the encoded interest size exceeds getMaxNdnPacketSize().</exception>
 public long expressInterest(Name name, OnData onData, WireFormat wireFormat)
 {
     return expressInterest(name, null, onData, null, wireFormat);
 }
Пример #8
0
 /// <summary>
 /// Override to call the base class wireDecode then populate the certificate
 /// fields.
 /// </summary>
 ///
 /// <param name="input">The input byte array to be decoded as an immutable Blob.</param>
 /// <param name="wireFormat">A WireFormat object used to decode the input.</param>
 public override void wireDecode(Blob input, WireFormat wireFormat)
 {
     base.wireDecode(input,wireFormat);
     try {
         decode();
     } catch (DerDecodingException ex) {
         throw new EncodingException(ex.Message);
     }
 }
Пример #9
0
 /// <summary>
 /// Wire encode the Data object, digest it and set its SignatureInfo to
 /// a DigestSha256.
 /// </summary>
 ///
 /// <param name="data"></param>
 /// <param name="wireFormat">A WireFormat object used to encode the input.</param>
 public void signWithSha256(Data data, WireFormat wireFormat)
 {
     identityManager_.signWithSha256(data, wireFormat);
 }
Пример #10
0
 /// <summary>
 /// Encode this DelegationSet for a particular wire format.
 /// </summary>
 ///
 /// <param name="wireFormat">A WireFormat object used to encode this DelegationSet.</param>
 /// <returns>The encoded buffer.</returns>
 public Blob wireEncode(WireFormat wireFormat)
 {
     return wireFormat.encodeDelegationSet(this);
 }
Пример #11
0
        /// <summary>
        /// Register prefix with the connected NDN hub and call onInterest when a
        /// matching interest is received. To register a prefix with NFD, you must
        /// first call setCommandSigningInfo.
        /// Use default ForwardingFlags.
        /// </summary>
        ///
        /// <param name="prefix">A Name for the prefix to register. This copies the Name.</param>
        /// <param name="onInterest">onInterest.onInterest(prefix, interest, face, interestFilterId, filter). The onInterest callback should supply the Data with face.putData(). NOTE: You must not change the prefix or filter objects - if you need to change them then make a copy. If onInterest is null, it is ignored and you must call setInterestFilter. NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.</param>
        /// <param name="onRegisterFailed">NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.</param>
        /// <param name="wireFormat">A WireFormat object used to encode the message.</param>
        /// <returns>The registered prefix ID which can be used with
        /// removeRegisteredPrefix.</returns>
        /// <exception cref="IOException">For I/O error in sending the registration request.</exception>
        /// <exception cref="System.Security.SecurityException">If signing a command interest for NFD and cannotfind the private key for the certificateName.</exception>
        public long registerPrefix(Name prefix, OnInterestCallback onInterest,
				OnRegisterFailed onRegisterFailed, WireFormat wireFormat)
        {
            return registerPrefix(prefix, onInterest, onRegisterFailed, null,
                    new ForwardingFlags(), wireFormat);
        }
Пример #12
0
 /// <summary>
 /// Decode the input using a particular wire format and update this Name.
 /// </summary>
 ///
 /// <param name="input">The input blob to decode.</param>
 /// <param name="wireFormat">A WireFormat object used to decode the input.</param>
 /// <exception cref="EncodingException">For invalid encoding.</exception>
 public void wireDecode(Blob input, WireFormat wireFormat)
 {
     wireFormat.decodeName(this, input.buf(), false);
 }
Пример #13
0
        /// <summary>
        /// Check whether the received signed interest complies with the verification
        /// policy, and get the indication of the next verification step.
        /// </summary>
        ///
        /// <param name="interest">The interest with the signature to check.</param>
        /// <param name="stepCount"></param>
        /// <param name="onVerified">NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.</param>
        /// <param name="onValidationFailed">NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.</param>
        /// <returns>the indication of next verification step, null if there is no
        /// further step.</returns>
        public abstract ValidationRequest checkVerificationPolicy(
				Interest interest, int stepCount, OnVerifiedInterest onVerified,
				OnInterestValidationFailed onValidationFailed, WireFormat wireFormat);
Пример #14
0
 /// <summary>
 /// Override to call the base class wireDecode then update the public key name.
 /// </summary>
 ///
 /// <param name="input">The input byte array to be decoded as an immutable Blob.</param>
 /// <param name="wireFormat">A WireFormat object used to decode the input.</param>
 public override void wireDecode(Blob input, WireFormat wireFormat)
 {
     base.wireDecode(input,wireFormat);
     setPublicKeyName();
 }
Пример #15
0
        /// <summary>
        /// Call registerPrefix on the Face given to the constructor so that this
        /// MemoryContentCache will answer interests whose name has the prefix.
        /// Alternatively, if the Face's registerPrefix has already been called, then
        /// you can call this object's setInterestFilter.
        /// </summary>
        ///
        /// <param name="prefix">The Name for the prefix to register. This copies the Name.</param>
        /// <param name="onRegisterFailed">NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.</param>
        /// <param name="onDataNotFound">onDataNotFound.onInterest(prefix, interest, face, interestFilterId, filter). Your callback can find the Data packet for the interest and call face.putData(data).  If your callback cannot find the Data packet, it can optionally call storePendingInterest(interest, face) to store the pending interest in this object to be satisfied by a later call to add(data). If you want to automatically store all pending interests, you can simply use getStorePendingInterest() for onDataNotFound. If onDataNotFound is null, this does not use it. NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.</param>
        /// <param name="flags">See Face.registerPrefix.</param>
        /// <param name="wireFormat">See Face.registerPrefix.</param>
        /// <exception cref="IOException">For I/O error in sending the registration request.</exception>
        /// <exception cref="System.Security.SecurityException">If signing a command interest for NFD and cannotfind the private key for the certificateName.</exception>
        public void registerPrefix(Name prefix,
				OnRegisterFailed onRegisterFailed,
				OnInterestCallback onDataNotFound, ForwardingFlags flags,
				WireFormat wireFormat)
        {
            registerPrefix(prefix, onRegisterFailed, null, onDataNotFound, flags,
                    wireFormat);
        }
Пример #16
0
        /// <summary>
        /// Call registerPrefix on the Face given to the constructor so that this
        /// MemoryContentCache will answer interests whose name has the prefix.
        /// Alternatively, if the Face's registerPrefix has already been called, then
        /// you can call this object's setInterestFilter.
        /// </summary>
        ///
        /// <param name="prefix">The Name for the prefix to register. This copies the Name.</param>
        /// <param name="onRegisterFailed">NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.</param>
        /// <param name="onRegisterSuccess">receives a success message from the forwarder. If onRegisterSuccess is null, this does not use it. NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.</param>
        /// <param name="onDataNotFound">onDataNotFound.onInterest(prefix, interest, face, interestFilterId, filter). Your callback can find the Data packet for the interest and call face.putData(data).  If your callback cannot find the Data packet, it can optionally call storePendingInterest(interest, face) to store the pending interest in this object to be satisfied by a later call to add(data). If you want to automatically store all pending interests, you can simply use getStorePendingInterest() for onDataNotFound. If onDataNotFound is null, this does not use it. NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.</param>
        /// <param name="flags">See Face.registerPrefix.</param>
        /// <param name="wireFormat">See Face.registerPrefix.</param>
        /// <exception cref="IOException">For I/O error in sending the registration request.</exception>
        /// <exception cref="System.Security.SecurityException">If signing a command interest for NFD and cannotfind the private key for the certificateName.</exception>
        public void registerPrefix(Name prefix,
				OnRegisterFailed onRegisterFailed,
				OnRegisterSuccess onRegisterSuccess,
				OnInterestCallback onDataNotFound, ForwardingFlags flags,
				WireFormat wireFormat)
        {
            if (onDataNotFound != null)
                ILOG.J2CsMapping.Collections.Collections.Put(onDataNotFoundForPrefix_,prefix.toUri(),onDataNotFound);
            long registeredPrefixId = face_.registerPrefix(prefix, this,
                    onRegisterFailed, onRegisterSuccess, flags, wireFormat);
            ILOG.J2CsMapping.Collections.Collections.Add(registeredPrefixIdList_,registeredPrefixId);
        }
Пример #17
0
 /// <summary>
 /// Append a SignatureInfo for DigestSha256 to the Interest name, digest the
 /// name components and append a final name component with the signature bits
 /// (which is the digest).
 /// </summary>
 ///
 /// <param name="interest"></param>
 /// <param name="wireFormat">A WireFormat object used to encode the input.</param>
 public void signWithSha256(Interest interest, WireFormat wireFormat)
 {
     identityManager_.signInterestWithSha256(interest, wireFormat);
 }
Пример #18
0
        /// <summary>
        /// Register prefix with the connected NDN hub and call onInterest when a
        /// matching interest is received. To register a prefix with NFD, you must
        /// first call setCommandSigningInfo.
        /// </summary>
        ///
        /// <param name="prefix">A Name for the prefix to register. This copies the Name.</param>
        /// <param name="onInterest">onInterest.onInterest(prefix, interest, face, interestFilterId, filter). The onInterest callback should supply the Data with face.putData(). NOTE: You must not change the prefix or filter objects - if you need to change them then make a copy. If onInterest is null, it is ignored and you must call setInterestFilter. NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.</param>
        /// <param name="onRegisterFailed">NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.</param>
        /// <param name="onRegisterSuccess">receives a success message from the forwarder. If onRegisterSuccess is null, this does not use it. (The onRegisterSuccess parameter comes after onRegisterFailed because it can be null or omitted, unlike onRegisterFailed.) NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.</param>
        /// <param name="flags"></param>
        /// <param name="wireFormat">A WireFormat object used to encode the message.</param>
        /// <returns>The registered prefix ID which can be used with
        /// removeRegisteredPrefix.</returns>
        /// <exception cref="IOException">For I/O error in sending the registration request.</exception>
        /// <exception cref="System.Security.SecurityException">If signing a command interest for NFD and cannotfind the private key for the certificateName.</exception>
        public virtual long registerPrefix(Name prefix, OnInterestCallback onInterest,
				OnRegisterFailed onRegisterFailed,
				OnRegisterSuccess onRegisterSuccess, ForwardingFlags flags,
				WireFormat wireFormat)
        {
            // Get the registeredPrefixId now so we can return it to the caller.
            long registeredPrefixId = node_.getNextEntryId();

            node_.registerPrefix(registeredPrefixId, prefix, onInterest,
                    onRegisterFailed, onRegisterSuccess, flags, wireFormat,
                    commandKeyChain_, commandCertificateName_, this);

            return registeredPrefixId;
        }
Пример #19
0
 /// <summary>
 /// Decode the input using a particular wire format and update this
 /// DelegationSet, using addUnsorted() to preserve the given order and
 /// possible duplicates.
 /// </summary>
 ///
 /// <param name="input"></param>
 /// <param name="wireFormat">A WireFormat object used to decode the input.</param>
 /// <exception cref="EncodingException">For invalid encoding.</exception>
 public void wireDecode(ByteBuffer input, WireFormat wireFormat)
 {
     wireFormat.decodeDelegationSet(this, input, true);
 }
Пример #20
0
        public long registerPrefix(Name prefix, OnInterestCallback onInterest,
				OnRegisterSuccess onRegisterSuccess,
				OnRegisterFailed onRegisterFailed, ForwardingFlags flags,
				WireFormat wireFormat)
        {
            return registerPrefix(prefix, onInterest, onRegisterFailed,
                    onRegisterSuccess, flags, wireFormat);
        }
Пример #21
0
        /// <summary>
        /// Wire encode the Data object, sign it and set its signature.
        /// </summary>
        ///
        /// <param name="data"></param>
        /// <param name="identityName"></param>
        /// <param name="wireFormat">A WireFormat object used to encode the input. If omitted, use WireFormat getDefaultWireFormat().</param>
        public void signByIdentity(Data data, Name identityName,
				WireFormat wireFormat)
        {
            Name signingCertificateName;

            if (identityName.size() == 0) {
                Name inferredIdentity = policyManager_.inferSigningIdentity(data
                        .getName());
                if (inferredIdentity.size() == 0)
                    signingCertificateName = identityManager_
                            .getDefaultCertificateName();
                else
                    signingCertificateName = identityManager_
                            .getDefaultCertificateNameForIdentity(inferredIdentity);
            } else
                signingCertificateName = identityManager_
                        .getDefaultCertificateNameForIdentity(identityName);

            if (signingCertificateName.size() == 0)
                throw new SecurityException("No qualified certificate name found!");

            if (!policyManager_.checkSigningPolicy(data.getName(),
                    signingCertificateName))
                throw new SecurityException(
                        "Signing Cert name does not comply with signing policy");

            identityManager_.signByCertificate(data, signingCertificateName,
                    wireFormat);
        }
Пример #22
0
 /// <summary>
 /// Decode the input using a particular wire format and update this Name.
 /// </summary>
 ///
 /// <param name="input"></param>
 /// <param name="wireFormat">A WireFormat object used to decode the input.</param>
 /// <exception cref="EncodingException">For invalid encoding.</exception>
 public void wireDecode(ByteBuffer input, WireFormat wireFormat)
 {
     wireFormat.decodeName(this, input, true);
 }
Пример #23
0
        /// <summary>
        /// Send the Interest through the transport, read the entire response and call
        /// onData, onTimeout or onNetworkNack as described below.
        /// </summary>
        ///
        /// <param name="interest">The Interest to send.  This copies the Interest.</param>
        /// <param name="onData">expressInterest and data is the received Data object. NOTE: You must not change the interest object - if you need to change it then make a copy. NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.</param>
        /// <param name="onTimeout">interest given to expressInterest. If onTimeout is null, this does not use it. NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.</param>
        /// <param name="onNetworkNack">onNetworkNack.onNetworkNack(interest, networkNack) and does not call onTimeout. However, if a network Nack is received and onNetworkNack is null, do nothing and wait for the interest to time out. (Therefore, an application which does not yet process a network Nack reason treats a Nack the same as a timeout.) NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.</param>
        /// <param name="wireFormat">A WireFormat object used to encode the message.</param>
        /// <returns>The pending interest ID which can be used with
        /// removePendingInterest.</returns>
        /// <exception cref="IOException">For I/O error in sending the interest.</exception>
        /// <exception cref="System.Exception">If the encoded interest size exceeds getMaxNdnPacketSize().</exception>
        public virtual long expressInterest(Interest interest, OnData onData,
				OnTimeout onTimeout, OnNetworkNack onNetworkNack,
				WireFormat wireFormat)
        {
            long pendingInterestId = node_.getNextEntryId();

            // This copies the interest as required by Node.expressInterest.
            node_.expressInterest(pendingInterestId, interest, onData, onTimeout,
                    onNetworkNack, wireFormat, this);

            return pendingInterestId;
        }
Пример #24
0
 /// <summary>
 /// Encode this Name for a particular wire format.
 /// </summary>
 ///
 /// <param name="wireFormat">A WireFormat object used to encode this Name.</param>
 /// <returns>The encoded buffer.</returns>
 public Blob wireEncode(WireFormat wireFormat)
 {
     return wireFormat.encodeName(this);
 }
Пример #25
0
        /// <summary>
        /// Send the Interest through the transport, read the entire response and call
        /// onData as described below.
        /// Ignore if the interest times out.
        /// </summary>
        ///
        /// <param name="interest">The Interest to send.  This copies the Interest.</param>
        /// <param name="onData">expressInterest and data is the received Data object. NOTE: You must not change the interest object - if you need to change it then make a copy. NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.</param>
        /// <param name="wireFormat">A WireFormat object used to encode the message.</param>
        /// <returns>The pending interest ID which can be used with
        /// removePendingInterest.</returns>
        /// <exception cref="IOException">For I/O error in sending the interest.</exception>
        /// <exception cref="System.Exception">If the encoded interest size exceeds getMaxNdnPacketSize().</exception>
        public long expressInterest(Interest interest, OnData onData,
				WireFormat wireFormat)
        {
            return expressInterest(interest, onData, null, wireFormat);
        }
Пример #26
0
 /// <summary>
 /// Decode the input using a particular wire format and update this DelegationSet.
 /// </summary>
 ///
 /// <param name="input">The input blob to decode.</param>
 /// <param name="wireFormat">A WireFormat object used to decode the input.</param>
 /// <exception cref="EncodingException">For invalid encoding.</exception>
 public void wireDecode(Blob input, WireFormat wireFormat)
 {
     wireFormat.decodeDelegationSet(this, input.buf(), false);
 }
Пример #27
0
        /// <summary>
        /// Encode name as an Interest. If interestTemplate is not null, use its
        /// interest selectors.
        /// Send the Interest through the transport, read the entire response and call
        /// onData, onTimeout or onNetworkNack as described below.
        /// </summary>
        ///
        /// <param name="name">A Name for the interest. This copies the Name.</param>
        /// <param name="interestTemplate"></param>
        /// <param name="onData">expressInterest and data is the received Data object. NOTE: You must not change the interest object - if you need to change it then make a copy. NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.</param>
        /// <param name="onTimeout">interest given to expressInterest. If onTimeout is null, this does not use it. NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.</param>
        /// <param name="onNetworkNack">onNetworkNack.onNetworkNack(interest, networkNack) and does not call onTimeout. However, if a network Nack is received and onNetworkNack is null, do nothing and wait for the interest to time out. (Therefore, an application which does not yet process a network Nack reason treats a Nack the same as a timeout.) NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.</param>
        /// <param name="wireFormat">A WireFormat object used to encode the message.</param>
        /// <returns>The pending interest ID which can be used with
        /// removePendingInterest.</returns>
        /// <exception cref="IOException">For I/O error in sending the interest.</exception>
        /// <exception cref="System.Exception">If the encoded interest size exceeds getMaxNdnPacketSize().</exception>
        public virtual long expressInterest(Name name, Interest interestTemplate,
				OnData onData, OnTimeout onTimeout, OnNetworkNack onNetworkNack,
				WireFormat wireFormat)
        {
            long pendingInterestId = node_.getNextEntryId();

            // This copies the name object as required by Node.expressInterest.
            node_.expressInterest(pendingInterestId,
                    getInterestCopy(name, interestTemplate), onData, onTimeout,
                    onNetworkNack, wireFormat, this);

            return pendingInterestId;
        }
Пример #28
0
 /// <summary>
 /// Set the static default WireFormat used by default encoding and decoding
 /// methods.
 /// </summary>
 ///
 /// <param name="wireFormat"></param>
 public static void setDefaultWireFormat(WireFormat wireFormat)
 {
     defaultWireFormat_ = wireFormat;
 }
Пример #29
0
        /// <summary>
        /// Encode name as an Interest, using a default interest lifetime.
        /// Send the Interest through the transport, read the entire response and call
        /// onData, onTimeout or onNetworkNack as described below.
        /// </summary>
        ///
        /// <param name="name">A Name for the interest. This copies the Name.</param>
        /// <param name="onData">expressInterest and data is the received Data object. NOTE: You must not change the interest object - if you need to change it then make a copy. NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.</param>
        /// <param name="onTimeout">interest given to expressInterest. If onTimeout is null, this does not use it. NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.</param>
        /// <param name="onNetworkNack">onNetworkNack.onNetworkNack(interest, networkNack) and does not call onTimeout. However, if a network Nack is received and onNetworkNack is null, do nothing and wait for the interest to time out. (Therefore, an application which does not yet process a network Nack reason treats a Nack the same as a timeout.) NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.</param>
        /// <param name="wireFormat">A WireFormat object used to encode the message.</param>
        /// <returns>The pending interest ID which can be used with
        /// removePendingInterest.</returns>
        /// <exception cref="IOException">For I/O error in sending the interest.</exception>
        /// <exception cref="System.Exception">If the encoded interest size exceeds getMaxNdnPacketSize().</exception>
        public long expressInterest(Name name, OnData onData, OnTimeout onTimeout,
				OnNetworkNack onNetworkNack, WireFormat wireFormat)
        {
            return expressInterest(name, null, onData, onTimeout, onNetworkNack,
                    wireFormat);
        }
        /// <summary>
        /// Use wireFormat.decodeSignatureInfoAndValue to decode the last two name
        /// components of the signed interest. Look in the IdentityStorage for the
        /// public key with the name in the KeyLocator (if available) and use it to
        /// verify the interest. If the public key can't be found, call onVerifyFailed.
        /// </summary>
        ///
        /// <param name="interest">The interest with the signature to check.</param>
        /// <param name="stepCount"></param>
        /// <param name="onVerified">NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.</param>
        /// <param name="onValidationFailed">onValidationFailed.onInterestValidationFailed(interest, reason). NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.</param>
        /// <returns>null for no further step for looking up a certificate chain.</returns>
        public override ValidationRequest checkVerificationPolicy(Interest interest,
				int stepCount, OnVerifiedInterest onVerified,
				OnInterestValidationFailed onValidationFailed, WireFormat wireFormat)
        {
            if (interest.getName().size() < 2) {
                try {
                    onValidationFailed.onInterestValidationFailed(interest,
                            "The signed interest has less than 2 components: "
                                    + interest.getName().toUri());
                } catch (Exception exception) {
                    logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE,
                            "Error in onInterestValidationFailed", exception);
                }
                return null;
            }

            // Decode the last two name components of the signed interest
            Signature signature;
            try {
                signature = wireFormat.decodeSignatureInfoAndValue(interest
                        .getName().get(-2).getValue().buf(), interest.getName()
                        .get(-1).getValue().buf(), false);
            } catch (EncodingException ex) {
                logger_.log(
                        ILOG.J2CsMapping.Util.Logging.Level.INFO,
                        "Cannot decode the signed interest SignatureInfo and value",
                        ex);
                try {
                    onValidationFailed.onInterestValidationFailed(interest,
                            "Error decoding the signed interest signature: " + ex);
                } catch (Exception exception_0) {
                    logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE,
                            "Error in onInterestValidationFailed", exception_0);
                }
                return null;
            }

            String[] failureReason = new String[] { "unknown" };
            // wireEncode returns the cached encoding if available.
            if (verify(signature, interest.wireEncode(wireFormat), failureReason)) {
                try {
                    onVerified.onVerifiedInterest(interest);
                } catch (Exception ex_1) {
                    logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onVerifiedInterest", ex_1);
                }
            } else {
                try {
                    onValidationFailed.onInterestValidationFailed(interest,
                            failureReason[0]);
                } catch (Exception ex_2) {
                    logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE,
                            "Error in onInterestValidationFailed", ex_2);
                }
            }

            // No more steps, so return a null ValidationRequest.
            return null;
        }
Пример #31
0
        /// <summary>
        /// Encode name as an Interest. If interestTemplate is not null, use its
        /// interest selectors.
        /// Send the Interest through the transport, read the entire response and call
        /// onData or onTimeout as described below.
        /// </summary>
        ///
        /// <param name="name">A Name for the interest. This copies the Name.</param>
        /// <param name="interestTemplate"></param>
        /// <param name="onData">expressInterest and data is the received Data object. NOTE: You must not change the interest object - if you need to change it then make a copy. NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.</param>
        /// <param name="onTimeout">interest given to expressInterest. If onTimeout is null, this does not use it. NOTE: The library will log any exceptions thrown by this callback, but for better error handling the callback should catch and properly handle any exceptions.</param>
        /// <param name="wireFormat">A WireFormat object used to encode the message.</param>
        /// <returns>The pending interest ID which can be used with
        /// removePendingInterest.</returns>
        /// <exception cref="IOException">For I/O error in sending the interest.</exception>
        /// <exception cref="System.Exception">If the encoded interest size exceeds getMaxNdnPacketSize().</exception>
        public long expressInterest(Name name, Interest interestTemplate,
				OnData onData, OnTimeout onTimeout, WireFormat wireFormat)
        {
            return expressInterest(name, interestTemplate, onData, onTimeout, null,
                    wireFormat);
        }