Пример #1
0
            /// <summary>
            /// Create a new PendingInterest and set the timeoutTime_ based on the current
            /// time and the interest lifetime.
            /// </summary>
            ///
            /// <param name="interest">The interest.</param>
            /// <param name="face">packet to the face.</param>
            public PendingInterest(Interest interest, Face face)
            {
                interest_ = interest;
                face_     = face;

                // Set up timeoutTimeMilliseconds_.
                if (interest_.getInterestLifetimeMilliseconds() >= 0.0d)
                {
                    timeoutTimeMilliseconds_ = net.named_data.jndn.util.Common.getNowMilliseconds()
                                               + interest_.getInterestLifetimeMilliseconds();
                }
                else
                {
                    // No timeout.
                    timeoutTimeMilliseconds_ = -1.0d;
                }
            }
Пример #2
0
        /// <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)
        {
            prepareCommandInterestName(interest, wireFormat);
            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
 static void dumpInterest(Interest interest)
 {
     Console.Out.WriteLine("name: " + interest.getName().toUri());
     Console.Out.WriteLine("minSuffixComponents: " +
                           (interest.getMinSuffixComponents() >= 0 ?
                            "" + interest.getMinSuffixComponents() : "<none>"));
     Console.Out.WriteLine("maxSuffixComponents: " +
                           (interest.getMaxSuffixComponents() >= 0 ?
                            "" + interest.getMaxSuffixComponents() : "<none>"));
     Console.Out.Write("keyLocator: ");
     if (interest.getKeyLocator().getType() == KeyLocatorType.NONE)
     {
         Console.Out.WriteLine("<none>");
     }
     else if (interest.getKeyLocator().getType() == KeyLocatorType.KEY_LOCATOR_DIGEST)
     {
         Console.Out.WriteLine("KeyLocatorDigest: " + interest.getKeyLocator().getKeyData().toHex());
     }
     else if (interest.getKeyLocator().getType() == KeyLocatorType.KEYNAME)
     {
         Console.Out.WriteLine("KeyName: " + interest.getKeyLocator().getKeyName().toUri());
     }
     else
     {
         Console.Out.WriteLine("<unrecognized ndn_KeyLocatorType>");
     }
     Console.Out.WriteLine
         ("exclude: " + (interest.getExclude().size() > 0 ?
                         interest.getExclude().toUri() : "<none>"));
     Console.Out.WriteLine("lifetimeMilliseconds: " +
                           (interest.getInterestLifetimeMilliseconds() >= 0 ?
                            "" + interest.getInterestLifetimeMilliseconds() : "<none>"));
     Console.Out.WriteLine("childSelector: " +
                           (interest.getChildSelector() >= 0 ?
                            "" + interest.getChildSelector() : "<none>"));
     Console.Out.WriteLine("mustBeFresh: " + interest.getMustBeFresh());
     Console.Out.WriteLine("nonce: " +
                           (interest.getNonce().size() > 0 ?
                            "" + interest.getNonce().toHex() : "<none>"));
 }
Пример #4
0
        public virtual void onTimeout(Interest interest)
        {
            double interestLifetime = interest.getInterestLifetimeMilliseconds();

            if (interestLifetime < 0)
            {
                // Can't re-express.
                if (callerOnTimeout_ != null)
                {
                    try {
                        callerOnTimeout_.onTimeout(interest);
                    } catch (Exception ex) {
                        logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onTimeout", ex);
                    }
                }
                return;
            }

            double nextInterestLifetime = interestLifetime * 2;

            if (nextInterestLifetime > maxInterestLifetime_)
            {
                if (callerOnTimeout_ != null)
                {
                    try {
                        callerOnTimeout_.onTimeout(interest);
                    } catch (Exception ex_0) {
                        logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onTimeout", ex_0);
                    }
                }
                return;
            }

            Interest nextInterest = new Interest(interest);

            nextInterest.setInterestLifetimeMilliseconds(nextInterestLifetime);
            logger_.log(
                ILOG.J2CsMapping.Util.Logging.Level.FINE,
                "ExponentialReExpress: Increasing interest lifetime from {0} to {1} ms. Re-express interest {2}",
                new Object[] { interestLifetime, nextInterestLifetime,
                               nextInterest.getName().toUri() });
            try {
                face_.expressInterest(nextInterest, callerOnData_, this);
            } catch (IOException ex_1) {
                logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, null, ex_1);
            }
        }
Пример #5
0
            /// <summary>
            /// Create a new PendingInterest and set the timeoutTime_ based on the current
            /// time and the interest lifetime.
            /// </summary>
            ///
            /// <param name="interest">The interest.</param>
            /// <param name="face">packet to the face.</param>
            public PendingInterest(Interest interest, Face face)
            {
                interest_ = interest;
                face_     = face;

                // Set up timeoutTimeMilliseconds_.
                double interestLifetime = interest_
                                          .getInterestLifetimeMilliseconds();

                if (interestLifetime < 0.0d)
                {
                    // The InterestLifetime is omitted, so use a default.
                    interestLifetime = 4000.0d;
                }

                timeoutTimeMilliseconds_ = net.named_data.jndn.util.Common.getNowMilliseconds()
                                           + interestLifetime;
            }
Пример #6
0
        /// <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);
            }
        }
Пример #7
0
        private static ArrayList dumpInterest(Interest interest)
        {
            ArrayList result = new ArrayList();

            ILOG.J2CsMapping.Collections.Collections.Add(result, dump("name:", interest.getName().toUri()));
            ILOG.J2CsMapping.Collections.Collections.Add(result, dump(
                                                             "minSuffixComponents:",
                                                             (interest.getMinSuffixComponents() >= 0) ? (Object)(interest.getMinSuffixComponents()) : (Object)("<none>")));
            ILOG.J2CsMapping.Collections.Collections.Add(result, dump(
                                                             "maxSuffixComponents:",
                                                             (interest.getMaxSuffixComponents() >= 0) ? (Object)(interest.getMaxSuffixComponents()) : (Object)("<none>")));
            if (interest.getKeyLocator().getType() != net.named_data.jndn.KeyLocatorType.NONE)
            {
                if (interest.getKeyLocator().getType() == net.named_data.jndn.KeyLocatorType.KEY_LOCATOR_DIGEST)
                {
                    ILOG.J2CsMapping.Collections.Collections.Add(result, dump("keyLocator: KeyLocatorDigest:", interest
                                                                              .getKeyLocator().getKeyData().toHex()));
                }
                else if (interest.getKeyLocator().getType() == net.named_data.jndn.KeyLocatorType.KEYNAME)
                {
                    ILOG.J2CsMapping.Collections.Collections.Add(result, dump("keyLocator: KeyName:", interest
                                                                              .getKeyLocator().getKeyName().toUri()));
                }
                else
                {
                    ILOG.J2CsMapping.Collections.Collections.Add(result, dump("keyLocator: <unrecognized KeyLocatorType"));
                }
            }
            else
            {
                ILOG.J2CsMapping.Collections.Collections.Add(result, dump("keyLocator: <none>"));
            }
            ILOG.J2CsMapping.Collections.Collections.Add(result, dump("exclude:", (interest.getExclude().size() > 0) ? interest
                                                                      .getExclude().toUri() : "<none>"));
            ILOG.J2CsMapping.Collections.Collections.Add(result, dump("childSelector:",
                                                                      (interest.getChildSelector() >= 0) ? (Object)(interest.getChildSelector())
                                                                        : (Object)("<none>")));
            ILOG.J2CsMapping.Collections.Collections.Add(result, dump("mustBeFresh:", (interest.getMustBeFresh()) ? "true"
                                                        : "false"));
            ILOG.J2CsMapping.Collections.Collections.Add(result, dump("nonce:", (interest.getNonce().size() == 0) ? "<none>"
                                                        : interest.getNonce().toHex()));
            ILOG.J2CsMapping.Collections.Collections.Add(result, dump("lifetimeMilliseconds:",
                                                                      (interest.getInterestLifetimeMilliseconds() < 0) ? "<none>" : ""
                                                                      + (long)interest.getInterestLifetimeMilliseconds()));
            if (interest.getForwardingHint().size() > 0)
            {
                ILOG.J2CsMapping.Collections.Collections.Add(result, dump("forwardingHint:"));
                for (int i = 0; i < interest.getForwardingHint().size(); ++i)
                {
                    ILOG.J2CsMapping.Collections.Collections.Add(result, dump("  Preference: "
                                                                              + interest.getForwardingHint().get(i).getPreference()
                                                                              + ", Name: "
                                                                              + interest.getForwardingHint().get(i).getName().toUri()));
                }
            }
            else
            {
                ILOG.J2CsMapping.Collections.Collections.Add(result, dump("forwardingHint: <none>"));
            }
            return(result);
        }