示例#1
0
  public boolean createNewMessage(Message msg) {
    makeRoomForNewMessage(msg.getSize());

    msg.setTtl(this.msgTtl);
    msg.addProperty(ftStr, new Double(0));
    return super.createNewMessage(msg);
  }
  /**
   * Sets a message that this connection is currently transferring. If message passing is controlled
   * by external events, this method is not needed (but then e.g. {@link #finalizeTransfer()} and
   * {@link #isMessageTransferred()} will not work either). Only a one message at a time can be
   * transferred using one connection.
   *
   * @param from The host sending the message
   * @param m The message
   * @return The value returned by {@link MessageRouter#receiveMessage(Message, DTNHost)}
   */
  public int startTransfer(DTNHost from, Message m) {
    assert this.msgOnFly == null
        : "Already transferring "
            + this.msgOnFly
            + " from "
            + this.msgFromNode
            + " to "
            + this.getOtherNode(this.msgFromNode)
            + ". Can't "
            + "start transfer of "
            + m
            + " from "
            + from;

    this.msgFromNode = from;
    Message newMessage = m.replicate();
    int retVal = getOtherNode(from).receiveMessage(newMessage, from);

    if (retVal == MessageRouter.RCV_OK) {
      this.msgOnFly = newMessage;
      this.msgsize = m.getSize();
      this.msgsent = 0;
    }

    return retVal;
  }