/** * Create a default interest for a given {@link Name} using the client's * passed settings (see {@link #SimpleClient(long, long)}) * * @param name the {@link Name} of the data to retrieve * @return a default interest for the given name */ public Interest getDefaultInterest(Name name) { return new Interest(name, interestLifetime); } }
public Interest getInterest() { return new Interest(interest); }
@Override public void onTimeout(final Interest interest) { state.nRetries--; if (state.nRetries > 0) { try { face.expressInterest(new Interest(interest), this, this); } catch (IOException e) { LOG.log(Level.INFO, "Error while expressing interest: " + e.toString(), e); } } else { state.isDone = true; } }
private Interest buildNextInterest(long publisherId, long messageId) { Name name = PubSubNamespace.toMessageName(prefix, publisherId, messageId + 1); return new Interest(name); // TODO ms lifetime }
@Override public void announceExit(long id) throws IOException { LOGGER.log(Level.INFO, "Announcing publisher exit: {0} from {1}", new Object[]{id, broadcastPrefix}); Name name = PubSubNamespace.toAnnouncement(broadcastPrefix, id, PubSubNamespace.Announcement.EXIT); Interest interest = new Interest(name); face.expressInterest(interest, null); }
@Override public void announceEntrance(long id) throws IOException { LOGGER.log(Level.INFO, "Announcing publisher entrance: {0} to {1}", new Object[]{id, broadcastPrefix}); Name name = PubSubNamespace.toAnnouncement(broadcastPrefix, id, PubSubNamespace.Announcement.ENTRANCE); Interest interest = new Interest(name); face.expressInterest(interest, null); }
private Interest buildLatestInterest(long publisherId) { Name name = PubSubNamespace.toPublisherName(prefix, publisherId); Interest interest = new Interest(name); // TODO ms lifetime interest.setChildSelector(Interest.CHILD_SELECTOR_RIGHT); return interest; }
@Override public void publish(Blob message) throws IOException { open(); // will immediately return if already open long id = latestMessageId.getAndIncrement(); Name name = PubSubNamespace.toMessageName(prefix, id); contentStore.put(name, PubSubNamespace.toResponse(null, message)); LOGGER.log(Level.INFO, "Published message {0} to content store: {1}", new Object[]{id, name}); if (pendingInterestTable.has(new Interest(name))) { sendContent(face, name); // TODO extract satisfied interests } }
/** * Request a name on an existing face to verify the forwarder is working and * responding to requests. Note that the name must be served or cached on the * forwarder for this to return true. * * @param face a {@link Face} to ping * @param name a known {@link Name} that the remote node will answer to * @return true if successful, false otherwise */ public static boolean ping(final Face face, final Name name) { // build interest Interest interest = new Interest(name); interest.setInterestLifetimeMilliseconds(DEFAULT_TIMEOUT); interest.setMustBeFresh(true); // send packet try { Data data = FetchHelper.getData(face, interest); return data != null; } catch (IOException e) { LOG.log(Level.INFO, "Error sending ping interest", e); return false; } } }
/** * Get data using the exact name (without implicit digest). * <p/> * TODO: Allow authentication of retrieved data packets * * @param face Face instance * @param name Exact name of the data packet to retrieve * @return retrieved Data packet * @throws IOException when communication with NFD fails */ public static Data getData(final Face face, final Name name) throws IOException { FetchHelper fetcher = new FetchHelper(face); Interest interest = new Interest(name); interest.setInterestLifetimeMilliseconds(DEFAULT_TIMEOUT); interest.setMustBeFresh(false); // this is bug in jndn // interest.setMinSuffixComponents(1); // implicit digest // interest.setMaxSuffixComponents(1); // implicit digest return fetcher.getData(interest); }
/** * {@inheritDoc} */ @Override public void emit(final ByteBuffer buffer) { // @todo Implement NDNLP processing try { if (buffer.get(0) == Tlv.Interest || buffer.get(0) == Tlv.Data) { TlvDecoder decoder = new TlvDecoder(buffer); if (decoder.peekType(Tlv.Interest, buffer.remaining())) { Interest interest = new Interest(); interest.wireDecode(buffer, TlvWireFormat.get()); for (SignalOnSendInterest signal : onSendInterest) { signal.emit(interest); } } else if (decoder.peekType(Tlv.Data, buffer.remaining())) { Data data = new Data(); data.wireDecode(buffer, TlvWireFormat.get()); for (SignalOnSendData signal : onSendData) { signal.emit(data); } } } else { LOGGER.info("Received an unknown packet"); } } catch (EncodingException e) { LOGGER.log(Level.INFO, "Failed to decodeParameters incoming packet", e); } } }
@Override public void emit(ByteBuffer buffer) { try { if (isInterest(buffer) || isData(buffer)) { TlvDecoder decoder = new TlvDecoder(buffer); if (decoder.peekType(Tlv.Interest, buffer.remaining())) { Interest interest = new Interest(); interest.wireDecode(buffer, TlvWireFormat.get()); forward(interest, transport); } else if (decoder.peekType(Tlv.Data, buffer.remaining())) { Data data = new Data(); data.wireDecode(buffer, TlvWireFormat.get()); forward(data); } } else { LOGGER.warning("Received an unknown packet"); } } catch (EncodingException e) { LOGGER.log(Level.INFO, "Failed to decodeParameters incoming packet", e); } }
private Interest discover(BackoffRetryClient client, On<Long> onFound, On<Void> onComplete, On<Exception> onError) throws IOException { Interest interest = new Interest(topicPrefix); interest.setInterestLifetimeMilliseconds(STARTING_DISCOVERY_LIFETIME); interest.setExclude(excludeKnownPublishers()); client.retry(face, interest, (interest1, data) -> { if (stopped) { return; } LOGGER.log(Level.INFO, "Received discovery data ({0} bytes): {1}", new Object[]{data.getContent().size(), data.getName()}); found(data.getName(), onFound, onError); // TODO instead of inspecting name should look at content and examine for multiple publishers try { discover(client, onFound, onComplete, onError); // recursion } catch (IOException e) { LOGGER.log(Level.SEVERE, "Failed while discovering publishers, aborting: {0}", new Object[]{broadcastPrefix, e}); onError.on(e); // TODO re-call discover here? } }, interest2 -> { // TODO recall client here, we should never be done }); return interest; }
Interest interest = new Interest(name);
FetchHelper fetcher = new FetchHelper(face); Interest interest = new Interest(new Name(prefix)); interest.setInterestLifetimeMilliseconds(DEFAULT_TIMEOUT); interest.setMustBeFresh(true); interest = new Interest(new Name(prefix).appendSegment(i)); interest.setInterestLifetimeMilliseconds(DEFAULT_TIMEOUT); interest.setMustBeFresh(false);
@Override public void onData(Interest interest, Data data) { try { if (stream.current() >= lastRequestedSegment) { Interest dataBasedName = new Interest(interest).setName(data.getName()); if (stream.hasEnd()) { if (stream.current() < stream.end()) { requestRemainingSegments(face, dataBasedName, stream); } } else { requestNext(face, dataBasedName, stream); } } } catch (IOException e) { stream.onException(e); } }
/** * Replace the final component of an interest name with a segmented component; * if the interest name does not have a segmented component, this will add * one. * * @param interest the request * @param segmentNumber a segment number * @param marker a marker to use for segmenting the packet * @return a segmented interest (a copy of the passed interest) */ protected Interest replaceFinalComponent(Interest interest, long segmentNumber, byte marker) { Interest copied = new Interest(interest); Component lastComponent = Component.fromNumberWithMarker(segmentNumber, marker); Name newName = (SegmentationHelper.isSegmented(copied.getName(), marker)) ? copied.getName().getPrefix(-1) : new Name(copied.getName()); copied.setName(newName.append(lastComponent)); return copied; }