try { session = client.createSession(null, opts); session.connect(); rv = session.lookupDest(key, DEFAULT_TIMEOUT); } finally { if (session != null) session.destroySession();
/** * Get the SAM message-based session Destination. * * @return The SAM message-based session Destination. */ public Destination getDestination() { return session.getMyDestination(); }
/** * * @param session * @param msgId * @param size */ public void messageAvailable(I2PSession session, int msgId, long size) { // _log.debug("Message available: id = " + msgId + " size = " + size); try { byte msg[] = session.receiveMessage(msgId); if (msg != null) { out.write(msg); out.flush(); } } catch (I2PSessionException ise) { up = false; } catch (IOException ioe) { up = false; } }
/** @since 0.8.9 */ public PrivateKeyFile(File file, I2PSession session) { this(file, session.getMyDestination(), session.getDecryptionKey(), session.getPrivateKey()); }
public void setI2PDatagramMaker(I2PSession session) { sxPrivKey = session.getPrivateKey(); sxDestBytes = session.getMyDestination().toByteArray(); }
PublicKey pub = _session.getMyDestination().getPublicKey(); PrivateKey priv = _session.getDecryptionKey(); SimpleDataStructure[] keys = _context.keyGenerator().generateSigningKeys(type); pub.writeBytes(keyStream); I2PSession rv = _session.addSubsession(privateKeyStream, opts); boolean added = _subsessions.add(rv); if (!added) { _session.removeSubsession(rv); throw new I2PSessionException("dup"); rv.addMuxedSessionListener(_connectionManager.getMessageHandler(), protocol, defaultOptions.getLocalPort()); if (_log.shouldLog(Log.WARN)) _log.warn("Added subsession " + rv);
/** * If the destination is not set, read it in from the file. * Also sets the local privKey and signingPrivKey. */ public Destination getDestination() throws I2PSessionException, IOException, DataFormatException { if (dest == null) { I2PSession s = open(); if (s != null) { this.dest = new VerifiedDestination(s.getMyDestination()); this.privKey = s.getDecryptionKey(); this.signingPrivKey = s.getPrivateKey(); if (s.isOffline()) { _offlineExpiration = s.getOfflineExpiration(); _transientSigningPubKey = s.getTransientSigningPublicKey(); _offlineSignature = s.getOfflineSignature(); _transientSigningPrivKey = signingPrivKey; // set dummy SPK SigType type = dest.getSigningPublicKey().getType(); byte[] dbytes = new byte[type.getPrivkeyLen()]; signingPrivKey = new SigningPrivateKey(type, dbytes); } } } return this.dest; }
public static int[] getBWLimits(String host, int port) { int[] rv = null; try { I2PClient client = new I2PSimpleClient(); Properties opts = new Properties(); opts.put(I2PClient.PROP_TCP_HOST, host); opts.put(I2PClient.PROP_TCP_PORT, "" + port); I2PSession session = client.createSession(null, opts); session.connect(); rv = session.bandwidthLimits(); session.destroySession(); } catch (I2PSessionException ise) {} return rv; }
/** * Actually start working on outgoing connections. * Classes should override to start UDP side as well. * * Not specified in I2PTunnelTask but used in both * I2PTunnelClientBase and I2PTunnelServer so let's * implement it here too. */ public void startRunning() { synchronized (startLock) { try { _session.connect(); } catch(I2PSessionException exc) { throw new RuntimeException("failed to connect session", exc); } start(); startLock.notify(); } open = true; }
/** * I2PTunnelTask Methods * * Classes should override to close UDP side as well */ public boolean close(boolean forced) { if (!open) return true; if (_session != null) { try { _session.destroySession(); } catch (I2PSessionException ise) {} } l.log("Closing client " + toString()); open = false; return true; }
/** * @since 0.9.21 */ public void removeSubsession(I2PSession session) { if (!(session instanceof SubSession)) return; synchronized(_subsessionLock) { _subsessions.remove(session); SessionId id = ((SubSession) session).getSessionId(); if (id != null) _subsessionMap.remove(id); /// tell the subsession try { // doesn't really throw session.destroySession(); } catch (I2PSessionException ise) {} } // do we need this here? subsession.destroySession() calls primary Destination d = session.getMyDestination(); if (d != null) _context.keyRing().remove(d.calculateHash()); }
/** * @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); } }
if ( (_session != null) && (!_session.isClosed()) ) { try { _session.destroySession(); } catch (I2PSessionException ise) { _log.warn("Unable to destroy the session", ise);
_conPacketHandler = new ConnectionPacketHandler(_context); _timer = new RetransmissionTimer(_context, "Streaming Timer " + session.getMyDestination().calculateHash().toBase64().substring(0, 4)); _connectionHandler = new ConnectionHandler(_context, this, _timer); _tcbShare = new TCBShare(_context, _timer); _session.addMuxedSessionListener(_messageHandler, protocol, defaultOptions.getLocalPort()); _outboundQueue = new PacketQueue(_context, _timer); _recentlyClosed = new LHMCache<Long, Object>(64);
i2pSession.connect(); Destination localDestination = i2pSession.getMyDestination(); log.info("Local destination key (base64): " + localDestination.toBase64()); log.info("Local destination hash (base64): " + localDestination.calculateHash().toBase64());
int c = in.read(data); boolean ok = _session.sendMessage(_peerDestination, data, 0, c); if (_session != null) { try { _session.destroySession(); } catch (I2PSessionException ise) {
if (sess != null && !sess.isClosed()) { try { if (host.length() == 60 && host.endsWith(".b32.i2p")) { if (b != null) { Hash h = Hash.create(b); dest = sess.lookupDest(h, 20*1000); } else { dest = null; dest = sess.lookupDest(host, 20*1000);
/** * Create a new SAM message-based session handler * * @param destStream Input stream containing the destination keys * @param props Properties to setup the I2P session * @throws I2PSessionException */ public SAMMessageSessionHandler(InputStream destStream, Properties props) throws I2PSessionException { if (_log.shouldLog(Log.DEBUG)) _log.debug("Instantiating new SAM message-based session handler"); I2PClient client = I2PClientFactory.createClient(); if (!props.containsKey("inbound.nickname") && !props.containsKey("outbound.nickname")) { props.setProperty("inbound.nickname", "SAM UDP Client"); props.setProperty("outbound.nickname", "SAM UDP Client"); } _session = client.createSession(destStream, props); if (_log.shouldLog(Log.DEBUG)) _log.debug("Connecting I2P session..."); _session.connect(); if (_log.shouldLog(Log.DEBUG)) _log.debug("I2P session connected"); _session.addMuxedSessionListener(this, listenProtocol, listenPort); }
if (_session.isClosed()) { opts.setSendLeaseSet(false); try { boolean success = _session.sendMessage(dest, payload, 0, payload.length, repliable ? I2PSession.PROTO_DATAGRAM : I2PSession.PROTO_DATAGRAM_RAW, fromPort, toPort, opts);