/** * Get the payload carried by an I2P repliable datagram (previously loaded * with the loadI2PDatagram() method), verifying the datagram signature. * * @return A byte array containing the datagram payload * * @throws I2PInvalidDatagramException if the signature verification fails */ public byte[] getPayload() throws I2PInvalidDatagramException { this.verifySignature(); return this.extractPayload(); }
/** * Get the sender of an I2P repliable datagram (previously loaded with the * loadI2PDatagram() method), verifying the datagram signature. * * @return The Destination of the I2P repliable datagram sender * * @throws I2PInvalidDatagramException if the signature verification fails */ public Destination getSender() throws I2PInvalidDatagramException { this.verifySignature(); return this.extractSender(); }
/** * Extract the hash of the payload of an I2P repliable datagram (previously * loaded with the loadI2PDatagram() method), verifying the datagram * signature. * * As of 0.9.14, for signature types other than DSA_SHA1, this returns null. * * @return The hash of the payload of the I2P repliable datagram * @throws I2PInvalidDatagramException if the signature verification fails */ public Hash getHash() throws I2PInvalidDatagramException { // make sure it has a valid signature this.verifySignature(); return extractHash(); }
public void run() { I2PDatagramDissector diss = new I2PDatagramDissector(); _running = true; while (_running) { diss.loadI2PDatagram(msg); this.sink.send(diss.getSender(), diss.getPayload()); else this.sink.send(diss.extractSender(), diss.extractPayload()); } else {
if (toPort == _qPort) { I2PDatagramDissector dgDiss = new I2PDatagramDissector(); dgDiss.loadI2PDatagram(payload); payload = dgDiss.getPayload(); Destination from = dgDiss.getSender();
I2PDatagramDissector datagramDissector = new I2PDatagramDissector(); try { datagramDissector.loadI2PDatagram(msg); datagramDissector.verifySignature(); // TODO keep this line or remove it? byte[] payload = datagramDissector.extractPayload(); Destination sender = datagramDissector.getSender();
protected void messageReceived(byte[] msg, int proto, int fromPort, int toPort) { byte[] payload; Destination sender; try { synchronized (dgramDissector) { dgramDissector.loadI2PDatagram(msg); sender = dgramDissector.getSender(); payload = dgramDissector.extractPayload(); } } catch (DataFormatException e) { if (_log.shouldLog(Log.DEBUG)) { _log.debug("Dropping ill-formatted I2P repliable datagram", e); } return; } catch (I2PInvalidDatagramException e) { if (_log.shouldLog(Log.DEBUG)) { _log.debug("Dropping ill-signed I2P repliable datagram", e); } return; } try { recv.receiveDatagramBytes(sender, payload, proto, fromPort, toPort); } catch (IOException e) { _log.error("Error forwarding message to receiver", e); close(); } }
public void testDatagram() throws Exception{ ByteArrayOutputStream out = new ByteArrayOutputStream(); I2PClient client = I2PClientFactory.createClient(); Destination d = client.createDestination(out); I2PSession session = client.createSession(new ByteArrayInputStream(out.toByteArray()), null); I2PDatagramMaker dm = new I2PDatagramMaker(session); byte[] dg = dm.makeI2PDatagram(DataHelper.getASCII("What's the deal with 42?")); I2PDatagramDissector dd = new I2PDatagramDissector(); dd.loadI2PDatagram(dg); byte[] x = dd.getPayload(); assertTrue(DataHelper.eq(x, DataHelper.getASCII("What's the deal with 42?"))); x = dd.extractPayload(); assertTrue(DataHelper.eq(x, DataHelper.getASCII("What's the deal with 42?"))); assertEquals(d, dd.getSender()); assertEquals(d, dd.extractSender()); }
I2PDatagramDissector dd = new I2PDatagramDissector(); dd.loadI2PDatagram(data); dd.getPayload(); }catch(I2PInvalidDatagramException i2pide){ error = true; dd.getSender(); }catch(I2PInvalidDatagramException i2pide){ error = true; dd.getHash(); }catch(I2PInvalidDatagramException i2pide){ error = true;