Search in sources :

Example 21 with DatabaseStoreMessage

use of net.i2p.data.i2np.DatabaseStoreMessage in project i2p.i2p by i2p.

the class FloodOnlyLookupSelector method isMatch.

public boolean isMatch(I2NPMessage message) {
    if (message == null)
        return false;
    if (message instanceof DatabaseStoreMessage) {
        DatabaseStoreMessage dsm = (DatabaseStoreMessage) message;
        // is it worth making sure the reply came in on the right tunnel?
        if (_search.getKey().equals(dsm.getKey())) {
            _search.decrementRemaining();
            _matchFound = true;
            return true;
        }
    } else if (message instanceof DatabaseSearchReplyMessage) {
        DatabaseSearchReplyMessage dsrm = (DatabaseSearchReplyMessage) message;
        if (_search.getKey().equals(dsrm.getSearchKey())) {
            // TODO - dsrm.getFromHash() can't be trusted - check against the list of
            // those we sent the search to in _search ?
            // assume 0 new, all old, 0 invalid, 0 dup
            _context.profileManager().dbLookupReply(dsrm.getFromHash(), 0, dsrm.getNumReplies(), 0, 0, System.currentTimeMillis() - _search.getCreated());
            // Only process if we don't know enough floodfills or are starting up
            if (_search.shouldProcessDSRM()) {
                if (_log.shouldLog(Log.INFO))
                    _log.info(_search.getJobId() + ": Processing DSRM via SingleLookupJob, apparently from " + dsrm.getFromHash());
                // Chase the hashes from the reply
                _context.jobQueue().addJob(new SingleLookupJob(_context, dsrm));
            } else if (_log.shouldLog(Log.INFO)) {
                int remaining = _search.getLookupsRemaining();
                _log.info(_search.getJobId() + ": got a DSRM apparently from " + dsrm.getFromHash() + " when we were looking for " + _search.getKey() + ", with " + remaining + " outstanding searches");
            }
            // if no more left, time to fail
            int remaining = _search.decrementRemaining(dsrm.getFromHash());
            return remaining <= 0;
        }
    }
    return false;
}
Also used : DatabaseStoreMessage(net.i2p.data.i2np.DatabaseStoreMessage) DatabaseSearchReplyMessage(net.i2p.data.i2np.DatabaseSearchReplyMessage)

Aggregations

DatabaseStoreMessage (net.i2p.data.i2np.DatabaseStoreMessage)21 Hash (net.i2p.data.Hash)9 RouterInfo (net.i2p.data.router.RouterInfo)8 OutNetMessage (net.i2p.router.OutNetMessage)5 DatabaseSearchReplyMessage (net.i2p.data.i2np.DatabaseSearchReplyMessage)4 TunnelInfo (net.i2p.router.TunnelInfo)4 TunnelId (net.i2p.data.TunnelId)3 I2NPMessage (net.i2p.data.i2np.I2NPMessage)3 ArrayList (java.util.ArrayList)2 DatabaseEntry (net.i2p.data.DatabaseEntry)2 DeliveryStatusMessage (net.i2p.data.i2np.DeliveryStatusMessage)2 RouterIdentity (net.i2p.data.router.RouterIdentity)2 Job (net.i2p.router.Job)2 IOException (java.io.IOException)1 ServerSocketChannel (java.nio.channels.ServerSocketChannel)1 SocketChannel (java.nio.channels.SocketChannel)1 LeaseSet (net.i2p.data.LeaseSet)1 Payload (net.i2p.data.Payload)1 DataMessage (net.i2p.data.i2np.DataMessage)1 TunnelGatewayMessage (net.i2p.data.i2np.TunnelGatewayMessage)1