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>")); }
/// <summary> /// Find the certificate by the given interest. /// </summary> /// /// <param name="interest">The input interest object.</param> /// <returns>The found certificate which matches the interest, or null if not /// found. You must not modify the returned object. If you need to modify it, /// then make a copy.</returns> /// @note ChildSelector is not supported. public CertificateV2 find(Interest interest) { if (interest.getChildSelector() >= 0) { logger_.log( ILOG.J2CsMapping.Util.Logging.Level.FINE, "Certificate search using a ChildSelector is not supported. Searching as if this selector not specified"); } if (interest.getName().size() > 0 && interest.getName().get(-1).isImplicitSha256Digest()) { logger_.log(ILOG.J2CsMapping.Util.Logging.Level.FINE, "Certificate search using a name with an implicit digest is not yet supported"); } refresh(); Name firstKey = (Name)certificatesByName_.ceilingKey(interest .getName()); if (firstKey == null) { return(null); } /* foreach */ foreach (Object key in certificatesByName_.navigableKeySet().tailSet( firstKey)) { CertificateV2 certificate = ((CertificateCacheV2.Entry)certificatesByName_[(Name)key]).certificate_; if (!interest.getName().isPrefixOf(certificate.getName())) { break; } try { if (interest.matchesData(certificate)) { return(certificate); } } catch (EncodingException ex) { // We don't expect this. Promote to Error. throw new Exception("Error in Interest.matchesData: " + ex); } } return(null); }
public void onInterest(Name prefix, Interest interest, Face face, long interestFilterId, InterestFilter filter) { logger_.log(ILOG.J2CsMapping.Util.Logging.Level.INFO, "MemoryContentCache: Received Interest {0}", interest.toUri()); double nowMilliseconds = net.named_data.jndn.util.Common.getNowMilliseconds(); doCleanup(nowMilliseconds); 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; bool isFresh = true; if (i < staleTimeCache_.Count) { MemoryContentCache.StaleTimeContent staleTimeContent = staleTimeCache_[i]; content = staleTimeContent; isFresh = staleTimeContent.isFresh(nowMilliseconds); } else { // We have iterated over the first array. Get from the second. content = noStaleTimeCache_[i - staleTimeCache_.Count]; } if (interest.matchesName(content.getName()) && !(interest.getMustBeFresh() && !isFresh)) { if (interest.getChildSelector() < 0) { // No child selector, so send the first match that we have found. logger_.log(ILOG.J2CsMapping.Util.Logging.Level.INFO, "MemoryContentCache: Reply Data {0}", content.getName()); try { face.send(content.getDataEncoding()); } catch (IOException ex) { logger_.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 { logger_.log(ILOG.J2CsMapping.Util.Logging.Level.INFO, "MemoryContentCache: Reply Data to Interest {0}", interest.toUri()); face.send(selectedEncoding); } catch (IOException ex_0) { logger_.log(ILOG.J2CsMapping.Util.Logging.Level.SEVERE, null, ex_0); } } else { logger_.log(ILOG.J2CsMapping.Util.Logging.Level.INFO, "MemoryContentCache: onDataNotFound for {0}", interest.toUri()); // 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); } } } }
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); }