diff --git a/src/core/DTNHost.java b/src/core/DTNHost.java index 258be0450..e5babcec6 100644 --- a/src/core/DTNHost.java +++ b/src/core/DTNHost.java @@ -453,13 +453,7 @@ public void sendMessage(String id, DTNHost to) { * {@link MessageRouter#receiveMessage(Message, DTNHost)} */ public int receiveMessage(Message m, DTNHost from) { - int retVal = this.router.receiveMessage(m, from); - - if (retVal == MessageRouter.RCV_OK) { - m.addNodeOnPath(this); // add this node on the messages path - } - - return retVal; + return this.router.receiveMessage(m, from); } /** diff --git a/src/core/Message.java b/src/core/Message.java index d037b890b..3810af91e 100644 --- a/src/core/Message.java +++ b/src/core/Message.java @@ -82,6 +82,38 @@ public Message(DTNHost from, DTNHost to, String id, int size) { addNodeOnPath(from); } + /** + * Deep copies a message from another message. If new fields are + * introduced to this class, most likely they should be copied here too + * (unless done in constructor). + * @param m the other message + */ + protected Message(Message m) { + this.from = m.from; + this.to = m.to; + this.id = m.id; + this.size = m.size; + this.path = new ArrayList(m.path); + this.uniqueId = nextUniqueId; + + this.timeCreated = m.timeCreated; + this.timeReceived = m.timeReceived; + this.initTtl = m.initTtl; + this.responseSize = m.responseSize; + this.requestMsg = m.requestMsg; + this.properties = null; + this.appID = m.appID; + + if (m.properties != null) { + Set keys = m.properties.keySet(); + for (String key : keys) { + updateProperty(key, m.getProperty(key)); + } + } + + Message.nextUniqueId++; + } + /** * Returns the node this message is originally from * @return the node this message is originally from @@ -249,28 +281,6 @@ public String toString () { return id; } - /** - * Deep copies message data from other message. If new fields are - * introduced to this class, most likely they should be copied here too - * (unless done in constructor). - * @param m The message where the data is copied - */ - protected void copyFrom(Message m) { - this.path = new ArrayList(m.path); - this.timeCreated = m.timeCreated; - this.responseSize = m.responseSize; - this.requestMsg = m.requestMsg; - this.initTtl = m.initTtl; - this.appID = m.appID; - - if (m.properties != null) { - Set keys = m.properties.keySet(); - for (String key : keys) { - updateProperty(key, m.getProperty(key)); - } - } - } - /** * Adds a generic property for this message. The key can be any string but * it should be such that no other class accidently uses the same value. @@ -326,9 +336,7 @@ public void updateProperty(String key, Object value) throws SimError { * @return A replicate of the message */ public Message replicate() { - Message m = new Message(from, to, id, size); - m.copyFrom(this); - return m; + return new Message(this); } /** diff --git a/src/routing/MessageRouter.java b/src/routing/MessageRouter.java index 4d21233a1..bca46a837 100644 --- a/src/routing/MessageRouter.java +++ b/src/routing/MessageRouter.java @@ -329,13 +329,11 @@ public boolean requestDeliverableMessages(Connection con) { * than zero if the other node should try later (e.g. TRY_LATER_BUSY). */ public int receiveMessage(Message m, DTNHost from) { - Message newMessage = m.replicate(); - - this.putToIncomingBuffer(newMessage, from); - newMessage.addNodeOnPath(this.host); + this.putToIncomingBuffer(m, from); + m.addNodeOnPath(this.host); for (MessageListener ml : this.mListeners) { - ml.messageTransferStarted(newMessage, from, getHost()); + ml.messageTransferStarted(m, from, getHost()); } return RCV_OK; // superclass always accepts messages