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);
}
}
}
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;
}
}
}
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);
}
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);
}
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());
}
Aggregations