/** * Creates an <code>I2PBotePacket</code> from its byte array representation.<br/> * The header bytes determine whether <code>DataPacket</code> or a <code>CommunicationPacket</code> is created. * @param data * @throws MalformedPacketException If the byte array does not contain a valid <code>I2PBotePacket</code>. */ private static I2PBotePacket createPacket(byte[] data) throws MalformedPacketException { if (CommunicationPacket.isPrefixValid(data)) return CommunicationPacket.createPacket(data); else return DataPacket.createPacket(data); }
/** * Creates a <code>CommunicationPacket</code> from raw datagram data. The packet ID * is initialized from the input data.<br/> * Subclasses start reading at byte {@link #HEADER_LENGTH} after calling this constructor. * @param data */ protected CommunicationPacket(byte[] data) { super(data[5]); // byte 5 is the protocol version in a communication packet if (!isPrefixValid(data)) { byte[] prefix = Arrays.copyOf(data, PACKET_PREFIX.length); log.error("Packet prefix invalid. Expected: " + Arrays.toString(PACKET_PREFIX) + ", actual: " + Arrays.toString(prefix)); } checkPacketType(data[4]); packetId = new UniqueId(data, 6); sentSignal = new CountDownLatch(1); sentTime = -1; }