forked from I2P_Developers/i2p.i2p
Compare commits
2 Commits
i2p.i2p.2.
...
i2p.i2p.2.
Author | SHA1 | Date | |
---|---|---|---|
9982e3d470 | |||
5c3a6509db |
@ -8,6 +8,8 @@ import java.util.Properties;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
|
||||
import net.i2p.I2PAppContext;
|
||||
import net.i2p.app.MenuCallback;
|
||||
import net.i2p.app.MenuHandle;
|
||||
import net.i2p.apps.systray.UrlLauncher;
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.desktopgui.ExternalMain;
|
||||
@ -133,9 +135,22 @@ public class RunStandalone {
|
||||
System.setProperty("java.awt.headless", "false");
|
||||
ExternalMain dtg = new ExternalMain(_context, _context.clientAppManager(), null);
|
||||
dtg.startup();
|
||||
try {
|
||||
Thread.sleep(1000);
|
||||
} catch (InterruptedException ie) {}
|
||||
Callback cb = new Callback();
|
||||
MenuHandle mh = dtg.addMenu("i2psnark is running", cb);
|
||||
if (mh == null)
|
||||
System.out.println("addMenu failed!");
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static class Callback implements MenuCallback {
|
||||
public void clicked(MenuHandle handle) {
|
||||
System.out.println("Clicked! " + handle.getID());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -34,10 +34,10 @@ public class BuildTime {
|
||||
private static final long _latestTime;
|
||||
private static final long YEARS_25 = 25L*365*24*60*60*1000;
|
||||
/** update this periodically */
|
||||
private static final String EARLIEST = "2023-06-14 12:00:00 UTC";
|
||||
private static final String EARLIEST = "2023-01-01 12:00:00 UTC";
|
||||
// fallback if parse fails ticket #1976
|
||||
// date -d 202x-xx-xx +%s
|
||||
private static final long EARLIEST_LONG = 1686700800 * 1000L;
|
||||
private static final long EARLIEST_LONG = 1672531200 * 1000L;
|
||||
|
||||
static {
|
||||
// this is the standard format of build.timestamp as set in the top-level build.xml
|
||||
|
Binary file not shown.
@ -17,6 +17,7 @@ import java.net.UnknownHostException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
@ -89,12 +90,14 @@ public class Blocklist {
|
||||
private final File _blocklistFeedFile;
|
||||
private final boolean _haveIPv6;
|
||||
private boolean _started;
|
||||
private long _lastExpired = 0;
|
||||
// temp
|
||||
private final Map<Hash, String> _peerBlocklist = new HashMap<Hash, String>(4);
|
||||
|
||||
private static final String PROP_BLOCKLIST_ENABLED = "router.blocklist.enable";
|
||||
private static final String PROP_BLOCKLIST_DETAIL = "router.blocklist.detail";
|
||||
private static final String PROP_BLOCKLIST_FILE = "router.blocklist.file";
|
||||
private static final String PROP_BLOCKLIST_EXPIRE_INTERVAL = "router.blocklist.expireInterval";
|
||||
public static final String BLOCKLIST_FILE_DEFAULT = "blocklist.txt";
|
||||
private static final String BLOCKLIST_FEED_FILE = "docs/feed/blocklist/blocklist.txt";
|
||||
/** @since 0.9.48 */
|
||||
@ -147,6 +150,37 @@ public class Blocklist {
|
||||
_singleIPv6Blocklist = _haveIPv6 ? new LHMCache<BigInteger, Object>(MAX_IPV6_SINGLES) : null;
|
||||
}
|
||||
|
||||
|
||||
private int expireInterval(){
|
||||
String expireIntervalValue = _context.getProperty(PROP_BLOCKLIST_EXPIRE_INTERVAL, "0");
|
||||
try{
|
||||
Integer expireIntervalInt = 0;
|
||||
if (expireIntervalValue.endsWith("s")) {
|
||||
expireIntervalValue = expireIntervalValue.substring(0, expireIntervalValue.length() - 1);
|
||||
expireIntervalInt = Integer.parseInt(expireIntervalValue) * 1000;
|
||||
}else if(expireIntervalValue.endsWith("m")){
|
||||
expireIntervalValue = expireIntervalValue.substring(0, expireIntervalValue.length() - 1);
|
||||
expireIntervalInt = Integer.parseInt(expireIntervalValue) * 60000;
|
||||
}else if(expireIntervalValue.endsWith("h")){
|
||||
expireIntervalValue = expireIntervalValue.substring(0, expireIntervalValue.length() - 1);
|
||||
expireIntervalInt = Integer.parseInt(expireIntervalValue) * 3600000;
|
||||
}else if (expireIntervalValue.endsWith("d")) {
|
||||
expireIntervalValue = expireIntervalValue.substring(0, expireIntervalValue.length() - 1);
|
||||
expireIntervalInt = Integer.parseInt(expireIntervalValue) * 86400000;
|
||||
}else{
|
||||
expireIntervalInt = Integer.parseInt(expireIntervalValue);
|
||||
}
|
||||
if (expireIntervalInt < 0)
|
||||
expireIntervalInt = 0;
|
||||
return expireIntervalInt;
|
||||
}catch(NumberFormatException nfe){
|
||||
if (_log.shouldLog(_log.ERROR))
|
||||
_log.error("format error in "+PROP_BLOCKLIST_EXPIRE_INTERVAL, nfe);
|
||||
}
|
||||
// if we don't have a valid value in this field, return 0 which is the same as disabling it.
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Loads the following files in-order:
|
||||
* $I2P/blocklist.txt
|
||||
@ -193,6 +227,11 @@ public class Blocklist {
|
||||
// but it's important to have this initialized before we read in the netdb.
|
||||
//job.getTiming().setStartAfter(_context.clock().now() + 30*1000);
|
||||
_context.jobQueue().addJob(job);
|
||||
if (expireInterval() > 0) {
|
||||
Job cleanupJob = new CleanupJob();
|
||||
cleanupJob.getTiming().setStartAfter(_context.clock().now() + expireInterval());
|
||||
_context.jobQueue().addJob(cleanupJob);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -232,6 +271,32 @@ public class Blocklist {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class CleanupJob extends JobImpl {
|
||||
public CleanupJob() {
|
||||
super(_context);
|
||||
}
|
||||
public String getName(){
|
||||
return "Expire blocklist at user-defined interval of " + expireInterval();
|
||||
}
|
||||
public void runJob() {
|
||||
clear();
|
||||
_lastExpired = System.currentTimeMillis();
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Expiring blocklist entrys at" + _lastExpired);
|
||||
// schedule the next one
|
||||
super.requeue(expireInterval());
|
||||
}
|
||||
}
|
||||
|
||||
private void clear(){
|
||||
synchronized(_singleIPBlocklist) {
|
||||
_singleIPBlocklist.clear();
|
||||
}
|
||||
synchronized(_singleIPv6Blocklist) {
|
||||
_singleIPv6Blocklist.clear();
|
||||
}
|
||||
}
|
||||
|
||||
private class ReadinJob extends JobImpl {
|
||||
private final List<BLFile> _files;
|
||||
@ -285,13 +350,20 @@ public class Blocklist {
|
||||
reason = _x("Banned by router hash: {0}");
|
||||
else
|
||||
reason = _x("Banned by router hash");
|
||||
_context.banlist().banlistRouterForever(peer, reason, comment);
|
||||
banlistRouter(peer, reason, comment);
|
||||
}
|
||||
_peerBlocklist.clear();
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
private void banlistRouter(Hash peer, String reason, String comment) {
|
||||
if (expireInterval() > 0)
|
||||
_context.banlist().banlistRouter(peer, reason, comment, null, expireInterval());
|
||||
else
|
||||
_context.banlist().banlistRouterForever(peer, reason, comment);
|
||||
}
|
||||
|
||||
/**
|
||||
* The blocklist-country.txt file was created or updated.
|
||||
* Read it in. Not required normally, as the country file
|
||||
@ -886,6 +958,9 @@ public class Blocklist {
|
||||
/**
|
||||
* Does the peer's IP address appear in the blocklist?
|
||||
* If so, and it isn't banlisted, banlist it forever...
|
||||
* or, if the user configured an override, ban it for the
|
||||
* override period.
|
||||
* @since 0.9.29
|
||||
*/
|
||||
public boolean isBlocklisted(Hash peer) {
|
||||
List<byte[]> ips = getAddresses(peer);
|
||||
@ -905,6 +980,8 @@ public class Blocklist {
|
||||
/**
|
||||
* Does the peer's IP address appear in the blocklist?
|
||||
* If so, and it isn't banlisted, banlist it forever...
|
||||
* or, if the user configured an override, ban it for the
|
||||
* override period.
|
||||
* @since 0.9.29
|
||||
*/
|
||||
public boolean isBlocklisted(RouterInfo pinfo) {
|
||||
@ -1141,7 +1218,7 @@ public class Blocklist {
|
||||
_context.clock().now() + Banlist.BANLIST_DURATION_LOCALHOST);
|
||||
return;
|
||||
}
|
||||
_context.banlist().banlistRouterForever(peer, reason, sip);
|
||||
banlistRouter(peer, reason, sip);
|
||||
if (! _context.getBooleanPropertyDefaultTrue(PROP_BLOCKLIST_DETAIL))
|
||||
return;
|
||||
boolean shouldRunJob;
|
||||
@ -1169,7 +1246,7 @@ public class Blocklist {
|
||||
}
|
||||
public String getName() { return "Ban Peer by IP"; }
|
||||
public void runJob() {
|
||||
banlistForever(_peer, _ips);
|
||||
banlistRouter(_peer, _ips, expireInterval());
|
||||
synchronized (_inProcess) {
|
||||
_inProcess.remove(_peer);
|
||||
}
|
||||
@ -1185,7 +1262,13 @@ public class Blocklist {
|
||||
* So we also stagger these jobs.
|
||||
*
|
||||
*/
|
||||
private synchronized void banlistForever(Hash peer, List<byte[]> ips) {
|
||||
private void banlistRouter( Hash peer, String reason, String reasonCode, long duration) {
|
||||
if (duration > 0)
|
||||
_context.banlist().banlistRouter(peer, reason, reasonCode, null, System.currentTimeMillis()+expireInterval());
|
||||
else
|
||||
_context.banlist().banlistRouterForever(peer, reason, reasonCode);
|
||||
}
|
||||
private synchronized void banlistRouter(Hash peer, List<byte[]> ips, long duration) {
|
||||
// This only checks one file for now, pick the best one
|
||||
// user specified
|
||||
File blFile = null;
|
||||
@ -1205,7 +1288,7 @@ public class Blocklist {
|
||||
// just ban it and be done
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn("Banlisting " + peer);
|
||||
_context.banlist().banlistRouterForever(peer, "Banned");
|
||||
banlistRouter(peer, "Banned", "Banned", expireInterval());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -1236,7 +1319,7 @@ public class Blocklist {
|
||||
//reason = reason + " banned by " + BLOCKLIST_FILE_DEFAULT + " entry \"" + buf + "\"";
|
||||
if (_log.shouldLog(Log.WARN))
|
||||
_log.warn("Banlisting " + peer + " " + reason);
|
||||
_context.banlist().banlistRouterForever(peer, reason, buf.toString());
|
||||
banlistRouter(peer, reason, buf.toString(), expireInterval());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -8,7 +8,6 @@ import java.util.Properties;
|
||||
import net.i2p.data.Base64;
|
||||
import net.i2p.data.Hash;
|
||||
import net.i2p.data.SessionKey;
|
||||
import net.i2p.data.i2np.I2NPMessage;
|
||||
import net.i2p.util.ConcurrentHashSet;
|
||||
import net.i2p.util.NativeBigInteger;
|
||||
import net.i2p.util.RandomSource;
|
||||
@ -119,7 +118,7 @@ public class TunnelPoolSettings {
|
||||
_IPRestriction = DEFAULT_IP_RESTRICTION;
|
||||
_unknownOptions = new Properties();
|
||||
_randomKey = generateRandomKey();
|
||||
_msgIDBloomXor = RandomSource.getInstance().nextLong(I2NPMessage.MAX_ID_VALUE);
|
||||
_msgIDBloomXor = RandomSource.getInstance().nextLong();
|
||||
|
||||
if (_isExploratory && !_isInbound)
|
||||
_priority = EXPLORATORY_PRIORITY;
|
||||
|
@ -34,9 +34,9 @@ public class GarlicMessageHandler implements HandlerJobBuilder {
|
||||
|
||||
public GarlicMessageHandler(RouterContext context) {
|
||||
_context = context;
|
||||
_msgIDBloomXorLocal = RandomSource.getInstance().nextLong(I2NPMessage.MAX_ID_VALUE);
|
||||
_msgIDBloomXorRouter = RandomSource.getInstance().nextLong(I2NPMessage.MAX_ID_VALUE);
|
||||
_msgIDBloomXorTunnel = RandomSource.getInstance().nextLong(I2NPMessage.MAX_ID_VALUE);
|
||||
_msgIDBloomXorLocal = RandomSource.getInstance().nextLong();
|
||||
_msgIDBloomXorRouter = RandomSource.getInstance().nextLong();
|
||||
_msgIDBloomXorTunnel = RandomSource.getInstance().nextLong();
|
||||
}
|
||||
|
||||
public GarlicMessageHandler(RouterContext context, long msgIDBloomXorLocal, long msgIDBloomXorRouter, long msgIDBloomXorTunnel) {
|
||||
|
@ -26,7 +26,7 @@ public class FloodfillDatabaseLookupMessageHandler implements HandlerJobBuilder
|
||||
private RouterContext _context;
|
||||
private FloodfillNetworkDatabaseFacade _facade;
|
||||
private Log _log;
|
||||
private final long _msgIDBloomXor = RandomSource.getInstance().nextLong(I2NPMessage.MAX_ID_VALUE);
|
||||
private final long _msgIDBloomXor = RandomSource.getInstance().nextLong();
|
||||
|
||||
public FloodfillDatabaseLookupMessageHandler(RouterContext context, FloodfillNetworkDatabaseFacade facade) {
|
||||
_context = context;
|
||||
|
@ -24,7 +24,7 @@ import net.i2p.util.RandomSource;
|
||||
public class FloodfillDatabaseStoreMessageHandler implements HandlerJobBuilder {
|
||||
private RouterContext _context;
|
||||
private FloodfillNetworkDatabaseFacade _facade;
|
||||
private final long _msgIDBloomXor = RandomSource.getInstance().nextLong(I2NPMessage.MAX_ID_VALUE);
|
||||
private final long _msgIDBloomXor = RandomSource.getInstance().nextLong();
|
||||
|
||||
public FloodfillDatabaseStoreMessageHandler(RouterContext context, FloodfillNetworkDatabaseFacade facade) {
|
||||
_context = context;
|
||||
|
@ -988,7 +988,7 @@ public abstract class KademliaNetworkDatabaseFacade extends NetworkDatabaseFacad
|
||||
rv.setReceivedBy(to);
|
||||
} else if (leaseSet.getReceivedAsReply()) {
|
||||
rv.setReceivedAsReply();
|
||||
} else
|
||||
}
|
||||
if (leaseSet.getReceivedAsPublished()) {
|
||||
rv.setReceivedAsPublished(true);
|
||||
}
|
||||
|
@ -13,7 +13,6 @@ import java.util.Set;
|
||||
|
||||
import net.i2p.data.Hash;
|
||||
import net.i2p.data.router.RouterInfo;
|
||||
import net.i2p.data.i2np.I2NPMessage;
|
||||
import net.i2p.router.JobImpl;
|
||||
import net.i2p.router.Router;
|
||||
import net.i2p.router.RouterContext;
|
||||
@ -60,7 +59,7 @@ class StartExplorersJob extends JobImpl {
|
||||
private static final long MAX_LAG = 100;
|
||||
private static final long MAX_MSG_DELAY = 1500;
|
||||
|
||||
private final long _msgIDBloomXor = RandomSource.getInstance().nextLong(I2NPMessage.MAX_ID_VALUE);
|
||||
private final long _msgIDBloomXor = RandomSource.getInstance().nextLong();
|
||||
|
||||
public StartExplorersJob(RouterContext context, KademliaNetworkDatabaseFacade facade) {
|
||||
super(context);
|
||||
|
@ -136,7 +136,7 @@ public class TransportManager implements TransportEventListener {
|
||||
_dhThread = (_enableUDP || enableNTCP2) ? new DHSessionKeyBuilder.PrecalcRunner(context) : null;
|
||||
// always created, even if NTCP2 is not enabled, because ratchet needs it
|
||||
_xdhThread = new X25519KeyFactory(context);
|
||||
_msgIDBloomXor = _context.random().nextLong(I2NPMessage.MAX_ID_VALUE);
|
||||
_msgIDBloomXor = _context.random().nextLong();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -57,7 +57,7 @@ class InboundMessageDistributor implements GarlicMessageReceiver.CloveReceiver {
|
||||
_msgIDBloomXor = clienttps.getMsgIdBloomXor();
|
||||
} else {
|
||||
_clientNickname = "NULL/Expl";
|
||||
_msgIDBloomXor = RandomSource.getInstance().nextLong(I2NPMessage.MAX_ID_VALUE);
|
||||
_msgIDBloomXor = RandomSource.getInstance().nextLong();
|
||||
if (_log.shouldLog(Log.DEBUG))
|
||||
_log.debug("Initializing null or exploratory InboundMessageDistributor");
|
||||
}
|
||||
|
Reference in New Issue
Block a user