Power2All / torrust-actix

A multi-functional lightweight BitTorrent Tracker
MIT License
86 stars 5 forks source link

How to configure it to work with both ipv4 and ipv6? #29

Closed ryjer closed 9 months ago

ryjer commented 9 months ago

Hello Power2All, I found the tracker www.gbitt.info support both ipv4 and ipv6. But I can only make it supports ipv4 or ipv6. Can you tell me how to configure to make it works with both ipv4 and ipv6?

Thanks

Power2All commented 9 months ago

Easy, you can use the following 4 blocks for binding the server to it. The IPv4 and IPv6 addressses shown below are examples. Change them to the IP addresses you want them to bind, they both are set for SSL and/or without SSL (port 443 and port 80). Technically, you only need to use IPv4 set, and if you use CloudFlare, use their IPv4/IPv6 proxy, which the tracker software can recognize.

[[http_server]]
enabled = false
bind_address = "1.2.3.4:80"
threads = 2
ssl = false
ssl_key = ""
ssl_cert = ""

[[http_server]]
enabled = false
bind_address = "1.2.3.4:443"
threads = 2
ssl = true
ssl_key = "key.pem"
ssl_cert = "cert.pem"

[[http_server]]
enabled = true
bind_address = "[6313:4660:2a72:3448:3533:31da:b76d:c3b0]:80"
threads = 2
ssl = false
ssl_key = ""
ssl_cert = ""

[[http_server]]
enabled = true
bind_address = "[6313:4660:2a72:3448:3533:31da:b76d:c3b0]:443"
threads = 2
ssl = true
ssl_key = "key.pem"
ssl_cert = "cert.pem"
ryjer commented 9 months ago

With those configures

[[http_server]]
enabled = true 
bind_address = "0.0.0.0:6969"
ssl = false
ssl_key = ""
ssl_cert = ""

[[http_server]]
enabled = true
bind_address = "[::]:6969"
ssl = false
ssl_key = ""
ssl_cert = ""

It prints those error logs

2023-10-02 19:54:53.599576697 [INFO ][torrust_actix::logging] logging initialized.
2023-10-02 19:54:53.599782127 [INFO ][torrust_actix] torrust-actix - Version: 3.2.1
2023-10-02 19:54:53.606081704 [INFO ][torrust_actix::http_api] [API] Starting server listener on 0.0.0.0:8080
2023-10-02 19:54:53.606639868 [INFO ][actix_server::builder] starting 4 workers
2023-10-02 19:54:53.606698426 [INFO ][torrust_actix::http_service] [SERVICE] Starting server listener on 0.0.0.0:6969
2023-10-02 19:54:53.607050115 [INFO ][actix_server::builder] starting 4 workers
2023-10-02 19:54:53.607093423 [INFO ][torrust_actix::http_service] [SERVICE] Starting server listener on [::]:6969
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 98, kind: AddrInUse, message: "Address already in use" }', /home/ryjer/tmp/torrust-actix-3.2.1/src/http_service.rs:61:10
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

It seems not supports bind the seem port to both ipv4 and ipv6 address

Power2All commented 9 months ago

With those configures

[[http_server]]
enabled = true 
bind_address = "0.0.0.0:6969"
ssl = false
ssl_key = ""
ssl_cert = ""

[[http_server]]
enabled = true
bind_address = "[::]:6969"
ssl = false
ssl_key = ""
ssl_cert = ""

It prints those error logs

2023-10-02 19:54:53.599576697 [INFO ][torrust_actix::logging] logging initialized.
2023-10-02 19:54:53.599782127 [INFO ][torrust_actix] torrust-actix - Version: 3.2.1
2023-10-02 19:54:53.606081704 [INFO ][torrust_actix::http_api] [API] Starting server listener on 0.0.0.0:8080
2023-10-02 19:54:53.606639868 [INFO ][actix_server::builder] starting 4 workers
2023-10-02 19:54:53.606698426 [INFO ][torrust_actix::http_service] [SERVICE] Starting server listener on 0.0.0.0:6969
2023-10-02 19:54:53.607050115 [INFO ][actix_server::builder] starting 4 workers
2023-10-02 19:54:53.607093423 [INFO ][torrust_actix::http_service] [SERVICE] Starting server listener on [::]:6969
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 98, kind: AddrInUse, message: "Address already in use" }', /home/ryjer/tmp/torrust-actix-3.2.1/src/http_service.rs:61:10
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

It seems not supports bind the seem port to both ipv4 and ipv6 address

If you want to bind on any network interface, you only need [::]:6969 as this will bind on both IPv4 and IPv6. Hence the "already listening" error you see.

ryjer commented 9 months ago

Although the tcp4 and udp4 information in log and /api/stats is 0 with the configure [::]:6969, it does works at ipv4 qbittorrent client.

Thanks for your help.

Power2All commented 9 months ago

Although the tcp4 and udp4 information in log and /api/stats is 0 with the configure [::]:6969, it does works at ipv4 qbittorrent client.

Thanks for your help.

Correct, it's a iffy thing, that's why you should just use the IP's your interface uses, instead of [::] or 0.0.0.0. This way you have much more control how your application is listening and binding.