Skip to content

Commit

Permalink
feat: env boot
Browse files Browse the repository at this point in the history
  • Loading branch information
jerrita committed Apr 12, 2024
1 parent 1ca7b18 commit 3669b84
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
uses: docker/build-push-action@v5
with:
context: .
platforms: linux/amd64,linux/arm64
platforms: linux/amd64
push: true
tags: |
ghcr.io/${{ github.actor }}/peerban:latest
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ lazy_static = "1.4.0"
env_logger = "0.11.3"
log = "0.4.21"
async-trait = "0.1.79"
clap = { version = "4.5.4", features = ["derive"] }
clap = { version = "4.5.4", features = ["derive", "env"] }
regex = "1.10.4"

[profile.opt]
Expand Down
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
Usage: peerban [OPTIONS]

Options:
-b, --backend <BACKEND> [default: qb]
-e, --endpoint <ENDPOINT> [default: http://127.0.0.1:8080]
-a, --auth <AUTH> [default: admin:admin]
-s, --scan <SCAN> Scan interval in seconds. [default: 5]
-c, --clear Clear all bans before start.
-b, --backend <BACKEND> [env: BACKEND=] [default: qb]
-e, --endpoint <ENDPOINT> [env: ENDPOINT=] [default: http://127.0.0.1:8080]
-a, --auth <AUTH> [env: AUTH=] [default: admin:admin]
-s, --scan <SCAN> Scan interval in seconds. [env: SCAN=] [default: 5]
--pt Handle private tracker torrents. [env: PT=]
--clear Clear all bans before start. [env: CLEAR=]
-h, --help Print help
```

Expand Down
11 changes: 4 additions & 7 deletions src/daemon.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use regex::Regex;
use std::time::Instant;

use anyhow::Result;
use log::{debug, info, warn};
use regex::Regex;

use crate::backend::Backend;
use crate::peer::BannedPeer;
Expand Down Expand Up @@ -58,16 +58,13 @@ impl Daemon {
stat.torrents = torrents.len() as u64;
stat.peers = 0;
for torrent in torrents {
if !self.pt && !torrent.tracker.is_empty() {
debug!("Torrent: {}({})", torrent.name, torrent.hash);
if !self.pt {
let lower_tracker = torrent.tracker.to_lowercase();
if PT_KEYWORDS.iter().any(|&keyword| lower_tracker.contains(keyword)) || re.is_match(&lower_tracker) {
debug!("Private tracker torrent: {}({})", torrent.name, torrent.hash);
debug!("Private tracker detect.");
continue;
} else {
debug!("Torrent: {}({})", torrent.name, torrent.hash);
}
} else {
debug!("Torrent: {}({})", torrent.name, torrent.hash);
}

let peers = self.backend.get_peers(&torrent.hash).await?;
Expand Down
12 changes: 6 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ mod daemon;

#[derive(Parser, Debug)]
struct Args {
#[arg(short, long, default_value = "qb")]
#[arg(short, long, env, default_value = "qb")]
backend: String,
#[arg(short, long, default_value = "http://127.0.0.1:8080")]
#[arg(short, long, env, default_value = "http://127.0.0.1:8080")]
endpoint: String,
#[arg(short, long, default_value = "admin:admin")]
#[arg(short, long, env, default_value = "admin:admin")]
auth: String,
#[arg(short, long, default_value = "5", help = "Scan interval in seconds.")]
#[arg(short, long, env, default_value = "5", help = "Scan interval in seconds.")]
scan: u64,
#[arg(short, long, default_value = "false", help = "Handle private tracker torrents.")]
#[arg(long, env, default_value = "false", help = "Handle private tracker torrents.")]
pt: bool,
#[arg(short, long, default_value = "false", help = "Clear all bans before start.")]
#[arg(long, env, default_value = "false", help = "Clear all bans before start.")]
clear: bool,
}

Expand Down

0 comments on commit 3669b84

Please sign in to comment.