forked from I2P_Developers/i2p.i2p
Console: Add indication of current ff status on /configadvanced,
change immediately when config changes, force republish Router: RI rebuild locking
This commit is contained in:
@ -7,6 +7,7 @@ import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import net.i2p.data.DataHelper;
|
||||
import net.i2p.router.networkdb.kademlia.FloodfillNetworkDatabaseFacade;
|
||||
|
||||
/**
|
||||
* Handler to deal with form submissions from the advanced config form and act
|
||||
@ -83,6 +84,14 @@ public class ConfigAdvancedHandler extends FormHandler {
|
||||
/** @since 0.9.20 */
|
||||
private void saveFF() {
|
||||
boolean saved = _context.router().saveConfig(ConfigAdvancedHelper.PROP_FLOODFILL_PARTICIPANT, _ff);
|
||||
if (_ff.equals("false") || _ff.equals("true")) {
|
||||
FloodfillNetworkDatabaseFacade fndf = (FloodfillNetworkDatabaseFacade) _context.netDb();
|
||||
boolean wasFF = fndf.floodfillEnabled();
|
||||
boolean isFF = _ff.equals("true");
|
||||
fndf.setFloodfillEnabled(isFF);
|
||||
if (wasFF != isFF)
|
||||
_context.router().rebuildRouterInfo();
|
||||
}
|
||||
if (saved)
|
||||
addFormNotice(_("Configuration saved successfully"));
|
||||
else
|
||||
|
@ -35,4 +35,9 @@ public class ConfigAdvancedHelper extends HelperBase {
|
||||
return CHECKED;
|
||||
return "";
|
||||
}
|
||||
|
||||
/** @since 0.9.21 */
|
||||
public boolean isFloodfill() {
|
||||
return _context.netDb().floodfillEnabled();
|
||||
}
|
||||
}
|
||||
|
@ -25,7 +25,16 @@
|
||||
<div class="configure">
|
||||
<div class="wideload">
|
||||
<h3><%=intl._("Floodfill Configuration")%></h3>
|
||||
<p><%=intl._("Floodill participation helps the network, but may use more of your computer's resources.")%></p>
|
||||
<p><%=intl._("Floodill participation helps the network, but may use more of your computer's resources.")%>
|
||||
</p><p>
|
||||
<%
|
||||
if (advancedhelper.isFloodfill()) {
|
||||
%><%=intl._("This router is currently a floodfill participant.")%><%
|
||||
} else {
|
||||
%><%=intl._("This router is not currently a floodfill participant.")%><%
|
||||
}
|
||||
%>
|
||||
</p>
|
||||
<form action="" method="POST">
|
||||
<input type="hidden" name="nonce" value="<%=pageNonce%>" >
|
||||
<input type="hidden" name="action" value="ff" >
|
||||
|
@ -72,6 +72,7 @@ public class Router implements RouterClock.ClockShiftListener {
|
||||
/** full path */
|
||||
private String _configFilename;
|
||||
private RouterInfo _routerInfo;
|
||||
private final Object _routerInfoLock = new Object();
|
||||
/** not for external use */
|
||||
public final Object routerInfoFileLock = new Object();
|
||||
private final Object _configFileLock = new Object();
|
||||
@ -489,14 +490,20 @@ public class Router implements RouterClock.ClockShiftListener {
|
||||
* Our current router info.
|
||||
* Warning, may be null if called very early.
|
||||
*/
|
||||
public RouterInfo getRouterInfo() { return _routerInfo; }
|
||||
public RouterInfo getRouterInfo() {
|
||||
synchronized (_routerInfoLock) {
|
||||
return _routerInfo;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Caller must ensure info is valid - no validation done here.
|
||||
* Not for external use.
|
||||
*/
|
||||
public void setRouterInfo(RouterInfo info) {
|
||||
synchronized (_routerInfoLock) {
|
||||
_routerInfo = info;
|
||||
}
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info("setRouterInfo() : " + info, new Exception("I did it"));
|
||||
if (info != null)
|
||||
@ -817,7 +824,17 @@ public class Router implements RouterClock.ClockShiftListener {
|
||||
public void rebuildRouterInfo(boolean blockingRebuild) {
|
||||
if (_log.shouldLog(Log.INFO))
|
||||
_log.info("Rebuilding new routerInfo");
|
||||
synchronized (_routerInfoLock) {
|
||||
locked_rebuildRouterInfo(blockingRebuild);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Rebuild and republish our routerInfo since something significant
|
||||
* has changed.
|
||||
*/
|
||||
private void locked_rebuildRouterInfo(boolean blockingRebuild) {
|
||||
RouterInfo ri = null;
|
||||
if (_routerInfo != null)
|
||||
ri = new RouterInfo(_routerInfo);
|
||||
@ -957,7 +974,10 @@ public class Router implements RouterClock.ClockShiftListener {
|
||||
}
|
||||
|
||||
public boolean isHidden() {
|
||||
RouterInfo ri = _routerInfo;
|
||||
RouterInfo ri;
|
||||
synchronized (_routerInfoLock) {
|
||||
ri = _routerInfo;
|
||||
}
|
||||
if ( (ri != null) && (ri.isHidden()) )
|
||||
return true;
|
||||
String h = _context.getProperty(PROP_HIDDEN_HIDDEN);
|
||||
|
@ -277,7 +277,7 @@ public class FloodfillNetworkDatabaseFacade extends KademliaNetworkDatabaseFacad
|
||||
@Override
|
||||
protected PeerSelector createPeerSelector() { return new FloodfillPeerSelector(_context); }
|
||||
|
||||
synchronized void setFloodfillEnabled(boolean yes) {
|
||||
public synchronized void setFloodfillEnabled(boolean yes) {
|
||||
_floodfillEnabled = yes;
|
||||
if (yes && _floodThrottler == null) {
|
||||
_floodThrottler = new FloodThrottler();
|
||||
|
Reference in New Issue
Block a user