diff --git a/.gitignore b/.gitignore index 63acbef..a3cb010 100644 --- a/.gitignore +++ b/.gitignore @@ -15,5 +15,7 @@ buildNumber.properties .project # JDT-specific (Eclipse Java Development Tools) .classpath -# Log files +# retracker runtime files log/ +config.json +retracker.pid diff --git a/.settings/org.eclipse.core.resources.prefs b/.settings/org.eclipse.core.resources.prefs index f9fe345..839d647 100644 --- a/.settings/org.eclipse.core.resources.prefs +++ b/.settings/org.eclipse.core.resources.prefs @@ -1,4 +1,5 @@ eclipse.preferences.version=1 encoding//src/main/java=UTF-8 +encoding//src/main/resources=UTF-8 encoding//src/test/java=UTF-8 encoding/=UTF-8 diff --git a/notes.txt b/notes.txt index fcf3374..ec7c64f 100644 --- a/notes.txt +++ b/notes.txt @@ -12,7 +12,9 @@ on successful peer list retrieval - local tracker cache updated. If not, peers f On re-announce to destination trackers, proxied peer's real IP must be injected into announce request and other parameters should remain same as in original request. - +Whether retracker exposes its cache as tracker or not, the local tracker data shall be present all time. +When there is need to expose local tracker a tracker endpoint should be declare in config. Tracker endpoint +is HTTP or UDP server responsing to BitTorrent announces just like if it was any other regular torrent tracker. Maven exec with args: diff --git a/pom.xml b/pom.xml index 74a7554..2e5c608 100644 --- a/pom.xml +++ b/pom.xml @@ -60,6 +60,16 @@ logback-classic 1.5.11 + + com.fasterxml.jackson.core + jackson-core + 2.18.0 + + + com.fasterxml.jackson.core + jackson-databind + 2.18.0 + diff --git a/src/main/java/com/mykola2312/retracker/App.java b/src/main/java/com/mykola2312/retracker/App.java index 8223a6b..5d9e07d 100644 --- a/src/main/java/com/mykola2312/retracker/App.java +++ b/src/main/java/com/mykola2312/retracker/App.java @@ -1,6 +1,7 @@ package com.mykola2312.retracker; import java.io.File; +import java.io.IOException; import java.nio.file.Path; import org.apache.commons.cli.CommandLine; @@ -11,6 +12,8 @@ import org.apache.commons.cli.ParseException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.mykola2312.retracker.config.Config; + import ch.qos.logback.classic.Level; import ch.qos.logback.classic.LoggerContext; import ch.qos.logback.classic.encoder.PatternLayoutEncoder; @@ -21,9 +24,11 @@ public class App { private static final Logger log = LoggerFactory.getLogger(App.class); public static void main(String[] args) { + final Option logDirOpt = new Option("l", "log", true, "log dir path"); + final Option configFileOpt = new Option("c", "config", true, "config.json path"); final Options options = new Options() - .addOption("l", "log", true, "log dir path"); - final Option logDirOpt = options.getOption("log"); + .addOption(configFileOpt) + .addOption(logDirOpt); CommandLine cli = null; try { @@ -33,6 +38,21 @@ public class App { System.exit(1); } + String configFilePath = cli.getOptionValue(configFileOpt); + if (configFilePath == null) { + System.err.println("config.json path not specified. exiting"); + System.exit(1); + } + + // load config + Config config = null; + try { + config = Config.loadConfig(configFilePath); + } catch (IOException e) { + System.err.printf("failed to read %s: %s\n", configFilePath, e.toString()); + System.exit(1); + } + String logDirPath = cli.getOptionValue(logDirOpt); if (logDirPath != null) { // setup file logging diff --git a/src/main/java/com/mykola2312/retracker/config/Config.java b/src/main/java/com/mykola2312/retracker/config/Config.java new file mode 100644 index 0000000..a076fae --- /dev/null +++ b/src/main/java/com/mykola2312/retracker/config/Config.java @@ -0,0 +1,14 @@ +package com.mykola2312.retracker.config; + +import java.io.File; +import java.io.IOException; + +import com.fasterxml.jackson.databind.ObjectMapper; + +public class Config { + public static Config loadConfig(String configPath) throws IOException { + return new ObjectMapper() + .readerFor(Config.class) + .readValue(new File(configPath)); + } +}