/** * Write out the full message to the stream, including the 4 byte size and 1 * byte type header. * * @throws IOException */ @Override public void writeMessage(OutputStream out) throws I2CPMessageException, IOException { if (_sessionId <= 0) throw new I2CPMessageException("Unable to write out the message, as the session ID has not been defined"); if (_messageId < 0) throw new I2CPMessageException("Unable to write out the message, as the message ID has not been defined"); if (_payload == null) throw new I2CPMessageException("Unable to write out the message, as the payload has not been defined"); int size = 2 + 4 + 4 + _payload.getSize(); try { DataHelper.writeLong(out, 4, size); out.write((byte) MESSAGE_TYPE); DataHelper.writeLong(out, 2, _sessionId); DataHelper.writeLong(out, 4, _messageId); DataHelper.writeLong(out, 4, _payload.getSize()); out.write(_payload.getEncryptedData()); } catch (DataFormatException dfe) { throw new I2CPMessageException("Unable to write the message length or type", dfe); } }
/** * Write out the full message to the stream, including the 4 byte size and 1 * byte type header. Override the parent so we can be more mem efficient * * @throws IOException */ @Override public void writeMessage(OutputStream out) throws I2CPMessageException, IOException { if (_sessionId == null) throw new I2CPMessageException("No session ID"); if (_destination == null) throw new I2CPMessageException("No dest"); if (_payload == null) throw new I2CPMessageException("No payload"); if (_nonce < 0) throw new I2CPMessageException("No nonce"); int len = 2 + _destination.size() + _payload.getSize() + 4 + 4; try { DataHelper.writeLong(out, 4, len); out.write((byte) getType()); _sessionId.writeBytes(out); _destination.writeBytes(out); _payload.writeBytes(out); DataHelper.writeLong(out, 4, _nonce); } catch (DataFormatException dfe) { throw new I2CPMessageException("Error writing the msg", dfe); } }
if (_nonce < 0) throw new I2CPMessageException("No nonce"); int len = 2 + _destination.size() + _payload.getSize() + 4 + 4 + DataHelper.DATE_LENGTH;
id = new MessageId(nextID); _runner.setPayload(id, _payload); messageAvailable(id, _payload.getSize());
+ payload.getSize() + " for session " + message.getSessionId());
_clientMessage = msg; _clientMessageId = msg.getMessageId(); _clientMessageSize = msg.getPayload().getSize(); _from = msg.getFromDestination(); _to = msg.getDestination();