Search in sources :

Example 1 with Router

use of net.i2p.router.Router in project i2p.i2p by i2p.

the class MultiRouter method internalReseed.

private static void internalReseed() {
    HashSet<RouterInfo> riSet = new HashSet<RouterInfo>();
    for (Router r : _routers) {
        riSet.addAll(r.getContext().netDb().getRouters());
    }
    for (Router r : _routers) {
        for (RouterInfo ri : riSet) {
            r.getContext().netDb().publish(ri);
        }
    }
    _out.println(riSet.size() + " RouterInfos were reseeded");
}
Also used : RouterInfo(net.i2p.data.router.RouterInfo) Router(net.i2p.router.Router) HashSet(java.util.HashSet)

Example 2 with Router

use of net.i2p.router.Router in project i2p.i2p by i2p.

the class MultiRouter method main.

public static void main(String[] args) {
    if ((args == null) || (args.length < 1)) {
        usage();
        return;
    }
    Scanner scan = null;
    try {
        scan = new Scanner(args[0]);
        if (!scan.hasNextInt()) {
            usage();
            return;
        }
        nbrRouters = scan.nextInt();
        if (nbrRouters < 0) {
            usage();
            return;
        }
    } finally {
        if (scan != null)
            scan.close();
    }
    _out = System.out;
    buildClientProps(0);
    _defaultContext = new I2PAppContext(buildRouterProps(0));
    _defaultContext.clock().setOffset(0);
    _out.println("RouterConsole for Router 0 is listening on: 127.0.0.1:" + (BASE_PORT - 1));
    Runtime.getRuntime().addShutdownHook(new Thread() {

        @Override
        public void run() {
            _out.println("Shutting down in a few moments..");
            for (Router r : _routers) {
                r.shutdown(0);
            }
            try {
                Thread.sleep(1500);
            } catch (InterruptedException ie) {
            }
            Runtime.getRuntime().halt(0);
        }
    });
    for (int i = 0; i < nbrRouters; i++) {
        Router router = new Router(buildRouterProps(i));
        router.setKillVMOnEnd(false);
        _routers.add(router);
        _out.println("Router " + i + " was created");
        try {
            Thread.sleep(100);
        } catch (InterruptedException ie) {
        }
    }
    for (int i = 0; i < nbrRouters; i++) {
        final Router r = _routers.get(i);
        long offset = r.getContext().random().nextLong(Router.CLOCK_FUDGE_FACTOR / 2);
        if (r.getContext().random().nextBoolean())
            offset = 0 - offset;
        r.getContext().clock().setOffset(offset, true);
        /* Start the routers in separate threads since it takes some time. */
        (new Thread() {

            public void run() {
                r.runRouter();
            }
        }).start();
        try {
            Thread.sleep(100);
        } catch (InterruptedException ie) {
        }
        _out.println("Router " + i + " was started with time offset " + offset);
    }
    _out.println("All routers have been started");
    /* Wait for routers to start services and generate keys
         * before doing the internal reseed. */
    int waitForRouters = (nbrRouters / 10) * 1000;
    _out.println("Waiting " + waitForRouters / 1000 + " seconds for routers to start" + "before doing the internal reseed");
    try {
        Thread.sleep(waitForRouters);
    } catch (InterruptedException ie) {
    }
    internalReseed();
    waitForCompletion();
}
Also used : Scanner(java.util.Scanner) I2PAppContext(net.i2p.I2PAppContext) Router(net.i2p.router.Router)

Example 3 with Router

use of net.i2p.router.Router in project i2p.i2p by i2p.

the class FakeInputStream method setUp.

@BeforeClass
public static void setUp() {
    _context = new RouterContext(new Router());
    _context.initAll();
}
Also used : RouterContext(net.i2p.router.RouterContext) Router(net.i2p.router.Router) BeforeClass(org.junit.BeforeClass)

Example 4 with Router

use of net.i2p.router.Router 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)

Aggregations

Router (net.i2p.router.Router)4 RouterInfo (net.i2p.data.router.RouterInfo)2 RouterContext (net.i2p.router.RouterContext)2 BeforeClass (org.junit.BeforeClass)2 HashSet (java.util.HashSet)1 Scanner (java.util.Scanner)1 I2PAppContext (net.i2p.I2PAppContext)1 RouterIdentity (net.i2p.data.router.RouterIdentity)1