Search in sources :

Example 11 with I2PSession

use of net.i2p.client.I2PSession in project i2p.i2p by i2p.

the class I2PSnarkUtil method setMaxUpBW.

/**
 *  This updates ALL the session options (not just the bw) and tells the router
 *  @param limit KBps
 */
public void setMaxUpBW(int limit) {
    _maxUpBW = limit;
    // add a little for overhead
    _opts.put(PROP_MAX_BW, Integer.toString(limit * (1024 * 6 / 5)));
    _configured = true;
    if (_manager != null) {
        I2PSession sess = _manager.getSession();
        if (sess != null) {
            Properties newProps = new Properties();
            newProps.putAll(_opts);
            sess.updateOptions(newProps);
        }
    }
}
Also used : I2PSession(net.i2p.client.I2PSession) Properties(java.util.Properties)

Example 12 with I2PSession

use of net.i2p.client.I2PSession in project i2p.i2p by i2p.

the class IdleChecker method setTunnels.

/**
 *  Set in / out / in backup / out backup tunnel counts
 */
private void setTunnels(String i, String o, String ib, String ob) {
    _consec = 0;
    I2PSocketManager mgr = _util.getSocketManager();
    if (mgr != null) {
        I2PSession sess = mgr.getSession();
        if (sess != null) {
            if (_log.shouldLog(Log.INFO))
                _log.info("New tunnel settings " + i + " / " + o + " / " + ib + " / " + ob);
            Properties newProps = new Properties();
            newProps.setProperty("inbound.quantity", i);
            newProps.setProperty("outbound.quantity", o);
            newProps.setProperty("inbound.backupQuantity", ib);
            newProps.setProperty("outbound.backupQuantity", ob);
            sess.updateOptions(newProps);
            _lastIn = i;
            _lastOut = o;
        }
    }
}
Also used : I2PSocketManager(net.i2p.client.streaming.I2PSocketManager) I2PSession(net.i2p.client.I2PSession) Properties(java.util.Properties)

Example 13 with I2PSession

use of net.i2p.client.I2PSession in project i2p.i2p by i2p.

the class DatagramTest method testBadagram.

public void testBadagram() throws Exception {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    I2PClient client = I2PClientFactory.createClient();
    Destination d = client.createDestination(out);
    I2PSession session = client.createSession(new ByteArrayInputStream(out.toByteArray()), null);
    DSAEngine dsaEng = DSAEngine.getInstance();
    ByteArrayOutputStream dout = new ByteArrayOutputStream();
    d.writeBytes(dout);
    dsaEng.sign(Hash.FAKE_HASH.toByteArray(), session.getPrivateKey()).writeBytes(dout);
    dout.write(DataHelper.getASCII("blah"));
    byte[] data = dout.toByteArray();
    I2PDatagramDissector dd = new I2PDatagramDissector();
    dd.loadI2PDatagram(data);
    boolean error = false;
    try {
        dd.getPayload();
    } catch (I2PInvalidDatagramException i2pide) {
        error = true;
    }
    assertTrue(error);
    error = false;
    try {
        dd.getSender();
    } catch (I2PInvalidDatagramException i2pide) {
        error = true;
    }
    assertTrue(error);
    error = false;
    try {
        dd.getHash();
    } catch (I2PInvalidDatagramException i2pide) {
        error = true;
    }
    assertTrue(error);
}
Also used : Destination(net.i2p.data.Destination) DSAEngine(net.i2p.crypto.DSAEngine) ByteArrayInputStream(java.io.ByteArrayInputStream) I2PSession(net.i2p.client.I2PSession) I2PClient(net.i2p.client.I2PClient) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 14 with I2PSession

use of net.i2p.client.I2PSession in project i2p.i2p by i2p.

the class I2PSessionIT method testSendClosedMessage.

public void testSendClosedMessage() throws Exception {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Destination d = I2PClientFactory.createClient().createDestination(out);
    I2PSession session = new I2PSessionImpl2(I2PAppContext.getGlobalContext(), new ByteArrayInputStream(out.toByteArray()), null);
    boolean error = false;
    try {
        session.sendMessage(d, out.toByteArray());
    } catch (I2PSessionException i2pse) {
        error = true;
    }
    assertTrue(error);
}
Also used : Destination(net.i2p.data.Destination) ByteArrayInputStream(java.io.ByteArrayInputStream) I2PSession(net.i2p.client.I2PSession) I2PSessionException(net.i2p.client.I2PSessionException) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 15 with I2PSession

use of net.i2p.client.I2PSession in project i2p.i2p by i2p.

the class I2PSessionIT method testSendAndRecieve.

public void testSendAndRecieve() throws Exception {
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    Destination d = I2PClientFactory.createClient().createDestination(out);
    I2PSession session = new I2PSessionImpl2(I2PAppContext.getGlobalContext(), new ByteArrayInputStream(out.toByteArray()), null);
    session.connect();
    session.setSessionListener(this);
    _s = new HashSet<String>();
    _s.add("a");
    _s.add("b");
    _s.add("c");
    _s.add("d");
    session.sendMessage(d, DataHelper.getASCII("a"));
    session.sendMessage(d, DataHelper.getASCII("b"));
    session.sendMessage(d, DataHelper.getASCII("c"));
    session.sendMessage(d, DataHelper.getASCII("d"));
    for (int i = 0; (i < 20) && (!_s.isEmpty()); i++) {
        Thread.sleep(1000);
    }
    assertTrue(_s.isEmpty());
}
Also used : Destination(net.i2p.data.Destination) ByteArrayInputStream(java.io.ByteArrayInputStream) I2PSession(net.i2p.client.I2PSession) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Aggregations

I2PSession (net.i2p.client.I2PSession)37 Properties (java.util.Properties)13 I2PSessionException (net.i2p.client.I2PSessionException)12 ByteArrayInputStream (java.io.ByteArrayInputStream)10 Destination (net.i2p.data.Destination)10 I2PClient (net.i2p.client.I2PClient)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)8 IOException (java.io.IOException)8 I2PException (net.i2p.I2PException)5 Hash (net.i2p.data.Hash)4 File (java.io.File)3 FileInputStream (java.io.FileInputStream)3 I2PSimpleClient (net.i2p.client.I2PSimpleClient)3 I2PSocket (net.i2p.client.streaming.I2PSocket)3 DataFormatException (net.i2p.data.DataFormatException)3 Log (net.i2p.util.Log)3 InterruptedIOException (java.io.InterruptedIOException)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 GeneralSecurityException (java.security.GeneralSecurityException)2