* Naming service, addressbook, susidns:

- Replace img hack for susidns requesting addressbook update
      with registration and request through the NamingService
This commit is contained in:
zzz
2011-03-15 23:16:44 +00:00
parent 12c5b9c21c
commit 0352ca3ef6
5 changed files with 66 additions and 8 deletions

View File

@@ -21,13 +21,18 @@
package net.i2p.addressbook;
import java.util.Properties;
import net.i2p.I2PAppContext;
import net.i2p.client.naming.NamingServiceUpdater;
/**
* A thread that waits five minutes, then runs the addressbook daemon.
*
* @author Ragnarok
*
*/
class DaemonThread extends Thread {
class DaemonThread extends Thread implements NamingServiceUpdater {
private String[] args;
@@ -49,11 +54,21 @@ class DaemonThread extends Thread {
// Thread.sleep(5 * 60 * 1000);
//} catch (InterruptedException exp) {
//}
I2PAppContext.getGlobalContext().namingService().registerUpdater(this);
Daemon.main(this.args);
I2PAppContext.getGlobalContext().namingService().unregisterUpdater(this);
}
public void halt() {
Daemon.stop();
interrupt();
}
/**
* The NamingServiceUpdater interface
* @since 0.8.6
*/
public void update(Properties options) {
interrupt();
}
}

View File

@@ -33,6 +33,7 @@ import java.io.IOException;
import java.io.PrintWriter;
import java.util.Properties;
import net.i2p.I2PAppContext;
import net.i2p.util.SecureFileOutputStream;
public class SubscriptionsBean
@@ -130,15 +131,19 @@ public class SubscriptionsBean
if (action.equals(_("Save"))) {
save();
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 + "\">";
*******/
if (content != null && content.length() > 2) {
message = _("Subscriptions saved, updating addressbook from subscription sources now.");
// + "<img height=\"1\" width=\"1\" alt=\"\" " +
// "src=\"/addressbook/?wakeup=1&nonce=" + nonce + "\">";
I2PAppContext.getGlobalContext().namingService().requestUpdate(null);
} else {
message = _("Subscriptions saved.");
}

View File

@@ -31,6 +31,7 @@ public abstract class NamingService {
private final static Log _log = new Log(NamingService.class);
protected final I2PAppContext _context;
protected final Set<NamingServiceListener> _listeners;
protected final Set<NamingServiceUpdater> _updaters;
/** what classname should be used as the naming service impl? */
public static final String PROP_IMPL = "i2p.naming.impl";
@@ -45,6 +46,7 @@ public abstract class NamingService {
protected NamingService(I2PAppContext context) {
_context = context;
_listeners = new CopyOnWriteArraySet();
_updaters = new CopyOnWriteArraySet();
}
/**
@@ -315,12 +317,15 @@ public abstract class NamingService {
}
/**
* Ask the NamingService to update its database
* Should this be a separate interface? This is what addressbook needs
* @param options NamingService-specific, can be null
* Ask any registered updaters to update now
* @param options NamingService- or updater-specific, may be null
* @since 0.8.5
*/
public void requestUpdate(Properties options) {}
public void requestUpdate(Properties options) {
for (NamingServiceUpdater nsu : _updaters) {
nsu.update(options);
}
}
/**
* @since 0.8.5
@@ -336,6 +341,20 @@ public abstract class NamingService {
_listeners.remove(nsl);
}
/**
* @since 0.8.6
*/
public void registerUpdater(NamingServiceUpdater nsu) {
_updaters.add(nsu);
}
/**
* @since 0.8.6
*/
public void unregisterUpdater(NamingServiceUpdater nsu) {
_updaters.remove(nsu);
}
/**
* Same as lookup(hostname) but with in and out options
* Note that whether this (and lookup(hostname)) resolve B32 addresses is

View File

@@ -4,6 +4,9 @@ import java.util.Properties;
import net.i2p.data.Destination;
/**
* @since 0.8.6
*/
public interface NamingServiceListener {
/** also called when a NamingService is added or removed */

View File

@@ -0,0 +1,16 @@
package net.i2p.client.naming;
import java.util.Properties;
/**
* @since 0.8.6
*/
public interface NamingServiceUpdater {
/**
* Should not block.
* @param options Updater-specific, may be null
*/
public void update(Properties options);
}