I2P Address: [http://git.idk.i2p]

Skip to content
Snippets Groups Projects
Commit e22cb624 authored by jrandom's avatar jrandom Committed by zzz
Browse files

handle /setTime?blah&now=yyyyMMdd_HH:mm:ss.SSSS (updating the router's clock)

yes, we'll want to filter the access to the admin manager ;)
parent e923aa1f
No related branches found
No related tags found
No related merge requests found
...@@ -8,6 +8,9 @@ import java.io.OutputStream; ...@@ -8,6 +8,9 @@ import java.io.OutputStream;
import java.net.Socket; import java.net.Socket;
import java.util.Iterator; import java.util.Iterator;
import java.util.Set; import java.util.Set;
import java.util.Locale;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import net.i2p.data.Hash; import net.i2p.data.Hash;
import net.i2p.router.Router; import net.i2p.router.Router;
...@@ -48,6 +51,9 @@ class AdminRunner implements Runnable { ...@@ -48,6 +51,9 @@ class AdminRunner implements Runnable {
reply(out, _generator.generateStatsPage()); reply(out, _generator.generateStatsPage());
} else if (command.indexOf("/profile/") >= 0) { } else if (command.indexOf("/profile/") >= 0) {
replyText(out, getProfile(command)); replyText(out, getProfile(command));
} else if (command.indexOf("setTime") >= 0) {
setTime(command);
reply(out, "<html><body>Time updated</body></html>");
} else if (true || command.indexOf("routerConsole.html") > 0) { } else if (true || command.indexOf("routerConsole.html") > 0) {
reply(out, _context.router().renderStatusHTML()); reply(out, _context.router().renderStatusHTML());
} }
...@@ -105,4 +111,30 @@ class AdminRunner implements Runnable { ...@@ -105,4 +111,30 @@ class AdminRunner implements Runnable {
return "No such peer is being profiled\n"; return "No such peer is being profiled\n";
} }
private static final String FORMAT_STRING = "yyyyMMdd_HH:mm:ss.SSS";
private SimpleDateFormat _fmt = new SimpleDateFormat(FORMAT_STRING, Locale.UK);
private long getTime(String now) throws ParseException {
synchronized (_fmt) {
return _fmt.parse(now).getTime();
}
}
private void setTime(String cmd) {
int start = cmd.indexOf("now=");
String str = cmd.substring(start + 4, start+4+FORMAT_STRING.length());
try {
long now = getTime(str);
if (_log.shouldLog(Log.INFO))
_log.log(Log.INFO, "Admin time set to " + str);
setTime(now);
} catch (ParseException pe) {
_log.error("Invalid time specified [" + str + "]", pe);
}
}
private void setTime(long now) {
_context.clock().setNow(now);
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment