Example #1
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);
              }
        }
        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);
              }
        }
        public void setUp()
        {
            // retrieve NFD hostname to use
            String hostname = System.Environment.GetEnvironmentVariable("nfd.hostname");
            if (hostname == null) {
                hostname = "localhost";
            }

            // build face
            face = net.named_data.jndn.tests.integration_tests.IntegrationTestsCommon.buildFaceWithKeyChain(hostname);
        }
Example #4
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);
        }
        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);
        }
 /// <summary>
 /// Create a new MemoryContentCache to use the given Face.
 /// </summary>
 ///
 /// <param name="face"></param>
 /// <param name="cleanupIntervalMilliseconds">large number, then effectively the stale content will not be removed from the cache.</param>
 public MemoryContentCache(Face face, double cleanupIntervalMilliseconds)
 {
     this.onDataNotFoundForPrefix_ = new Hashtable();
     this.interestFilterIdList_ = new ArrayList<Int64>();
     this.registeredPrefixIdList_ = new ArrayList<Int64>();
     this.noStaleTimeCache_ = new ArrayList<Content>();
     this.staleTimeCache_ = new ArrayList<StaleTimeContent>();
     this.emptyComponent_ = new Name.Component();
     this.pendingInterestTable_ = new ArrayList<PendingInterest>();
     face_ = face;
     cleanupIntervalMilliseconds_ = cleanupIntervalMilliseconds;
     construct();
 }
            public void onInterest(Name localPrefix, Interest localInterest,
						Face localFace, long localInterestFilterId,
						InterestFilter localFilter)
            {
                outer_MemoryContentCache.storePendingInterest(localInterest, localFace);
            }
        public void onInterest(Name prefix, Interest interest, Face face,
				long interestFilterId, InterestFilter filter)
        {
            doCleanup();

            Name.Component selectedComponent = null;
            Blob selectedEncoding = null;
            // We need to iterate over both arrays.
            int totalSize = staleTimeCache_.Count + noStaleTimeCache_.Count;
            for (int i = 0; i < totalSize; ++i) {
                MemoryContentCache.Content  content;
                if (i < staleTimeCache_.Count)
                    content = staleTimeCache_[i];
                else
                    // We have iterated over the first array. Get from the second.
                    content = noStaleTimeCache_[i - staleTimeCache_.Count];

                if (interest.matchesName(content.getName())) {
                    if (interest.getChildSelector() < 0) {
                        // No child selector, so send the first match that we have found.
                        try {
                            face.send(content.getDataEncoding());
                        } catch (IOException ex) {
                            ILOG.J2CsMapping.Util.Logging.Logger.getLogger(typeof(MemoryContentCache).FullName)
                                    .log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, null, ex);
                        }
                        return;
                    } else {
                        // Update selectedEncoding based on the child selector.
                        Name.Component component;
                        if (content.getName().size() > interest.getName().size())
                            component = content.getName().get(
                                    interest.getName().size());
                        else
                            component = emptyComponent_;

                        bool gotBetterMatch = false;
                        if (selectedEncoding == null)
                            // Save the first match.
                            gotBetterMatch = true;
                        else {
                            if (interest.getChildSelector() == 0) {
                                // Leftmost child.
                                if (component.compare(selectedComponent) < 0)
                                    gotBetterMatch = true;
                            } else {
                                // Rightmost child.
                                if (component.compare(selectedComponent) > 0)
                                    gotBetterMatch = true;
                            }
                        }

                        if (gotBetterMatch) {
                            selectedComponent = component;
                            selectedEncoding = content.getDataEncoding();
                        }
                    }
                }
            }

            if (selectedEncoding != null) {
                // We found the leftmost or rightmost child.
                try {
                    face.send(selectedEncoding);
                } catch (IOException ex_0) {
                    ILOG.J2CsMapping.Util.Logging.Logger.getLogger(typeof(MemoryContentCache).FullName).log(
                            ILOG.J2CsMapping.Util.Logging.Level.SEVERE, null, ex_0);
                }
            } else {
                // Call the onDataNotFound callback (if defined).
                Object onDataNotFound = ILOG.J2CsMapping.Collections.Collections.Get(onDataNotFoundForPrefix_,prefix.toUri());
                if (onDataNotFound != null) {
                    try {
                        ((OnInterestCallback) onDataNotFound).onInterest(prefix,
                                interest, face, interestFilterId, filter);
                    } catch (Exception ex_1) {
                        logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onDataNotFound", ex_1);
                    }
                }
            }
        }
 /// <summary>
 /// Store an interest from an OnInterest callback in the internal pending
 /// interest table (normally because there is no Data packet available yet to
 /// satisfy the interest). add(data) will check if the added Data packet
 /// satisfies any pending interest and send it through the face.
 /// </summary>
 ///
 /// <param name="interest"></param>
 /// <param name="face"></param>
 public void storePendingInterest(Interest interest, Face face)
 {
     ILOG.J2CsMapping.Collections.Collections.Add(pendingInterestTable_,new MemoryContentCache.PendingInterest (interest, face));
 }
        public void setInterestFilter(long interestFilterId,
				InterestFilter filter, OnInterestCallback onInterest, Face face)
        {
            ILOG.J2CsMapping.Collections.Collections.Add(table_,new InterestFilterTable.Entry (interestFilterId, filter, onInterest, face));
        }
Example #11
0
 /// <summary>
 /// Create a new KeyChain with the the default IdentityManager and a
 /// NoVerifyPolicyManager.
 /// </summary>
 ///
 public KeyChain()
 {
     this.face_ = null;
     identityManager_ = new IdentityManager();
     policyManager_ = new NoVerifyPolicyManager();
 }
Example #12
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="registeredPrefixId"></param>
        /// <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). If onInterest is null, it is ignored and you must call setInterestFilter.</param>
        /// <param name="onRegisterFailed">prefix.</param>
        /// <param name="onRegisterSuccess">receives a success message from the forwarder. If onRegisterSuccess is null, this does not use it.</param>
        /// <param name="flags"></param>
        /// <param name="wireFormat">A WireFormat object used to encode the message.</param>
        /// <param name="commandKeyChain">The KeyChain object for signing interests.</param>
        /// <param name="commandCertificateName">The certificate name for signing interests.</param>
        /// <param name="face"></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(long registeredPrefixId, Name prefix,
				OnInterestCallback onInterest, OnRegisterFailed onRegisterFailed,
				OnRegisterSuccess onRegisterSuccess, ForwardingFlags flags,
				WireFormat wireFormat, KeyChain commandKeyChain,
				Name commandCertificateName, Face face)
        {
            nfdRegisterPrefix(registeredPrefixId, new Name(prefix), onInterest,
                    onRegisterFailed, onRegisterSuccess, flags, commandKeyChain,
                    commandCertificateName, wireFormat, face);
        }
        private static CallbackCounter runExpressNameTest(Face face,
				String interestName)
        {
            return runExpressNameTest(face, interestName, 10000, false);
        }
            public void onInterest(Name prefix, Interest interest, Face face,
						long interestFilterId, InterestFilter filter)
            {
                ++interestCallbackCount[0];
                    Data data = new Data(interest.getName());
                    data.setContent(new Blob("SUCCESS"));

                    try {
                        outer_TestFaceCallRegisterMethods.keyChain.sign(data, outer_TestFaceCallRegisterMethods.certificateName);
                    } catch (SecurityException ex) {
                        net.named_data.jndn.tests.integration_tests.TestFaceCallRegisterMethods.logger.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, null, ex);
                    }
                    try {
                        face.putData(data);
                    } catch (IOException ex_0) {
                        net.named_data.jndn.tests.integration_tests.TestFaceCallRegisterMethods.logger.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, null, ex_0);
                    }
            }
        /// <summary>
        /// Create a Face using a the given KeyChain and certificate name.
        /// </summary>
        ///
        /// <param name="keyChain">The KeyChain. This calls keyChain.setFace with the created Face.</param>
        /// <param name="certificateName">The signing certificate name to use with keyChain.</param>
        /// <param name="hostname"></param>
        /// <returns>A Face configured with a valid signing key chain.</returns>
        /// <exception cref="System.Security.SecurityException"></exception>
        public static Face buildFaceWithKeyChain(String hostname,
				KeyChain keyChain, Name certificateName)
        {
            Face face = new Face(hostname);
            keyChain.setFace(face);
            face.setCommandSigningInfo(keyChain, certificateName);

            return face;
        }
Example #16
0
            public Anonymous_C3(Node paramouter_Node, Interest interestCopy_0,
						OnNetworkNack onNetworkNack_1, Face face_2, OnTimeout onTimeout_3,
						long pendingInterestId_4, WireFormat wireFormat_5, OnData onData_6)
            {
                this.interestCopy = interestCopy_0;
                    this.onNetworkNack = onNetworkNack_1;
                    this.face = face_2;
                    this.onTimeout = onTimeout_3;
                    this.pendingInterestId = pendingInterestId_4;
                    this.wireFormat = wireFormat_5;
                    this.onData = onData_6;
                    this.outer_Node = paramouter_Node;
            }
Example #17
0
                /// <param name="prefix"></param>
                /// <param name="onRegisterFailed"></param>
                /// <param name="onRegisterSuccess"></param>
                /// <param name="registeredPrefixId"></param>
                /// <param name="onInterest">The callback to add if register succeeds.</param>
                /// <param name="face_0"></param>
                public Info(Name prefix, OnRegisterFailed onRegisterFailed,
						OnRegisterSuccess onRegisterSuccess,
						long registeredPrefixId, OnInterestCallback onInterest,
						Face face_0)
                {
                    prefix_ = prefix;
                    onRegisterFailed_ = onRegisterFailed;
                    onRegisterSuccess_ = onRegisterSuccess;
                    registeredPrefixId_ = registeredPrefixId;
                    onInterest_ = onInterest;
                    face_ = face_0;
                }
Example #18
0
        /// <summary>
        /// Do the work of registerPrefix to register with NFD.
        /// </summary>
        ///
        /// <param name="registeredPrefixId">registeredPrefixTable_ (assuming it has already been done).</param>
        /// <param name="prefix"></param>
        /// <param name="onInterest"></param>
        /// <param name="onRegisterFailed"></param>
        /// <param name="onRegisterSuccess"></param>
        /// <param name="flags"></param>
        /// <param name="commandKeyChain"></param>
        /// <param name="commandCertificateName"></param>
        /// <param name="wireFormat_0"></param>
        /// <param name="face_1"></param>
        /// <exception cref="System.Security.SecurityException">If cannot find the private key for thecertificateName.</exception>
        private void nfdRegisterPrefix(long registeredPrefixId, Name prefix,
				OnInterestCallback onInterest, OnRegisterFailed onRegisterFailed,
				OnRegisterSuccess onRegisterSuccess, ForwardingFlags flags,
				KeyChain commandKeyChain, Name commandCertificateName,
				WireFormat wireFormat_0, Face face_1)
        {
            if (commandKeyChain == null)
                throw new Exception(
                        "registerPrefix: The command KeyChain has not been set. You must call setCommandSigningInfo.");
            if (commandCertificateName.size() == 0)
                throw new Exception(
                        "registerPrefix: The command certificate name has not been set. You must call setCommandSigningInfo.");

            ControlParameters controlParameters = new ControlParameters();
            controlParameters.setName(prefix);
            controlParameters.setForwardingFlags(flags);

            Interest commandInterest = new Interest();

            // Determine whether to use remote prefix registration.
            bool faceIsLocal;
            try {
                faceIsLocal = isLocal();
            } catch (IOException ex) {
                logger_.log(
                        ILOG.J2CsMapping.Util.Logging.Level.INFO,
                        "Register prefix failed: Error attempting to determine if the face is local: {0}",
                        ex);
                try {
                    onRegisterFailed.onRegisterFailed(prefix);
                } catch (Exception exception) {
                    logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onRegisterFailed",
                            exception);
                }
                return;
            }

            if (faceIsLocal) {
                commandInterest.setName(new Name("/localhost/nfd/rib/register"));
                // The interest is answered by the local host, so set a short timeout.
                commandInterest.setInterestLifetimeMilliseconds(2000.0d);
            } else {
                commandInterest.setName(new Name("/localhop/nfd/rib/register"));
                // The host is remote, so set a longer timeout.
                commandInterest.setInterestLifetimeMilliseconds(4000.0d);
            }

            // NFD only accepts TlvWireFormat packets.
            commandInterest.getName().append(
                    controlParameters.wireEncode(net.named_data.jndn.encoding.TlvWireFormat.get()));
            makeCommandInterest(commandInterest, commandKeyChain,
                    commandCertificateName, net.named_data.jndn.encoding.TlvWireFormat.get());

            // Send the registration interest.
            Node.RegisterResponse  response = new Node.RegisterResponse (
                    new RegisterResponse.Info(prefix, onRegisterFailed,
                            onRegisterSuccess, registeredPrefixId, onInterest, face_1),
                    this);
            try {
                expressInterest(getNextEntryId(), commandInterest, response,
                        response, null, wireFormat_0, face_1);
            } catch (IOException ex_2) {
                // Can't send the interest. Call onRegisterFailed.
                logger_.log(
                        ILOG.J2CsMapping.Util.Logging.Level.INFO,
                        "Register prefix failed: Error sending the register prefix interest to the forwarder: {0}",
                        ex_2);
                try {
                    onRegisterFailed.onRegisterFailed(prefix);
                } catch (Exception exception_3) {
                    logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, "Error in onRegisterFailed",
                            exception_3);
                }
            }
        }
Example #19
0
        /// <summary>
        /// Do the work of expressInterest once we know we are connected. Add the entry
        /// to the PIT, encode and send the interest.
        /// </summary>
        ///
        /// <param name="pendingInterestId"></param>
        /// <param name="interestCopy"></param>
        /// <param name="onData"></param>
        /// <param name="onTimeout"></param>
        /// <param name="onNetworkNack"></param>
        /// <param name="wireFormat">A WireFormat object used to encode the message.</param>
        /// <param name="face"></param>
        /// <exception cref="IOException">For I/O error in sending the interest.</exception>
        /// <exception cref="System.Exception">If the encoded interest size exceeds getMaxNdnPacketSize().</exception>
        internal void expressInterestHelper(long pendingInterestId,
				Interest interestCopy, OnData onData, OnTimeout onTimeout,
				OnNetworkNack onNetworkNack, WireFormat wireFormat, Face face)
        {
            PendingInterestTable.Entry pendingInterest = pendingInterestTable_
                    .add(pendingInterestId, interestCopy, onData, onTimeout,
                            onNetworkNack);
            if (pendingInterest == null)
                // removePendingInterest was already called with the pendingInterestId.
                return;

            if (onTimeout != null
                    || interestCopy.getInterestLifetimeMilliseconds() >= 0.0d) {
                // Set up the timeout.
                double delayMilliseconds = interestCopy
                        .getInterestLifetimeMilliseconds();
                if (delayMilliseconds < 0.0d)
                    // Use a default timeout delay.
                    delayMilliseconds = 4000.0d;

                face.callLater(delayMilliseconds, new Node.Anonymous_C0 (this, pendingInterest));
            }

            // Special case: For timeoutPrefix_ we don't actually send the interest.
            if (!timeoutPrefix_.match(interestCopy.getName())) {
                Blob encoding = interestCopy.wireEncode(wireFormat);
                if (encoding.size() > getMaxNdnPacketSize())
                    throw new Exception(
                            "The encoded interest size exceeds the maximum limit getMaxNdnPacketSize()");
                transport_.send(encoding.buf());
            }
        }
Example #20
0
        /// <summary>
        /// Add an entry to the local interest filter table to call the onInterest
        /// callback for a matching incoming Interest. This method only modifies the
        /// library's local callback table and does not register the prefix with the
        /// forwarder. It will always succeed. To register a prefix with the forwarder,
        /// use registerPrefix.
        /// </summary>
        ///
        /// <param name="interestFilterId"></param>
        /// <param name="filter"></param>
        /// <param name="onInterest">onInterest.onInterest(prefix, interest, face, interestFilterId, filter).</param>
        /// <param name="face">The face which is passed to the onInterest callback.</param>
        public void setInterestFilter(long interestFilterId,
				InterestFilter filter, OnInterestCallback onInterest, Face face)
        {
            interestFilterTable_.setInterestFilter(interestFilterId,
                    new InterestFilter(filter), onInterest, face);
        }
            /// <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;
            }
        static void Main(string[] args)
        {
            var interest = new Interest();
              interest.wireDecode(new Blob(TlvInterest));
              Console.Out.WriteLine("Interest:");
              dumpInterest(interest);

              // Set the name again to clear the cached encoding so we encode again.
              interest.setName(interest.getName());
              var encoding = interest.wireEncode();
              Console.Out.WriteLine("");
              Console.Out.WriteLine("Re-encoded interest " + encoding.toHex());

              var reDecodedInterest = new Interest();
              reDecodedInterest.wireDecode(encoding);
              Console.Out.WriteLine("");
              Console.Out.WriteLine("Re-decoded Interest:");
              dumpInterest(reDecodedInterest);

              var freshInterest = new Interest(new Name("/ndn/abc"));
              freshInterest.setMinSuffixComponents(4);
              freshInterest.setMaxSuffixComponents(6);
              freshInterest.setInterestLifetimeMilliseconds(30000);
              freshInterest.setChildSelector(1);
              freshInterest.setMustBeFresh(true);
              freshInterest.getKeyLocator().setType(KeyLocatorType.KEY_LOCATOR_DIGEST);
              freshInterest.getKeyLocator().setKeyData
            (new Blob(new byte[] {
              0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
              0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F }));
              freshInterest.getExclude().appendComponent(new Name("abc").get(0)).appendAny();

              var identityStorage = new MemoryIdentityStorage();
              var privateKeyStorage = new MemoryPrivateKeyStorage();
              var keyChain = new KeyChain
            (new IdentityManager(identityStorage, privateKeyStorage),
              new SelfVerifyPolicyManager(identityStorage));

              // Initialize the storage.
              var keyName = new Name("/testname/DSK-123");
              var certificateName = keyName.getSubName(0, keyName.size() - 1).append
            ("KEY").append(keyName.get(-1)).append("ID-CERT").append("0");
              identityStorage.addKey(keyName, KeyType.RSA, new Blob(DEFAULT_RSA_PUBLIC_KEY_DER));
              privateKeyStorage.setKeyPairForKeyName
            (keyName, KeyType.RSA, new ByteBuffer(DEFAULT_RSA_PUBLIC_KEY_DER),
             new ByteBuffer(DEFAULT_RSA_PRIVATE_KEY_DER));

              // Make a Face just so that we can sign the interest.
              var face = new Face("localhost");
              face.setCommandSigningInfo(keyChain, certificateName);
              face.makeCommandInterest(freshInterest);

              Interest reDecodedFreshInterest = new Interest();
              reDecodedFreshInterest.wireDecode(freshInterest.wireEncode());
              Console.Out.WriteLine("");
              Console.Out.WriteLine("Re-decoded fresh Interest:");
              dumpInterest(reDecodedFreshInterest);

              VerifyCallbacks callbacks = new VerifyCallbacks("Freshly-signed Interest");
              keyChain.verifyInterest(reDecodedFreshInterest, callbacks, callbacks);
        }
Example #23
0
        /// <summary>
        /// Initiate segment fetching. For more details, see the documentation for
        /// the class.
        /// </summary>
        ///
        /// <param name="face">This calls face.expressInterest to fetch more segments.</param>
        /// <param name="baseInterest">This interest may include a custom InterestLifetime and selectors that will propagate to all subsequent Interests. The only exception is that the initial Interest will be forced to include selectors "ChildSelector=1" and "MustBeFresh=true" which will be turned off in subsequent Interests.</param>
        /// <param name="validatorKeyChain">fetching and call onError with SEGMENT_VERIFICATION_FAILED. This does not make a copy of the KeyChain; the object must remain valid while fetching. If validatorKeyChain is null, this does not validate the data packet.</param>
        /// <param name="onComplete">content of all the segments. 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="onError">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>
        public static void fetch(Face face, Interest baseInterest,
				KeyChain validatorKeyChain, SegmentFetcher.OnComplete  onComplete, SegmentFetcher.OnError  onError)
        {
            new SegmentFetcher(face, validatorKeyChain, DontVerifySegment,
                    onComplete, onError).fetchFirstSegment(baseInterest);
        }
Example #24
0
        /// <summary>
        /// Send the Interest through the transport, read the entire response and call
        /// onData, onTimeout or onNetworkNack as described below.
        /// </summary>
        ///
        /// <param name="pendingInterestId"></param>
        /// <param name="interestCopy">to use.</param>
        /// <param name="onData">expressInterest and data is the received Data object.</param>
        /// <param name="onTimeout">interest given to expressInterest. If onTimeout is null, this does not use it.</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.</param>
        /// <param name="wireFormat">A WireFormat object used to encode the message.</param>
        /// <param name="face"></param>
        /// <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 void expressInterest(long pendingInterestId,
				Interest interestCopy, OnData onData,
				OnTimeout onTimeout, OnNetworkNack onNetworkNack,
				WireFormat wireFormat, Face face)
        {
            // Set the nonce in our copy of the Interest so it is saved in the PIT.
            interestCopy.setNonce(nonceTemplate_);
            interestCopy.refreshNonce();

            if (connectStatus_ == net.named_data.jndn.Node.ConnectStatus.CONNECT_COMPLETE) {
                // We are connected. Simply send the interest without synchronizing.
                expressInterestHelper(pendingInterestId, interestCopy, onData,
                        onTimeout, onNetworkNack, wireFormat, face);
                return;
            }

             lock (onConnectedCallbacks_) {
                        // TODO: Properly check if we are already connected to the expected host.
                        if (!transport_.isAsync()) {
                            // The simple case: Just do a blocking connect and express.
                            transport_.connect(connectionInfo_, this, null);
                            expressInterestHelper(pendingInterestId, interestCopy, onData,
                                    onTimeout, onNetworkNack, wireFormat, face);
                            // Make future calls to expressInterest send directly to the Transport.
                            connectStatus_ = net.named_data.jndn.Node.ConnectStatus.CONNECT_COMPLETE;

                            return;
                        }

                        // Handle the async case.
                        if (connectStatus_ == net.named_data.jndn.Node.ConnectStatus.UNCONNECTED) {
                            connectStatus_ = net.named_data.jndn.Node.ConnectStatus.CONNECT_REQUESTED;

                            // expressInterestHelper will be called by onConnected.
                            ILOG.J2CsMapping.Collections.Collections.Add(onConnectedCallbacks_,new Node.Anonymous_C3 (this, interestCopy, onNetworkNack, face,
                                                    onTimeout, pendingInterestId, wireFormat, onData));

                            IRunnable onConnected = new Node.Anonymous_C2 (this);
                            transport_.connect(connectionInfo_, this, onConnected);
                        } else if (connectStatus_ == net.named_data.jndn.Node.ConnectStatus.CONNECT_REQUESTED) {
                            // Still connecting. add to the interests to express by onConnected.
                            ILOG.J2CsMapping.Collections.Collections.Add(onConnectedCallbacks_,new Node.Anonymous_C1 (this, interestCopy, onData, onTimeout,
                                                    onNetworkNack, wireFormat, face, pendingInterestId));
                        } else if (connectStatus_ == net.named_data.jndn.Node.ConnectStatus.CONNECT_COMPLETE)
                            // We have to repeat this check for CONNECT_COMPLETE in case the
                            // onConnected callback was called while we were waiting to enter this
                            // synchronized block.
                            expressInterestHelper(pendingInterestId, interestCopy, onData,
                                    onTimeout, onNetworkNack, wireFormat, face);
                        else
                            // Don't expect this to happen.
                            throw new Exception("Node: Unrecognized _connectStatus "
                                    + connectStatus_);
                    }
        }
Example #25
0
        /// <summary>
        /// Initiate segment fetching. For more details, see the documentation for
        /// the class.
        /// </summary>
        ///
        /// <param name="face">This calls face.expressInterest to fetch more segments.</param>
        /// <param name="baseInterest">This interest may include a custom InterestLifetime and selectors that will propagate to all subsequent Interests. The only exception is that the initial Interest will be forced to include selectors "ChildSelector=1" and "MustBeFresh=true" which will be turned off in subsequent Interests.</param>
        /// <param name="verifySegment">and call onError.onError with ErrorCode.SEGMENT_VERIFICATION_FAILED. If data validation is not required, use DontVerifySegment. 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="onComplete">content of all the segments. 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="onError">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>
        public static void fetch(Face face, Interest baseInterest,
				SegmentFetcher.VerifySegment  verifySegment, SegmentFetcher.OnComplete  onComplete, SegmentFetcher.OnError  onError)
        {
            new SegmentFetcher(face, null, verifySegment, onComplete, onError)
                    .fetchFirstSegment(baseInterest);
        }
Example #26
0
 /// <summary>
 /// Set the Face which will be used to fetch required certificates.
 /// </summary>
 ///
 /// <param name="face">The Face object.</param>
 public void setFace(Face face)
 {
     face_ = face;
 }
        // 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;
        }
Example #28
0
 /// <summary>
 /// Create a new KeyChain with the given IdentityManager and PolicyManager.
 /// </summary>
 ///
 /// <param name="identityManager">An object of a subclass of IdentityManager.</param>
 /// <param name="policyManager">An object of a subclass of PolicyManager.</param>
 public KeyChain(IdentityManager identityManager, PolicyManager policyManager)
 {
     this.face_ = null;
     identityManager_ = identityManager;
     policyManager_ = policyManager;
 }
 public void setUp()
 {
     face = new Face("localhost");
 }
            /// <summary>
            /// Create a new Entry with the given values.
            /// </summary>
            ///
            /// <param name="interestFilterId">The ID from Node.getNextEntryId().</param>
            /// <param name="filter">The InterestFilter for this entry.</param>
            /// <param name="onInterest">The callback to call.</param>
            /// <param name="face"></param>
            public Entry(long interestFilterId, InterestFilter filter,
					OnInterestCallback onInterest, Face face)
            {
                interestFilterId_ = interestFilterId;
                filter_ = filter;
                onInterest_ = onInterest;
                face_ = face;
            }