@Override protected byte[] doWriteMessage() throws I2CPMessageException, IOException { if (_sessionId == null) throw new I2CPMessageException("Unable to write out the message as there is not enough data"); ByteArrayOutputStream os = new ByteArrayOutputStream(64); try { _sessionId.writeBytes(os); } catch (DataFormatException dfe) { throw new I2CPMessageException("Error writing out the message data", dfe); } return os.toByteArray(); }
@Override protected byte[] doWriteMessage() throws I2CPMessageException, IOException { if (_sessionId == null) throw new I2CPMessageException("No data"); ByteArrayOutputStream os = new ByteArrayOutputStream(256); try { _sessionId.writeBytes(os); DataHelper.writeLong(os, 1, _endpoints.size()); for (int i = 0; i < _endpoints.size(); i++) { _endpoints.get(i).writeBytes(os); } } catch (DataFormatException dfe) { throw new I2CPMessageException("Error writing out the message data", dfe); } return os.toByteArray(); }
@Override protected byte[] doWriteMessage() throws I2CPMessageException, IOException { if (_sessionId == null || _sessionConfig == null) throw new I2CPMessageException("Unable to write out the message as there is not enough data"); ByteArrayOutputStream os = new ByteArrayOutputStream(64); try { _sessionId.writeBytes(os); _sessionConfig.writeBytes(os); } catch (DataFormatException dfe) { throw new I2CPMessageException("Error writing out the message data", dfe); } return os.toByteArray(); }
@Override protected byte[] doWriteMessage() throws I2CPMessageException, IOException { if (_sessionId == null) throw new I2CPMessageException("Unable to write out the message as there is not enough data"); ByteArrayOutputStream os = new ByteArrayOutputStream(64); try { _sessionId.writeBytes(os); DataHelper.writeLong(os, 1, _status); } catch (DataFormatException dfe) { throw new I2CPMessageException("Error writing out the message data", dfe); } return os.toByteArray(); }
protected byte[] doWriteMessage() throws I2CPMessageException, IOException { int len = 7; if (_code == RESULT_SUCCESS) { if (_dest == null) throw new I2CPMessageException("Unable to write out the message as there is not enough data"); len += _dest.size(); } ByteArrayOutputStream os = new ByteArrayOutputStream(len); try { _sessionId.writeBytes(os); DataHelper.writeLong(os, 4, _reqID); DataHelper.writeLong(os, 1, _code); if (_code == RESULT_SUCCESS) _dest.writeBytes(os); } catch (DataFormatException dfe) { throw new I2CPMessageException("bad data", dfe); } return os.toByteArray(); }
@Override protected byte[] doWriteMessage() throws I2CPMessageException, IOException { if (_sessionId == null) throw new I2CPMessageException("Unable to write out the message as there is not enough data"); ByteArrayOutputStream os = new ByteArrayOutputStream(256); try { _sessionId.writeBytes(os); DataHelper.writeLong(os, 1, _endpoints.size()); for (int i = 0; i < _endpoints.size(); i++) { Hash router = getRouter(i); router.writeBytes(os); TunnelId tunnel = getTunnelId(i); tunnel.writeBytes(os); } DataHelper.writeDate(os, _end); } catch (DataFormatException dfe) { throw new I2CPMessageException("Error writing out the message data", dfe); } return os.toByteArray(); }
@Override protected byte[] doWriteMessage() throws I2CPMessageException, IOException { if ((_sessionId == null) || (_severity == null) || (_reason == null)) throw new I2CPMessageException("Not enough information to construct the message"); ByteArrayOutputStream os = new ByteArrayOutputStream(32); try { _sessionId.writeBytes(os); _severity.writeBytes(os); _reason.writeBytes(os); if (_messageId == null) { _messageId = new MessageId(); _messageId.setMessageId(0); } _messageId.writeBytes(os); } catch (DataFormatException dfe) { throw new I2CPMessageException("Error writing out the message data", dfe); } return os.toByteArray(); }
@Override protected byte[] doWriteMessage() throws I2CPMessageException, IOException { if ((_sessionId == null) || (_signingPrivateKey == null) || (_privateKey == null) || (_leaseSet == null)) throw new I2CPMessageException("Unable to write out the message as there is not enough data"); int size = 4 // sessionId + _signingPrivateKey.length() + PrivateKey.KEYSIZE_BYTES + _leaseSet.size(); ByteArrayOutputStream os = new ByteArrayOutputStream(size); try { _sessionId.writeBytes(os); _signingPrivateKey.writeBytes(os); _privateKey.writeBytes(os); _leaseSet.writeBytes(os); } catch (DataFormatException dfe) { throw new I2CPMessageException("Error writing out the message data", dfe); } return os.toByteArray(); }
protected byte[] doWriteMessage() throws I2CPMessageException, IOException { int len; if (_lookupType == LOOKUP_HASH) { if (_hash == null) throw new I2CPMessageException("Unable to write out the message as there is not enough data"); len = 11 + Hash.HASH_LENGTH; } else if (_lookupType == LOOKUP_HOST) { if (_host == null) throw new I2CPMessageException("Unable to write out the message as there is not enough data"); len = 12 + _host.length(); } else { throw new I2CPMessageException("bad type"); } ByteArrayOutputStream os = new ByteArrayOutputStream(len); try { _sessionId.writeBytes(os); DataHelper.writeLong(os, 4, _reqID); DataHelper.writeLong(os, 4, _timeout); DataHelper.writeLong(os, 1, _lookupType); if (_lookupType == LOOKUP_HASH) { _hash.writeBytes(os); } else { DataHelper.writeString(os, _host); } } catch (DataFormatException dfe) { throw new I2CPMessageException("bad data", dfe); } return os.toByteArray(); }
@Override protected byte[] doWriteMessage() throws I2CPMessageException, IOException { int type = _leaseSet.getType(); if (_sessionId == null || _leaseSet == null || (type != DatabaseEntry.KEY_TYPE_META_LS2 && (_signingPrivateKey == null || _privateKey == null))) throw new I2CPMessageException("Unable to write out the message as there is not enough data"); int size = 4 // sessionId + 1 // type + _leaseSet.size() + _signingPrivateKey.length() + _privateKey.length(); ByteArrayOutputStream os = new ByteArrayOutputStream(size); try { _sessionId.writeBytes(os); os.write(_leaseSet.getType()); _leaseSet.writeBytes(os); if (type != DatabaseEntry.KEY_TYPE_META_LS2) { _signingPrivateKey.writeBytes(os); for (PrivateKey pk : getPrivateKeys()) { pk.writeBytes(os); } } } catch (DataFormatException dfe) { throw new I2CPMessageException("Error writing out the message data", dfe); } return os.toByteArray(); }
/** * 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); } }
DataHelper.writeLong(out, 4, len); out.write((byte) MESSAGE_TYPE); _sessionId.writeBytes(out); _destination.writeBytes(out); _payload.writeBytes(out);