Search in sources :

Example 1 with DatabaseEntry

use of net.i2p.data.DatabaseEntry in project i2p.i2p by i2p.

the class FloodfillStoreJob method succeed.

/**
 * Send was totally successful
 */
@Override
protected void succeed() {
    super.succeed();
    if (_facade.isVerifyInProgress(_state.getTarget())) {
        if (_log.shouldLog(Log.INFO))
            _log.info("Skipping verify, one already in progress for: " + _state.getTarget());
        return;
    }
    if (getContext().router().gracefulShutdownInProgress()) {
        if (_log.shouldLog(Log.INFO))
            _log.info("Skipping verify, shutdown in progress for: " + _state.getTarget());
        return;
    }
    // Get the time stamp from the data we sent, so the Verify job can meke sure that
    // it finds something stamped with that time or newer.
    DatabaseEntry data = _state.getData();
    boolean isRouterInfo = data.getType() == DatabaseEntry.KEY_TYPE_ROUTERINFO;
    // default false since 0.9.7.1
    if (isRouterInfo && !getContext().getBooleanProperty(PROP_RI_VERIFY)) {
        _facade.routerInfoPublishSuccessful();
        return;
    }
    long published = data.getDate();
    // we should always have exactly one successful entry
    Hash sentTo = null;
    try {
        sentTo = _state.getSuccessful().iterator().next();
    } catch (NoSuchElementException nsee) {
    }
    getContext().jobQueue().addJob(new FloodfillVerifyStoreJob(getContext(), _state.getTarget(), published, isRouterInfo, sentTo, _facade));
}
Also used : DatabaseEntry(net.i2p.data.DatabaseEntry) Hash(net.i2p.data.Hash) NoSuchElementException(java.util.NoSuchElementException)

Example 2 with DatabaseEntry

use of net.i2p.data.DatabaseEntry in project i2p.i2p by i2p.

the class FloodfillVerifyStoreJob method resend.

/**
 *  the netDb store failed to verify, so resend it to a random floodfill peer
 *  Fixme - since we now store closest-to-the-key, this is likely to store to the
 *  very same ff as last time, until the stats get bad enough to switch.
 *  Therefore, pass the failed ff through as a don't-store-to.
 *  Let's also add the one we just tried to verify with, as they could be a pair of no-flooders.
 *  So at least we'll try THREE ffs round-robin if things continue to fail...
 */
private void resend() {
    DatabaseEntry ds = _facade.lookupLocally(_key);
    if (ds != null) {
        Set<Hash> toSkip = new HashSet<Hash>(2);
        if (_sentTo != null)
            toSkip.add(_sentTo);
        if (_target != null)
            toSkip.add(_target);
        _facade.sendStore(_key, ds, null, null, FloodfillNetworkDatabaseFacade.PUBLISH_TIMEOUT, toSkip);
    }
}
Also used : DatabaseEntry(net.i2p.data.DatabaseEntry) Hash(net.i2p.data.Hash) HashSet(java.util.HashSet)

Example 3 with DatabaseEntry

use of net.i2p.data.DatabaseEntry in project i2p.i2p by i2p.

the class FloodfillNetworkDatabaseFacade method getKnownRouterData.

public List<RouterInfo> getKnownRouterData() {
    List<RouterInfo> rv = new ArrayList<RouterInfo>();
    DataStore ds = getDataStore();
    if (ds != null) {
        for (DatabaseEntry o : ds.getEntries()) {
            if (o.getType() == DatabaseEntry.KEY_TYPE_ROUTERINFO)
                rv.add((RouterInfo) o);
        }
    }
    return rv;
}
Also used : RouterInfo(net.i2p.data.router.RouterInfo) ArrayList(java.util.ArrayList) DatabaseEntry(net.i2p.data.DatabaseEntry)

Example 4 with DatabaseEntry

use of net.i2p.data.DatabaseEntry in project i2p.i2p by i2p.

the class UDPTransport method messageReceived.

/**
 * infinite loop
 *    public RouterAddress getCurrentAddress() {
 *        if (needsRebuild())
 *            rebuildExternalAddress(false);
 *        return super.getCurrentAddress();
 *    }
 **
 */
@Override
public void messageReceived(I2NPMessage inMsg, RouterIdentity remoteIdent, Hash remoteIdentHash, long msToReceive, int bytesReceived) {
    if (inMsg.getType() == DatabaseStoreMessage.MESSAGE_TYPE) {
        DatabaseStoreMessage dsm = (DatabaseStoreMessage) inMsg;
        DatabaseEntry entry = dsm.getEntry();
        if (entry == null)
            return;
        if (entry.getType() == DatabaseEntry.KEY_TYPE_ROUTERINFO && ((RouterInfo) entry).getNetworkId() != _networkID) {
            // this is pre-0.6.1.10, so it isn't going to happen any more
            /*
                if (remoteIdentHash != null) {
                    _context.banlist().banlistRouter(remoteIdentHash, "Sent us a peer from the wrong network");
                    dropPeer(remoteIdentHash);
                    if (_log.shouldLog(Log.ERROR))
                        _log.error("Dropping the peer " + remoteIdentHash
                                   + " because they are in the wrong net");
                } else if (remoteIdent != null) {
                    _context.banlist().banlistRouter(remoteIdent.calculateHash(), "Sent us a peer from the wrong network");
                    dropPeer(remoteIdent.calculateHash());
                    if (_log.shouldLog(Log.ERROR))
                        _log.error("Dropping the peer " + remoteIdent.calculateHash()
                                   + " because they are in the wrong net");
                }
                 */
            Hash peerHash = entry.getHash();
            PeerState peer = getPeerState(peerHash);
            if (peer != null) {
                RemoteHostId remote = peer.getRemoteHostId();
                _dropList.add(remote);
                _context.statManager().addRateData("udp.dropPeerDroplist", 1);
                _context.simpleTimer2().addEvent(new RemoveDropList(remote), DROPLIST_PERIOD);
            }
            markUnreachable(peerHash);
            _context.banlist().banlistRouter(peerHash, "Part of the wrong network, version = " + ((RouterInfo) entry).getVersion());
            // _context.banlist().banlistRouter(peerHash, "Part of the wrong network", STYLE);
            if (peer != null)
                sendDestroy(peer);
            dropPeer(peerHash, false, "wrong network");
            if (_log.shouldLog(Log.WARN))
                _log.warn("Dropping the peer " + peerHash + " because they are in the wrong net: " + entry);
            return;
        } else {
            if (entry.getType() == DatabaseEntry.KEY_TYPE_ROUTERINFO) {
                if (_log.shouldLog(Log.DEBUG))
                    _log.debug("Received an RI from the same net");
            } else {
                if (_log.shouldLog(Log.DEBUG))
                    _log.debug("Received a leaseSet: " + dsm);
            }
        }
    } else {
        if (_log.shouldLog(Log.DEBUG))
            _log.debug("Received another message: " + inMsg.getClass().getName());
    }
    PeerState peer = getPeerState(remoteIdentHash);
    super.messageReceived(inMsg, remoteIdent, remoteIdentHash, msToReceive, bytesReceived);
    if (peer != null)
        peer.expireInboundMessages();
}
Also used : RouterInfo(net.i2p.data.router.RouterInfo) DatabaseStoreMessage(net.i2p.data.i2np.DatabaseStoreMessage) DatabaseEntry(net.i2p.data.DatabaseEntry) Hash(net.i2p.data.Hash)

Example 5 with DatabaseEntry

use of net.i2p.data.DatabaseEntry in project i2p.i2p by i2p.

the class HandleDatabaseLookupMessageJob method runJob.

public void runJob() {
    if (_log.shouldLog(Log.DEBUG))
        _log.debug("Handling database lookup message for " + _message.getSearchKey());
    Hash fromKey = _message.getFrom();
    if (_log.shouldLog(Log.DEBUG)) {
        if (_message.getReplyTunnel() != null)
            _log.debug("dbLookup received with replies going to " + fromKey + " (tunnel " + _message.getReplyTunnel() + ")");
    }
    // If we are hidden we should not get queries, log and return
    if (getContext().router().isHidden()) {
        if (_log.shouldLog(Log.WARN)) {
            _log.warn("Uninvited dbLookup received with replies going to " + fromKey + " (tunnel " + _message.getReplyTunnel() + ")");
        }
        return;
    }
    // i2pd bug?
    if (_message.getSearchKey().equals(Hash.FAKE_HASH)) {
        if (_log.shouldWarn())
            _log.warn("Zero lookup", new Exception());
        getContext().statManager().addRateData("netDb.DLMAllZeros", 1);
        return;
    }
    DatabaseLookupMessage.Type lookupType = _message.getSearchType();
    // only lookup once, then cast to correct type
    DatabaseEntry dbe = getContext().netDb().lookupLocally(_message.getSearchKey());
    if (dbe != null && dbe.getType() == DatabaseEntry.KEY_TYPE_LEASESET && (lookupType == DatabaseLookupMessage.Type.ANY || lookupType == DatabaseLookupMessage.Type.LS)) {
        LeaseSet ls = (LeaseSet) dbe;
        // We have to be very careful here to decide whether or not to send out the leaseSet,
        // to avoid anonymity vulnerabilities.
        // As this is complex, lots of comments follow...
        boolean isLocal = getContext().clientManager().isLocal(ls.getDestination());
        boolean shouldPublishLocal = isLocal && getContext().clientManager().shouldPublishLeaseSet(_message.getSearchKey());
        // true for received in a DatabaseStoreMessage unsolicited
        if (ls.getReceivedAsPublished()) {
            // Local leasesets are not handled here
            if (_log.shouldLog(Log.INFO))
                _log.info("We have the published LS " + _message.getSearchKey() + ", answering query");
            getContext().statManager().addRateData("netDb.lookupsMatchedReceivedPublished", 1);
            sendData(_message.getSearchKey(), ls, fromKey, _message.getReplyTunnel());
        } else if (shouldPublishLocal && answerAllQueries()) {
            // We are floodfill, and this is our local leaseset, and we publish it.
            // Only send it out if it is in our estimated keyspace.
            // For this, we do NOT use their dontInclude list as it can't be trusted
            // (i.e. it could mess up the closeness calculation)
            Set<Hash> closestHashes = getContext().netDb().findNearestRouters(_message.getSearchKey(), CLOSENESS_THRESHOLD, null);
            if (weAreClosest(closestHashes)) {
                // It's in our keyspace, so give it to them
                if (_log.shouldLog(Log.INFO))
                    _log.info("We have local LS " + _message.getSearchKey() + ", answering query, in our keyspace");
                getContext().statManager().addRateData("netDb.lookupsMatchedLocalClosest", 1);
                sendData(_message.getSearchKey(), ls, fromKey, _message.getReplyTunnel());
            } else {
                // Lie, pretend we don't have it
                if (_log.shouldLog(Log.INFO))
                    _log.info("We have local LS " + _message.getSearchKey() + ", NOT answering query, out of our keyspace");
                getContext().statManager().addRateData("netDb.lookupsMatchedLocalNotClosest", 1);
                Set<Hash> routerHashSet = getNearestRouters(lookupType);
                sendClosest(_message.getSearchKey(), routerHashSet, fromKey, _message.getReplyTunnel());
            }
        } else {
            // Lie, pretend we don't have it
            if (_log.shouldLog(Log.INFO))
                _log.info("We have LS " + _message.getSearchKey() + ", NOT answering query - local? " + isLocal + " shouldPublish? " + shouldPublishLocal + " RAP? " + ls.getReceivedAsPublished() + " RAR? " + ls.getReceivedAsReply());
            getContext().statManager().addRateData("netDb.lookupsMatchedRemoteNotClosest", 1);
            Set<Hash> routerHashSet = getNearestRouters(lookupType);
            sendClosest(_message.getSearchKey(), routerHashSet, fromKey, _message.getReplyTunnel());
        }
    } else if (dbe != null && dbe.getType() == DatabaseEntry.KEY_TYPE_ROUTERINFO && lookupType != DatabaseLookupMessage.Type.LS) {
        RouterInfo info = (RouterInfo) dbe;
        if (info.isCurrent(EXPIRE_DELAY)) {
            if ((info.isHidden()) || (isUnreachable(info) && !publishUnreachable())) {
                if (_log.shouldLog(Log.DEBUG))
                    _log.debug("Not answering a query for a netDb peer who isn't reachable");
                Set<Hash> us = Collections.singleton(getContext().routerHash());
                sendClosest(_message.getSearchKey(), us, fromKey, _message.getReplyTunnel());
            } else {
                // send that routerInfo to the _message.getFromHash peer
                if (_log.shouldLog(Log.DEBUG))
                    _log.debug("We do have key " + _message.getSearchKey() + " locally as a router info.  sending to " + fromKey);
                sendData(_message.getSearchKey(), info, fromKey, _message.getReplyTunnel());
            }
        } else {
            // expired locally - return closest peer hashes
            Set<Hash> routerHashSet = getNearestRouters(lookupType);
            if (_log.shouldLog(Log.DEBUG))
                _log.debug("Expired " + _message.getSearchKey() + " locally.  sending back " + routerHashSet.size() + " peers to " + fromKey);
            sendClosest(_message.getSearchKey(), routerHashSet, fromKey, _message.getReplyTunnel());
        }
    } else {
        // not found locally - return closest peer hashes
        Set<Hash> routerHashSet = getNearestRouters(lookupType);
        if (_log.shouldLog(Log.DEBUG))
            _log.debug("We do not have key " + _message.getSearchKey() + " locally.  sending back " + routerHashSet.size() + " peers to " + fromKey);
        sendClosest(_message.getSearchKey(), routerHashSet, fromKey, _message.getReplyTunnel());
    }
}
Also used : DatabaseLookupMessage(net.i2p.data.i2np.DatabaseLookupMessage) LeaseSet(net.i2p.data.LeaseSet) LeaseSet(net.i2p.data.LeaseSet) Set(java.util.Set) HashSet(java.util.HashSet) RouterInfo(net.i2p.data.router.RouterInfo) DatabaseEntry(net.i2p.data.DatabaseEntry) Hash(net.i2p.data.Hash)

Aggregations

DatabaseEntry (net.i2p.data.DatabaseEntry)16 Hash (net.i2p.data.Hash)11 RouterInfo (net.i2p.data.router.RouterInfo)9 LeaseSet (net.i2p.data.LeaseSet)4 Date (java.util.Date)2 HashSet (java.util.HashSet)2 DatabaseStoreMessage (net.i2p.data.i2np.DatabaseStoreMessage)2 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 Map (java.util.Map)1 NoSuchElementException (java.util.NoSuchElementException)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 DatabaseLookupMessage (net.i2p.data.i2np.DatabaseLookupMessage)1 DatabaseSearchReplyMessage (net.i2p.data.i2np.DatabaseSearchReplyMessage)1 I2NPMessage (net.i2p.data.i2np.I2NPMessage)1