Implement UDP start/stop

Add UDP config, default false
Change UDP port
This commit is contained in:
zzz
2025-04-25 11:57:51 -04:00
parent 8ff2c93b0a
commit e157028db4
3 changed files with 29 additions and 10 deletions

View File

@ -5,6 +5,10 @@
# minimum 900 (15 minutes), maximum 21600 (6 hours)
interval=1620
#
# Enable UDP announces
# default false
udp=false
#
# UDP connection lifetime in seconds
# minimum 60 (1 minute), maximum 21600 (6 hours)
lifetime=1200

View File

@ -52,11 +52,11 @@ public class UDPHandler implements I2PSessionMuxedListener {
// conn ID to dest and time added
private final Map<Long, DestAndTime> _connectCache;
private final Cleaner _cleaner;
private volatile boolean _running;
// The listen port.
// We listen on all ports, so the announce URL
// doesn't need a port.
public static final int PORT = I2PSession.PORT_ANY;
// Not configurable.
public static final int PORT = 6969;
private static final long MAGIC = 0x41727101980L;
private static final int ACTION_CONNECT = 0;
private static final int ACTION_ANNOUNCE = 1;
@ -82,12 +82,21 @@ public class UDPHandler implements I2PSessionMuxedListener {
}
public void start() {
_running = true;
(new I2PAppThread(new Waiter(), "ZzzOT UDP startup", true)).start();
}
/**
* @since 0.20.0
*/
public void stop() {
_running = false;
_cleaner.cancel();
}
private class Waiter implements Runnable {
public void run() {
while (true) {
while (_running) {
// requires I2P 0.9.53 (1.7.0)
List<I2PSession> sessions = _tunnel.getSessions();
if (sessions.isEmpty()) {

View File

@ -70,6 +70,8 @@ public class ZzzOTController implements ClientApp {
private static boolean _showfooter;
private static String _footertext;
private static boolean _fullScrape;
private final boolean _enableUDP;
private UDPHandler _udp;
private ClientAppState _state = UNINITIALIZED;
@ -83,6 +85,8 @@ public class ZzzOTController implements ClientApp {
private static final String PROP_FOOTERTEXT = "footertext";
private static final String PROP_FULLSCRAPE = "allowFullScrape";
private static final String DEFAULT_FULLSCRAPE = "false";
private static final String PROP_UDP = "udp";
private static final String DEFAULT_UDP = "false";
private static final String CONFIG_FILE = "zzzot.config";
private static final String BACKUP_SUFFIX = ".jetty8";
private static final String[] xmlFiles = {
@ -114,6 +118,7 @@ public class ZzzOTController implements ClientApp {
_showfooter = Boolean.parseBoolean(props.getProperty(PROP_SHOWFOOTER, DEFAULT_SHOWFOOTER));
_footertext = props.getProperty(PROP_FOOTERTEXT, DEFAULT_FOOTERTEXT);
_fullScrape = Boolean.parseBoolean(props.getProperty(PROP_FULLSCRAPE, DEFAULT_FULLSCRAPE));
_enableUDP = Boolean.parseBoolean(props.getProperty(PROP_UDP, DEFAULT_UDP));
_state = INITIALIZED;
}
@ -186,12 +191,11 @@ public class ZzzOTController implements ClientApp {
startJetty(pluginDir, dest);
startI2PTunnel(pluginDir, dest);
_zzzot.start();
/*
// requires I2P 0.9.53 (1.7.0)
UDPHandler udp = new UDPHandler(_context, _tunnel.getTunnel(), _zzzot);
udp.start();
*/
// SeedlessAnnouncer.announce(_tunnel);
// requires I2P 0.9.66 (2.9.0)
if (_enableUDP) {
_udp = new UDPHandler(_context, _tunnel.getTunnel(), _zzzot);
_udp.start();
}
}
@ -247,6 +251,8 @@ public class ZzzOTController implements ClientApp {
private void stop() {
stopI2PTunnel();
stopJetty();
if (_udp != null)
_udp.stop();
_zzzot.stop();
}