Search in sources :

Example 46 with RouterInfo

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

the class ProfileOrganizer method isSelectable.

public boolean isSelectable(Hash peer) {
    NetworkDatabaseFacade netDb = _context.netDb();
    // the CLI shouldn't depend upon the netDb
    if (netDb == null)
        return true;
    if (_context.router() == null)
        return true;
    if ((_context.banlist() != null) && (_context.banlist().isBanlisted(peer))) {
        // never select a banlisted peer
        return false;
    }
    RouterInfo info = _context.netDb().lookupRouterInfoLocally(peer);
    if (null != info) {
        if (info.isHidden()) {
            if (_log.shouldLog(Log.WARN))
                _log.warn("Peer " + peer.toBase64() + " is marked as hidden, disallowing its use");
            return false;
        } else {
            boolean exclude = TunnelPeerSelector.shouldExclude(_context, info);
            if (exclude) {
                // _log.warn("Peer " + peer.toBase64() + " has capabilities or other stats suggesting we avoid it");
                return false;
            } else {
                // _log.info("Peer " + peer.toBase64() + " is locally known, allowing its use");
                return true;
            }
        }
    } else {
        // _log.warn("Peer " + peer.toBase64() + " is NOT locally known, disallowing its use");
        return false;
    }
}
Also used : NetworkDatabaseFacade(net.i2p.router.NetworkDatabaseFacade) RouterInfo(net.i2p.data.router.RouterInfo)

Example 47 with RouterInfo

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

the class SingleLookupJob method runJob.

public void runJob() {
    Hash from = _dsrm.getFromHash();
    int limit = Math.min(_dsrm.getNumReplies(), MAX_TO_FOLLOW);
    for (int i = 0; i < limit; i++) {
        Hash peer = _dsrm.getReply(i);
        if (// us
        peer.equals(getContext().routerHash()))
            continue;
        if (// unusual?
        peer.equals(from))
            continue;
        RouterInfo ri = getContext().netDb().lookupRouterInfoLocally(peer);
        if (ri == null)
            getContext().jobQueue().addJob(new SingleSearchJob(getContext(), peer, from));
        else if (ri.getPublished() < getContext().clock().now() - 60 * 60 * 1000 || !FloodfillNetworkDatabaseFacade.isFloodfill(ri))
            getContext().jobQueue().addJob(new SingleSearchJob(getContext(), peer, peer));
    }
}
Also used : RouterInfo(net.i2p.data.router.RouterInfo) Hash(net.i2p.data.Hash)

Example 48 with RouterInfo

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

the class CommSystemFacadeImpl method getCountry.

/**
 *  Uses the transport IP first because that lookup is fast,
 *  then the IP from the netDb.
 *
 *  As of 0.9.32, works only for literal IPs, returns null for host names.
 *
 *  @param peer not ourselves - use getOurCountry() for that
 *  @return two-letter lower-case country code or null
 */
@Override
public String getCountry(Hash peer) {
    byte[] ip = TransportImpl.getIP(peer);
    // if (ip != null && ip.length == 4)
    if (ip != null)
        return _geoIP.get(ip);
    RouterInfo ri = _context.netDb().lookupRouterInfoLocally(peer);
    if (ri == null)
        return null;
    ip = getValidIP(ri);
    if (ip != null)
        return _geoIP.get(ip);
    return null;
}
Also used : RouterInfo(net.i2p.data.router.RouterInfo)

Example 49 with RouterInfo

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

the class CapacityCalculator method calc.

public static double calc(PeerProfile profile) {
    double capacity;
    if (tooOld(profile)) {
        capacity = 1;
    } else {
        RateStat acceptStat = profile.getTunnelCreateResponseTime();
        RateStat rejectStat = profile.getTunnelHistory().getRejectionRate();
        RateStat failedStat = profile.getTunnelHistory().getFailedRate();
        double capacity10m = estimateCapacity(acceptStat, rejectStat, failedStat, 10 * 60 * 1000);
        // if we actively know they're bad, who cares if they used to be good?
        if (capacity10m <= 0) {
            capacity = 0;
        } else {
            double capacity30m = estimateCapacity(acceptStat, rejectStat, failedStat, 30 * 60 * 1000);
            double capacity60m = estimateCapacity(acceptStat, rejectStat, failedStat, 60 * 60 * 1000);
            double capacity1d = estimateCapacity(acceptStat, rejectStat, failedStat, 24 * 60 * 60 * 1000);
            capacity = capacity10m * periodWeight(10 * 60 * 1000) + capacity30m * periodWeight(30 * 60 * 1000) + capacity60m * periodWeight(60 * 60 * 1000) + capacity1d * periodWeight(24 * 60 * 60 * 1000);
        }
    }
    // now take into account non-rejection tunnel rejections (which haven't
    // incremented the rejection counter, since they were only temporary)
    RouterContext context = profile.getContext();
    long now = context.clock().now();
    if (profile.getTunnelHistory().getLastRejectedTransient() > now - 5 * 60 * 1000)
        capacity = 1;
    else if (profile.getTunnelHistory().getLastRejectedProbabalistic() > now - 5 * 60 * 1000)
        capacity -= context.random().nextInt(5);
    // boost new profiles
    if (now - profile.getFirstHeardAbout() < 45 * 60 * 1000)
        capacity += BONUS_NEW;
    // boost connected peers
    if (profile.isEstablished())
        capacity += BONUS_ESTABLISHED;
    // boost same country
    if (profile.isSameCountry()) {
        double bonus = BONUS_SAME_COUNTRY;
        String b = context.getProperty(PROP_COUNTRY_BONUS);
        if (b != null) {
            try {
                bonus = Double.parseDouble(b);
            } catch (NumberFormatException nfe) {
            }
        }
        capacity += bonus;
    }
    // penalize unreachable peers
    if (profile.wasUnreachable())
        capacity -= PENALTY_UNREACHABLE;
    // credit non-floodfill to reduce conn limit issues at floodfills
    // TODO only if we aren't floodfill ourselves?
    RouterInfo ri = context.netDb().lookupRouterInfoLocally(profile.getPeer());
    if (!FloodfillNetworkDatabaseFacade.isFloodfill(ri))
        capacity += BONUS_NON_FLOODFILL;
    // a tiny tweak to break ties and encourage closeness, -.25 to +.25
    capacity -= profile.getXORDistance() * (BONUS_XOR / 128);
    capacity += profile.getCapacityBonus();
    if (capacity < 0)
        capacity = 0;
    return capacity;
}
Also used : RateStat(net.i2p.stat.RateStat) RouterInfo(net.i2p.data.router.RouterInfo) RouterContext(net.i2p.router.RouterContext)

Example 50 with RouterInfo

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

the class PersistRouterInfoJob method runJob.

public void runJob() {
    Log _log = getContext().logManager().getLog(PersistRouterInfoJob.class);
    if (_log.shouldLog(Log.DEBUG))
        _log.debug("Persisting updated router info");
    File infoFile = new File(getContext().getRouterDir(), CreateRouterInfoJob.INFO_FILENAME);
    RouterInfo info = getContext().router().getRouterInfo();
    FileOutputStream fos = null;
    synchronized (getContext().router().routerInfoFileLock) {
        try {
            fos = new SecureFileOutputStream(infoFile);
            info.writeBytes(fos);
        } catch (DataFormatException dfe) {
            _log.error("Error rebuilding the router information", dfe);
        } catch (IOException ioe) {
            _log.error("Error writing out the rebuilt router information", ioe);
        } finally {
            if (fos != null)
                try {
                    fos.close();
                } catch (IOException ioe) {
                }
        }
    }
}
Also used : DataFormatException(net.i2p.data.DataFormatException) Log(net.i2p.util.Log) RouterInfo(net.i2p.data.router.RouterInfo) FileOutputStream(java.io.FileOutputStream) SecureFileOutputStream(net.i2p.util.SecureFileOutputStream) SecureFileOutputStream(net.i2p.util.SecureFileOutputStream) IOException(java.io.IOException) File(java.io.File)

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