Search in sources :

Example 21 with JSONRPC2Error

use of com.thetransactioncompany.jsonrpc2.JSONRPC2Error in project i2pplus by I2PPlus.

the class I2PControlHandler method process.

private JSONRPC2Response process(JSONRPC2Request req) {
    JSONRPC2Error err = _helper.validateParams(null, req);
    if (err != null)
        return new JSONRPC2Response(err, req.getID());
    /**
     ** only if we enable host/port changes
     *        if (_context == null) {
     *            return new JSONRPC2Response(
     *                       new JSONRPC2Error(JSONRPC2Error.INTERNAL_ERROR.getCode(),
     *                                         "RouterContext was not initialized. Query failed"),
     *                       req.getID());
     *        }
     ***
     */
    Map<String, Object> inParams = req.getNamedParams();
    Map<String, Object> outParams = new HashMap<String, Object>(4);
    boolean restartNeeded = false;
    boolean settingsSaved = false;
    String inParam;
    if (inParams.containsKey("i2pcontrol.password")) {
        if ((inParam = (String) inParams.get("i2pcontrol.password")) != null) {
            if (_secMan.setPasswd(inParam)) {
                outParams.put("i2pcontrol.password", null);
                settingsSaved = true;
            }
        }
    }
    /**
     **
     *        if (inParams.containsKey("i2pcontrol.address")) {
     *            String oldAddress = _conf.getConf("i2pcontrol.listen.address", "127.0.0.1");
     *            if ((inParam = (String) inParams.get("i2pcontrol.address")) != null) {
     *                if ((oldAddress == null || !inParam.equals(oldAddress.toString()) &&
     *                        (inParam.equals("0.0.0.0") || inParam.equals("127.0.0.1")))) {
     *                    InetAddress[] newAddress;
     *
     *                    try {
     *                        newAddress = InetAddress.getAllByName(inParam);
     *                    } catch (UnknownHostException e) {
     *                        return new JSONRPC2Response(
     *                                   new JSONRPC2Error(JSONRPC2Error.INVALID_PARAMS.getCode(),
     *                                                     "\"i2pcontrol.address\" must be a string representing a hostname or ipaddress. " + inParam + " isn't valid."),
     *                                   req.getID());
     *                    }
     *                    try {
     *                        SslSocketConnector ssl = I2PControlController.buildSslListener(inParam, _conf.getConf("i2pcontrol.listen.port", 7650));
     *                        I2PControlController.clearListeners();
     *                        I2PControlController.replaceListener(ssl);
     *                        _conf.setConf("i2pcontrol.listen.address", inParam);
     *
     *                        ConfigurationManager.writeConfFile();
     *                        outParams.put("i2pcontrol.address", null);
     *                        settingsSaved = true;
     *                    } catch (Exception e) {
     *                        _conf.setConf("i2pcontrol.listen.address", oldAddress);
     *                        try {
     *                            SslSocketConnector ssl = I2PControlController.buildSslListener(inParam, _conf.getConf("i2pcontrol.listen.port", 7650));
     *                            I2PControlController.clearListeners();
     *                            I2PControlController.replaceListener(ssl);
     *                        } catch (Exception e2) {
     *                            _log.log(Log.CRIT, "Unable to resume server on previous listening ip.");
     *                        }
     *                        _log.error("Client tried to set listen address to, " + newAddress.toString() + " which isn't valid.", e);
     *                        return new JSONRPC2Response(
     *                                   new JSONRPC2Error(JSONRPC2Error.INVALID_PARAMS.getCode(),
     *                                                     "\"i2pcontrol.address\" has been set to an invalid address, reverting. "),    req.getID());
     *                    }
     *                }
     *            } else {
     *                outParams.put("i2pcontrol.address", oldAddress);
     *            }
     *            outParams.put("RestartNeeded", restartNeeded);
     *        }
     ***
     */
    outParams.put("SettingsSaved", settingsSaved);
    return new JSONRPC2Response(outParams, req.getID());
}
Also used : HashMap(java.util.HashMap) JSONRPC2Response(com.thetransactioncompany.jsonrpc2.JSONRPC2Response) JSONRPC2Error(com.thetransactioncompany.jsonrpc2.JSONRPC2Error)

Example 22 with JSONRPC2Error

use of com.thetransactioncompany.jsonrpc2.JSONRPC2Error in project i2pplus by I2PPlus.

the class NetworkSettingHandler method process.

private JSONRPC2Response process(JSONRPC2Request req) {
    JSONRPC2Error err = _helper.validateParams(null, req);
    if (err != null)
        return new JSONRPC2Response(err, req.getID());
    if (_context == null) {
        return new JSONRPC2Response(new JSONRPC2Error(JSONRPC2Error.INTERNAL_ERROR.getCode(), "RouterContext was not initialized. Query failed"), req.getID());
    }
    Map<String, Object> inParams = req.getNamedParams();
    Map<String, Object> outParams = new HashMap<String, Object>(4);
    boolean restartNeeded = false;
    boolean settingsSaved = false;
    String inParam;
    if (inParams.containsKey("i2p.router.net.ntcp.port")) {
        String oldNTCPPort = _context.getProperty(NTCPTransport.PROP_I2NP_NTCP_PORT);
        if ((inParam = (String) inParams.get("i2p.router.net.ntcp.port")) != null) {
            if (oldNTCPPort == null || !oldNTCPPort.equals(inParam.trim())) {
                Integer newPort;
                try {
                    newPort = Integer.valueOf(inParam);
                    if (newPort < 1 || newPort > 65535) {
                        throw new NumberFormatException();
                    }
                } catch (NumberFormatException e) {
                    return new JSONRPC2Response(new JSONRPC2Error(JSONRPC2Error.INVALID_PARAMS.getCode(), "\"i2p.router.net.ntcp.port\" must be a string representing a number in the range 1-65535. " + inParam + " isn't valid."), req.getID());
                }
                Map<String, String> config = new HashMap<String, String>();
                config.put(NTCPTransport.PROP_I2NP_NTCP_PORT, String.valueOf(newPort));
                config.put(NTCPTransport.PROP_I2NP_NTCP_AUTO_PORT, "false");
                _context.router().saveConfig(config, null);
                restartNeeded = true;
            }
            settingsSaved = true;
        } else {
            String sAutoPort = _context.getProperty(NTCPTransport.PROP_I2NP_NTCP_AUTO_PORT, "true");
            boolean oldAutoPort = "true".equalsIgnoreCase(sAutoPort);
            if (oldAutoPort) {
                String oldSSUPort = "" + _context.getProperty(UDPTransport.PROP_INTERNAL_PORT, 8887);
                outParams.put("i2p.router.net.ntcp.port", oldSSUPort);
            } else {
                outParams.put("i2p.router.net.ntcp.port", oldNTCPPort);
            }
        }
    }
    if (inParams.containsKey("i2p.router.net.ntcp.hostname")) {
        String oldNTCPHostname = _context.getProperty(NTCPTransport.PROP_I2NP_NTCP_HOSTNAME);
        if ((inParam = (String) inParams.get("i2p.router.net.ntcp.hostname")) != null) {
            if (oldNTCPHostname == null || !oldNTCPHostname.equals(inParam.trim())) {
                _context.router().saveConfig(NTCPTransport.PROP_I2NP_NTCP_HOSTNAME, inParam);
                restartNeeded = true;
            }
            settingsSaved = true;
        } else {
            outParams.put("i2p.router.net.ntcp.hostname", oldNTCPHostname);
        }
    }
    if (inParams.containsKey("i2p.router.net.ntcp.autoip")) {
        String oldNTCPAutoIP = _context.getProperty(NTCPTransport.PROP_I2NP_NTCP_AUTO_IP);
        if ((inParam = (String) inParams.get("i2p.router.net.ntcp.autoip")) != null) {
            inParam = inParam.trim().toLowerCase();
            if (oldNTCPAutoIP == null || !oldNTCPAutoIP.equals(inParam)) {
                if ("always".equals(inParam) || "true".equals(inParam) || "false".equals(inParam)) {
                    _context.router().saveConfig(NTCPTransport.PROP_I2NP_NTCP_AUTO_IP, inParam);
                    restartNeeded = true;
                } else {
                    return new JSONRPC2Response(new JSONRPC2Error(JSONRPC2Error.INVALID_PARAMS.getCode(), "\"i2p.router.net.ntcp.autoip\" can only be always, true or false. " + inParam + " isn't valid."), req.getID());
                }
            }
            settingsSaved = true;
        } else {
            outParams.put("i2p.router.net.ntcp.autoip", oldNTCPAutoIP);
        }
    }
    if (inParams.containsKey("i2p.router.net.ssu.port")) {
        String oldSSUPort = "" + _context.getProperty(UDPTransport.PROP_INTERNAL_PORT, 8887);
        if ((inParam = (String) inParams.get("i2p.router.net.ssu.port")) != null) {
            if (oldSSUPort == null || !oldSSUPort.equals(inParam.trim())) {
                Integer newPort;
                try {
                    newPort = Integer.valueOf(inParam);
                    if (newPort < 1 || newPort > 65535) {
                        throw new NumberFormatException();
                    }
                } catch (NumberFormatException e) {
                    return new JSONRPC2Response(new JSONRPC2Error(JSONRPC2Error.INVALID_PARAMS.getCode(), "\"i2p.router.net.ssu.port\" must be a string representing a number in the range 1-65535. " + inParam + " isn't valid."), req.getID());
                }
                Map<String, String> config = new HashMap<String, String>();
                config.put(UDPTransport.PROP_EXTERNAL_PORT, String.valueOf(newPort));
                config.put(UDPTransport.PROP_INTERNAL_PORT, String.valueOf(newPort));
                _context.router().saveConfig(config, null);
                restartNeeded = true;
            }
            settingsSaved = true;
        } else {
            outParams.put("i2p.router.net.ssu.port", oldSSUPort);
        }
    }
    if (inParams.containsKey("i2p.router.net.ssu.hostname")) {
        String oldSSUHostname = _context.getProperty(UDPTransport.PROP_EXTERNAL_HOST);
        if ((inParam = (String) inParams.get("i2p.router.net.ssu.hostname")) != null) {
            if (oldSSUHostname == null || !oldSSUHostname.equals(inParam.trim())) {
                _context.router().saveConfig(UDPTransport.PROP_EXTERNAL_HOST, inParam);
                restartNeeded = true;
            }
            settingsSaved = true;
        } else {
            outParams.put("i2p.router.net.ssu.hostname", oldSSUHostname);
        }
    }
    if (inParams.containsKey("i2p.router.net.ssu.autoip")) {
        String oldSSUAutoIP = _context.getProperty(UDPTransport.PROP_SOURCES);
        if ((inParam = (String) inParams.get("i2p.router.net.ssu.autoip")) != null) {
            inParam = inParam.trim().toLowerCase();
            if (oldSSUAutoIP == null || !oldSSUAutoIP.equals(inParam)) {
                if (inParam.equals("ssu") || inParam.equals("local,ssu") || inParam.equals("upnp,ssu") || inParam.equals("local,upnp,ssu")) {
                    _context.router().saveConfig(UDPTransport.PROP_SOURCES, inParam);
                    restartNeeded = true;
                } else {
                    return new JSONRPC2Response(new JSONRPC2Error(JSONRPC2Error.INVALID_PARAMS.getCode(), "\"i2p.router.net.ssu.autoip\" can only be ssu/local,upnp,ssu/local/ssu/upnp,ssu. " + inParam + " isn't valid."), req.getID());
                }
            }
            settingsSaved = true;
        } else {
            outParams.put("i2p.router.net.ssu.autoip", oldSSUAutoIP);
        }
    }
    // Non-setable key.
    if (inParams.containsKey("i2p.router.net.ssu.detectedip")) {
        if ((inParam = (String) inParams.get("i2p.router.net.ssu.autoip")) == null) {
            byte[] ipBytes = _context.router().getRouterInfo().getTargetAddress("SSU").getIP();
            try {
                InetAddress i = InetAddress.getByAddress(ipBytes);
                outParams.put("i2p.router.net.ssu.detectedip", i.getHostAddress());
            } catch (UnknownHostException e) {
                outParams.put("i2p.router.net.ssu.detectedip", "Failed to parse ip address");
            }
        }
    }
    if (inParams.containsKey("i2p.router.net.upnp")) {
        String oldUPNP = _context.getProperty(TransportManager.PROP_ENABLE_UPNP);
        if ((inParam = (String) inParams.get("i2p.router.net.upnp")) != null) {
            if (oldUPNP == null || !oldUPNP.equals(inParam.trim())) {
                _context.router().saveConfig(TransportManager.PROP_ENABLE_UPNP, inParam);
                restartNeeded = true;
            }
            settingsSaved = true;
        } else {
            outParams.put("i2p.router.net.upnp", oldUPNP);
        }
    }
    if (inParams.containsKey("i2p.router.net.bw.share")) {
        String oldShare = _context.router().getConfigSetting(Router.PROP_BANDWIDTH_SHARE_PERCENTAGE);
        if ((inParam = (String) inParams.get("i2p.router.net.bw.share")) != null) {
            if (oldShare == null || !oldShare.equals(inParam.trim())) {
                Integer percent;
                try {
                    percent = Integer.parseInt(inParam);
                    if (percent < 0 || percent > 100 || inParam.length() == 0) {
                        throw new NumberFormatException();
                    }
                } catch (NumberFormatException e) {
                    return new JSONRPC2Response(new JSONRPC2Error(JSONRPC2Error.INVALID_PARAMS.getCode(), "\"i2p.router.net.bw.share\" A positive integer must supplied, \"" + inParam + "\" isn't valid"), req.getID());
                }
                _context.router().saveConfig(Router.PROP_BANDWIDTH_SHARE_PERCENTAGE, inParam);
            }
            settingsSaved = true;
        } else {
            outParams.put("i2p.router.net.bw.share", oldShare);
        }
    }
    if (inParams.containsKey("i2p.router.net.bw.in")) {
        String oldBWIn = _context.getProperty(FIFOBandwidthRefiller.PROP_INBOUND_BANDWIDTH);
        if ((inParam = (String) inParams.get("i2p.router.net.bw.in")) != null) {
            Integer rate;
            try {
                rate = Integer.parseInt(inParam);
                if (rate < 0 || inParam.length() == 0) {
                    throw new NumberFormatException();
                }
            } catch (NumberFormatException e) {
                return new JSONRPC2Response(new JSONRPC2Error(JSONRPC2Error.INVALID_PARAMS.getCode(), "\"i2p.router.net.bw.in\" A positive integer must supplied, " + inParam + " isn't valid"), req.getID());
            }
            Integer burstRate = (rate * BW_BURST_PCT) / 100;
            Integer burstSize = (burstRate * BW_BURST_TIME);
            if (oldBWIn == null || !oldBWIn.equals(rate.toString())) {
                Map<String, String> config = new HashMap<String, String>();
                config.put(FIFOBandwidthRefiller.PROP_INBOUND_BANDWIDTH, rate.toString());
                config.put(FIFOBandwidthRefiller.PROP_INBOUND_BURST_BANDWIDTH, burstRate.toString());
                config.put(FIFOBandwidthRefiller.PROP_INBOUND_BANDWIDTH_PEAK, burstSize.toString());
                _context.router().saveConfig(config, null);
                _context.bandwidthLimiter().reinitialize();
            }
            settingsSaved = true;
        } else {
            outParams.put("i2p.router.net.bw.in", oldBWIn);
        }
    }
    if (inParams.containsKey("i2p.router.net.bw.out")) {
        String oldBWOut = _context.getProperty(FIFOBandwidthRefiller.PROP_OUTBOUND_BANDWIDTH);
        if ((inParam = (String) inParams.get("i2p.router.net.bw.out")) != null) {
            Integer rate;
            try {
                rate = Integer.parseInt(inParam);
                if (rate < 0 || inParam.length() == 0)
                    throw new NumberFormatException();
            } catch (NumberFormatException e) {
                return new JSONRPC2Response(new JSONRPC2Error(JSONRPC2Error.INVALID_PARAMS.getCode(), "\"i2p.router.net.bw.out\" A positive integer must supplied, " + inParam + " isn't valid"), req.getID());
            }
            Integer burstRate = (rate * BW_BURST_PCT) / 100;
            Integer burstSize = (burstRate * BW_BURST_TIME);
            if (oldBWOut == null || !oldBWOut.equals(rate.toString())) {
                Map<String, String> config = new HashMap<String, String>();
                config.put(FIFOBandwidthRefiller.PROP_OUTBOUND_BANDWIDTH, rate.toString());
                config.put(FIFOBandwidthRefiller.PROP_OUTBOUND_BURST_BANDWIDTH, burstRate.toString());
                config.put(FIFOBandwidthRefiller.PROP_OUTBOUND_BANDWIDTH_PEAK, burstSize.toString());
                _context.router().saveConfig(config, null);
                _context.bandwidthLimiter().reinitialize();
            }
            settingsSaved = true;
        } else {
            outParams.put("i2p.router.net.bw.out", oldBWOut);
        }
    }
    if (inParams.containsKey("i2p.router.net.laptopmode")) {
        String oldLaptopMode = _context.getProperty(UDPTransport.PROP_LAPTOP_MODE);
        if ((inParam = (String) inParams.get("i2p.router.net.laptopmode")) != null) {
            if (oldLaptopMode == null || !oldLaptopMode.equals(inParam.trim())) {
                _context.router().saveConfig(UDPTransport.PROP_LAPTOP_MODE, String.valueOf(inParam));
            }
            settingsSaved = true;
        } else {
            outParams.put("i2p.router.net.laptopmode", oldLaptopMode);
        }
    }
    if (settingsSaved)
        _context.router().saveConfig();
    outParams.put("SettingsSaved", settingsSaved);
    outParams.put("RestartNeeded", restartNeeded);
    return new JSONRPC2Response(outParams, req.getID());
}
Also used : UnknownHostException(java.net.UnknownHostException) HashMap(java.util.HashMap) JSONRPC2Response(com.thetransactioncompany.jsonrpc2.JSONRPC2Response) JSONRPC2Error(com.thetransactioncompany.jsonrpc2.JSONRPC2Error) InetAddress(java.net.InetAddress)

Example 23 with JSONRPC2Error

use of com.thetransactioncompany.jsonrpc2.JSONRPC2Error in project i2pplus by I2PPlus.

the class RouterInfoHandler method process.

@SuppressWarnings("unchecked")
private JSONRPC2Response process(JSONRPC2Request req) {
    JSONRPC2Error err = _helper.validateParams(null, req);
    if (err != null)
        return new JSONRPC2Response(err, req.getID());
    if (_context == null) {
        return new JSONRPC2Response(new JSONRPC2Error(JSONRPC2Error.INTERNAL_ERROR.getCode(), "RouterContext was not initialized. Query failed"), req.getID());
    }
    Map<String, Object> inParams = req.getNamedParams();
    Map outParams = new HashMap();
    if (inParams.containsKey("i2p.router.version")) {
        try {
            Class rvClass = Class.forName("net.i2p.router.RouterVersion");
            java.lang.reflect.Field field = rvClass.getDeclaredField("FULL_VERSION");
            String fullVersion = (String) field.get(new RouterVersion());
            outParams.put("i2p.router.version", fullVersion);
        }// Ignore
         catch (Exception e) {
        }
    }
    if (inParams.containsKey("i2p.router.uptime")) {
        Router router = _context.router();
        if (router == null) {
            outParams.put("i2p.router.uptime", 0);
        } else {
            outParams.put("i2p.router.uptime", router.getUptime());
        }
    }
    if (inParams.containsKey("i2p.router.status")) {
        outParams.put("i2p.router.status", _context.throttle().getLocalizedTunnelStatus());
    }
    if (inParams.containsKey("i2p.router.net.status")) {
        outParams.put("i2p.router.net.status", getNetworkStatus().ordinal());
    }
    if (inParams.containsKey("i2p.router.net.bw.inbound.1s")) {
        outParams.put("i2p.router.net.bw.inbound.1s", _context.bandwidthLimiter().getReceiveBps());
    }
    if (inParams.containsKey("i2p.router.net.bw.outbound.1s")) {
        outParams.put("i2p.router.net.bw.outbound.1s", _context.bandwidthLimiter().getSendBps());
    }
    if (inParams.containsKey("i2p.router.net.bw.inbound.15s")) {
        outParams.put("i2p.router.net.bw.inbound.15s", _context.bandwidthLimiter().getReceiveBps15s());
    }
    if (inParams.containsKey("i2p.router.net.bw.outbound.15s")) {
        outParams.put("i2p.router.net.bw.outbound.15s", _context.bandwidthLimiter().getSendBps15s());
    }
    if (inParams.containsKey("i2p.router.net.tunnels.participating")) {
        outParams.put("i2p.router.net.tunnels.participating", _context.tunnelManager().getParticipatingCount());
    }
    if (inParams.containsKey("i2p.router.netdb.knownpeers")) {
        // Why max(-1, 0) is used I don't know, it is the implementation used in the router console.
        outParams.put("i2p.router.netdb.knownpeers", Math.max(_context.netDb().getKnownRouters() - 1, 0));
    }
    if (inParams.containsKey("i2p.router.netdb.activepeers")) {
        outParams.put("i2p.router.netdb.activepeers", _context.commSystem().countActivePeers());
    }
    if (inParams.containsKey("i2p.router.netdb.fastpeers")) {
        outParams.put("i2p.router.netdb.fastpeers", _context.profileOrganizer().countFastPeers());
    }
    if (inParams.containsKey("i2p.router.netdb.highcapacitypeers")) {
        outParams.put("i2p.router.netdb.highcapacitypeers", _context.profileOrganizer().countHighCapacityPeers());
    }
    if (inParams.containsKey("i2p.router.netdb.isreseeding")) {
        outParams.put("i2p.router.netdb.isreseeding", Boolean.valueOf(System.getProperty("net.i2p.router.web.ReseedHandler.reseedInProgress")).booleanValue());
    }
    return new JSONRPC2Response(outParams, req.getID());
}
Also used : HashMap(java.util.HashMap) JSONRPC2Response(com.thetransactioncompany.jsonrpc2.JSONRPC2Response) Router(net.i2p.router.Router) RouterVersion(net.i2p.router.RouterVersion) JSONRPC2Error(com.thetransactioncompany.jsonrpc2.JSONRPC2Error) HashMap(java.util.HashMap) Map(java.util.Map)

Example 24 with JSONRPC2Error

use of com.thetransactioncompany.jsonrpc2.JSONRPC2Error in project i2pplus by I2PPlus.

the class RouterManagerHandler method process.

private JSONRPC2Response process(JSONRPC2Request req) {
    JSONRPC2Error err = _helper.validateParams(null, req);
    if (err != null)
        return new JSONRPC2Response(err, req.getID());
    if (_context == null) {
        return new JSONRPC2Response(new JSONRPC2Error(JSONRPC2Error.INTERNAL_ERROR.getCode(), "RouterContext was not initialized. Query failed"), req.getID());
    }
    Map<String, Object> inParams = req.getNamedParams();
    final Map<String, Object> outParams = new HashMap<String, Object>(4);
    if (inParams.containsKey("Shutdown")) {
        outParams.put("Shutdown", null);
        (new Thread() {

            @Override
            public void run() {
                try {
                    Thread.sleep(SHUTDOWN_WAIT);
                } catch (InterruptedException e) {
                }
                _context.addShutdownTask(new UpdateWrapperManagerTask(Router.EXIT_HARD));
                _context.router().shutdown(Router.EXIT_HARD);
            }
        }).start();
        return new JSONRPC2Response(outParams, req.getID());
    }
    if (inParams.containsKey("Restart")) {
        outParams.put("Restart", null);
        (new Thread() {

            @Override
            public void run() {
                try {
                    Thread.sleep(SHUTDOWN_WAIT);
                } catch (InterruptedException e) {
                }
                _context.addShutdownTask(new UpdateWrapperManagerTask(Router.EXIT_HARD_RESTART));
                _context.router().shutdown(Router.EXIT_HARD_RESTART);
            }
        }).start();
        return new JSONRPC2Response(outParams, req.getID());
    }
    if (inParams.containsKey("ShutdownGraceful")) {
        outParams.put("ShutdownGraceful", null);
        (new Thread() {

            @Override
            public void run() {
                try {
                    Thread.sleep(SHUTDOWN_WAIT);
                } catch (InterruptedException e) {
                }
                _context.addShutdownTask(new UpdateWrapperManagerTask(Router.EXIT_GRACEFUL));
                _context.router().shutdownGracefully();
            }
        }).start();
        return new JSONRPC2Response(outParams, req.getID());
    }
    if (inParams.containsKey("RestartGraceful")) {
        outParams.put("RestartGraceful", null);
        (new Thread() {

            @Override
            public void run() {
                try {
                    Thread.sleep(SHUTDOWN_WAIT);
                } catch (InterruptedException e) {
                }
                _context.addShutdownTask(new UpdateWrapperManagerTask(Router.EXIT_GRACEFUL_RESTART));
                _context.router().shutdownGracefully(Router.EXIT_GRACEFUL_RESTART);
            }
        }).start();
        return new JSONRPC2Response(outParams, req.getID());
    }
    if (inParams.containsKey("Reseed")) {
        outParams.put("Reseed", null);
        (new Thread() {

            @Override
            public void run() {
                ReseedChecker reseeder = new ReseedChecker(_context);
                reseeder.requestReseed();
            }
        }).start();
        return new JSONRPC2Response(outParams, req.getID());
    }
    if (inParams.containsKey("FindUpdates")) {
        Thread t = new Thread() {

            @Override
            public void run() {
                ClientAppManager clmgr = I2PAppContext.getCurrentContext().clientAppManager();
                if (clmgr == null) {
                    outParams.put("FindUpdates", "ClientAppManager is null");
                    return;
                }
                UpdateManager upmgr = (UpdateManager) clmgr.getRegisteredApp(UpdateManager.APP_NAME);
                if (upmgr == null) {
                    outParams.put("FindUpdates", "UpdateManager is null");
                    return;
                }
                boolean updateIsAvailable = upmgr.checkAvailable(UpdateType.ROUTER_SIGNED) != null;
                outParams.put("FindUpdates", updateIsAvailable);
            }
        };
        t.start();
        try {
            t.join();
        } catch (InterruptedException e) {
        }
        return new JSONRPC2Response(outParams, req.getID());
    }
    if (inParams.containsKey("Update")) {
        Thread t = new Thread() {

            @Override
            public void run() {
                ClientAppManager clmgr = I2PAppContext.getCurrentContext().clientAppManager();
                if (clmgr == null) {
                    outParams.put("Update", "ClientAppManager is null");
                    return;
                }
                UpdateManager upmgr = (UpdateManager) clmgr.getRegisteredApp(UpdateManager.APP_NAME);
                if (upmgr == null) {
                    outParams.put("Update", "UpdateManager is null");
                    return;
                }
                boolean updateStarted = upmgr.update(UpdateType.ROUTER_SIGNED);
                if (!updateStarted) {
                    outParams.put("Update", "Update not started");
                    return;
                }
                boolean isUpdating = upmgr.isUpdateInProgress(UpdateType.ROUTER_SIGNED);
                while (isUpdating) {
                    try {
                        Thread.sleep(100);
                    } catch (Exception e) {
                    }
                    isUpdating = upmgr.isUpdateInProgress(UpdateType.ROUTER_SIGNED);
                }
                outParams.put("Update", upmgr.getStatus());
            }
        };
        t.start();
        try {
            t.join();
        } catch (InterruptedException e) {
        }
        return new JSONRPC2Response(outParams, req.getID());
    }
    return new JSONRPC2Response(outParams, req.getID());
}
Also used : ReseedChecker(net.i2p.router.networkdb.reseed.ReseedChecker) HashMap(java.util.HashMap) JSONRPC2Response(com.thetransactioncompany.jsonrpc2.JSONRPC2Response) ClientAppManager(net.i2p.app.ClientAppManager) JSONRPC2Error(com.thetransactioncompany.jsonrpc2.JSONRPC2Error) UpdateManager(net.i2p.update.UpdateManager)

Aggregations

JSONRPC2Error (com.thetransactioncompany.jsonrpc2.JSONRPC2Error)24 JSONRPC2Response (com.thetransactioncompany.jsonrpc2.JSONRPC2Response)24 HashMap (java.util.HashMap)24 Map (java.util.Map)6 InetAddress (java.net.InetAddress)3 UnknownHostException (java.net.UnknownHostException)3 ClientAppManager (net.i2p.app.ClientAppManager)3 AuthToken (net.i2p.i2pcontrol.security.AuthToken)3 Router (net.i2p.router.Router)3 RouterVersion (net.i2p.router.RouterVersion)3 ReseedChecker (net.i2p.router.networkdb.reseed.ReseedChecker)3 Rate (net.i2p.stat.Rate)3 RateStat (net.i2p.stat.RateStat)3 UpdateManager (net.i2p.update.UpdateManager)3