Skip to content

Commit

Permalink
Mutli-Homing
Browse files Browse the repository at this point in the history
  • Loading branch information
doadin committed Jan 15, 2022
1 parent 2316088 commit a79106a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 40 deletions.
33 changes: 13 additions & 20 deletions deluge/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -938,12 +938,13 @@ def is_ipv4(ip):
import socket

try:
if windows_check():
return socket.inet_aton(ip)
else:
return socket.inet_pton(socket.AF_INET, ip)
for interface in ip.split(','):
socket.inet_pton(socket.AF_INET, interface)
return True
except OSError:
return False
log.warning('Unable to verify IPv6 Address with socket.')

return False


def is_ipv6(ip):
Expand All @@ -961,22 +962,14 @@ def is_ipv6(ip):
"""

try:
import ipaddress
except ImportError:
import socket
import socket

try:
return socket.inet_pton(socket.AF_INET6, ip)
except (OSError, AttributeError):
if windows_check():
log.warning('Unable to verify IPv6 Address on Windows.')
return True
else:
try:
return ipaddress.IPv6Address(decode_bytes(ip))
except ipaddress.AddressValueError:
pass
try:
for interface in ip.split(','):
socket.inet_pton(socket.AF_INET6, interface)
return True
except OSError:
log.warning('Unable to verify IPv6 Address with socket.')

return False

Expand Down
27 changes: 21 additions & 6 deletions deluge/core/preferencesmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,24 +206,39 @@ def __set_listen_on(self):
listen_ports = self.config['listen_ports']

if self.config['listen_interface']:
interface = self.config['listen_interface'].strip()
interfaces = self.config['listen_interface'].strip()
else:
interface = '0.0.0.0'
interfaces = '0.0.0.0'

lib_interfaces = []
for interface in interfaces.split(','):
interface = interface.strip()
try:
# add square brackets to ipv6 only, as needed by lib torrent
lib_interfaces.append(
'[' + interface + ']'
if deluge.common.is_ipv6(interface)
else interface
)
except ValueError:
# ip address format failed, assume network interface name
lib_interfaces.append(interface)

log.debug(
'Listen Interface: %s, Ports: %s with use_sys_port: %s',
interface,
lib_interfaces,
listen_ports,
self.config['listen_use_sys_port'],
)
interfaces = [
f'{interface}:{port}'
interface_port_list = [
f'{lib_interfaces}:{port}'
for port in range(listen_ports[0], listen_ports[1] + 1)
for lib_interface in lib_interfaces
]
self.core.apply_session_settings(
{
'listen_system_port_fallback': self.config['listen_use_sys_port'],
'listen_interfaces': ','.join(interfaces),
'listen_interfaces': ','.join(interface_port_list),
}
)

Expand Down
18 changes: 4 additions & 14 deletions deluge/ui/web/js/deluge-all/preferences/NetworkPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,6 @@
*/
Ext.namespace('Deluge.preferences');

// custom Vtype for vtype:'IPAddress'
Ext.apply(Ext.form.VTypes, {
IPAddress: function (v) {
return /^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$/.test(v);
},
IPAddressText: 'Must be a numeric IP address',
IPAddressMask: /[\d\.]/i,
});

/**
* @class Deluge.preferences.Network
* @extends Ext.form.FormPanel
Expand All @@ -35,7 +26,7 @@ Deluge.preferences.Network = Ext.extend(Ext.form.FormPanel, {
fieldset = this.add({
xtype: 'fieldset',
border: false,
title: _('Incoming Address'),
title: _('Incoming Interfaces (coma separated)'),
style: 'margin-bottom: 5px; padding-bottom: 0px;',
autoHeight: true,
labelWidth: 1,
Expand All @@ -47,8 +38,7 @@ Deluge.preferences.Network = Ext.extend(Ext.form.FormPanel, {
name: 'listen_interface',
fieldLabel: '',
labelSeparator: '',
width: 200,
vtype: 'IPAddress',
width: 250,
})
);

Expand Down Expand Up @@ -98,7 +88,7 @@ Deluge.preferences.Network = Ext.extend(Ext.form.FormPanel, {
fieldset = this.add({
xtype: 'fieldset',
border: false,
title: _('Outgoing Interface'),
title: _('Outgoing Interfaces (coma separated)'),
style: 'margin-bottom: 5px; padding-bottom: 0px;',
autoHeight: true,
labelWidth: 1,
Expand All @@ -110,7 +100,7 @@ Deluge.preferences.Network = Ext.extend(Ext.form.FormPanel, {
name: 'outgoing_interface',
fieldLabel: '',
labelSeparator: '',
width: 40,
width: 250,
})
);

Expand Down

0 comments on commit a79106a

Please sign in to comment.