Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions src/core/DTNHost.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down
58 changes: 33 additions & 25 deletions src/core/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<DTNHost>(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<String> 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
Expand Down Expand Up @@ -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<DTNHost>(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<String> 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.
Expand Down Expand Up @@ -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);
}

/**
Expand Down
8 changes: 3 additions & 5 deletions src/routing/MessageRouter.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down