byte[] result = new byte[length + 4]; System.arraycopy(array, 0, result, length - array.length + 3, array.length); uint32ToByteArrayBE(length, result, 0); if (isNegative) result[4] |= 0x80;
/** * Writes message to to the output stream. */ @Override public void serialize(String name, byte[] message, OutputStream out) throws IOException { byte[] header = new byte[4 + COMMAND_LEN + 4 + 4 /* checksum */]; uint32ToByteArrayBE(params.getPacketMagic(), header, 0); // The header array is initialized to zero by Java so we don't have to worry about // NULL terminating the string here. for (int i = 0; i < name.length() && i < COMMAND_LEN; i++) { header[4 + i] = (byte) (name.codePointAt(i) & 0xFF); } Utils.uint32ToByteArrayLE(message.length, header, 4 + COMMAND_LEN); byte[] hash = Sha256Hash.hashTwice(message); System.arraycopy(hash, 0, header, 4 + COMMAND_LEN + 4, 4); out.write(header); out.write(message); if (log.isDebugEnabled()) log.debug("Sending {} message: {}", name, HEX.encode(header) + HEX.encode(message)); }
byte[] result = new byte[length + 4]; System.arraycopy(array, 0, result, length - array.length + 3, array.length); uint32ToByteArrayBE(length, result, 0); if (isNegative) result[4] |= 0x80;
byte[] result = new byte[length + 4]; System.arraycopy(array, 0, result, length - array.length + 3, array.length); uint32ToByteArrayBE(length, result, 0); if (isNegative) result[4] |= 0x80;
byte[] result = new byte[length + 4]; System.arraycopy(array, 0, result, length - array.length + 3, array.length); uint32ToByteArrayBE(length, result, 0); if (isNegative) result[4] |= 0x80;
/** * Writes message to to the output stream. */ @Override public void serialize(String name, byte[] message, OutputStream out) throws IOException { byte[] header = new byte[4 + COMMAND_LEN + 4 + 4 /* checksum */]; uint32ToByteArrayBE(params.getPacketMagic(), header, 0); // The header array is initialized to zero by Java so we don't have to worry about // NULL terminating the string here. for (int i = 0; i < name.length() && i < COMMAND_LEN; i++) { header[4 + i] = (byte) (name.codePointAt(i) & 0xFF); } Utils.uint32ToByteArrayLE(message.length, header, 4 + COMMAND_LEN); byte[] hash = Sha256Hash.hashTwice(message); System.arraycopy(hash, 0, header, 4 + COMMAND_LEN + 4, 4); out.write(header); out.write(message); if (log.isDebugEnabled()) log.debug("Sending {} message: {}", name, HEX.encode(header) + HEX.encode(message)); }
/** * Writes message to to the output stream. */ @Override public void serialize(String name, byte[] message, OutputStream out) throws IOException { byte[] header = new byte[4 + COMMAND_LEN + 4 + 4 /* checksum */]; uint32ToByteArrayBE(params.getPacketMagic(), header, 0); // The header array is initialized to zero by Java so we don't have to worry about // NULL terminating the string here. for (int i = 0; i < name.length() && i < COMMAND_LEN; i++) { header[4 + i] = (byte) (name.codePointAt(i) & 0xFF); } Utils.uint32ToByteArrayLE(message.length, header, 4 + COMMAND_LEN); byte[] hash = Sha256Hash.hashTwice(message); System.arraycopy(hash, 0, header, 4 + COMMAND_LEN + 4, 4); out.write(header); out.write(message); if (log.isDebugEnabled()) log.debug("Sending {} message: {}", name, HEX.encode(header) + HEX.encode(message)); }
/** * Writes message to to the output stream. */ @Override public void serialize(String name, byte[] message, OutputStream out) throws IOException { byte[] header = new byte[4 + COMMAND_LEN + 4 + 4 /* checksum */]; uint32ToByteArrayBE(params.getPacketMagic(), header, 0); // The header array is initialized to zero by Java so we don't have to worry about // NULL terminating the string here. for (int i = 0; i < name.length() && i < COMMAND_LEN; i++) { header[4 + i] = (byte) (name.codePointAt(i) & 0xFF); } Utils.uint32ToByteArrayLE(message.length, header, 4 + COMMAND_LEN); byte[] hash = Sha256Hash.hashTwice(message); System.arraycopy(hash, 0, header, 4 + COMMAND_LEN + 4, 4); out.write(header); out.write(message); if (log.isDebugEnabled()) log.debug("Sending {} message: {}", name, HEX.encode(header) + HEX.encode(message)); }
/** * <p>Writes the given message to the other side of the connection, prefixing it with the proper 4-byte prefix.</p> * * <p>Provides a write-order guarantee.</p> * * @throws IllegalStateException If the encoded message is larger than the maximum message size. */ public void write(MessageType msg) throws IllegalStateException { byte[] messageBytes = msg.toByteArray(); checkState(messageBytes.length <= maxMessageSize); byte[] messageLength = new byte[4]; Utils.uint32ToByteArrayBE(messageBytes.length, messageLength, 0); try { MessageWriteTarget target = writeTarget.get(); target.writeBytes(messageLength); target.writeBytes(messageBytes); } catch (IOException e) { closeConnection(); } } }
/** * <p>Writes the given message to the other side of the connection, prefixing it with the proper 4-byte prefix.</p> * * <p>Provides a write-order guarantee.</p> * * @throws IllegalStateException If the encoded message is larger than the maximum message size. */ public void write(MessageType msg) throws IllegalStateException { byte[] messageBytes = msg.toByteArray(); checkState(messageBytes.length <= maxMessageSize); byte[] messageLength = new byte[4]; Utils.uint32ToByteArrayBE(messageBytes.length, messageLength, 0); try { MessageWriteTarget target = writeTarget.get(); target.writeBytes(messageLength); target.writeBytes(messageBytes); } catch (IOException e) { closeConnection(); } } }
/** * <p>Writes the given message to the other side of the connection, prefixing it with the proper 4-byte prefix.</p> * * <p>Provides a write-order guarantee.</p> * * @throws IllegalStateException If the encoded message is larger than the maximum message size. */ public void write(MessageType msg) throws IllegalStateException { byte[] messageBytes = msg.toByteArray(); checkState(messageBytes.length <= maxMessageSize); byte[] messageLength = new byte[4]; Utils.uint32ToByteArrayBE(messageBytes.length, messageLength, 0); try { MessageWriteTarget target = writeTarget.get(); target.writeBytes(messageLength); target.writeBytes(messageBytes); } catch (IOException e) { closeConnection(); } } }
/** * <p>Writes the given message to the other side of the connection, prefixing it with the proper 4-byte prefix.</p> * * <p>Provides a write-order guarantee.</p> * * @throws IllegalStateException If the encoded message is larger than the maximum message size. */ public void write(MessageType msg) throws IllegalStateException { byte[] messageBytes = msg.toByteArray(); checkState(messageBytes.length <= maxMessageSize); byte[] messageLength = new byte[4]; Utils.uint32ToByteArrayBE(messageBytes.length, messageLength, 0); try { MessageWriteTarget target = writeTarget.get(); target.writeBytes(messageLength); target.writeBytes(messageBytes); } catch (IOException e) { closeConnection(); } } }
@Override public boolean add(Rule element) { if (outStream != null && element instanceof BlockAndValidity) { try { outStream.write((int) (params.getPacketMagic() >>> 24)); outStream.write((int) (params.getPacketMagic() >>> 16)); outStream.write((int) (params.getPacketMagic() >>> 8)); outStream.write((int) params.getPacketMagic()); byte[] block = ((BlockAndValidity)element).block.bitcoinSerialize(); byte[] length = new byte[4]; Utils.uint32ToByteArrayBE(block.length, length, 0); outStream.write(Utils.reverseBytes(length)); outStream.write(block); ((BlockAndValidity)element).block = null; } catch (IOException e) { throw new RuntimeException(e); } } return super.add(element); } };
Utils.uint32ToByteArrayBE(messageBytes.length, messageLength, 0); client.writeBytes(new byte[]{messageLength[0], messageLength[1]}); Thread.sleep(10); Utils.uint32ToByteArrayBE(messageBytes2.length, messageLength2, 0); byte[] sendBytes = Arrays.copyOf(new byte[] {messageBytes[messageBytes.length-1]}, 1 + messageBytes2.length*2 + messageLength2.length*2); System.arraycopy(messageLength2, 0, sendBytes, 1, 4); Utils.uint32ToByteArrayBE(messageBytes2.length, messageLength2, 0); client.writeBytes(new byte[]{messageLength2[0], messageLength2[1]}); Thread.sleep(10); Utils.uint32ToByteArrayBE(msg5.toByteArray().length, messageLength5, 0); client.writeBytes(messageLength5);