Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow inst stats to be fetched from onion insts. #29

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ COPY ./src/ ./src/
RUN crystal build ./src/instances.cr --release

FROM alpine:latest
RUN apk add --no-cache gc pcre libgcc
RUN apk add --no-cache gc pcre libgcc yaml
WORKDIR /app
RUN addgroup -g 1000 -S invidious && \
adduser -u 1000 -S invidious -G invidious
COPY ./assets/ ./assets/
COPY ./config.yml ./config.yml
COPY --from=builder /app/instances .

EXPOSE 3000
Expand Down
9 changes: 9 additions & 0 deletions config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Uses the system's CURL binary to do so.
fetch_onion_instance_stats: true

# TOR's Sock proxy address that CURL uses to connect to hidden services
tor_sock_proxy_address: "127.0.0.1"
tor_sock_proxy_port: 9050

# Minutes before refreshing the instance stats
minutes_between_refresh: 30
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
version: '3'
services:
tor-socks-proxy:
container_name: tor-socks-proxy
image: peterdavehello/tor-socks-proxy:latest
ports:
- "127.0.0.1:8853:53/udp"
- "127.0.0.1:9150:9150/tcp"
restart: unless-stopped

instances:
build: .
restart: unless-stopped
Expand Down
6 changes: 6 additions & 0 deletions src/helpers/helpers.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require "yaml"

def load_config
config = YAML.parse(File.read("config.yml"))
return config
end
22 changes: 21 additions & 1 deletion src/instances.cr
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ require "http/client"
require "kemal"
require "uri"

require "./helpers/*"

CONFIG = load_config()

Kemal::CLI.new ARGV

macro rendered(filename)
Expand Down Expand Up @@ -68,6 +72,22 @@ spawn do

case type = host.split(".")[-1]
when "onion"
type = "onion"

if CONFIG["fetch_onion_instance_stats"]?
begin
args = Process.parse_arguments("--socks5-hostname '#{CONFIG["tor_sock_proxy_address"]}:#{CONFIG["tor_sock_proxy_port"]}' 'http://#{uri.host}/api/v1/stats'")
response = nil
Process.run("curl", args: args) do |result|
data = result.output.read_line
response = JSON.parse(data)
end

stats = response
rescue ex
stats = nil
end
end
when "i2p"
else
type = uri.scheme.not_nil!
Expand All @@ -88,7 +108,7 @@ spawn do
INSTANCES.clear
INSTANCES.merge! instances

sleep 5.minutes
sleep CONFIG["minutes_between_refresh"].as_i.minutes
end
end

Expand Down