add json config parsing
This commit is contained in:
parent
07c3128753
commit
b7b772af86
6 changed files with 53 additions and 4 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -15,5 +15,7 @@ buildNumber.properties
|
||||||
.project
|
.project
|
||||||
# JDT-specific (Eclipse Java Development Tools)
|
# JDT-specific (Eclipse Java Development Tools)
|
||||||
.classpath
|
.classpath
|
||||||
# Log files
|
# retracker runtime files
|
||||||
log/
|
log/
|
||||||
|
config.json
|
||||||
|
retracker.pid
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
eclipse.preferences.version=1
|
eclipse.preferences.version=1
|
||||||
encoding//src/main/java=UTF-8
|
encoding//src/main/java=UTF-8
|
||||||
|
encoding//src/main/resources=UTF-8
|
||||||
encoding//src/test/java=UTF-8
|
encoding//src/test/java=UTF-8
|
||||||
encoding/<project>=UTF-8
|
encoding/<project>=UTF-8
|
||||||
|
|
|
||||||
|
|
@ -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
|
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.
|
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:
|
Maven exec with args:
|
||||||
|
|
|
||||||
10
pom.xml
10
pom.xml
|
|
@ -60,6 +60,16 @@
|
||||||
<artifactId>logback-classic</artifactId>
|
<artifactId>logback-classic</artifactId>
|
||||||
<version>1.5.11</version>
|
<version>1.5.11</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-core</artifactId>
|
||||||
|
<version>2.18.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-databind</artifactId>
|
||||||
|
<version>2.18.0</version>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
package com.mykola2312.retracker;
|
package com.mykola2312.retracker;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
|
||||||
import org.apache.commons.cli.CommandLine;
|
import org.apache.commons.cli.CommandLine;
|
||||||
|
|
@ -11,6 +12,8 @@ import org.apache.commons.cli.ParseException;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import com.mykola2312.retracker.config.Config;
|
||||||
|
|
||||||
import ch.qos.logback.classic.Level;
|
import ch.qos.logback.classic.Level;
|
||||||
import ch.qos.logback.classic.LoggerContext;
|
import ch.qos.logback.classic.LoggerContext;
|
||||||
import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
|
import ch.qos.logback.classic.encoder.PatternLayoutEncoder;
|
||||||
|
|
@ -21,9 +24,11 @@ public class App {
|
||||||
private static final Logger log = LoggerFactory.getLogger(App.class);
|
private static final Logger log = LoggerFactory.getLogger(App.class);
|
||||||
|
|
||||||
public static void main(String[] args) {
|
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()
|
final Options options = new Options()
|
||||||
.addOption("l", "log", true, "log dir path");
|
.addOption(configFileOpt)
|
||||||
final Option logDirOpt = options.getOption("log");
|
.addOption(logDirOpt);
|
||||||
|
|
||||||
CommandLine cli = null;
|
CommandLine cli = null;
|
||||||
try {
|
try {
|
||||||
|
|
@ -33,6 +38,21 @@ public class App {
|
||||||
System.exit(1);
|
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);
|
String logDirPath = cli.getOptionValue(logDirOpt);
|
||||||
if (logDirPath != null) {
|
if (logDirPath != null) {
|
||||||
// setup file logging
|
// setup file logging
|
||||||
|
|
|
||||||
14
src/main/java/com/mykola2312/retracker/config/Config.java
Normal file
14
src/main/java/com/mykola2312/retracker/config/Config.java
Normal file
|
|
@ -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));
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Reference in a new issue