/// <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);
        }
Beispiel #2
0
            /// <summary>
            /// Create a component whose value is the marker appended with the
            /// nonNegativeInteger encoding of the number.
            /// </summary>
            ///
            /// <param name="number">The number to be encoded.</param>
            /// <param name="marker">The marker to use as the first byte of the component.</param>
            /// <returns>The component value.</returns>
            public static Name.Component fromNumberWithMarker(long number, int marker)
            {
                if (number < 0)
                    number = 0;

                TlvEncoder encoder = new TlvEncoder(9);
                // Encode backwards.
                encoder.writeNonNegativeInteger(number);
                encoder.writeNonNegativeInteger((long) marker);
                return new Name.Component (new Blob(encoder.getOutput(), false));
            }
Beispiel #3
0
            /// <summary>
            /// Create a component whose value is the nonNegativeInteger encoding of the
            /// number.
            /// </summary>
            ///
            /// <param name="number">The number to be encoded.</param>
            /// <returns>The component value.</returns>
            public static Name.Component fromNumber(long number)
            {
                if (number < 0)
                    number = 0;

                TlvEncoder encoder = new TlvEncoder(8);
                encoder.writeNonNegativeInteger(number);
                return new Name.Component (new Blob(encoder.getOutput(), false));
            }