MCPcopy Create free account
hub / github.com/akeranen/the-one / messageTransferred

Method messageTransferred

routing/MessageRouter.java:340–387  ·  view source on GitHub ↗

This method should be called (on the receiving host) after a message was successfully transferred. The transferred message is put to the message buffer unless this host is the final recipient of the message. @param id Id of the transferred message @param from Host the message was from (previous hop)

(String id, DTNHost from)

Source from the content-addressed store, hash-verified

338 * @return The message that this host received
339 */
340 public Message messageTransferred(String id, DTNHost from) {
341 Message incoming = removeFromIncomingBuffer(id, from);
342 boolean isFinalRecipient;
343 boolean isFirstDelivery; // is this first delivered instance of the msg
344
345
346 if (incoming == null) {
347 throw new SimError("No message with ID " + id + " in the incoming "+
348 "buffer of " + this.host);
349 }
350
351 incoming.setReceiveTime(SimClock.getTime());
352
353 // Pass the message to the application (if any) and get outgoing message
354 Message outgoing = incoming;
355 for (Application app : getApplications(incoming.getAppID())) {
356 // Note that the order of applications is significant
357 // since the next one gets the output of the previous.
358 outgoing = app.handle(outgoing, this.host);
359 if (outgoing == null) break; // Some app wanted to drop the message
360 }
361
362 Message aMessage = (outgoing==null)?(incoming):(outgoing);
363 // If the application re-targets the message (changes 'to')
364 // then the message is not considered as 'delivered' to this host.
365 isFinalRecipient = aMessage.getTo() == this.host;
366 isFirstDelivery = isFinalRecipient &&
367 !isDeliveredMessage(aMessage);
368
369 if (!isFinalRecipient && outgoing!=null) {
370 // not the final recipient and app doesn't want to drop the message
371 // -> put to buffer
372 addToMessages(aMessage, false);
373 } else if (isFirstDelivery) {
374 this.deliveredMessages.put(id, aMessage);
375 } else if (outgoing == null) {
376 // Blacklist messages that an app wants to drop.
377 // Otherwise the peer will just try to send it back again.
378 this.blacklistedMessages.put(id, null);
379 }
380
381 for (MessageListener ml : this.mListeners) {
382 ml.messageTransferred(aMessage, from, this.host,
383 isFirstDelivery);
384 }
385
386 return aMessage;
387 }
388
389 /**
390 * Puts a message to incoming messages buffer. Two messages with the

Callers

nothing calls this directly

Calls 11

setReceiveTimeMethod · 0.95
getTimeMethod · 0.95
getApplicationsMethod · 0.95
getAppIDMethod · 0.95
getToMethod · 0.95
isDeliveredMessageMethod · 0.95
addToMessagesMethod · 0.95
messageTransferredMethod · 0.65
handleMethod · 0.45
putMethod · 0.45

Tested by

no test coverage detected