Moved API to only exist in the Authenticate message.
Added new graph trackers for using the new RouterInfo features for more resent bw/part. tunnels stats. Added class handling versions.
This commit is contained in:
15
src/net/i2p/itoopie/ItoopieVersion.java
Normal file
15
src/net/i2p/itoopie/ItoopieVersion.java
Normal file
@ -0,0 +1,15 @@
|
||||
package net.i2p.itoopie;
|
||||
|
||||
/**
|
||||
* Defines version of utilized I2PControl API and version of itoopie.
|
||||
* @author hottuna
|
||||
*
|
||||
*/
|
||||
public class ItoopieVersion {
|
||||
|
||||
/** Version of itoopie */
|
||||
public static final String VERSION = "0.0.1";
|
||||
|
||||
/** Version of the I2PControl API implemented */
|
||||
public static final int I2PCONTROL_API_VERSION = 1;
|
||||
}
|
@ -22,9 +22,8 @@ import java.text.SimpleDateFormat;
|
||||
import javax.swing.JFrame;
|
||||
|
||||
import net.i2p.itoopie.configuration.ConfigurationManager;
|
||||
import net.i2p.itoopie.gui.component.chart.BandwidthTracker;
|
||||
import net.i2p.itoopie.gui.component.chart.DummyDataCollector;
|
||||
import net.i2p.itoopie.gui.component.chart.RateStatTracker;
|
||||
import net.i2p.itoopie.gui.component.chart.InboundBandwidthTracker;
|
||||
import net.i2p.itoopie.gui.component.chart.OutboundBandwidthTracker;
|
||||
import net.i2p.itoopie.gui.component.chart.ObjRecorder2Trace2DAdapter;
|
||||
import net.i2p.itoopie.i18n.Transl;
|
||||
|
||||
@ -73,9 +72,9 @@ public class BandwidthChart {
|
||||
// force ranges:
|
||||
chart.getAxisY().setRangePolicy(new RangePolicyMinimumViewport(new Range(0, 5)));
|
||||
|
||||
new ObjRecorder2Trace2DAdapter(dataBWOut, new BandwidthTracker("bw.sendRate", 60*1000L), "m_value", updateInterval);
|
||||
new ObjRecorder2Trace2DAdapter(dataBWOut, new InboundBandwidthTracker(), "m_value", updateInterval);
|
||||
// new ObjRecorder2Trace2DAdapter(dataBWIn, new DummyDataCollector(0.5, 1000), "m_number", updateInterval);
|
||||
new ObjRecorder2Trace2DAdapter(dataBWIn, new BandwidthTracker("bw.recvRate", 60*1000L), "m_value", updateInterval);
|
||||
new ObjRecorder2Trace2DAdapter(dataBWIn, new OutboundBandwidthTracker(), "m_value", updateInterval);
|
||||
// new ObjRecorder2Trace2DAdapter(dataBWOut, new DummyDataCollector(0.5, 1000), "m_number", updateInterval);
|
||||
return chart;
|
||||
}
|
||||
|
@ -22,8 +22,7 @@ import java.text.SimpleDateFormat;
|
||||
import javax.swing.JFrame;
|
||||
|
||||
import net.i2p.itoopie.configuration.ConfigurationManager;
|
||||
import net.i2p.itoopie.gui.component.chart.DummyDataCollector;
|
||||
import net.i2p.itoopie.gui.component.chart.RateStatTracker;
|
||||
import net.i2p.itoopie.gui.component.chart.ParticipatingTunnelsTracker;
|
||||
import net.i2p.itoopie.gui.component.chart.ObjRecorder2Trace2DAdapter;
|
||||
import net.i2p.itoopie.i18n.Transl;
|
||||
|
||||
@ -64,7 +63,7 @@ public class ParticipatingTunnelsChart {
|
||||
// force ranges:
|
||||
chart.getAxisY().setRangePolicy(new RangePolicyMinimumViewport(new Range(0, 20)));
|
||||
|
||||
new ObjRecorder2Trace2DAdapter(dataPartTunnels, new RateStatTracker("tunnel.participatingTunnels", 60*1000L), "m_value", updateInterval);
|
||||
new ObjRecorder2Trace2DAdapter(dataPartTunnels, new ParticipatingTunnelsTracker(), "m_value", updateInterval);
|
||||
//new ObjRecorder2Trace2DAdapter(dataPartTunnels, new DummyDataCollector(0.5, 1000), "m_number", updateInterval);
|
||||
return chart;
|
||||
}
|
||||
|
@ -1,13 +1,18 @@
|
||||
package net.i2p.itoopie.gui.component.chart;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.thetransactioncompany.jsonrpc2.client.JSONRPC2SessionException;
|
||||
|
||||
import net.i2p.itoopie.configuration.ConfigurationManager;
|
||||
import net.i2p.itoopie.i2pcontrol.InvalidParametersException;
|
||||
import net.i2p.itoopie.i2pcontrol.InvalidPasswordException;
|
||||
import net.i2p.itoopie.i2pcontrol.methods.GetRateStat;
|
||||
import net.i2p.itoopie.i2pcontrol.methods.GetRouterInfo;
|
||||
import net.i2p.itoopie.i2pcontrol.methods.RouterInfo.ROUTER_INFO;
|
||||
|
||||
public class BandwidthTracker extends Thread {
|
||||
public class InboundBandwidthTracker extends Thread {
|
||||
|
||||
private static ConfigurationManager _conf = ConfigurationManager.getInstance();
|
||||
/** Last read bw */
|
||||
@ -17,19 +22,11 @@ public class BandwidthTracker extends Thread {
|
||||
private final static int DEFAULT_UPDATE_INTERVAL = 100; // Update every 100th ms
|
||||
|
||||
private int updateInterval = _conf.getConf("graph.updateinterval", DEFAULT_UPDATE_INTERVAL);
|
||||
|
||||
/** Which RateStat to measure from the router */
|
||||
private String rateStat;
|
||||
|
||||
/** Which period of a stat to measure */
|
||||
private long period;
|
||||
|
||||
/**
|
||||
* Start daemon that checks to current inbound bandwidth of the router.
|
||||
*/
|
||||
public BandwidthTracker(String rateStat, long period) {
|
||||
this.rateStat = rateStat;
|
||||
this.period = period;
|
||||
public InboundBandwidthTracker() {
|
||||
this.setDaemon(true);
|
||||
this.start();
|
||||
}
|
||||
@ -39,13 +36,14 @@ public class BandwidthTracker extends Thread {
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
EnumMap<ROUTER_INFO, Object> em;
|
||||
while (true) {
|
||||
try {
|
||||
m_value = GetRateStat.execute(rateStat, period) / 1024; //Bytes -> KBytes
|
||||
em = GetRouterInfo.execute(ROUTER_INFO.BW_INBOUND_1S);
|
||||
double dbl = (Double) em.get(ROUTER_INFO.BW_INBOUND_1S);
|
||||
m_value = dbl / 1024; //Bytes -> KBytes
|
||||
} catch (InvalidPasswordException e) {
|
||||
} catch (JSONRPC2SessionException e) {
|
||||
} catch (InvalidParametersException e) {
|
||||
}
|
||||
|
||||
try {
|
@ -0,0 +1,57 @@
|
||||
package net.i2p.itoopie.gui.component.chart;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.thetransactioncompany.jsonrpc2.client.JSONRPC2SessionException;
|
||||
|
||||
import net.i2p.itoopie.configuration.ConfigurationManager;
|
||||
import net.i2p.itoopie.i2pcontrol.InvalidParametersException;
|
||||
import net.i2p.itoopie.i2pcontrol.InvalidPasswordException;
|
||||
import net.i2p.itoopie.i2pcontrol.methods.GetRateStat;
|
||||
import net.i2p.itoopie.i2pcontrol.methods.GetRouterInfo;
|
||||
import net.i2p.itoopie.i2pcontrol.methods.RouterInfo.ROUTER_INFO;
|
||||
|
||||
public class OutboundBandwidthTracker extends Thread {
|
||||
|
||||
private static ConfigurationManager _conf = ConfigurationManager.getInstance();
|
||||
/** Last read bw */
|
||||
private double m_value = 0;
|
||||
|
||||
/** Poll router for current ratestat every updateInterval seconds */
|
||||
private final static int DEFAULT_UPDATE_INTERVAL = 100; // Update every 100th ms
|
||||
|
||||
private int updateInterval = _conf.getConf("graph.updateinterval", DEFAULT_UPDATE_INTERVAL);
|
||||
|
||||
/**
|
||||
* Start daemon that checks to current inbound bandwidth of the router.
|
||||
*/
|
||||
public OutboundBandwidthTracker() {
|
||||
this.setDaemon(true);
|
||||
this.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Runnable#run()
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
EnumMap<ROUTER_INFO, Object> em;
|
||||
while (true) {
|
||||
try {
|
||||
em = GetRouterInfo.execute(ROUTER_INFO.BW_OUTBOUND_1S);
|
||||
double dbl = (Double) em.get(ROUTER_INFO.BW_OUTBOUND_1S);
|
||||
m_value = dbl / 1024; //Bytes -> KBytes
|
||||
} catch (InvalidPasswordException e) {
|
||||
} catch (JSONRPC2SessionException e) {
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(updateInterval);
|
||||
} catch (InterruptedException e) {
|
||||
// nop
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,57 @@
|
||||
package net.i2p.itoopie.gui.component.chart;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.thetransactioncompany.jsonrpc2.client.JSONRPC2SessionException;
|
||||
|
||||
import net.i2p.itoopie.configuration.ConfigurationManager;
|
||||
import net.i2p.itoopie.i2pcontrol.InvalidParametersException;
|
||||
import net.i2p.itoopie.i2pcontrol.InvalidPasswordException;
|
||||
import net.i2p.itoopie.i2pcontrol.methods.GetRateStat;
|
||||
import net.i2p.itoopie.i2pcontrol.methods.GetRouterInfo;
|
||||
import net.i2p.itoopie.i2pcontrol.methods.RouterInfo.ROUTER_INFO;
|
||||
|
||||
public class ParticipatingTunnelsTracker extends Thread {
|
||||
|
||||
private static ConfigurationManager _conf = ConfigurationManager.getInstance();
|
||||
/** Last read bw */
|
||||
private double m_value = 0;
|
||||
|
||||
/** Poll router for current ratestat every updateInterval seconds */
|
||||
private final static int DEFAULT_UPDATE_INTERVAL = 100; // Update every 100th ms
|
||||
|
||||
private int updateInterval = _conf.getConf("graph.updateinterval", DEFAULT_UPDATE_INTERVAL);
|
||||
|
||||
/**
|
||||
* Start daemon that checks to current inbound bandwidth of the router.
|
||||
*/
|
||||
public ParticipatingTunnelsTracker() {
|
||||
this.setDaemon(true);
|
||||
this.start();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see java.lang.Runnable#run()
|
||||
*/
|
||||
@Override
|
||||
public void run() {
|
||||
EnumMap<ROUTER_INFO, Object> em;
|
||||
while (true) {
|
||||
try {
|
||||
em = GetRouterInfo.execute(ROUTER_INFO.TUNNELS_PARTICIPATING);
|
||||
Long nbr = (Long) em.get(ROUTER_INFO.TUNNELS_PARTICIPATING);
|
||||
m_value = nbr.doubleValue();
|
||||
} catch (InvalidPasswordException e) {
|
||||
} catch (JSONRPC2SessionException e) {
|
||||
}
|
||||
|
||||
try {
|
||||
Thread.sleep(updateInterval);
|
||||
} catch (InterruptedException e) {
|
||||
// nop
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
12
src/net/i2p/itoopie/i2pcontrol/InvalidI2PControlAPI.java
Normal file
12
src/net/i2p/itoopie/i2pcontrol/InvalidI2PControlAPI.java
Normal file
@ -0,0 +1,12 @@
|
||||
package net.i2p.itoopie.i2pcontrol;
|
||||
|
||||
public class InvalidI2PControlAPI extends Exception {
|
||||
|
||||
private static final long serialVersionUID = -8120904521634957457L;
|
||||
|
||||
|
||||
public InvalidI2PControlAPI(String msg){
|
||||
super(msg);
|
||||
}
|
||||
|
||||
}
|
@ -78,7 +78,6 @@ public class JSONRPC2Interface {
|
||||
}
|
||||
HashMap outParams = (HashMap) req.getParams();
|
||||
outParams.put("Token", token); // Add authentication token
|
||||
outParams.put("API", ItoopieVersion.I2PCONTROL_API_VERSION);
|
||||
req.setParams(outParams);
|
||||
|
||||
JSONRPC2Response resp = null;
|
||||
|
@ -6,6 +6,7 @@ import java.util.Map;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import net.i2p.itoopie.ItoopieVersion;
|
||||
import net.i2p.itoopie.configuration.ConfigurationManager;
|
||||
import net.i2p.itoopie.i2pcontrol.InvalidParametersException;
|
||||
import net.i2p.itoopie.i2pcontrol.InvalidPasswordException;
|
||||
@ -28,6 +29,7 @@ public class Authenticate {
|
||||
Map outParams = new HashMap();
|
||||
outParams.put("Password",
|
||||
_conf.getConf("server.password", _conf.getConf("server.password", DEFAULT_PASSWORD)));
|
||||
outParams.put("API", ItoopieVersion.I2PCONTROL_API_VERSION);
|
||||
req.setParams(outParams);
|
||||
|
||||
JSONRPC2Response resp = null;
|
||||
|
Reference in New Issue
Block a user