use of net.i2p.data.i2np.DataMessage in project i2p.i2p by i2p.
the class FragmentTest method createPending.
protected PendingGatewayMessage createPending(int size, boolean includeRouter, boolean includeTunnel) {
DataMessage m = new DataMessage(_context);
byte[] data = new byte[size];
_context.random().nextBytes(data);
m.setData(data);
m.setUniqueId(_context.random().nextLong(I2NPMessage.MAX_ID_VALUE));
m.setMessageExpiration(_context.clock().now() + 60 * 1000);
Hash toRouter = null;
TunnelId toTunnel = null;
if (includeRouter) {
toRouter = new Hash(new byte[Hash.HASH_LENGTH]);
_context.random().nextBytes(toRouter.getData());
}
if (includeTunnel)
toTunnel = new TunnelId(1 + _context.random().nextLong(TunnelId.MAX_ID_VALUE));
return new PendingGatewayMessage(m, toRouter, toTunnel);
}
use of net.i2p.data.i2np.DataMessage in project i2p.i2p by i2p.
the class GatewayITBase method testRouter.
@Test
public void testRouter() throws Exception {
int runCount = 1;
List<DataMessage> messages = new ArrayList<DataMessage>(runCount);
long start = _context.clock().now();
for (int i = 0; i < runCount; i++) {
DataMessage m = getTestMessage(64);
Hash to = new Hash(new byte[Hash.HASH_LENGTH]);
java.util.Arrays.fill(to.getData(), (byte) 0xFF);
messages.add(m);
_gw.add(m, to, null);
}
Thread.sleep(1000);
List<I2NPMessage> received = _receiver.clearReceived();
for (int i = 0; i < messages.size(); i++) {
assertTrue(received.contains(((I2NPMessage) messages.get(i))));
}
}
use of net.i2p.data.i2np.DataMessage in project i2p.i2p by i2p.
the class GatewayITBase method testSmall.
@Test
public void testSmall() throws Exception {
int runCount = 1;
List<DataMessage> messages = new ArrayList<DataMessage>(runCount);
long start = _context.clock().now();
for (int i = 0; i < runCount; i++) {
DataMessage m = getTestMessage(64);
messages.add(m);
_gw.add(m, null, null);
}
Thread.sleep(1000);
List<I2NPMessage> received = _receiver.clearReceived();
for (int i = 0; i < messages.size(); i++) {
assertTrue(received.contains(((I2NPMessage) messages.get(i))));
}
}
use of net.i2p.data.i2np.DataMessage in project i2p.i2p by i2p.
the class GatewayITBase method testTunnel.
@Test
public void testTunnel() throws Exception {
int runCount = 1;
List<DataMessage> messages = new ArrayList<DataMessage>(runCount);
long start = _context.clock().now();
for (int i = 0; i < runCount; i++) {
DataMessage m = getTestMessage(64);
Hash to = new Hash(new byte[Hash.HASH_LENGTH]);
java.util.Arrays.fill(to.getData(), (byte) 0xFF);
TunnelId tunnel = new TunnelId(42);
byte[] data = m.toByteArray();
messages.add(m);
_gw.add(m, to, tunnel);
}
Thread.sleep(1000);
List<I2NPMessage> received = _receiver.clearReceived();
for (int i = 0; i < messages.size(); i++) {
assertTrue(received.contains(((I2NPMessage) messages.get(i))));
}
}
use of net.i2p.data.i2np.DataMessage in project i2p.i2p by i2p.
the class OutboundClientMessageOneShotJob method buildClove.
/**
* Build the payload clove that will be used for all of the messages,
* placing the clove in the status structure.
*
* @return null on failure
*/
private PayloadGarlicConfig buildClove() {
PayloadGarlicConfig clove = new PayloadGarlicConfig();
DeliveryInstructions instructions = new DeliveryInstructions();
instructions.setDeliveryMode(DeliveryInstructions.DELIVERY_MODE_DESTINATION);
instructions.setDestination(_to.calculateHash());
// defaults
// instructions.setDelayRequested(false);
// instructions.setDelaySeconds(0);
// instructions.setEncrypted(false);
clove.setCertificate(Certificate.NULL_CERT);
clove.setDeliveryInstructions(instructions);
clove.setExpiration(OVERALL_TIMEOUT_MS_DEFAULT + getContext().clock().now());
clove.setId(getContext().random().nextLong(I2NPMessage.MAX_ID_VALUE));
DataMessage msg = new DataMessage(getContext());
Payload p = _clientMessage.getPayload();
if (p == null)
return null;
byte[] d = p.getEncryptedData();
if (d == null)
return null;
msg.setData(d);
msg.setMessageExpiration(clove.getExpiration());
clove.setPayload(msg);
// _log.debug(getJobId() + ": Built payload clove with id " + clove.getId());
return clove;
}
Aggregations