new tunnelcontrol commands: router.setBandwidthLimitKBps, router.getBandwidthLimitKBps, router.getBandwidthStats

This commit is contained in:
knaccc
2019-03-27 11:13:02 +00:00
parent dcfae751ca
commit a4d6161072
3 changed files with 43 additions and 4 deletions
+12
View File
@@ -163,6 +163,18 @@ specified host and port. Note that the base 32 I2P destination address determini
`tunnel-control.sh router.externalPort`
#### Set the bandwidth limit, measured in KBps. Returns "OK".
`tunnel-control.sh router.setBandwidthLimitKBps <KBps>`
#### Get the bandwidth limit, measured in KBps
`tunnel-control.sh router.getBandwidthLimitKBps`
#### Get bandwidth statistics. Returns a comma separated list of statistics, such as: 1sRateInKBps=12.34,1sRateOutKBps=12.34,5mRateInKBps=12.34,5mRateOutKBps=12.34,avgRateInKBps=12.34,avgRateOutKBps=12.34,totalInMB=12.34,totalOutMB=12.34
`tunnel-control.sh router.getBandwidthStats`
## Watch the I2P log for messages
@@ -183,6 +183,9 @@ public class RouterWrapper {
}
}
public int getBandwidthLimitKBps() {
return Integer.parseInt(routerProperties.get("i2np.inboundKBytesPerSecond").toString());
}
public void updateBandwidthLimitKBps(int n) {
routerProperties.put("i2np.inboundKBytesPerSecond", n);
@@ -24,10 +24,8 @@ import java.net.ServerSocket;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.Random;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
public class TunnelControl implements Runnable {
@@ -633,6 +631,32 @@ public class TunnelControl implements Runnable {
break;
}
case "router.setBandwidthLimitKBps": {
int n = Integer.parseInt(args[1]);
routerWrapper.updateBandwidthLimitKBps(n);
out.println("OK");
break;
}
case "router.getBandwidthLimitKBps": {
out.println(routerWrapper.getBandwidthLimitKBps());
break;
}
case "router.getBandwidthStats": {
Map<String, Double> stats = new HashMap<>();
stats.put("1sRateInKBps", routerWrapper.get1sRateInKBps());
stats.put("1sRateOutKBps", routerWrapper.get1sRateOutKBps());
stats.put("5mRateInKBps", routerWrapper.get5mRateInKBps());
stats.put("5mRateOutKBps", routerWrapper.get5mRateOutKBps());
stats.put("avgRateInKBps", routerWrapper.getAvgRateInKBps());
stats.put("avgRateOutKBps", routerWrapper.getAvgRateOutKBps());
stats.put("totalInMB", routerWrapper.getTotalInMB());
stats.put("totalOutMB", routerWrapper.getTotalOutMB());
out.println(stats.entrySet().stream().map(e->e.getKey()+"="+e.getValue()).collect(Collectors.joining(",")));
break;
}
case "sam.create": {
String[] samArgs = new String[]{"sam.keys", "127.0.0.1", "7656", "i2cp.tcp.host=127.0.0.1", "i2cp.tcp.port=7654"};
I2PAppContext context = routerWrapper.getRouter().getContext();