Changeset 07e79ce


Ignore:
Timestamp:
May 17, 2004 12:59:29 AM (17 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
292363e
Parents:
1cf7dac
git-author:
jrandom <jrandom> (05/17/04 00:59:29)
git-committer:
zzz <zzz@…> (05/17/04 00:59:29)
Message:
  • do a db store after a successful db search (healing the netDb)
  • timeout each peer in a db search after 10 seconds, not 30
  • logging
Location:
router/java/src/net/i2p/router
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/message/OutboundClientMessageJob.java

    r1cf7dac r07e79ce  
    641641            boolean alreadySuccessful = _status.success();
    642642            MessageId msgId = _status.getMessage().getMessageId();
    643             if (_log.shouldLog(Log.DEBUG))
    644                 _log.debug(OutboundClientMessageJob.this.getJobId()
    645                            + ": SUCCESS!  Message delivered completely for message " + msgId
    646                            + " after " + sendTime + "ms [for "
    647                            +  _status.getMessage().getMessageId() + "]");
     643            if (_log.shouldLog(Log.INFO))
     644                _log.info(OutboundClientMessageJob.this.getJobId()
     645                           + ": SUCCESS!  msg " + msgId
     646                           + " sent after " + sendTime + "ms after "
     647                           + _status.getNumLookups() + " lookups and "
     648                           + _status.getNumSent() + " sends");
    648649           
    649650            if ( (_key != null) && (_tags != null) && (_tags.size() > 0) ) {
  • router/java/src/net/i2p/router/networkdb/kademlia/SearchJob.java

    r1cf7dac r07e79ce  
    5858    private static final int SEARCH_PRIORITY = 400; // large because the search is probably for a real search
    5959   
    60     private static final long PER_PEER_TIMEOUT = 30*1000;
     60    /**
     61     * How long will we give each peer to reply to our search?
     62     *
     63     */
     64    private static final long PER_PEER_TIMEOUT = 10*1000;
     65   
     66    /**
     67     * give ourselves 30 seconds to send out the value found to the closest
     68     * peers /after/ we get a successful match.  If this fails, no biggie, but
     69     * this'll help heal the network so subsequent searches will find the data.
     70     *
     71     */
     72    private static final long RESEND_TIMEOUT = 30*1000;
    6173   
    6274    /**
     
    104116    protected void searchNext() {
    105117        if (_state.completed()) {
    106             if (_log.shouldLog(Log.INFO))
    107                 _log.info(getJobId() + ": Already completed");
     118            if (_log.shouldLog(Log.DEBUG))
     119                _log.debug(getJobId() + ": Already completed");
    108120            return;
    109121        }
     
    156168            if (_log.shouldLog(Log.INFO))
    157169                _log.info(getJobId() + ": Too many searches already pending (pending: "
    158                           + _state.getPending().size() + " max: " + getBredth() + ")",
    159                           new Exception("too many pending"));
     170                          + _state.getPending().size() + " max: " + getBredth() + ")");
    160171            requeuePending();
    161172            return;
     
    167178                if (_log.shouldLog(Log.INFO))
    168179                    _log.info(getJobId() + ": No peers left, and none pending!  Already searched: "
    169                               + _state.getAttempted().size() + " failed: " + _state.getFailed().size(),
    170                               new Exception("none left"));
     180                              + _state.getAttempted().size() + " failed: " + _state.getFailed().size());
    171181                fail();
    172182            } else {
     
    175185                    _log.info(getJobId() + ": No peers left, but some are pending!  Pending: "
    176186                              + _state.getPending().size() + " attempted: " + _state.getAttempted().size()
    177                               + " failed: " + _state.getFailed().size(),
    178                               new Exception("none left, but pending"));
     187                              + " failed: " + _state.getFailed().size());
    179188                requeuePending();
    180189                return;
     
    188197                    if (_log.shouldLog(Log.WARN))
    189198                        _log.warn(getJobId() + ": Error selecting closest hash that wasnt a router! "
    190                                   + peer + " : " + ds);
     199                                  + peer + " : " + (ds == null ? "null" : ds.getClass().getName()));
    191200                } else {
    192201                    sendSearch((RouterInfo)ds);
     
    238247        } else {
    239248            if (_log.shouldLog(Log.DEBUG))
    240                 _log.debug(getJobId() + ": Send search to " + router);
     249                _log.debug(getJobId() + ": Send search to " + router.getIdentity().getHash().toBase64());
    241250        }
    242251
     
    425434                        _duplicatePeers++;
    426435                    }
    427                     if (_log.shouldLog(Log.INFO))
    428                         _log.info(getJobId() + ": dbSearchReply received on search containing router "
     436                    if (_log.shouldLog(Log.DEBUG))
     437                        _log.debug(getJobId() + ": dbSearchReply received on search containing router "
    429438                                  + ri.getIdentity().getHash() + " with publishDate of "
    430439                                  + new Date(ri.getPublished()));
     
    436445                } else {
    437446                    if (_log.shouldLog(Log.ERROR))
    438                         _log.error(getJobId() + ": Received an invalid peer from " + _peer + ": "
    439                                    + ri, new Exception("Invalid peer"));
     447                        _log.error(getJobId() + ": Received an invalid peer from " + _peer + ": " + ri);
    440448                    _invalidPeers++;
    441449                }
     
    486494     * Search was totally successful
    487495     */
    488     protected void succeed() {
     496    private void succeed() {
    489497        if (_log.shouldLog(Log.INFO))
    490             _log.info(getJobId() + ": Succeeded search for key " + _state.getTarget());
     498            _log.info(getJobId() + ": Succeeded search for key " + _state.getTarget()
     499                      + " after querying " + _state.getAttempted().size());
    491500        if (_log.shouldLog(Log.DEBUG))
    492501            _log.debug(getJobId() + ": State of successful search: " + _state);
     
    499508        if (_onSuccess != null)
    500509            _context.jobQueue().addJob(_onSuccess);
     510       
     511        resend();
     512    }
     513   
     514    /**
     515     * After we get the data we were searching for, rebroadcast it to the peers
     516     * we would query first if we were to search for it again (healing the network).
     517     *
     518     */
     519    private void resend() {
     520        DataStructure ds = _facade.lookupLeaseSetLocally(_state.getTarget());
     521        if (ds == null)
     522            ds = _facade.lookupRouterInfoLocally(_state.getTarget());
     523        if (ds != null)
     524            _context.jobQueue().addJob(new StoreJob(_context, _facade, _state.getTarget(),
     525                                                    ds, null, null, RESEND_TIMEOUT,
     526                                                    _state.getSuccessful()));
    501527    }
    502528
  • router/java/src/net/i2p/router/networkdb/kademlia/SearchMessageSelector.java

    r1cf7dac r07e79ce  
    3737    }
    3838   
    39     public String toString() { return "Search selector [" + _id + "] looking for a reply from " + _peer + " with regards to " + _state.getTarget(); }
     39    public String toString() {
     40        return "Search selector [" + _id + "] looking for a reply from " + _peer
     41               + " with regards to " + _state.getTarget();
     42    }
    4043   
    4144    public boolean continueMatching() {
    4245        if (_found) {
    4346            if (_log.shouldLog(Log.DEBUG))
    44                 _log.debug("[" + _id + "] Dont continue matching! looking for a reply from " + _peer + " with regards to " + _state.getTarget());
     47                _log.debug("[" + _id + "] Dont continue matching! looking for a reply from "
     48                           + _peer + " with regards to " + _state.getTarget());
    4549            return false;
    4650        }
     
    5155    public boolean isMatch(I2NPMessage message) {
    5256        if (_log.shouldLog(Log.DEBUG))
    53             _log.debug("[" + _id + "] isMatch("+message.getClass().getName() + ") [want dbStore or dbSearchReply from " + _peer + " for " + _state.getTarget() + "]");
     57            _log.debug("[" + _id + "] isMatch("+message.getClass().getName()
     58                       + ") [want dbStore or dbSearchReply from " + _peer
     59                       + " for " + _state.getTarget() + "]");
    5460        if (message instanceof DatabaseStoreMessage) {
    5561            DatabaseStoreMessage msg = (DatabaseStoreMessage)message;
    5662            if (msg.getKey().equals(_state.getTarget())) {
    5763                if (_log.shouldLog(Log.DEBUG))
    58                     _log.debug("[" + _id + "] Was a DBStore of the key we're looking for.  May not have been from who we're checking against though, but DBStore doesn't include that info");
     64                    _log.debug("[" + _id + "] Was a DBStore of the key we're looking for.  "
     65                               + "May not have been from who we're checking against though, "
     66                               + "but DBStore doesn't include that info");
    5967                _found = true;
    6068                return true;
     
    6977                if (msg.getSearchKey().equals(_state.getTarget())) {
    7078                    if (_log.shouldLog(Log.DEBUG))
    71                         _log.debug("[" + _id + "] Was a DBSearchReply from who we're checking with for a key we're looking for");
     79                        _log.debug("[" + _id + "] Was a DBSearchReply from who we're "
     80                                   + "checking with for a key we're looking for");
    7281                    _found = true;
    7382                    return true;
    7483                } else {
    7584                    if (_log.shouldLog(Log.DEBUG))
    76                         _log.debug("[" + _id + "] Was a DBSearchReply from who we're checking with but NOT for the key we're looking for");
     85                        _log.debug("[" + _id + "] Was a DBSearchReply from who we're checking "
     86                                   + "with but NOT for the key we're looking for");
    7787                    return false;
    7888                }
    7989            } else {
    8090                if (_log.shouldLog(Log.DEBUG))
    81                     _log.debug("[" + _id + "] DBSearchReply from someone we are not checking with [" + msg.getFromHash() + ", not " + _state.getTarget() + "]");
     91                    _log.debug("[" + _id + "] DBSearchReply from someone we are not checking with ["
     92                               + msg.getFromHash() + ", not " + _state.getTarget() + "]");
    8293                return false;
    8394            }
  • router/java/src/net/i2p/router/networkdb/kademlia/SearchState.java

    r1cf7dac r07e79ce  
    130130        else
    131131            buf.append(" completed on ").append(new Date(_completed));
    132         buf.append(" Attempted: ");
     132        buf.append("\n\tAttempted: ");
    133133        synchronized (_attemptedPeers) {
     134            buf.append(_attemptedPeers.size()).append(' ');
    134135            for (Iterator iter = _attemptedPeers.iterator(); iter.hasNext(); ) {
    135136                Hash peer = (Hash)iter.next();
     
    137138            }
    138139        }
    139         buf.append(" Pending: ");
     140        buf.append("\n\tPending: ");
    140141        synchronized (_pendingPeers) {
     142            buf.append(_pendingPeers.size()).append(' ');
    141143            for (Iterator iter = _pendingPeers.iterator(); iter.hasNext(); ) {
    142144                Hash peer = (Hash)iter.next();
     
    144146            }
    145147        }
    146         buf.append(" Failed: ");
     148        buf.append("\n\tFailed: ");
    147149        synchronized (_failedPeers) {
     150            buf.append(_failedPeers.size()).append(' ');
    148151            for (Iterator iter = _failedPeers.iterator(); iter.hasNext(); ) {
    149152                Hash peer = (Hash)iter.next();
     
    151154            }
    152155        }
    153         buf.append(" Successful: ");
     156        buf.append("\n\tSuccessful: ");
    154157        synchronized (_successfulPeers) {
     158            buf.append(_successfulPeers.size()).append(' ');
    155159            for (Iterator iter = _successfulPeers.iterator(); iter.hasNext(); ) {
    156160                Hash peer = (Hash)iter.next();
  • router/java/src/net/i2p/router/networkdb/kademlia/SearchUpdateReplyFoundJob.java

    r1cf7dac r07e79ce  
    2626    private SearchJob _job;
    2727   
    28     public SearchUpdateReplyFoundJob(RouterContext context, RouterInfo peer, SearchState state, KademliaNetworkDatabaseFacade facade, SearchJob job) {
     28    public SearchUpdateReplyFoundJob(RouterContext context, RouterInfo peer,
     29                                     SearchState state, KademliaNetworkDatabaseFacade facade,
     30                                     SearchJob job) {
    2931        super(context);
    3032        _log = context.logManager().getLog(SearchUpdateReplyFoundJob.class);
     
    3840    public void runJob() {
    3941        if (_log.shouldLog(Log.INFO))
    40             _log.info(getJobId() + ": Reply from " + _peer + " with message " + _message.getClass().getName());
     42            _log.info(getJobId() + ": Reply from " + _peer.toBase64()
     43                      + " with message " + _message.getClass().getName());
    4144       
    4245        if (_message instanceof DatabaseStoreMessage) {
     
    4851            } else if (msg.getValueType() == DatabaseStoreMessage.KEY_TYPE_ROUTERINFO) {
    4952                if (_log.shouldLog(Log.INFO))
    50                     _log.info(getJobId() + ": dbStore received on search containing router " + msg.getKey() + " with publishDate of " + new Date(msg.getRouterInfo().getPublished()));
     53                    _log.info(getJobId() + ": dbStore received on search containing router "
     54                              + msg.getKey() + " with publishDate of "
     55                              + new Date(msg.getRouterInfo().getPublished()));
    5156                _facade.store(msg.getKey(), msg.getRouterInfo());
    5257            } else {
  • router/java/src/net/i2p/router/networkdb/kademlia/StoreJob.java

    r1cf7dac r07e79ce  
    8282    public StoreJob(RouterContext context, KademliaNetworkDatabaseFacade facade, Hash key,
    8383                    DataStructure data, Job onSuccess, Job onFailure, long timeoutMs) {
     84        this(context, facade, key, data, onSuccess, onFailure, timeoutMs, null);
     85    }
     86   
     87    /**
     88     * @param toSkip set of peer hashes of people we dont want to send the data to (e.g. we
     89     *               already know they have it).  This can be null.
     90     */
     91    public StoreJob(RouterContext context, KademliaNetworkDatabaseFacade facade, Hash key,
     92                    DataStructure data, Job onSuccess, Job onFailure, long timeoutMs, Set toSkip) {
    8493        super(context);
    8594        _log = context.logManager().getLog(StoreJob.class);
    8695        _context.statManager().createRateStat("netDb.storeSent", "How many netDb store messages have we sent?", "Network Database", new long[] { 5*60*1000l, 60*60*1000l, 24*60*60*1000l });
    8796        _facade = facade;
    88         _state = new StoreState(key, data);
     97        _state = new StoreState(key, data, toSkip);
    8998        _onSuccess = onSuccess;
    9099        _onFailure = onFailure;
     
    386395
    387396        public StoreState(Hash key, DataStructure data) {
     397            this(key, data, null);
     398        }
     399        public StoreState(Hash key, DataStructure data, Set toSkip) {
    388400            _key = key;
    389401            _data = data;
     
    391403            _pendingPeerTimes = new HashMap(16);
    392404            _attemptedPeers = new HashSet(16);
     405            if (toSkip != null)
     406                _attemptedPeers.addAll(toSkip);
    393407            _failedPeers = new HashSet(16);
    394408            _successfulPeers = new HashSet(16);
Note: See TracChangeset for help on using the changeset viewer.