public List<MockForwarder.PitEntry> extract(Name name) { ArrayList<MockForwarder.PitEntry> entries = new ArrayList<>(); for (int i = name.size(); i >= 0; i--) { Name prefix = name.getPrefix(i); List<MockForwarder.PitEntry> pendingInterests = pit.get(prefix); if (pendingInterests != null) { entries.addAll(pendingInterests); pendingInterests.clear(); // TODO is this necessary } } return entries; }
@Override public Optional<NameTree<T>> find(Name name) { if (name.size() == 0) { return Optional.of(this); } else { Name.Component first = name.get(0); DefaultNameTree<T> child = children.get(first); if (child == null) { return Optional.empty(); } else { return child.find(name.size() > 1 ? name.getSubName(1) : new Name()); } } }
/** * @param content the content to check (e.g. /a/b/c) * @param interest the interest to check from (e.g. /a/b) * @return the next component from a Data packet after specified Interest * components (e.g. c); if the Data is not longer than the Interest, return an * empty component. */ private static Name.Component getNextComponentAfterLastInterestComponent(Data content, Interest interest) { if (content.getName().size() > interest.getName().size()) { return content.getName().get(interest.getName().size()); } else { return new Name.Component(); } }
/** * Determine if a name is segmented, i.e. if it ends with the correct marker type. * * @param name the name of a packet * @param marker the marker type (the initial byte of the component) * @return true if the name is segmented */ public static boolean isSegmented(Name name, byte marker) { return name.size() > 0 && name.get(-1).getValue().buf().get(0) == marker; }
@Override public Optional<NameTree<T>> delete(Name name) { if (name.size() == 0) { return Optional.of(parent.deleteChild(this.component)); } else { Name.Component first = name.get(0); DefaultNameTree<T> child = children.get(first); if (child == null) { return Optional.empty(); } else { if (children.size() == 1) { children.remove(first); } return child.delete(name.getSubName(1)); } } }
@Override public NameTree<T> insert(Name name, T content) { Name.Component first = name.get(0); DefaultNameTree<T> child = children.get(first); if (child == null) { child = new DefaultNameTree<>(this); child.component = first; children.put(first, child); } if (name.size() == 1) { child.content = content; return child; } else { return child.insert(name.getSubName(1), content); } }
/** * Retrieve the segment number from the last component of a name. * * @param name the name of a packet * @param marker the marker type (the initial byte of the component) * @return the segment number * @throws EncodingException if the name does not have a final component of the correct marker type */ public static long parseSegment(Name name, byte marker) throws EncodingException { if (name.size() == 0) { throw new EncodingException("No components to parse."); } return name.get(-1).toNumberWithMarker(marker); }
public List<MockForwarder.FibEntry> find(Interest interest) { ArrayList<MockForwarder.FibEntry> entries = new ArrayList<>(); for (int i = interest.getName().size(); i >= 0; i--) { Name prefix = interest.getName().getPrefix(i); MockForwarder.FibEntry entry = fib.get(prefix); if (entry != null) { entries.add(entry); if (!entry.getFlags().getChildInherit() || entry.getFlags().getCapture()) { break; } } } return entries; } }
private static long findMarkerFromEnd(Name name, int marker) throws EncodingException { for (int i = name.size() - 1; i >= 0; i--) { try { return name.get(i).toNumberWithMarker(marker); } catch (EncodingException e) { // do nothing } } throw new EncodingException("Failed to find marker " + marker + " in name: " + name.toUri()); }
/** * Helper to encode names using an existing encoding context; could be merged * to Tlv0_1_1WireFormat.java. * * @param name the {@link Name} to encode * @param encoder the current {@link TlvEncoder} context to encode with */ public static void encodeName(final Name name, final TlvEncoder encoder) { int saveLength = encoder.getLength(); for (int i = name.size() - 1; i >= 0; --i) { encoder.writeBlobTlv(Tlv.NameComponent, name.get(i).getValue().buf()); } encoder.writeTypeAndLength(Tlv.Name, encoder.getLength() - saveLength); }
public void emit(final Interest interest) { final Name localhostRegistration = new Name("/localhost/nfd/rib"); if (!interest.getName().getPrefix(localhostRegistration.size()).equals(localhostRegistration) || interest.getName().get(CONTROL_COMMAND_NAME_OFFSET).toString().equals("register")) { return;