// 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; }
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); } }
static void Main(string[] args) { var face = new Face (new TcpTransport(), new TcpTransport.ConnectionInfo("localhost")); // For now, when setting face.setCommandSigningInfo, use a key chain with // a default private key instead of the system default key chain. This // is OK for now because NFD is configured to skip verification, so it // ignores the system default key chain. var identityStorage = new MemoryIdentityStorage(); var privateKeyStorage = new MemoryPrivateKeyStorage(); var keyChain = new KeyChain (new IdentityManager(identityStorage, privateKeyStorage), new SelfVerifyPolicyManager(identityStorage)); keyChain.setFace(face); // 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)); face.setCommandSigningInfo(keyChain, certificateName); var echo = new Echo(keyChain, certificateName); var prefix = new Name("/testecho"); Console.Out.WriteLine("Register prefix " + prefix.toUri()); face.registerPrefix(prefix, echo, echo); // The main event loop. // Wait to receive one interest for the prefix. while (echo.responseCount_ < 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); } }