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

Skip to content
Snippets Groups Projects
Commit 4b6989ef authored by zzz's avatar zzz
Browse files

* Addressbook, susidns: Rework addressbook into a

      HttpServlet, so susidns can kick it when the subscription
      list changes
parent c10ea84a
No related branches found
No related tags found
No related merge requests found
......@@ -21,24 +21,43 @@
package net.i2p.addressbook;
import javax.servlet.GenericServlet;
import java.util.Random;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* A wrapper for addressbook to allow it to be started as a web application.
*
* This was a GenericServlet, we make it an HttpServlet solely to provide a hook
* for SusiDNS to wake us up when the subscription list changes.
*
* @author Ragnarok
*
*/
public class Servlet extends GenericServlet {
public class Servlet extends HttpServlet {
private Thread _thread;
private String _nonce;
private static final String PROP_NONCE = "addressbook.nonce";
/* (non-Javadoc)
* @see javax.servlet.Servlet#service(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
/**
* Hack to allow susidns to kick the daemon when the subscription list changes.
* URL must be /addressbook/ with wakeup param set, and nonce param set from system property.
*
* (non-Javadoc)
* see javax.servlet.Servlet#service(javax.servlet.ServletRequest, javax.servlet.ServletResponse)
*/
public void service(ServletRequest request, ServletResponse response) {
public void service(HttpServletRequest request, HttpServletResponse response) {
//System.err.println("Got request nonce = " + request.getParameter("nonce"));
if (_thread != null && request.getParameter("wakeup") != null &&
_nonce != null && _nonce.equals(request.getParameter("nonce"))) {
//System.err.println("Sending interrupt");
_thread.interrupt();
}
// no output
}
/* (non-Javadoc)
......@@ -49,15 +68,19 @@ public class Servlet extends GenericServlet {
try {
super.init(config);
} catch (ServletException exp) {
System.err.println("Addressbook init exception: " + exp);
}
_nonce = "" + Math.abs((new Random()).nextLong());
// put the nonce where susidns can get it
System.setProperty(PROP_NONCE, _nonce);
String[] args = new String[1];
args[0] = config.getInitParameter("home");
DaemonThread thread = new DaemonThread(args);
thread.setDaemon(true);
thread.setName("Addressbook");
thread.start();
_thread = new DaemonThread(args);
_thread.setDaemon(true);
_thread.setName("Addressbook");
_thread.start();
System.out.println("INFO: Starting Addressbook " + Daemon.VERSION);
System.out.println("INFO: config root under " + args[0]);
//System.out.println("INFO: config root under " + args[0]);
}
}
......@@ -13,4 +13,10 @@
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>addressbook</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
</web-app>
......@@ -128,7 +128,19 @@ public class SubscriptionsBean
if( lastSerial != null && serial != null && serial.compareTo( lastSerial ) == 0 ) {
if( action.compareToIgnoreCase( "save") == 0 ) {
save();
message = "Subscriptions saved.";
String nonce = System.getProperty("addressbook.nonce");
if (nonce != null) {
// Yes this is a hack.
// No it doesn't work on a text-mode browser.
// Fetching from the addressbook servlet
// with the correct parameters will kick off a
// config reload and fetch.
message = "Subscriptions saved, updating addressbook from subscription sources now." +
"<img height=\"1\" width=\"1\" alt=\"\" " +
"src=\"/addressbook/?wakeup=1&nonce=" + nonce + "\">";
} else {
message = "Subscriptions saved.";
}
}
else if( action.compareToIgnoreCase( "reload") == 0 ) {
reload();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment