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) {
}
}
}
}
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);
}
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;
}
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);
}
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;
}
Aggregations