qbittorrent / qBittorrent

qBittorrent BitTorrent client
https://www.qbittorrent.org
Other
27.52k stars 3.91k forks source link

Rebind IPv6 when it changes (has workaround) #18785

Open ljcbaby opened 1 year ago

ljcbaby commented 1 year ago

qBittorrent & operating system versions

qBittorrent: 4.5.2 x64 Operating system: Ubuntu 22.04 LTS Qt: 5.15.3 libtorrent-rasterbar: 2.0.8.0

What is the problem?

When the server's ipv6 address changes, qBittorrent is unable to sense the change and rebind the new address

Steps to reproduce

  1. start qBittorrent and bind all address on eth0
  2. re-call PPPoE on route (make ipv6 address perfix change)
  3. use sudo netstat -tlnp to see port binding status, found qBittorrent's ipv6 binds don't change

Additional context

No response

Log(s) & preferences file(s)

No response

linxc-0515 commented 1 year ago

I have the same problem

apooridiot commented 1 year ago

I have the same problem

Ling128 commented 1 year ago

the same problem.

Hill-98 commented 1 year ago

I wrote a script myself to solve this problem, you can use qBittorrent Web API to rebind addresses when IPv6 changes.

script code:

curl -F 'json={"current_interface_address": "0.0.0.0"}' -sS http://127.0.0.1:8080/api/v2/app/setPreferences
sleep 3
curl -F 'json={"current_interface_address": ""}' -sS http://127.0.0.1:8080/api/v2/app/setPreferences

127.0.0.1:8080 is qBittorrent WebUI url

ljcbaby commented 1 year ago

I wrote a script myself to solve this problem, you can use qBittorrent Web API to rebind addresses when IPv6 changes.

script code:

curl -F 'json={"current_interface_address": "0.0.0.0"}' -sS http://127.0.0.1:8080/api/v2/app/setPreferences
sleep 3
curl -F 'json={"current_interface_address": ""}' -sS http://127.0.0.1:8080/api/v2/app/setPreferences

127.0.0.1:8080 is qBittorrent WebUI url

thank you for your help i wrote a bash and temporarily fix the problem

use it in crontab

#!/bin/bash

current_ipv6=$(ip -6 addr show ens33 | grep global | awk '{print $2}')
record_file="/var/ipv6.record"
log_file="/var/log/ipv6.log"

clean_log_file() {
    lines_to_deal=800

    unchanged_lines=$(head -n "$lines_to_deal" "$log_file" | grep "IPv6 unchanged" | wc -l)

    if [ $unchanged_lines -eq 0 ]; then
        sed -i "1,600d" "$log_file"
    else
        sed -i "1,${lines_to_deal}{/unchanged/d}" "$log_file"
    fi
}

# if log file is too big
if [ $(wc -l < "$log_file") -gt 1000 ]; then
    echo "$(date +"%Y-%m-%d %H:%M:%S") - Log file is too big, cleaning..." >> "$log_file"
    clean_log_file
fi

if [ -z "$current_ipv6" ]; then
    echo "$(date +"%Y-%m-%d %H:%M:%S") - No IPv6 address found." >> "$log_file"
    exit 0
fi

if [ -f "$record_file" ]; then
    previous_ipv6=$(cat "$record_file")
else
    previous_ipv6=""
fi

# if else
if [ "$current_ipv6" != "$previous_ipv6" ]; then
    echo "$(date +"%Y-%m-%d %H:%M:%S") - IPv6 changed from $previous_ipv6 to $current_ipv6" >> "$log_file"

    curl -F 'json={"current_interface_address": "0.0.0.0"}' -sS http://127.0.0.1:8080/api/v2/app/setPreferences
    sleep 3
    curl -F 'json={"current_interface_address": ""}' -sS http://127.0.0.1:8080/api/v2/app/setPreferences

    echo "$current_ipv6" > "$record_file"
else
    echo "$(date +"%Y-%m-%d %H:%M:%S") - IPv6 unchanged." >> "$log_file"
fi

exit 0
obsession9 commented 8 months ago

I have the same problem. I think it can be solved by pseudo code like below:

// original binding logic
fun old_bind_logic() { ... }

fun new_bind_logic() {

  if( 'Network Interface' set 'Any Interface' ) {
    switch ( option 'Optional IP Address to bind to' ) {
      case 'All Address':
         bind('0.0.0.0') // accept all IPv4 connection
         bind('::') // accept all IPv6 connection
      case 'All IPv4 Address'
        bind('0.0.0.0')
      case 'All IPv6 Address'
         bind('::')
      else
        else old_bind_logic()
    }
  }
  else old_bind_logic()
}

These options come from the Advanced tab in the options window in the web UI.