示例#1
0
  /** write the message body to the output array, starting at the given index */
  protected int writeMessageBody(byte out[], int curIndex) throws I2NPMessageException {
    if ((_tunnelId == null) || ((_msg == null) && (_msgData == null))) {
      _log.log(Log.CRIT, "failing to write out gateway message");
      throw new I2NPMessageException(
          "Not enough data to write out (id=" + _tunnelId + " data=" + _msg + ")");
    }

    DataHelper.toLong(out, curIndex, 4, _tunnelId.getTunnelId());
    curIndex += 4;
    synchronized (this) {
      if (_msgData == null) {
        _msgData = _msg.toByteArray();
        _msg = null;
      }
    }
    DataHelper.toLong(out, curIndex, 2, _msgData.length);
    curIndex += 2;
    // where is this coming from?
    if (curIndex + _msgData.length > out.length) {
      _log.log(
          Log.ERROR,
          "output buffer too small idx: "
              + curIndex
              + " len: "
              + _msgData.length
              + " outlen: "
              + out.length);
      throw new I2NPMessageException(
          "Too much data to write out (id=" + _tunnelId + " data=" + _msg + ")");
    }
    System.arraycopy(_msgData, 0, out, curIndex, _msgData.length);
    curIndex += _msgData.length;
    return curIndex;
  }
示例#2
0
 protected int calculateWrittenLength() {
   synchronized (this) {
     if (_msgData == null) {
       _msgData = _msg.toByteArray();
       _msg = null;
     }
   }
   return _msgData.length + 4 + 2;
 }