Changeset 9d5e8dd for router


Ignore:
Timestamp:
Jan 20, 2016 4:44:40 PM (5 years ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
d82591a
Parents:
07e85e0
Message:

make network ID configurable for testing

Location:
router/java/src/net/i2p/router
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • router/java/src/net/i2p/router/Router.java

    r07e85e0 r9d5e8dd  
    101101
    102102    /** used to differentiate routerInfo files on different networks */
    103     public static final int NETWORK_ID = 2;
     103    private static final int DEFAULT_NETWORK_ID = 2;
     104    private static final String PROP_NETWORK_ID = "router.networkID";
     105    private final int _networkID;
    104106   
    105107    /** coalesce stats this often - should be a little less than one minute, so the graphs get updated */
     
    348350            saveConfig();
    349351        }
     352        int id = DEFAULT_NETWORK_ID;
     353        String sid = _config.get(PROP_NETWORK_ID);
     354        if (sid != null) {
     355            try {
     356                id = Integer.parseInt(sid);
     357            } catch (NumberFormatException nfe) {}
     358        }
     359        _networkID = id;
    350360        changeState(State.INITIALIZED);
    351361        // *********  Start no threads before here ********* //
     
    537547        return Math.max(1000, System.currentTimeMillis() - _started);
    538548    }
     549
     550    /**
     551     *  The network ID. Default 2.
     552     *  May be changed with the config property router.networkID (restart required).
     553     *  Change only if running a test network to prevent cross-network contamination.
     554     *  @since 0.9.25
     555     */
     556    public int getNetworkID() { return _networkID; }
    539557   
    540558    /**
  • router/java/src/net/i2p/router/StatisticsManager.java

    r07e85e0 r9d5e8dd  
    3333    private final Log _log;
    3434    private final RouterContext _context;
     35    private final String _networkID;
    3536   
    3637    public final static String PROP_PUBLISH_RANKINGS = "router.publishPeerRankings";
     
    4748        _pct = new DecimalFormat("#0.00%", new DecimalFormatSymbols(Locale.UK));
    4849        _log = context.logManager().getLog(StatisticsManager.class);
     50        _networkID = Integer.toString(context.router().getNetworkID());
    4951    }
    5052       
     
    7375        if (CoreVersion.VERSION.equals("0.9.23"))
    7476            stats.setProperty("coreVersion", CoreVersion.VERSION);
    75         stats.setProperty(RouterInfo.PROP_NETWORK_ID, Integer.toString(Router.NETWORK_ID));
     77        stats.setProperty(RouterInfo.PROP_NETWORK_ID, _networkID);
    7678        stats.setProperty(RouterInfo.PROP_CAPABILITIES, _context.router().getCapabilities());
    7779
  • router/java/src/net/i2p/router/networkdb/kademlia/FloodfillNetworkDatabaseFacade.java

    r07e85e0 r9d5e8dd  
    480480        // yikes don't do this - stack overflow //  getFloodfillPeers().size() == 0 ||
    481481        // yikes2 don't do this either - deadlock! // getKnownRouters() < MIN_REMAINING_ROUTERS ||
    482         if (info.getNetworkId() == Router.NETWORK_ID &&
     482        if (info.getNetworkId() == _networkID &&
    483483            (getKBucketSetSize() < MIN_REMAINING_ROUTERS ||
    484484             _context.router().getUptime() < DONT_FAIL_PERIOD ||
  • router/java/src/net/i2p/router/networkdb/kademlia/KademliaNetworkDatabaseFacade.java

    r07e85e0 r9d5e8dd  
    7171    private volatile long _lastRIPublishTime;
    7272    private NegativeLookupCache _negativeCache;
     73    protected final int _networkID;
    7374
    7475    /**
     
    157158        _context = context;
    158159        _log = _context.logManager().getLog(getClass());
     160        _networkID = context.router().getNetworkID();
    159161        _peerSelector = createPeerSelector();
    160162        _publishingLeaseSets = new HashMap<Hash, RepublishLeaseSetJob>(8);
     
    890892            return "Invalid routerInfo signature";
    891893        }
    892         if (routerInfo.getNetworkId() != Router.NETWORK_ID){
     894        if (routerInfo.getNetworkId() != _networkID){
    893895            _context.banlist().banlistRouter(key, "Not in our network");
    894896            if (_log.shouldLog(Log.WARN))
  • router/java/src/net/i2p/router/networkdb/kademlia/PersistentDataStore.java

    r07e85e0 r9d5e8dd  
    5555    private volatile boolean _initialized;
    5656    private final boolean _flat;
     57    private final int _networkID;
    5758   
    5859    private final static int READ_DELAY = 2*60*1000;
     
    6667    public PersistentDataStore(RouterContext ctx, String dbDir, KademliaNetworkDatabaseFacade facade) throws IOException {
    6768        super(ctx);
     69        _networkID = ctx.router().getNetworkID();
    6870        _flat = ctx.getBooleanProperty(PROP_FLAT);
    6971        _dbDir = getDbDir(dbDir);
     
    506508                    RouterInfo ri = new RouterInfo();
    507509                    ri.readBytes(fis, true);  // true = verify sig on read
    508                     if (ri.getNetworkId() != Router.NETWORK_ID) {
     510                    if (ri.getNetworkId() != _networkID) {
    509511                        corrupt = true;
    510512                        if (_log.shouldLog(Log.ERROR))
  • router/java/src/net/i2p/router/transport/udp/EstablishmentManager.java

    r07e85e0 r9d5e8dd  
    4343    private final UDPTransport _transport;
    4444    private final PacketBuilder _builder;
     45    private final int _networkID;
    4546
    4647    /** map of RemoteHostId to InboundEstablishState */
     
    144145        _context = ctx;
    145146        _log = ctx.logManager().getLog(EstablishmentManager.class);
     147        _networkID = ctx.router().getNetworkID();
    146148        _transport = transport;
    147149        _builder = new PacketBuilder(ctx, transport);
     
    253255        RouterIdentity toIdentity = toRouterInfo.getIdentity();
    254256        Hash toHash = toIdentity.calculateHash();
    255         if (toRouterInfo.getNetworkId() != Router.NETWORK_ID) {
     257        if (toRouterInfo.getNetworkId() != _networkID) {
    256258            _context.banlist().banlistRouter(toHash);
    257259            _transport.markUnreachable(toHash);
     
    766768            _log.info("Completing to the peer after IB confirm: " + peer);
    767769        DeliveryStatusMessage dsm = new DeliveryStatusMessage(_context);
    768         dsm.setArrival(Router.NETWORK_ID); // overloaded, sure, but future versions can check this
     770        dsm.setArrival(_networkID); // overloaded, sure, but future versions can check this
    769771                                           // This causes huge values in the inNetPool.droppedDeliveryStatusDelay stat
    770772                                           // so it needs to be caught in InNetMessagePool.
  • router/java/src/net/i2p/router/transport/udp/UDPTransport.java

    r07e85e0 r9d5e8dd  
    8888    private int _mtu_ipv6;
    8989    private boolean _mismatchLogged;
     90    private final int _networkID;
    9091
    9192    /**
     
    219220    public UDPTransport(RouterContext ctx, DHSessionKeyBuilder.Factory dh) {
    220221        super(ctx);
     222        _networkID = ctx.router().getNetworkID();
    221223        _dhFactory = dh;
    222224        _log = ctx.logManager().getLog(UDPTransport.class);
     
    12901292                return;
    12911293            if (entry.getType() == DatabaseEntry.KEY_TYPE_ROUTERINFO &&
    1292                 ((RouterInfo) entry).getNetworkId() != Router.NETWORK_ID) {
     1294                ((RouterInfo) entry).getNetworkId() != _networkID) {
    12931295                // this is pre-0.6.1.10, so it isn't going to happen any more
    12941296
Note: See TracChangeset for help on using the changeset viewer.