Пример #1
0
        static void Main(string[] args)
        {
            try {
            var face = new Face
              (new TcpTransport(), new TcpTransport.ConnectionInfo("localhost"));

            var counter = new Counter1();

            Console.Out.WriteLine("Enter a word to echo:");
            var word = Console.In.ReadLine();

            var name = new Name("/testecho");
            name.append(word);
            Console.Out.WriteLine("Express name " + name.toUri());
            face.expressInterest(name, counter, counter);

            // The main event loop.
            while (counter.callbackCount_ < 1) {
              face.processEvents();

              // We need to sleep for a few milliseconds so we don't use 100% of the CPU.
              System.Threading.Thread.Sleep(5);
            }
              } catch (Exception e) {
            Console.Out.WriteLine("exception: " + e.Message);
              }
        }
Пример #2
0
 /// <summary>
 /// Create a new Name with the components in the given name.
 /// </summary>
 ///
 /// <param name="name">The name with components to copy from.</param>
 public Name(Name name)
 {
     this.changeCount_ = 0;
     this.haveHashCode_ = false;
     this.hashCodeChangeCount_ = 0;
     components_ = new ArrayList<Component>(name.components_);
 }
Пример #3
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);
        }
Пример #4
0
        public void testAppend()
        {
            // could possibly split this into different tests
            String uri = "/localhost/user/folders/files/%00%0F";
            Name name = new Name(uri);
            Name name2 = new Name("/localhost").append(new Name("/user/folders/"));
            Assert.AssertEquals("Name constructed by appending names has " + name2.size()
                    + " components instead of 3", 3, name2.size());
            Assert.AssertTrue("Name constructed with append has wrong suffix", name2
                    .get(2).getValue().equals(new Blob("folders")));
            name2 = name2.append("files");
            Assert.AssertEquals("Name constructed by appending string has " + name2.size()
                    + " components instead of 4", 4, name2.size());
            name2 = name2.appendSegment(15);
            Assert.AssertTrue(
                    "Name constructed by appending segment has wrong segment value",
                    name2.get(4).getValue()
                            .equals(new Blob(new int[] { 0x00, 0x0F })));

            Assert.AssertTrue(
                    "Name constructed with append is not equal to URI constructed name",
                    name2.equals(name));
            Assert.AssertEquals("Name constructed with append has wrong URI",
                    name.toUri(), name2.toUri());
        }
        /// <summary>
        /// Delete a pair of asymmetric keys. If the key doesn't exist, do nothing.
        /// </summary>
        ///
        /// <param name="keyName">The name of the key pair.</param>
        public override void deleteKeyPair(Name keyName)
        {
            String keyUri = keyName.toUri();

            ILOG.J2CsMapping.Collections.Collections.Remove(publicKeyStore_,keyUri);
            ILOG.J2CsMapping.Collections.Collections.Remove(privateKeyStore_,keyUri);
        }
        /// <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
        static void Main(string[] args)
        {
            try {
            var face = new Face("aleph.ndn.ucla.edu");

            var counter = new Counter();

            // Try to fetch anything.
            var name1 = new Name("/");
            Console.Out.WriteLine("Express name " + name1.toUri());
            face.expressInterest(name1, counter, counter);

            // Try to fetch using a known name.
            var name2 = new Name("/ndn/edu/ucla/remap/demo/ndn-js-test/hello.txt/%FDU%8D%9DM");
            Console.Out.WriteLine("Express name " + name2.toUri());
            face.expressInterest(name2, counter, counter);

            // Expect this to time out.
            var name3 = new Name("/test/timeout");
            Console.Out.WriteLine("Express name " + name3.toUri());
            face.expressInterest(name3, counter, counter);

            // The main event loop.
            while (counter.callbackCount_ < 3) {
              face.processEvents();
              // We need to sleep for a few milliseconds so we don't use 100% of the CPU.
              System.Threading.Thread.Sleep(5);
            }
              } catch (Exception e) {
            Console.Out.WriteLine("exception: " + e.Message);
              }
        }
Пример #8
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;
 }
Пример #9
0
 /// <summary>
 /// Create a new Face for communication with an NDN hub at host using the
 /// default port 6363 and the default TcpTransport.
 /// </summary>
 ///
 /// <param name="host">The host of the NDN hub.</param>
 public Face(String host)
 {
     this.commandKeyChain_ = null;
     this.commandCertificateName_ = new Name();
     node_ = new Node(new TcpTransport(), new TcpTransport.ConnectionInfo(
             host, 6363));
 }
        public void testCompare()
        {
            Name.Component c7f = new Name("/%7F").get(0);
            Name.Component c80 = new Name("/%80").get(0);
            Name.Component c81 = new Name("/%81").get(0);

            Assert.AssertTrue("%81 should be greater than %80", c81.compare(c80) > 0);
            Assert.AssertTrue("%80 should be greater than %7f", c80.compare(c7f) > 0);
        }
Пример #11
0
        /// <summary>
        /// Create an IdentityCertificate from the content in the data packet.
        /// </summary>
        ///
        /// <param name="data">The data packet with the content to decode.</param>
        public IdentityCertificate(Data data)
            : base(data)
        {
            this.publicKeyName_ = new Name();

            if (!isCorrectName(data.getName()))
                throw new SecurityException("Wrong Identity Certificate Name!");

            setPublicKeyName();
        }
        public void setUp()
        {
            Name[] localCertificateName = new Name[1];
            keyChain = net.named_data.jndn.tests.integration_tests.IntegrationTestsCommon.buildKeyChain(localCertificateName);
            certificateName = localCertificateName[0];

            faceIn = net.named_data.jndn.tests.integration_tests.IntegrationTestsCommon.buildFaceWithKeyChain("localhost",
                    keyChain, certificateName);
            faceOut = net.named_data.jndn.tests.integration_tests.IntegrationTestsCommon.buildFaceWithKeyChain("localhost",
                    keyChain, certificateName);
        }
Пример #13
0
        /// <summary>
        /// Create a group manager with the given values. The group manager namespace
        /// is /{prefix}/read/{dataType} .
        /// </summary>
        ///
        /// <param name="prefix">The prefix for the group manager namespace.</param>
        /// <param name="dataType">The data type for the group manager namespace.</param>
        /// <param name="database"></param>
        /// <param name="keySize">The group key will be an RSA key with keySize bits.</param>
        /// <param name="freshnessHours"></param>
        /// <param name="keyChain"></param>
        public GroupManager(Name prefix, Name dataType, GroupManagerDb database,
				int keySize, int freshnessHours, KeyChain keyChain)
        {
            namespace_ = new Name(prefix).append(net.named_data.jndn.encrypt.algo.Encryptor.NAME_COMPONENT_READ)
                    .append(dataType);
            database_ = database;
            keySize_ = keySize;
            freshnessHours_ = freshnessHours;

            keyChain_ = keyChain;
        }
Пример #14
0
        /// <summary>
        /// Prepare an encrypted data packet by encrypting the payload using the key
        /// according to the params. In addition, this prepares the encoded
        /// EncryptedContent with the encryption result using keyName and params. The
        /// encoding is set as the content of the data packet. If params defines an
        /// asymmetric encryption algorithm and the payload is larger than the maximum
        /// plaintext size, this encrypts the payload with a symmetric key that is
        /// asymmetrically encrypted and provided as a nonce in the content of the data
        /// packet. The packet's /{dataName}/ is updated to be
        /// /{dataName}/FOR/{keyName}
        /// </summary>
        ///
        /// <param name="data">The data packet which is updated.</param>
        /// <param name="payload">The payload to encrypt.</param>
        /// <param name="keyName">The key name for the EncryptedContent.</param>
        /// <param name="key">The encryption key value.</param>
        /// <param name="params">The parameters for encryption.</param>
        public static void encryptData(Data data, Blob payload, Name keyName,
				Blob key, EncryptParams paras)
        {
            data.getName().append(NAME_COMPONENT_FOR).append(keyName);

            EncryptAlgorithmType algorithmType = paras.getAlgorithmType();

            if (algorithmType == net.named_data.jndn.encrypt.algo.EncryptAlgorithmType.AesCbc
                    || algorithmType == net.named_data.jndn.encrypt.algo.EncryptAlgorithmType.AesEcb) {
                EncryptedContent content = encryptSymmetric(payload, key, keyName,
                        paras);
                data.setContent(content.wireEncode(net.named_data.jndn.encoding.TlvWireFormat.get()));
            } else if (algorithmType == net.named_data.jndn.encrypt.algo.EncryptAlgorithmType.RsaPkcs
                    || algorithmType == net.named_data.jndn.encrypt.algo.EncryptAlgorithmType.RsaOaep) {
                // Java doesn't have a direct way to get the maximum plain text size, so
                // try to encrypt the payload first and catch the error if it is too big.
                try {
                    EncryptedContent content_0 = encryptAsymmetric(payload, key,
                            keyName, paras);
                    data.setContent(content_0.wireEncode(net.named_data.jndn.encoding.TlvWireFormat.get()));
                    return;
                } catch (IllegalBlockSizeException ex) {
                    // The payload is larger than the maximum plaintext size. Continue.
                }

                // 128-bit nonce.
                ByteBuffer nonceKeyBuffer = ILOG.J2CsMapping.NIO.ByteBuffer.allocate(16);
                net.named_data.jndn.util.Common.getRandom().nextBytes(nonceKeyBuffer.array());
                Blob nonceKey = new Blob(nonceKeyBuffer, false);

                Name nonceKeyName = new Name(keyName);
                nonceKeyName.append("nonce");

                EncryptParams symmetricParams = new EncryptParams(
                        net.named_data.jndn.encrypt.algo.EncryptAlgorithmType.AesCbc, net.named_data.jndn.encrypt.algo.AesAlgorithm.BLOCK_SIZE);

                EncryptedContent nonceContent = encryptSymmetric(payload, nonceKey,
                        nonceKeyName, symmetricParams);

                EncryptedContent payloadContent = encryptAsymmetric(nonceKey, key,
                        keyName, paras);

                Blob nonceContentEncoding = nonceContent.wireEncode();
                Blob payloadContentEncoding = payloadContent.wireEncode();
                ByteBuffer content_1 = ILOG.J2CsMapping.NIO.ByteBuffer.allocate(nonceContentEncoding
                        .size() + payloadContentEncoding.size());
                content_1.put(payloadContentEncoding.buf());
                content_1.put(nonceContentEncoding.buf());
                content_1.flip();

                data.setContent(new Blob(content_1, false));
            } else
                throw new Exception("Unsupported encryption method");
        }
Пример #15
0
        /// <summary>
        /// Create a Consumer to use the given ConsumerDb, Face and other values.
        /// </summary>
        ///
        /// <param name="face">The face used for data packet and key fetching.</param>
        /// <param name="keyChain">The keyChain used to verify data packets.</param>
        /// <param name="groupName"></param>
        /// <param name="consumerName"></param>
        /// <param name="database">The ConsumerDb database for storing decryption keys.</param>
        public Consumer(Face face, KeyChain keyChain, Name groupName,
				Name consumerName, ConsumerDb database)
        {
            this.cKeyMap_ = new Hashtable();
                    this.dKeyMap_ = new Hashtable();
            database_ = database;
            keyChain_ = keyChain;
            face_ = face;
            groupName_ = new Name(groupName);
            consumerName_ = new Name(consumerName);
        }
Пример #16
0
 /// <summary>
 /// Create a new ControlParameters where all values are unspecified.
 /// </summary>
 ///
 public ControlParameters()
 {
     this.name_ = null;
     this.faceId_ = -1;
     this.uri_ = "";
     this.localControlFeature_ = -1;
     this.origin_ = -1;
     this.cost_ = -1;
     this.flags_ = new ForwardingFlags();
     this.strategy_ = new Name();
     this.expirationPeriod_ = -1.0d;
 }
Пример #17
0
 /// <summary>
 /// Create a new Data object with default values and where the signature is a
 /// blank Sha256WithRsaSignature.
 /// </summary>
 ///
 public Data()
 {
     this.signature_ = new ChangeCounter(
             new Sha256WithRsaSignature());
     this.name_ = new ChangeCounter(new Name());
     this.metaInfo_ = new ChangeCounter(new MetaInfo());
     this.content_ = new Blob();
     this.lpPacket_ = null;
     this.defaultWireEncoding_ = new SignedBlob();
     this.defaultFullName_ = new Name();
     this.getDefaultWireEncodingChangeCount_ = 0;
     this.changeCount_ = 0;
 }
Пример #18
0
 public void testSegment()
 {
     Name expected = new Name("/%00%27%10");
     Assert.AssertTrue(expected.get(0).isSegment());
     long number = 10000;
     Assert.AssertEquals("appendSegment did not create the expected component",
             expected, new Name().appendSegment(number));
     try {
         Assert.AssertEquals("toSegment did not return the expected value", number,
                 expected.get(0).toSegment());
     } catch (EncodingException ex) {
         Assert.Fail("Error while parsing a nonNegativeInteger: " + ex.Message);
     }
 }
Пример #19
0
 /// <summary>
 /// Create a new Node for communication with an NDN hub with the given
 /// Transport object and connectionInfo.
 /// </summary>
 ///
 /// <param name="transport">A Transport object used for communication.</param>
 /// <param name="connectionInfo"></param>
 public Node(Transport transport, Transport.ConnectionInfo connectionInfo)
 {
     this.pendingInterestTable_ = new PendingInterestTable();
     this.interestFilterTable_ = new InterestFilterTable();
     this.registeredPrefixTable_ = new RegisteredPrefixTable(
             interestFilterTable_);
     this.delayedCallTable_ = new DelayedCallTable();
     this.onConnectedCallbacks_ = ILOG.J2CsMapping.Collections.Collections
             .synchronizedList(new ArrayList());
     this.commandInterestGenerator_ = new CommandInterestGenerator();
     this.timeoutPrefix_ = new Name("/local/timeout");
     this.lastEntryIdLock_ = new Object();
     this.connectStatus_ = net.named_data.jndn.Node.ConnectStatus.UNCONNECTED;
     transport_ = transport;
     connectionInfo_ = connectionInfo;
 }
Пример #20
0
        /// <summary>
        /// Add a new DelegationSet.Delegation to the list of delegations, sorted by
        /// preference number then by name. If there is already a delegation with the
        /// same name, update its preference, and remove any extra delegations with the
        /// same name.
        /// </summary>
        ///
        /// <param name="preference">The preference number.</param>
        /// <param name="name">The delegation name. This makes a copy of the name.</param>
        public void add(int preference, Name name)
        {
            remove(name);

            DelegationSet.Delegation  newDelegation = new DelegationSet.Delegation (preference, name);
            // Find the index of the first entry where it is not less than newDelegation.
            int i = 0;
            while (i < delegations_.Count) {
                if (delegations_[i].compare(newDelegation) >= 0)
                    break;

                ++i;
            }

            delegations_.Insert(i, newDelegation);
        }
        public bool add(long registeredPrefixId, Name prefix,
				long relatedInterestFilterId)
        {
            int removeRequestIndex = removeRequests_.indexOf(registeredPrefixId);
            if (removeRequestIndex >= 0) {
                // removeRegisteredPrefix was called with the registeredPrefixId returned
                //   by registerPrefix before we got here, so don't add a registered
                //   prefix table entry.
                ILOG.J2CsMapping.Collections.Collections.RemoveAt(removeRequests_,removeRequestIndex);
                return false;
            }

            ILOG.J2CsMapping.Collections.Collections.Add(table_,new RegisteredPrefixTable.Entry (registeredPrefixId, prefix,
                            relatedInterestFilterId));
            return true;
        }
Пример #22
0
 public void testNumberWithMarker()
 {
     Name expected = new Name("/%AA%03%E8");
     long number = 1000;
     int marker = 0xAA;
     Assert.AssertEquals(
             "fromNumberWithMarker did not create the expected component",
             expected, new Name().append(net.named_data.jndn.Name.Component
                     .fromNumberWithMarker(number, marker)));
     try {
         Assert.AssertEquals(
                 "toNumberWithMarker did not return the expected value",
                 number, expected.get(0).toNumberWithMarker(marker));
     } catch (EncodingException ex) {
         Assert.Fail("Error while parsing a nonNegativeInteger: " + ex.Message);
     }
 }
Пример #23
0
        /// <summary>
        /// Determine if the provided NDN regex matches the given Name.
        /// </summary>
        ///
        /// <param name="pattern">The NDN regex.</param>
        /// <param name="name">The Name to match against the regex.</param>
        /// <returns>The Matcher object from Pattern.matcher after the first find, or
        /// null if the pattern does not match.</returns>
        public static Matcher match(String pattern, Name name)
        {
            String nameUri = name.toUri();

            pattern = sanitizeSets(pattern);

            pattern = pattern.Replace("<>", "(?:<.+?>)");
            pattern = pattern.Replace(">", "");
            // Explicitly use regex replace for portability.
            pattern = ILOG.J2CsMapping.Text.Pattern.Compile("<(?!!)").Matcher(pattern).replaceAll("/");

            Matcher match = ILOG.J2CsMapping.Text.Pattern.Compile(pattern).Matcher(nameUri);
            if (match.Find())
                return match;
            else
                return null;
        }
Пример #24
0
        /// <summary>
        /// Fetch a certificate from the cache.
        /// </summary>
        ///
        /// <param name="certificateName"></param>
        /// <returns>A new copy of the IdentityCertificate, or null if not found.</returns>
        public IdentityCertificate getCertificate(Name certificateName)
        {
            Blob certData = (Blob) ILOG.J2CsMapping.Collections.Collections.Get(cache_,certificateName.toUri());
            if (certData == null)
                return null;

            IdentityCertificate cert = new IdentityCertificate();
            try {
                cert.wireDecode(certData.buf());
            } catch (EncodingException ex) {
                ILOG.J2CsMapping.Util.Logging.Logger.getLogger(typeof(CertificateCache).FullName).log(
                        ILOG.J2CsMapping.Util.Logging.Level.SEVERE, null, ex);
                throw new Exception(ex.Message);
            }

            return cert;
        }
Пример #25
0
        public void testOperateAesDecryptionKey()
        {
            // Test construction.
            ConsumerDb database = new Sqlite3ConsumerDb(System.IO.Path.GetFullPath(databaseFilePath.Name));

            // Generate key blobs.
            Blob[] encryptionKeyBlob = { null };
            Blob[] decryptionKeyBlob = { null };
            generateAesKeys(encryptionKeyBlob, decryptionKeyBlob);

            Name keyName = new Name(
                    "/alice/health/samples/activity/steps/C-KEY/20150928080000/20150928090000!");
            keyName.append(new Name("FOR/alice/health/read/activity!"));
            database.addKey(keyName, decryptionKeyBlob[0]);
            Blob resultBlob = database.getKey(keyName);

            AssertTrue(decryptionKeyBlob[0].equals(resultBlob));

            database.deleteKey(keyName);
            resultBlob = database.getKey(keyName);

            AssertEquals(0, resultBlob.size());
        }
Пример #26
0
        /// <summary>
        /// Get the public key name from the full certificate name.
        /// </summary>
        ///
        /// <param name="certificateName">The full certificate name.</param>
        /// <returns>The related public key name.</returns>
        public static Name certificateNameToPublicKeyName(Name certificateName)
        {
            String idString = "ID-CERT";
            bool foundIdString = false;
            int idCertComponentIndex = certificateName.size() - 1;
            for (; idCertComponentIndex + 1 > 0; --idCertComponentIndex) {
                if (certificateName.get(idCertComponentIndex).toEscapedString()
                        .equals(idString)) {
                    foundIdString = true;
                    break;
                }
            }

            if (!foundIdString)
                throw new Exception("Incorrect identity certificate name "
                        + certificateName.toUri());

            Name tempName = certificateName.getSubName(0, idCertComponentIndex);
            String keyString = "KEY";
            bool foundKeyString = false;
            int keyComponentIndex = 0;
            for (; keyComponentIndex < tempName.size(); keyComponentIndex++) {
                if (tempName.get(keyComponentIndex).toEscapedString()
                        .equals(keyString)) {
                    foundKeyString = true;
                    break;
                }
            }

            if (!foundKeyString)
                throw new Exception("Incorrect identity certificate name "
                        + certificateName.toUri());

            return tempName.getSubName(0, keyComponentIndex).append(
                    tempName.getSubName(keyComponentIndex + 1, tempName.size()
                            - keyComponentIndex - 1));
        }
        // Returns a CallbackCounter object so we can test data callback, nack callback
        // and timeout behavior.
        private static CallbackCounter runExpressNameTest(Face face,
				String interestName, double timeout, bool useOnNack)
        {
            Name name = new Name(interestName);
            CallbackCounter counter = new CallbackCounter();
            try {
                if (useOnNack)
                    // Debug: Use one of the simpler forms
                    face.expressInterest(new Interest(name), counter, counter,
                            counter, net.named_data.jndn.encoding.WireFormat.getDefaultWireFormat());
                else
                    face.expressInterest(name, counter, counter);
            } catch (IOException ex) {
                ILOG.J2CsMapping.Util.Logging.Logger.getLogger(typeof(TestFaceInterestMethods).FullName).log(
                        ILOG.J2CsMapping.Util.Logging.Level.SEVERE, null, ex);
                return null;
            }

            double startTime = getNowMilliseconds();
            while (getNowMilliseconds() - startTime < timeout
                    && counter.onDataCallCount_ == 0
                    && counter.onTimeoutCallCount_ == 0
                    && counter.onNetworkNackCallCount_ == 0) {
                try {
                    try {
                        face.processEvents();
                    } catch (IOException ex_0) {
                        ILOG.J2CsMapping.Util.Logging.Logger.getLogger(typeof(TestFaceInterestMethods).FullName)
                                .log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, null, ex_0);
                        break;
                    } catch (EncodingException ex_1) {
                        ILOG.J2CsMapping.Util.Logging.Logger.getLogger(typeof(TestFaceInterestMethods).FullName)
                                .log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, null, ex_1);
                        break;
                    }

                    // We need to sleep for a few milliseconds so we don't use 100% of the CPU.
                    ILOG.J2CsMapping.Threading.ThreadWrapper.sleep(10);
                } catch (ThreadInterruptedException ex_2) {
                    ILOG.J2CsMapping.Util.Logging.Logger.getLogger(typeof(TestFaceInterestMethods).FullName).log(
                            ILOG.J2CsMapping.Util.Logging.Level.SEVERE, null, ex_2);
                    break;
                }
            }

            return counter;
        }
        public void testRemovePending()
        {
            Name name = new Name("/ndn/edu/ucla/remap/");
            CallbackCounter counter = new CallbackCounter();
            long interestID;
            try {
                interestID = face.expressInterest(name, counter, counter);
            } catch (IOException ex) {
                Fail("Error in expressInterest: " + ex);
                return;
            }

            face.removePendingInterest(interestID);

            double timeout = 10000;
            double startTime = getNowMilliseconds();
            while (getNowMilliseconds() - startTime < timeout
                    && counter.onDataCallCount_ == 0
                    && counter.onTimeoutCallCount_ == 0) {
                try {
                    face.processEvents();
                } catch (IOException ex_0) {
                    Fail("Error in processEvents: " + ex_0);
                    return;
                } catch (EncodingException ex_1) {
                    Fail("Error in processEvents: " + ex_1);
                    return;
                }

                try {
                    // We need to sleep for a few milliseconds so we don't use 100% of the CPU.
                    ILOG.J2CsMapping.Threading.ThreadWrapper.sleep(10);
                } catch (ThreadInterruptedException ex_2) {
                    Fail("Error in sleep: " + ex_2);
                    return;
                }
            }

            AssertEquals(
                    "Should not have called data callback after interest was removed",
                    0, counter.onDataCallCount_);
            AssertTrue(
                    "Should not have called timeout callback after interest was removed",
                    counter.onTimeoutCallCount_ == 0);
        }
 /// <summary>
 /// Override to always indicate that the signing certificate name and data name
 /// satisfy the signing policy.
 /// </summary>
 ///
 /// <param name="dataName">The name of data to be signed.</param>
 /// <param name="certificateName">The name of signing certificate.</param>
 /// <returns>true to indicate that the signing certificate can be used to sign
 /// the data.</returns>
 public override bool checkSigningPolicy(Name dataName, Name certificateName)
 {
     return true;
 }
 /// <summary>
 /// Override to indicate that the signing identity cannot be inferred.
 /// </summary>
 ///
 /// <param name="dataName">The name of data to be signed.</param>
 /// <returns>An empty name because cannot infer.</returns>
 public override Name inferSigningIdentity(Name dataName)
 {
     return new Name();
 }