/** * Decrypts the <code>CommunicationPacket</code> inside this packet. * @throws DataFormatException * @throws MalformedPacketException */ private CommunicationPacket decrypt(I2PSession i2pSession) throws DataFormatException, MalformedPacketException { PrivateKey privateKey = i2pSession.getDecryptionKey(); byte[] decryptedData = Util.decrypt(payload, privateKey); return CommunicationPacket.createPacket(decryptedData); } }
/** * 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 packet from a byte array and fires listeners. * @param packetData * @param sender */ private void dispatchPacket(byte[] packetData, Destination sender) { CommunicationPacket packet; try { packet = CommunicationPacket.createPacket(packetData); logPacket(packet, sender); firePacketReceivedEvent(packet, sender); } catch (MalformedPacketException e) { log.warn("Ignoring unparseable packet.", e); firePacketReceivedEvent(new MalformedCommunicationPacket(), sender); } }