use of net.i2p.data.i2np.I2NPMessage in project i2p.i2p by i2p.
the class SearchJob method sendRouterSearch.
/**
* we're searching for a router, so we can just send direct
*/
protected void sendRouterSearch(RouterInfo router) {
int timeout = _facade.getPeerTimeout(router.getIdentity().getHash());
long expiration = getContext().clock().now() + timeout;
// use the 4-arg one so we pick up the override in ExploreJob
// I2NPMessage msg = buildMessage(expiration);
I2NPMessage msg = buildMessage(null, router.getIdentity().getHash(), expiration, router);
if (msg == null) {
getContext().jobQueue().addJob(new FailedJob(getContext(), router));
return;
}
if (_log.shouldLog(Log.DEBUG))
_log.debug(getJobId() + ": Sending router search directly to " + router.getIdentity().getHash() + " for " + _state.getTarget());
SearchMessageSelector sel = new SearchMessageSelector(getContext(), router, _expiration, _state);
SearchUpdateReplyFoundJob reply = new SearchUpdateReplyFoundJob(getContext(), router, _state, _facade, this);
SendMessageDirectJob j = new SendMessageDirectJob(getContext(), msg, router.getIdentity().getHash(), reply, new FailedJob(getContext(), router), sel, timeout, OutNetMessage.PRIORITY_EXPLORATORY);
if (FloodfillNetworkDatabaseFacade.isFloodfill(router))
_floodfillSearchesOutstanding++;
j.runJob();
// getContext().jobQueue().addJob(j);
}
use of net.i2p.data.i2np.I2NPMessage 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.I2NPMessage 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.I2NPMessage 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.I2NPMessage in project i2p.i2p by i2p.
the class ExploreJob method buildMessage.
/**
* Build the database search message, but unlike the normal searches, we're more explicit in
* what we /dont/ want. We don't just ask them to ignore the peers we've already searched
* on, but to ignore a number of the peers we already know about (in the target key's bucket) as well.
*
* Perhaps we may want to ignore other keys too, such as the ones in nearby
* buckets, but we probably don't want the dontIncludePeers set to get too
* massive (aka sending the entire routing table as 'dont tell me about these
* guys'). but maybe we do. dunno. lots of implications.
*
* FloodfillPeerSelector would add only the floodfill peers,
* and PeerSelector doesn't include the floodfill peers,
* so we add the ff peers ourselves and then use the regular PeerSelector.
*
* @param replyTunnelId tunnel to receive replies through, or our router hash if replyGateway is null
* @param replyGateway gateway for the reply tunnel, if null, we are sending direct, do not encrypt
* @param expiration when the search should stop
* @param peer the peer to send it to
*
* @return a DatabaseLookupMessage or GarlicMessage or null on error
*/
@Override
protected I2NPMessage buildMessage(TunnelId replyTunnelId, Hash replyGateway, long expiration, RouterInfo peer) {
DatabaseLookupMessage msg = new DatabaseLookupMessage(getContext(), true);
msg.setSearchKey(getState().getTarget());
msg.setFrom(replyGateway);
// Moved below now that DLM makes a copy
// msg.setDontIncludePeers(getState().getClosestAttempted(MAX_CLOSEST));
Set<Hash> dontIncludePeers = getState().getClosestAttempted(MAX_CLOSEST);
msg.setMessageExpiration(expiration);
if (replyTunnelId != null)
msg.setReplyTunnel(replyTunnelId);
int available = MAX_CLOSEST - dontIncludePeers.size();
if (available > 0) {
// Supported as of 0.7.9
if (dontIncludePeers.add(Hash.FAKE_HASH))
available--;
}
// supported as of 0.9.16. TODO remove fake hash above
msg.setSearchType(DatabaseLookupMessage.Type.EXPL);
KBucketSet<Hash> ks = _facade.getKBuckets();
Hash rkey = getContext().routingKeyGenerator().getRoutingKey(getState().getTarget());
// in a few releases, we can (and should) remove this,
// as routers will honor the above flag, and we want the table to include
// only non-floodfills.
// Removed in 0.8.8, good thing, as we had well over MAX_CLOSEST floodfills.
// if (available > 0 && ks != null) {
// List peers = _peerSelector.selectFloodfillParticipants(rkey, available, ks);
// int len = peers.size();
// if (len > 0)
// msg.getDontIncludePeers().addAll(peers);
// }
available = MAX_CLOSEST - dontIncludePeers.size();
if (available > 0) {
// selectNearestExplicit adds our hash to the dontInclude set (3rd param) ...
// And we end up with MAX_CLOSEST+1 entries.
// We don't want our hash in the message's don't-include list though.
// We're just exploring, but this could give things away, and tie our exploratory tunnels to our router,
// so let's not put our hash in there.
Set<Hash> dontInclude = new HashSet<Hash>(dontIncludePeers);
List<Hash> peers = _peerSelector.selectNearestExplicit(rkey, available, dontInclude, ks);
dontIncludePeers.addAll(peers);
}
if (_log.shouldLog(Log.DEBUG))
_log.debug("Peers we don't want to hear about: " + dontIncludePeers);
msg.setDontIncludePeers(dontIncludePeers);
// Now encrypt if we can
I2NPMessage outMsg;
if (replyTunnelId != null && getContext().getProperty(IterativeSearchJob.PROP_ENCRYPT_RI, IterativeSearchJob.DEFAULT_ENCRYPT_RI)) {
// request encrypted reply?
if (DatabaseLookupMessage.supportsEncryptedReplies(peer)) {
MessageWrapper.OneTimeSession sess;
sess = MessageWrapper.generateSession(getContext());
if (_log.shouldLog(Log.INFO))
_log.info(getJobId() + ": Requesting encrypted reply from " + peer.getIdentity().calculateHash() + ' ' + sess.key + ' ' + sess.tag);
msg.setReplySession(sess.key, sess.tag);
}
// may be null
outMsg = MessageWrapper.wrap(getContext(), msg, peer);
if (_log.shouldLog(Log.DEBUG))
_log.debug(getJobId() + ": Encrypted exploratory DLM for " + getState().getTarget() + " to " + peer.getIdentity().calculateHash());
} else {
outMsg = msg;
}
return outMsg;
}
Aggregations