forked from I2P_Developers/i2p.i2p
* Naming service, addressbook, susidns:
- Replace img hack for susidns requesting addressbook update with registration and request through the NamingService
This commit is contained in:
@@ -21,13 +21,18 @@
|
|||||||
|
|
||||||
package net.i2p.addressbook;
|
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.
|
* A thread that waits five minutes, then runs the addressbook daemon.
|
||||||
*
|
*
|
||||||
* @author Ragnarok
|
* @author Ragnarok
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class DaemonThread extends Thread {
|
class DaemonThread extends Thread implements NamingServiceUpdater {
|
||||||
|
|
||||||
private String[] args;
|
private String[] args;
|
||||||
|
|
||||||
@@ -49,11 +54,21 @@ class DaemonThread extends Thread {
|
|||||||
// Thread.sleep(5 * 60 * 1000);
|
// Thread.sleep(5 * 60 * 1000);
|
||||||
//} catch (InterruptedException exp) {
|
//} catch (InterruptedException exp) {
|
||||||
//}
|
//}
|
||||||
|
I2PAppContext.getGlobalContext().namingService().registerUpdater(this);
|
||||||
Daemon.main(this.args);
|
Daemon.main(this.args);
|
||||||
|
I2PAppContext.getGlobalContext().namingService().unregisterUpdater(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void halt() {
|
public void halt() {
|
||||||
Daemon.stop();
|
Daemon.stop();
|
||||||
interrupt();
|
interrupt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The NamingServiceUpdater interface
|
||||||
|
* @since 0.8.6
|
||||||
|
*/
|
||||||
|
public void update(Properties options) {
|
||||||
|
interrupt();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -33,6 +33,7 @@ import java.io.IOException;
|
|||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
|
import net.i2p.I2PAppContext;
|
||||||
import net.i2p.util.SecureFileOutputStream;
|
import net.i2p.util.SecureFileOutputStream;
|
||||||
|
|
||||||
public class SubscriptionsBean
|
public class SubscriptionsBean
|
||||||
@@ -130,15 +131,19 @@ public class SubscriptionsBean
|
|||||||
if (action.equals(_("Save"))) {
|
if (action.equals(_("Save"))) {
|
||||||
save();
|
save();
|
||||||
String nonce = System.getProperty("addressbook.nonce");
|
String nonce = System.getProperty("addressbook.nonce");
|
||||||
|
/*******
|
||||||
if (nonce != null) {
|
if (nonce != null) {
|
||||||
// Yes this is a hack.
|
// Yes this is a hack.
|
||||||
// No it doesn't work on a text-mode browser.
|
// No it doesn't work on a text-mode browser.
|
||||||
// Fetching from the addressbook servlet
|
// Fetching from the addressbook servlet
|
||||||
// with the correct parameters will kick off a
|
// with the correct parameters will kick off a
|
||||||
// config reload and fetch.
|
// config reload and fetch.
|
||||||
message = _("Subscriptions saved, updating addressbook from subscription sources now.") +
|
*******/
|
||||||
"<img height=\"1\" width=\"1\" alt=\"\" " +
|
if (content != null && content.length() > 2) {
|
||||||
"src=\"/addressbook/?wakeup=1&nonce=" + nonce + "\">";
|
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 {
|
} else {
|
||||||
message = _("Subscriptions saved.");
|
message = _("Subscriptions saved.");
|
||||||
}
|
}
|
||||||
|
@@ -31,6 +31,7 @@ public abstract class NamingService {
|
|||||||
private final static Log _log = new Log(NamingService.class);
|
private final static Log _log = new Log(NamingService.class);
|
||||||
protected final I2PAppContext _context;
|
protected final I2PAppContext _context;
|
||||||
protected final Set<NamingServiceListener> _listeners;
|
protected final Set<NamingServiceListener> _listeners;
|
||||||
|
protected final Set<NamingServiceUpdater> _updaters;
|
||||||
|
|
||||||
/** what classname should be used as the naming service impl? */
|
/** what classname should be used as the naming service impl? */
|
||||||
public static final String PROP_IMPL = "i2p.naming.impl";
|
public static final String PROP_IMPL = "i2p.naming.impl";
|
||||||
@@ -45,6 +46,7 @@ public abstract class NamingService {
|
|||||||
protected NamingService(I2PAppContext context) {
|
protected NamingService(I2PAppContext context) {
|
||||||
_context = context;
|
_context = context;
|
||||||
_listeners = new CopyOnWriteArraySet();
|
_listeners = new CopyOnWriteArraySet();
|
||||||
|
_updaters = new CopyOnWriteArraySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -315,12 +317,15 @@ public abstract class NamingService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ask the NamingService to update its database
|
* Ask any registered updaters to update now
|
||||||
* Should this be a separate interface? This is what addressbook needs
|
* @param options NamingService- or updater-specific, may be null
|
||||||
* @param options NamingService-specific, can be null
|
|
||||||
* @since 0.8.5
|
* @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
|
* @since 0.8.5
|
||||||
@@ -336,6 +341,20 @@ public abstract class NamingService {
|
|||||||
_listeners.remove(nsl);
|
_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
|
* Same as lookup(hostname) but with in and out options
|
||||||
* Note that whether this (and lookup(hostname)) resolve B32 addresses is
|
* Note that whether this (and lookup(hostname)) resolve B32 addresses is
|
||||||
|
@@ -4,6 +4,9 @@ import java.util.Properties;
|
|||||||
|
|
||||||
import net.i2p.data.Destination;
|
import net.i2p.data.Destination;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @since 0.8.6
|
||||||
|
*/
|
||||||
public interface NamingServiceListener {
|
public interface NamingServiceListener {
|
||||||
|
|
||||||
/** also called when a NamingService is added or removed */
|
/** also called when a NamingService is added or removed */
|
||||||
|
@@ -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);
|
||||||
|
}
|
||||||
|
|
Reference in New Issue
Block a user