Search in sources :

Example 76 with RouterInfo

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

the class UDPFlooder method run.

public void run() {
    long nextSend = _context.clock().now();
    while (_alive) {
        try {
            synchronized (_peers) {
                if (_peers.isEmpty())
                    _peers.wait();
            }
        } catch (InterruptedException ie) {
        }
        long now = _context.clock().now();
        if (now >= nextSend) {
            // peers always grows, so this is fairly safe
            for (int i = 0; i < _peers.size(); i++) {
                PeerState peer = _peers.get(i);
                DataMessage m = new DataMessage(_context);
                // new byte[4096];
                byte[] data = _floodData;
                // _context.random().nextBytes(data);
                m.setData(data);
                m.setMessageExpiration(_context.clock().now() + 10 * 1000);
                m.setUniqueId(_context.random().nextLong(I2NPMessage.MAX_ID_VALUE));
                if (true) {
                    RouterInfo to = _context.netDb().lookupRouterInfoLocally(peer.getRemotePeer());
                    if (to == null)
                        continue;
                    OutNetMessage msg = new OutNetMessage(_context, m, m.getMessageExpiration(), 500, to);
                    // warning, getStatLog() can be null
                    // _context.statManager().getStatLog().addData(peer.getRemotePeer().toBase64().substring(0,6), "udp.floodDataSent", 1, 0);
                    _transport.send(msg);
                } else {
                    _transport.send(m, peer);
                }
            }
            nextSend = now + calcFloodDelay();
        }
        long delay = nextSend - now;
        if (delay > 0) {
            if (delay > 10 * 1000) {
                long fd = calcFloodDelay();
                if (delay > fd) {
                    nextSend = now + fd;
                    delay = fd;
                }
            }
            try {
                Thread.sleep(delay);
            } catch (InterruptedException ie) {
            }
        }
    }
}
Also used : OutNetMessage(net.i2p.router.OutNetMessage) DataMessage(net.i2p.data.i2np.DataMessage) RouterInfo(net.i2p.data.router.RouterInfo)

Example 77 with RouterInfo

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

the class RouterITBase method routerClassSetup.

@BeforeClass
public static void routerClassSetup() {
    // order of these matters
    Router r = new Router();
    _context = new RouterContext(r);
    _context.initAll();
    r.runRouter();
    RouterIdentity rIdentity = new TestRouterIdentity();
    RouterInfo rInfo = new RouterInfo();
    rInfo.setIdentity(rIdentity);
    r.setRouterInfo(rInfo);
    _config = prepareConfig(8);
}
Also used : RouterIdentity(net.i2p.data.router.RouterIdentity) RouterInfo(net.i2p.data.router.RouterInfo) RouterContext(net.i2p.router.RouterContext) Router(net.i2p.router.Router) BeforeClass(org.junit.BeforeClass)

Example 78 with RouterInfo

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

the class DatabaseStoreMessageTest method createDataStructure.

public DataStructure createDataStructure() throws DataFormatException {
    DatabaseStoreMessage msg = new DatabaseStoreMessage(I2PAppContext.getGlobalContext());
    RouterInfo info = (RouterInfo) new RouterInfoTest().createDataStructure();
    msg.setMessageExpiration(Clock.getInstance().now());
    msg.setUniqueId(666);
    msg.setEntry(info);
    return msg;
}
Also used : RouterInfo(net.i2p.data.router.RouterInfo) RouterInfoTest(net.i2p.data.router.RouterInfoTest)

Example 79 with RouterInfo

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

the class DummyNetworkDatabaseFacade method startup.

public void startup() {
    RouterInfo info = _context.router().getRouterInfo();
    _routers.put(info.getIdentity().getHash(), info);
}
Also used : RouterInfo(net.i2p.data.router.RouterInfo)

Example 80 with RouterInfo

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

the class OutboundClientMessageOneShotJob method getNextLease.

/**
 *  Choose a lease from his leaseset to send the message to. Sets _lease.
 *  Sets _wantACK if it's new or changed.
 *  @return success
 */
private boolean getNextLease() {
    // set in runJob if found locally
    if (_leaseSet == null) {
        _leaseSet = getContext().netDb().lookupLeaseSetLocally(_to.calculateHash());
        if (_leaseSet == null) {
            // shouldn't happen
            if (_log.shouldLog(Log.WARN))
                _log.warn(getJobId() + ": Lookup locally didn't find the leaseSet for " + _toString);
            return false;
        }
    }
    // Use the same lease if it's still good
    // Even if _leaseSet changed, _leaseSet.getEncryptionKey() didn't...
    _lease = _cache.leaseCache.get(_hashPair);
    if (_lease != null) {
        // if outbound tunnel length == 0 && lease.firsthop.isBacklogged() don't use it ??
        if (!_lease.isExpired(Router.CLOCK_FUDGE_FACTOR / 4)) {
            // it (due to failure for example) we won't continue to use it.
            for (int i = 0; i < _leaseSet.getLeaseCount(); i++) {
                Lease lease = _leaseSet.getLease(i);
                // if (_lease.equals(lease)) {
                if (_lease.getTunnelId().equals(lease.getTunnelId()) && _lease.getGateway().equals(lease.getGateway())) {
                    if (_log.shouldLog(Log.INFO))
                        _log.info(getJobId() + ": Found in cache - lease for " + _toString);
                    return true;
                }
            }
        }
        // remove only if still equal to _lease (concurrent)
        _cache.leaseCache.remove(_hashPair, _lease);
        if (_log.shouldLog(Log.INFO))
            _log.info(getJobId() + ": Expired from cache - lease for " + _toString);
    }
    // get the possible leases
    List<Lease> leases = new ArrayList<Lease>(_leaseSet.getLeaseCount());
    // first try to get ones that really haven't expired
    for (int i = 0; i < _leaseSet.getLeaseCount(); i++) {
        Lease lease = _leaseSet.getLease(i);
        if (!lease.isExpired(Router.CLOCK_FUDGE_FACTOR / 4))
            leases.add(lease);
    }
    if (leases.isEmpty()) {
        // try again with a fudge factor
        for (int i = 0; i < _leaseSet.getLeaseCount(); i++) {
            Lease lease = _leaseSet.getLease(i);
            if (!lease.isExpired(Router.CLOCK_FUDGE_FACTOR))
                leases.add(lease);
        }
    }
    if (leases.isEmpty()) {
        if (_log.shouldLog(Log.INFO))
            _log.info(getJobId() + ": No leases found from: " + _leaseSet);
        return false;
    }
    // randomize the ordering (so leases with equal # of failures per next
    // sort are randomly ordered)
    Collections.shuffle(leases, getContext().random());
    // Avoid a lease on a gateway we think is unreachable, if possible
    for (int i = 0; i < leases.size(); i++) {
        Lease l = leases.get(i);
        /**
         ***  Anonymity concerns with this, as the dest could act unreachable just to us, then
         ***  look at our lease selection.
         ***  Let's just look at whether the gw thinks it is unreachable instead -
         ***  unfortunately the "U" is rarely seen.
         *            if (!getContext().commSystem().wasUnreachable(l.getGateway())) {
         **
         */
        RouterInfo ri = getContext().netDb().lookupRouterInfoLocally(l.getGateway());
        if (ri == null || ri.getCapabilities().indexOf(Router.CAPABILITY_UNREACHABLE) < 0) {
            _lease = l;
            break;
        }
        if (_log.shouldLog(Log.WARN))
            _log.warn(getJobId() + ": Skipping unreachable gateway " + l.getGateway() + " for " + _toString);
    }
    if (_lease == null) {
        _lease = leases.get(0);
        if (_log.shouldLog(Log.WARN))
            _log.warn(getJobId() + ": All leases are unreachable for " + _toString);
    }
    _cache.leaseCache.put(_hashPair, _lease);
    if (_log.shouldLog(Log.INFO))
        _log.info(getJobId() + ": Added to cache - lease for " + _toString);
    _wantACK = true;
    return true;
}
Also used : Lease(net.i2p.data.Lease) RouterInfo(net.i2p.data.router.RouterInfo) ArrayList(java.util.ArrayList)

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