Changeset ccab73f


Ignore:
Timestamp:
May 13, 2009 5:42:24 PM (11 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
757855a
Parents:
9df0472
Message:
Location:
router/java/src/net/i2p/router/networkdb/kademlia
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/networkdb/kademlia/FloodfillStoreJob.java

    r9df0472 rccab73f  
    1313import net.i2p.data.DataStructure;
    1414import net.i2p.data.Hash;
     15import net.i2p.data.LeaseSet;
     16import net.i2p.data.RouterInfo;
    1517import net.i2p.router.Job;
    1618import net.i2p.router.RouterContext;
     
    4648    protected void succeed() {
    4749        super.succeed();
    48         if (_state != null)
    49             getContext().jobQueue().addJob(new FloodfillVerifyStoreJob(getContext(), _state.getTarget(), _facade));
     50        if (_state != null) {
     51            // Get the time stamp from the data we sent, so the Verify job can meke sure that
     52            // it finds something stamped with that time or newer.
     53            long published = 0;
     54            boolean isRouterInfo = false;
     55            DataStructure data = _state.getData();
     56            if (data instanceof RouterInfo) {
     57                published = ((RouterInfo) data).getPublished();
     58                isRouterInfo = true;
     59            } else if (data instanceof LeaseSet) {
     60                published = ((LeaseSet) data).getEarliestLeaseDate();
     61            }
     62            getContext().jobQueue().addJob(new FloodfillVerifyStoreJob(getContext(), _state.getTarget(),
     63                                                                       published, isRouterInfo, _facade));
     64        }
    5065    }
    5166   
  • router/java/src/net/i2p/router/networkdb/kademlia/FloodfillVerifyStoreJob.java

    r9df0472 rccab73f  
    66import net.i2p.data.DataStructure;
    77import net.i2p.data.Hash;
     8import net.i2p.data.LeaseSet;
     9import net.i2p.data.RouterInfo;
    810import net.i2p.data.i2np.DatabaseLookupMessage;
    911import net.i2p.data.i2np.DatabaseSearchReplyMessage;
     
    3032    private long _expiration;
    3133    private long _sendTime;
     34    private long _published;
     35    private boolean _isRouterInfo;
    3236   
    3337    private static final int VERIFY_TIMEOUT = 10*1000;
    3438   
    35     public FloodfillVerifyStoreJob(RouterContext ctx, Hash key, FloodfillNetworkDatabaseFacade facade) {
     39    public FloodfillVerifyStoreJob(RouterContext ctx, Hash key, long published, boolean isRouterInfo, FloodfillNetworkDatabaseFacade facade) {
    3640        super(ctx);
    3741        _key = key;
     42        _published = published;
     43        _isRouterInfo = isRouterInfo;
    3844        _log = ctx.logManager().getLog(getClass());
    3945        _facade = facade;
    4046        // wait 10 seconds before trying to verify the store
    4147        getTiming().setStartAfter(ctx.clock().now() + VERIFY_TIMEOUT);
    42         getContext().statManager().createRateStat("netDb.floodfillVerifyOK", "How long a floodfill verify takes when it succeeds", "NetworkDatabase", new long[] { 60*1000, 10*60*1000, 60*60*1000 });
    43         getContext().statManager().createRateStat("netDb.floodfillVerifyFail", "How long a floodfill verify takes when it fails", "NetworkDatabase", new long[] { 60*1000, 10*60*1000, 60*60*1000 });
    44         getContext().statManager().createRateStat("netDb.floodfillVerifyTimeout", "How long a floodfill verify takes when it times out", "NetworkDatabase", new long[] { 60*1000, 10*60*1000, 60*60*1000 });
     48        getContext().statManager().createRateStat("netDb.floodfillVerifyOK", "How long a floodfill verify takes when it succeeds", "NetworkDatabase", new long[] { 60*60*1000 });
     49        getContext().statManager().createRateStat("netDb.floodfillVerifyFail", "How long a floodfill verify takes when it fails", "NetworkDatabase", new long[] { 60*60*1000 });
     50        getContext().statManager().createRateStat("netDb.floodfillVerifyTimeout", "How long a floodfill verify takes when it times out", "NetworkDatabase", new long[] { 60*60*1000 });
    4551    }
    4652    public String getName() { return "Verify netdb store"; }
     53
     54    /**
     55     *  Wait 10 seconds, then query a random floodfill for the leaseset or routerinfo
     56     *  that we just stored to a (hopefully different) floodfill peer.
     57     *
     58     *  If it fails (after waiting up to another 10 seconds), resend the data.
     59     *  If the queried data is older than what we stored, that counts as a fail.
     60     **/
    4761    public void runJob() {
    4862        _target = pickTarget();
     
    119133            long delay = getContext().clock().now() - _sendTime;
    120134            if (_message instanceof DatabaseStoreMessage) {
    121                 // store ok, w00t!
    122                 // Hmm should we verify it's as recent as the one we sent???
    123                 getContext().profileManager().dbLookupSuccessful(_target, delay);
    124                 getContext().statManager().addRateData("netDb.floodfillVerifyOK", delay, 0);
    125             } else {
    126                 // store failed, boo, hiss!
    127                 if (_message instanceof DatabaseSearchReplyMessage) {
    128                     // assume 0 old, all new, 0 invalid, 0 dup
    129                     getContext().profileManager().dbLookupReply(_target,  0,
     135                // Verify it's as recent as the one we sent
     136                boolean success = false;
     137                DatabaseStoreMessage dsm = (DatabaseStoreMessage)_message;
     138                if (_isRouterInfo && dsm.getValueType() == DatabaseStoreMessage.KEY_TYPE_ROUTERINFO)
     139                    success = dsm.getRouterInfo().getPublished() >= _published;
     140                else if ((!_isRouterInfo) && dsm.getValueType() == DatabaseStoreMessage.KEY_TYPE_LEASESET)
     141                    success = dsm.getLeaseSet().getEarliestLeaseDate() >= _published;
     142                if (success) {
     143                    // store ok, w00t!
     144                    getContext().profileManager().dbLookupSuccessful(_target, delay);
     145                    getContext().statManager().addRateData("netDb.floodfillVerifyOK", delay, 0);
     146                    return;
     147                }
     148                if (_log.shouldLog(Log.WARN))
     149                    _log.warn("Verify failed - older");
     150            } else if (_message instanceof DatabaseSearchReplyMessage) {
     151                // assume 0 old, all new, 0 invalid, 0 dup
     152                getContext().profileManager().dbLookupReply(_target,  0,
    130153                                ((DatabaseSearchReplyMessage)_message).getNumReplies(), 0, 0, delay);
    131                 }
    132                 getContext().statManager().addRateData("netDb.floodfillVerifyFail", delay, 0);
    133                 resend();
    134154            }
     155            // store failed, boo, hiss!
     156            getContext().statManager().addRateData("netDb.floodfillVerifyFail", delay, 0);
     157            resend();
    135158        }       
    136159        public void setMessage(I2NPMessage message) { _message = message; }
Note: See TracChangeset for help on using the changeset viewer.