use of net.i2p.data.i2np.I2NPMessage in project i2p.i2p by i2p.
the class FragmentHandler method receiveComplete.
private void receiveComplete(FragmentedMessage msg) {
if (msg == null)
return;
_completed++;
String stringified = null;
if (_log.shouldLog(Log.DEBUG))
stringified = msg.toString();
byte[] data = null;
try {
int fragmentCount = msg.getFragmentCount();
// toByteArray destroys the contents of the message completely
data = msg.toByteArray();
if (data == null)
// fragments already released???
throw new I2NPMessageException("null data");
if (_log.shouldLog(Log.DEBUG))
// + Base64.encode(data)
_log.debug("RECV(" + data.length + "): ");
// + " " + _context.sha().calculateHash(data).toBase64());
// TODO read in as unknown message for outbound tunnels,
// since this will just be packaged in a TunnelGatewayMessage.
// Not a big savings since most everything is a GarlicMessage
// and so the readMessage() call is fast.
// The unencrypted messages at the OBEP are (V)TBMs
// and perhaps an occasional DatabaseLookupMessage
I2NPMessage m = new I2NPMessageHandler(_context).readMessage(data);
// + msg.toString());
noteReception(m.getUniqueId(), fragmentCount - 1, "complete: ");
noteCompletion(m.getUniqueId());
_receiver.receiveComplete(m, msg.getTargetRouter(), msg.getTargetTunnel());
} catch (I2NPMessageException ime) {
if (stringified == null)
stringified = msg.toString();
if (_log.shouldLog(Log.WARN)) {
_log.warn("Error receiving fragmented message (corrupt?): " + stringified, ime);
_log.warn("DUMP:\n" + HexDump.dump(data));
_log.warn("RAW:\n" + Base64.encode(data));
}
}
}
use of net.i2p.data.i2np.I2NPMessage in project i2p.i2p by i2p.
the class FragmentHandler method receiveComplete.
/**
* Zero-copy reception of an unfragmented message
* @since 0.9
*/
private void receiveComplete(byte[] data, int offset, int len, Hash router, TunnelId tunnelId) {
_completed++;
try {
if (_log.shouldLog(Log.DEBUG))
_log.debug("RECV unfrag(" + len + ')');
// TODO read in as unknown message for outbound tunnels,
// since this will just be packaged in a TunnelGatewayMessage.
// Not a big savings since most everything is a GarlicMessage
// and so the readMessage() call is fast.
// The unencrypted messages at the OBEP are (V)TBMs
// and perhaps an occasional DatabaseLookupMessage
I2NPMessageHandler h = new I2NPMessageHandler(_context);
h.readMessage(data, offset, len);
I2NPMessage m = h.lastRead();
// + msg.toString());
noteReception(m.getUniqueId(), 0, "complete: ");
noteCompletion(m.getUniqueId());
_receiver.receiveComplete(m, router, tunnelId);
} catch (I2NPMessageException ime) {
if (_log.shouldLog(Log.WARN)) {
_log.warn("Error receiving unfragmented message (corrupt?)", ime);
_log.warn("DUMP:\n" + HexDump.dump(data, offset, len));
_log.warn("RAW:\n" + Base64.encode(data, offset, len));
}
}
}
use of net.i2p.data.i2np.I2NPMessage in project i2p.i2p by i2p.
the class OutboundMessageDistributor method distribute.
private void distribute(I2NPMessage msg, RouterInfo target, TunnelId tunnel) {
I2NPMessage m = msg;
if (tunnel != null) {
TunnelGatewayMessage t = new TunnelGatewayMessage(_context);
t.setMessage(msg);
t.setTunnelId(tunnel);
t.setMessageExpiration(m.getMessageExpiration());
m = t;
}
if (_context.routerHash().equals(target.getIdentity().calculateHash())) {
if (_log.shouldLog(Log.DEBUG))
_log.debug("queueing inbound message to ourselves: " + m);
// TODO if UnknownI2NPMessage, convert it.
// See FragmentHandler.receiveComplete()
_context.inNetMessagePool().add(m, null, null);
return;
} else {
OutNetMessage out = new OutNetMessage(_context, m, _context.clock().now() + MAX_DISTRIBUTE_TIME, _priority, target);
if (_log.shouldLog(Log.DEBUG))
_log.debug("queueing outbound message to " + target.getIdentity().calculateHash());
_context.outNetMessagePool().add(out);
}
}
use of net.i2p.data.i2np.I2NPMessage in project i2p.i2p by i2p.
the class GatewayITBase method testLarge.
@Test
public void testLarge() 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(1024);
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.I2NPMessage in project i2p.i2p by i2p.
the class SearchUpdateReplyFoundJob method runJob.
public void runJob() {
if (_isFloodfillPeer)
_job.decrementOutstandingFloodfillSearches();
I2NPMessage message = _message;
if (_log.shouldLog(Log.INFO))
_log.info(getJobId() + ": Reply from " + _peer.toBase64() + " with message " + message.getClass().getSimpleName());
long howLong = System.currentTimeMillis() - _sentOn;
// assume requests are 1KB (they're almost always much smaller, but tunnels have a fixed size)
int msgSize = 1024;
if (_replyTunnel != null) {
for (int i = 0; i < _replyTunnel.getLength(); i++) getContext().profileManager().tunnelDataPushed(_replyTunnel.getPeer(i), howLong, msgSize);
_replyTunnel.incrementVerifiedBytesTransferred(msgSize);
}
if (_outTunnel != null) {
for (int i = 0; i < _outTunnel.getLength(); i++) getContext().profileManager().tunnelDataPushed(_outTunnel.getPeer(i), howLong, msgSize);
_outTunnel.incrementVerifiedBytesTransferred(msgSize);
}
if (message instanceof DatabaseStoreMessage) {
long timeToReply = _state.dataFound(_peer);
DatabaseStoreMessage msg = (DatabaseStoreMessage) message;
DatabaseEntry entry = msg.getEntry();
try {
_facade.store(msg.getKey(), entry);
getContext().profileManager().dbLookupSuccessful(_peer, timeToReply);
} catch (UnsupportedCryptoException iae) {
// don't blame the peer
getContext().profileManager().dbLookupSuccessful(_peer, timeToReply);
_state.abort();
// searchNext() will call fail()
} catch (IllegalArgumentException iae) {
if (_log.shouldLog(Log.WARN))
_log.warn("Peer " + _peer + " sent us invalid data: ", iae);
// blame the peer
getContext().profileManager().dbLookupReply(_peer, 0, 0, 1, 0, timeToReply);
}
} else if (message instanceof DatabaseSearchReplyMessage) {
_job.replyFound((DatabaseSearchReplyMessage) message, _peer);
} else {
if (_log.shouldLog(Log.ERROR))
_log.error(getJobId() + ": What?! Reply job matched a strange message: " + message);
return;
}
_job.searchNext();
}
Aggregations