/** * Create a new SAM DATAGRAM session on an existing I2P session. * * @param props unused for now * @since 0.9.25 */ protected SAMDatagramSession(I2PSession sess, Properties props, int listenPort, SAMDatagramReceiver recv) throws IOException, DataFormatException, I2PSessionException { super(sess, I2PSession.PROTO_DATAGRAM, listenPort); this.recv = recv; dgramMaker = new I2PDatagramMaker(getI2PSession()); }
public I2PSinkAnywhere(I2PSession sess, boolean raw) { this.sess = sess; this.raw = raw; // create maker if (raw) { this.maker = null; } else { this.maker = new I2PDatagramMaker(); this.maker.setI2PDatagramMaker(this.sess); } }
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()); }
/** * @param src ignored * @throws RuntimeException if session is closed */ public synchronized void send(Destination src, byte[] data) { //System.out.print("w"); // create payload byte[] payload; if(!this.raw) { synchronized(this.maker) { payload = this.maker.makeI2PDatagram(data); } } else payload = data; // send message try { this.sess.sendMessage(this.dest, payload, (this.raw ? I2PSession.PROTO_DATAGRAM_RAW : I2PSession.PROTO_DATAGRAM), I2PSession.PORT_UNSPECIFIED, I2PSession.PORT_UNSPECIFIED); } catch (I2PSessionException ise) { throw new RuntimeException("failed to send data", ise); } }
/** * Construct a new I2PDatagramMaker that will be able to create I2P * repliable datagrams going to be sent through the specified I2PSession. * * @param session I2PSession used to send I2PDatagrams through */ public I2PDatagramMaker(I2PSession session) { this.setI2PDatagramMaker(session); }
I2PDatagramMaker dgMaker = new I2PDatagramMaker(_session); payload = dgMaker.makeI2PDatagram(payload); if (payload == null) { if (_log.shouldLog(Log.WARN))
/** * @param to - where it's going * @throws RuntimeException if session is closed */ public synchronized void send(Destination to, byte[] data) { // create payload byte[] payload; if(!this.raw) { synchronized(this.maker) { payload = this.maker.makeI2PDatagram(data); } } else payload = data; // send message try { this.sess.sendMessage(to, payload, (this.raw ? I2PSession.PROTO_DATAGRAM_RAW : I2PSession.PROTO_DATAGRAM), I2PSession.PORT_UNSPECIFIED, I2PSession.PORT_UNSPECIFIED); } catch (I2PSessionException ise) { throw new RuntimeException("failed to send data", ise); } }
/** * Send bytes through a SAM DATAGRAM session. * * @since 0.9.25 */ public boolean sendBytes(String dest, byte[] data, int proto, int fromPort, int toPort, boolean sendLeaseSet, int sendTags, int tagThreshold, int expiration) throws DataFormatException, I2PSessionException { if (data.length > DGRAM_SIZE_MAX) throw new DataFormatException("Datagram size exceeded (" + data.length + ")"); byte[] dgram ; synchronized (dgramMaker) { dgram = dgramMaker.makeI2PDatagram(data); } return sendBytesThroughMessageSession(dest, dgram, I2PSession.PROTO_DATAGRAM, fromPort, toPort, sendLeaseSet, sendTags,tagThreshold, expiration); }
/** * Create a new SAM DATAGRAM session. * * @param dest Base64-encoded destination (private key) * @param props Properties to setup the I2P session * @param recv Object that will receive incoming data * @throws IOException * @throws DataFormatException * @throws I2PSessionException */ protected SAMDatagramSession(String dest, Properties props, SAMDatagramReceiver recv) throws IOException, DataFormatException, I2PSessionException { super(dest, props); this.recv = recv; dgramMaker = new I2PDatagramMaker(getI2PSession()); }
public I2PSink(I2PSession sess, Destination dest, boolean raw) { this.sess = sess; this.dest = dest; this.raw = raw; // create maker if (raw) { this.maker = null; } else { this.maker = new I2PDatagramMaker(); this.maker.setI2PDatagramMaker(this.sess); } }
/** * Send bytes through a SAM DATAGRAM session. * * @param dest Destination * @param data Bytes to be sent * @param proto ignored, will always use PROTO_DATAGRAM (17) * * @return True if the data was sent, false otherwise * @throws DataFormatException on unknown / bad dest * @throws I2PSessionException on serious error, probably session closed */ public boolean sendBytes(String dest, byte[] data, int proto, int fromPort, int toPort) throws DataFormatException, I2PSessionException { if (data.length > DGRAM_SIZE_MAX) throw new DataFormatException("Datagram size exceeded (" + data.length + ")"); byte[] dgram ; synchronized (dgramMaker) { dgram = dgramMaker.makeI2PDatagram(data); } return sendBytesThroughMessageSession(dest, dgram, I2PSession.PROTO_DATAGRAM, fromPort, toPort); }
/** * Create a new SAM DATAGRAM session. * * Caller MUST call start(). * * @param destStream Input stream containing the destination keys * @param props Properties to setup the I2P session * @param recv Object that will receive incoming data * @throws IOException * @throws DataFormatException * @throws I2PSessionException */ public SAMDatagramSession(InputStream destStream, Properties props, SAMDatagramReceiver recv) throws IOException, DataFormatException, I2PSessionException { super(destStream, props); this.recv = recv; dgramMaker = new I2PDatagramMaker(getI2PSession()); }
private void sendDatagram(byte[] data, Destination destination) throws I2PSessionException { byte[] replyableDatagram = datagramMaker.makeI2PDatagram(data); i2pSession.sendMessage(destination, replyableDatagram, I2PSession.PROTO_DATAGRAM, I2PSession.PORT_UNSPECIFIED, I2PSession.PORT_UNSPECIFIED); }
/** * @param i2pSession * @param i2pReceiver */ public I2PSendQueue(I2PSession i2pSession, I2PPacketDispatcher i2pReceiver) { super("I2PSendQueue"); this.i2pSession = i2pSession; i2pReceiver.addPacketListener(this); packetQueue = new PacketQueue(); runningBatches = new ConcurrentHashSet<PacketBatch>(); datagramMaker = new I2PDatagramMaker(i2pSession); }