forked from I2P_Developers/i2p.i2p
Compare commits
1 Commits
i2p-window
...
i2p.i2p.2.
Author | SHA1 | Date | |
---|---|---|---|
bc90b5fd66 |
@ -38,12 +38,15 @@ public class FloodfillDatabaseStoreMessageHandler implements HandlerJobBuilder {
|
||||
}
|
||||
|
||||
public Job createJob(I2NPMessage receivedMessage, RouterIdentity from, Hash fromHash) {
|
||||
Job j = new HandleFloodfillDatabaseStoreMessageJob(_context, (DatabaseStoreMessage)receivedMessage, from, fromHash, _facade, _msgIDBloomXor);
|
||||
if (false) {
|
||||
j.runJob();
|
||||
return null;
|
||||
} else {
|
||||
return j;
|
||||
}
|
||||
DatabaseStoreMessage dsm = (DatabaseStoreMessage)receivedMessage;
|
||||
// store to client db if received by that client
|
||||
Hash by = dsm.getEntry().getReceivedBy();
|
||||
FloodfillNetworkDatabaseFacade netdb;
|
||||
if (by != null)
|
||||
netdb = (FloodfillNetworkDatabaseFacade) _context.clientNetDb(by);
|
||||
else
|
||||
netdb = _facade;
|
||||
Job j = new HandleFloodfillDatabaseStoreMessageJob(_context, dsm, from, fromHash, netdb, _msgIDBloomXor);
|
||||
return j;
|
||||
}
|
||||
}
|
||||
|
@ -1,7 +1,5 @@
|
||||
package net.i2p.router.tunnel;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import net.i2p.data.DatabaseEntry;
|
||||
import net.i2p.data.Hash;
|
||||
import net.i2p.data.LeaseSet;
|
||||
@ -19,16 +17,11 @@ import net.i2p.data.i2np.OutboundTunnelBuildReplyMessage;
|
||||
import net.i2p.data.i2np.TunnelBuildReplyMessage;
|
||||
import net.i2p.data.i2np.VariableTunnelBuildReplyMessage;
|
||||
import net.i2p.router.ClientMessage;
|
||||
import net.i2p.router.Job;
|
||||
import net.i2p.router.OutNetMessage;
|
||||
import net.i2p.router.ReplyJob;
|
||||
import net.i2p.router.RouterContext;
|
||||
import net.i2p.router.TunnelInfo;
|
||||
import net.i2p.router.TunnelPoolSettings;
|
||||
import net.i2p.router.message.GarlicMessageReceiver;
|
||||
import net.i2p.router.networkdb.kademlia.FloodfillNetworkDatabaseFacade;
|
||||
import net.i2p.router.networkdb.kademlia.FloodfillNetworkDatabaseSegmentor;
|
||||
import net.i2p.router.networkdb.kademlia.FloodfillDatabaseStoreMessageHandler;
|
||||
import net.i2p.util.Log;
|
||||
import net.i2p.util.RandomSource;
|
||||
|
||||
@ -55,13 +48,11 @@ class InboundMessageDistributor implements GarlicMessageReceiver.CloveReceiver {
|
||||
|
||||
if (_client != null) {
|
||||
TunnelPoolSettings clienttps = _context.tunnelManager().getInboundSettings(_client);
|
||||
if (_log.shouldLog(Log.DEBUG)){
|
||||
_log.debug("Initializing client for " + _client.toBase32());
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Initializing client (nickname: "
|
||||
+ clienttps.getDestinationNickname()
|
||||
+ " b32: " + _client.toBase32()
|
||||
+ ") InboundMessageDistributor with tunnel pool settings: " + clienttps);
|
||||
}
|
||||
_clientNickname = clienttps.getDestinationNickname();
|
||||
_msgIDBloomXor = clienttps.getMsgIdBloomXor();
|
||||
} else {
|
||||
@ -108,6 +99,7 @@ class InboundMessageDistributor implements GarlicMessageReceiver.CloveReceiver {
|
||||
// LS or RI and client or expl., so that we can safely follow references
|
||||
// in a reply to a LS lookup over client tunnels.
|
||||
// ILJ would also have to follow references via client tunnels
|
||||
/****
|
||||
DatabaseSearchReplyMessage orig = (DatabaseSearchReplyMessage) msg;
|
||||
if (orig.getNumReplies() > 0) {
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
@ -117,6 +109,7 @@ class InboundMessageDistributor implements GarlicMessageReceiver.CloveReceiver {
|
||||
newMsg.setSearchKey(orig.getSearchKey());
|
||||
msg = newMsg;
|
||||
}
|
||||
****/
|
||||
break;
|
||||
|
||||
case DatabaseStoreMessage.MESSAGE_TYPE:
|
||||
@ -133,7 +126,6 @@ class InboundMessageDistributor implements GarlicMessageReceiver.CloveReceiver {
|
||||
if (_context.routerHash().equals(key))
|
||||
return;
|
||||
RouterInfo ri = (RouterInfo) dsm.getEntry();
|
||||
ri.setReceivedBy(_client);
|
||||
if (!key.equals(ri.getIdentity().getHash()))
|
||||
return;
|
||||
if (!ri.isValid())
|
||||
@ -176,7 +168,7 @@ class InboundMessageDistributor implements GarlicMessageReceiver.CloveReceiver {
|
||||
return;
|
||||
|
||||
} // switch
|
||||
} else { // client == null/exploratory
|
||||
} else {
|
||||
// expl. tunnel
|
||||
switch (type) {
|
||||
case DatabaseStoreMessage.MESSAGE_TYPE:
|
||||
@ -224,89 +216,7 @@ class InboundMessageDistributor implements GarlicMessageReceiver.CloveReceiver {
|
||||
+ " (for client " + _clientNickname + " ("
|
||||
+ ((_client != null) ? _client.toBase32() : "null")
|
||||
+ ") to target=NULL/tunnel=NULL " + msg);
|
||||
// Tunnel Build Messages and Delivery Status Messages (used for tunnel
|
||||
// testing) need to go back to the inNetMessagePool, whether or not
|
||||
// they came through a client tunnel.
|
||||
if ( (type == OutboundTunnelBuildReplyMessage.MESSAGE_TYPE) ||
|
||||
(type == TunnelBuildReplyMessage.MESSAGE_TYPE) ||
|
||||
(type == VariableTunnelBuildReplyMessage.MESSAGE_TYPE) ||
|
||||
(type == DeliveryStatusMessage.MESSAGE_TYPE)) {
|
||||
_context.inNetMessagePool().add(msg, null, null, _msgIDBloomXor);
|
||||
return;
|
||||
}
|
||||
|
||||
// Handling of client tunnel messages need explicit handling
|
||||
// in the context of the client subDb.
|
||||
if (_client != null) {
|
||||
// For now, the only client message we know how to handle here is a DSM.
|
||||
// There aren't normally DSM messages here, but it should be safe to store
|
||||
// them in the client netDb.
|
||||
if (type == DatabaseStoreMessage.MESSAGE_TYPE) {
|
||||
DatabaseStoreMessage dsm = (DatabaseStoreMessage)msg;
|
||||
// Ensure the reply info is cleared, just in case
|
||||
dsm.setReplyToken(0);
|
||||
dsm.setReplyTunnel(null);
|
||||
dsm.setReplyGateway(null);
|
||||
|
||||
// We need to replicate some of the handling that was previously
|
||||
// performed when these types of messages were passed back to
|
||||
// the inNetMessagePool.
|
||||
// There's important inline handling made when fetching the original messages.
|
||||
List<OutNetMessage> origMessages = _context.messageRegistry().getOriginalMessages(msg);
|
||||
int sz = origMessages.size();
|
||||
if (sz > 0) {
|
||||
dsm.setReceivedAsReply();
|
||||
}
|
||||
if (dsm.getEntry().isLeaseSet()) {
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info("[client: " + _clientNickname + "] Saving LS DSM from client tunnel.");
|
||||
FloodfillDatabaseStoreMessageHandler _FDSMH = new FloodfillDatabaseStoreMessageHandler(_context, (FloodfillNetworkDatabaseFacade) _context.clientNetDb(_client));
|
||||
Job j = _FDSMH.createJob(msg, null, null);
|
||||
j.runJob();
|
||||
if (sz > 0) {
|
||||
for (int i = 0; i < sz; i++) {
|
||||
OutNetMessage omsg = origMessages.get(i);
|
||||
ReplyJob job = omsg.getOnReplyJob();
|
||||
if (job != null) {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Setting ReplyJob ("
|
||||
+ job + ") for original message:"
|
||||
+ omsg + "; with reply message [id: "
|
||||
+ msg.getUniqueId()
|
||||
+ " Class: "
|
||||
+ msg.getClass().getSimpleName()
|
||||
+ "] full message: " + msg);
|
||||
else if (_log.shouldLog(Log.INFO))
|
||||
_log.info("Setting a ReplyJob ("
|
||||
+ job + ") for original message class "
|
||||
+ omsg.getClass().getSimpleName()
|
||||
+ " with reply message class "
|
||||
+ msg.getClass().getSimpleName());
|
||||
job.setMessage(msg);
|
||||
_context.jobQueue().addJob(job);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
} else {
|
||||
// drop it, since the data we receive shouldn't include router references.
|
||||
_context.statManager().addRateData("tunnel.dropDangerousClientTunnelMessage", 1,
|
||||
DatabaseStoreMessage.MESSAGE_TYPE);
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn("Dropped dangerous RI DSM message from a tunnel for " + _clientNickname
|
||||
+ " ("+ _client.toBase32() + ") : " + dsm, new Exception("cause"));
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Don't know what to do with other message types here.
|
||||
// But, in testing, it is uncommon to end up here.
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn("[client: " + _clientNickname + "] Dropping a client message from a tunnel due to lack of delivery handling instructions. Message: " + msg);
|
||||
return;
|
||||
} else {
|
||||
// These messages came down a exploratory tunnel since client == null.
|
||||
_context.inNetMessagePool().add(msg, null, null, _msgIDBloomXor);
|
||||
}
|
||||
_context.inNetMessagePool().add(msg, null, null, _msgIDBloomXor);
|
||||
}
|
||||
} else if (_context.routerHash().equals(target)) {
|
||||
if (type == GarlicMessage.MESSAGE_TYPE)
|
||||
@ -380,53 +290,7 @@ class InboundMessageDistributor implements GarlicMessageReceiver.CloveReceiver {
|
||||
_log.info("Storing garlic LS down tunnel for: " + dsm.getKey() + " sent to: "
|
||||
+ _clientNickname + " ("
|
||||
+ (_client != null ? _client.toBase32() : ") router"));
|
||||
if (_client != null) {
|
||||
// We need to replicate some of the handling that was previously
|
||||
// performed when these types of messages were passed back to
|
||||
// the inNetMessagePool.
|
||||
// There's important inline handling made when fetching the original messages.
|
||||
List<OutNetMessage> origMessages = _context.messageRegistry().getOriginalMessages(data);
|
||||
int sz = origMessages.size();
|
||||
if (sz > 0)
|
||||
dsm.setReceivedAsReply();
|
||||
// ToDo: This should actually have a try and catch.
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info("Store the LS in the correct dbid subDb: " + _client.toBase32());
|
||||
FloodfillDatabaseStoreMessageHandler _FDSMH = new FloodfillDatabaseStoreMessageHandler(_context, (FloodfillNetworkDatabaseFacade) _context.clientNetDb(_client));
|
||||
Job j = _FDSMH.createJob(data, null, null);
|
||||
j.runJob();
|
||||
if (sz > 0) {
|
||||
for (int i = 0; i < sz; i++) {
|
||||
OutNetMessage omsg = origMessages.get(i);
|
||||
ReplyJob job = omsg.getOnReplyJob();
|
||||
if (job != null) {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Setting ReplyJob ("
|
||||
+ job + ") for original message:"
|
||||
+ omsg + "; with reply message [id: "
|
||||
+ data.getUniqueId()
|
||||
+ " Class: "
|
||||
+ data.getClass().getSimpleName()
|
||||
+ "] full message: " + data);
|
||||
else if (_log.shouldLog(Log.INFO))
|
||||
_log.info("Setting a ReplyJob ("
|
||||
+ job + ") for original message class "
|
||||
+ omsg.getClass().getSimpleName()
|
||||
+ " with reply message class "
|
||||
+ data.getClass().getSimpleName());
|
||||
job.setMessage(data);
|
||||
_context.jobQueue().addJob(job);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (_client == null) {
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.info("Routing Exploratory Tunnel message back to the inNetMessagePool.");
|
||||
_context.inNetMessagePool().add(dsm, null, null, _msgIDBloomXor);
|
||||
} else {
|
||||
if (_log.shouldLog(Log.ERROR))
|
||||
_log.error("No handling provisions for message: " + data);
|
||||
}
|
||||
_context.inNetMessagePool().add(dsm, null, null, _msgIDBloomXor);
|
||||
} else {
|
||||
if (_client != null) {
|
||||
// drop it, since the data we receive shouldn't include router
|
||||
@ -444,13 +308,10 @@ class InboundMessageDistributor implements GarlicMessageReceiver.CloveReceiver {
|
||||
// We must send to the InNetMessagePool so the message can be matched
|
||||
// and the search marked as successful.
|
||||
// note that encrypted replies to RI lookups is currently disables in ISJ, we won't get here.
|
||||
|
||||
// ... and inject it.
|
||||
_context.statManager().addRateData("tunnel.inboundI2NPGarlicRIDSM", 1);
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info("Storing garlic RI from exploratory tunnel for: "
|
||||
+ dsm.getKey()
|
||||
+ " dsm: " + dsm);
|
||||
_log.info("Storing garlic RI down tunnel (" + _clientNickname
|
||||
+ ") for: " + dsm.getKey());
|
||||
_context.inNetMessagePool().add(dsm, null, null, _msgIDBloomXor);
|
||||
}
|
||||
} else if (_client != null && type == DatabaseSearchReplyMessage.MESSAGE_TYPE) {
|
||||
@ -460,6 +321,7 @@ class InboundMessageDistributor implements GarlicMessageReceiver.CloveReceiver {
|
||||
// in a reply to a LS lookup over client tunnels.
|
||||
// ILJ would also have to follow references via client tunnels
|
||||
DatabaseSearchReplyMessage orig = (DatabaseSearchReplyMessage) data;
|
||||
/****
|
||||
if (orig.getNumReplies() > 0) {
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info("Removing replies from a garlic DSRM down a tunnel for " + _client + ": " + data);
|
||||
@ -468,15 +330,8 @@ class InboundMessageDistributor implements GarlicMessageReceiver.CloveReceiver {
|
||||
newMsg.setSearchKey(orig.getSearchKey());
|
||||
orig = newMsg;
|
||||
}
|
||||
// Client DSRM are safe to pass back to the inNetMessagePool when
|
||||
// the replies are stripped.
|
||||
// Even though the inNetMessagePool will lack information to understand
|
||||
// the client context, DSRM will be matched against their search,
|
||||
// which will place the handling back in the client context.
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Passing inbound garlic DSRM back to inNetMessagePool for client " + _clientNickname
|
||||
+ "; msg: " + orig);
|
||||
_context.inNetMessagePool().add(orig, null, null, _msgIDBloomXor);
|
||||
****/
|
||||
_context.inNetMessagePool().add(orig, null, null, _msgIDBloomXor);
|
||||
} else if (type == DataMessage.MESSAGE_TYPE) {
|
||||
// a data message targetting the local router is how we send load tests (real
|
||||
// data messages target destinations)
|
||||
@ -493,17 +348,7 @@ class InboundMessageDistributor implements GarlicMessageReceiver.CloveReceiver {
|
||||
+ _clientNickname + " (" + _client.toBase32() + ") : "
|
||||
+ data, new Exception("cause"));
|
||||
} else {
|
||||
if ((type == OutboundTunnelBuildReplyMessage.MESSAGE_TYPE) ||
|
||||
(type == TunnelBuildReplyMessage.MESSAGE_TYPE) ||
|
||||
(type == VariableTunnelBuildReplyMessage.MESSAGE_TYPE) ||
|
||||
(type == DeliveryStatusMessage.MESSAGE_TYPE)) {
|
||||
_context.inNetMessagePool().add(data, null, null, _msgIDBloomXor);
|
||||
} else if (_client != null) {
|
||||
_log.warn("Dropping inbound Message for client " + _clientNickname
|
||||
+ " due to lack of handling instructions. Msg: " + data);
|
||||
} else {
|
||||
_context.inNetMessagePool().add(data, null, null, _msgIDBloomXor);
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
|
Reference in New Issue
Block a user