Search in sources :

Example 21 with RouterInfo

use of net.i2p.data.router.RouterInfo in project i2p.i2p by i2p.

the class IterativeSearchJob method newPeerToTry.

/**
 *  A new (floodfill) peer was discovered that may have the answer.
 *  @param peer may not actually be new
 */
void newPeerToTry(Hash peer) {
    // don't ask ourselves or the target
    if (peer.equals(getContext().routerHash()) || peer.equals(_key))
        return;
    if (getContext().banlist().isBanlistedForever(peer)) {
        if (_log.shouldLog(Log.INFO))
            _log.info(getJobId() + ": banlisted peer from DSRM " + peer);
        return;
    }
    RouterInfo ri = getContext().netDb().lookupRouterInfoLocally(peer);
    if (ri != null && !FloodfillNetworkDatabaseFacade.isFloodfill(ri)) {
        if (_log.shouldLog(Log.INFO))
            _log.info(getJobId() + ": non-ff peer from DSRM " + peer);
        return;
    }
    synchronized (this) {
        if (_failedPeers.contains(peer) || _unheardFrom.contains(peer) || _skippedPeers.contains(peer))
            // already tried or skipped
            return;
        if (!_toTry.add(peer))
            // already in the list
            return;
    }
    if (_log.shouldLog(Log.INFO))
        _log.info(getJobId() + ": new peer from DSRM: known? " + (ri != null) + ' ' + peer);
    retry();
}
Also used : RouterInfo(net.i2p.data.router.RouterInfo)

Example 22 with RouterInfo

use of net.i2p.data.router.RouterInfo 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 23 with RouterInfo

use of net.i2p.data.router.RouterInfo in project i2p.i2p by i2p.

the class FloodfillNetworkDatabaseFacade method flood.

/**
 *  Send to a subset of all floodfill peers.
 *  We do this to implement Kademlia within the floodfills, i.e.
 *  we flood to those closest to the key.
 */
public void flood(DatabaseEntry ds) {
    Hash key = ds.getHash();
    RouterKeyGenerator gen = _context.routerKeyGenerator();
    Hash rkey = gen.getRoutingKey(key);
    FloodfillPeerSelector sel = (FloodfillPeerSelector) getPeerSelector();
    List<Hash> peers = sel.selectFloodfillParticipants(rkey, MAX_TO_FLOOD, getKBuckets());
    // todo key cert skip?
    long until = gen.getTimeTillMidnight();
    if (until < NEXT_RKEY_LS_ADVANCE_TIME || (ds.getType() == DatabaseEntry.KEY_TYPE_ROUTERINFO && until < NEXT_RKEY_RI_ADVANCE_TIME)) {
        // to avoid lookup faulures after midnight, also flood to some closest to the
        // next routing key for a period of time before midnight.
        Hash nkey = gen.getNextRoutingKey(key);
        List<Hash> nextPeers = sel.selectFloodfillParticipants(nkey, NEXT_FLOOD_QTY, getKBuckets());
        int i = 0;
        for (Hash h : nextPeers) {
            // But other implementations may not...
            if (h.equals(key))
                continue;
            // todo key cert skip?
            if (!peers.contains(h)) {
                peers.add(h);
                i++;
            }
        }
        if (i > 0 && _log.shouldLog(Log.INFO))
            _log.info("Flooding the entry for " + key + " to " + i + " more, just before midnight");
    }
    int flooded = 0;
    for (int i = 0; i < peers.size(); i++) {
        Hash peer = peers.get(i);
        RouterInfo target = lookupRouterInfoLocally(peer);
        if ((target == null) || (_context.banlist().isBanlisted(peer)))
            continue;
        // But other implementations may not...
        if (ds.getType() == DatabaseEntry.KEY_TYPE_ROUTERINFO && peer.equals(key))
            continue;
        if (peer.equals(_context.routerHash()))
            continue;
        DatabaseStoreMessage msg = new DatabaseStoreMessage(_context);
        msg.setEntry(ds);
        OutNetMessage m = new OutNetMessage(_context, msg, _context.clock().now() + FLOOD_TIMEOUT, FLOOD_PRIORITY, target);
        Job floodFail = new FloodFailedJob(_context, peer);
        m.setOnFailedSendJob(floodFail);
        // we want to give credit on success, even if we aren't sure,
        // because otherwise no use noting failure
        Job floodGood = new FloodSuccessJob(_context, peer);
        m.setOnSendJob(floodGood);
        _context.commSystem().processMessage(m);
        flooded++;
        if (_log.shouldLog(Log.INFO))
            _log.info("Flooding the entry for " + key.toBase64() + " to " + peer.toBase64());
    }
    if (_log.shouldLog(Log.INFO))
        _log.info("Flooded the data to " + flooded + " of " + peers.size() + " peers");
}
Also used : OutNetMessage(net.i2p.router.OutNetMessage) RouterInfo(net.i2p.data.router.RouterInfo) RouterKeyGenerator(net.i2p.data.router.RouterKeyGenerator) DatabaseStoreMessage(net.i2p.data.i2np.DatabaseStoreMessage) Hash(net.i2p.data.Hash) Job(net.i2p.router.Job)

Example 24 with RouterInfo

use of net.i2p.data.router.RouterInfo in project i2p.i2p by i2p.

the class TransportImpl method wasUnreachable.

/**
 * Was the peer UNreachable (outbound only) the last time we tried it?
 * This is NOT reset if the peer contacts us.
 */
public boolean wasUnreachable(Hash peer) {
    long now = _context.clock().now();
    synchronized (_wasUnreachableEntries) {
        Long when = _wasUnreachableEntries.get(peer);
        if (when != null) {
            if (when.longValue() + WAS_UNREACHABLE_PERIOD < now) {
                _unreachableEntries.remove(peer);
                return false;
            } else {
                return true;
            }
        }
    }
    RouterInfo ri = _context.netDb().lookupRouterInfoLocally(peer);
    if (ri == null)
        return false;
    return null == ri.getTargetAddress(this.getStyle());
}
Also used : RouterInfo(net.i2p.data.router.RouterInfo)

Example 25 with RouterInfo

use of net.i2p.data.router.RouterInfo in project i2p.i2p by i2p.

the class OutboundMessageFragments method add.

/**
 * Add a new message to the active pool
 */
public void add(OutNetMessage msg) {
    RouterInfo target = msg.getTarget();
    if (target == null)
        return;
    PeerState peer = _transport.getPeerState(target.getIdentity().calculateHash());
    try {
        // will throw IAE if peer == null
        OutboundMessageState state = new OutboundMessageState(_context, msg, peer);
        peer.add(state);
        add(peer);
    } catch (IllegalArgumentException iae) {
        _transport.failed(msg, "Peer disconnected quickly");
        return;
    }
}
Also used : RouterInfo(net.i2p.data.router.RouterInfo)

Aggregations

RouterInfo (net.i2p.data.router.RouterInfo)95 Hash (net.i2p.data.Hash)45 ArrayList (java.util.ArrayList)18 RouterAddress (net.i2p.data.router.RouterAddress)17 DataFormatException (net.i2p.data.DataFormatException)11 IOException (java.io.IOException)10 RouterIdentity (net.i2p.data.router.RouterIdentity)10 DatabaseEntry (net.i2p.data.DatabaseEntry)9 OutNetMessage (net.i2p.router.OutNetMessage)9 File (java.io.File)8 DatabaseStoreMessage (net.i2p.data.i2np.DatabaseStoreMessage)8 Properties (java.util.Properties)7 LeaseSet (net.i2p.data.LeaseSet)6 BigInteger (java.math.BigInteger)5 Date (java.util.Date)5 SigType (net.i2p.crypto.SigType)5 TunnelId (net.i2p.data.TunnelId)5 TunnelInfo (net.i2p.router.TunnelInfo)5 FileOutputStream (java.io.FileOutputStream)4 HashMap (java.util.HashMap)4