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 8f4d18e
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 21 deletions.
9 changes: 8 additions & 1 deletion deluge/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,8 @@ def is_ipv4(ip):
return socket.inet_aton(ip)
else:
return socket.inet_pton(socket.AF_INET, ip)
for interface in ip.split(','):
return socket.inet_pton(socket.AF_INET, interface)
except OSError:
return False

Expand All @@ -962,7 +964,12 @@ def is_ipv6(ip):
"""

try:
import ipaddress
for interface in ip.split(','):
return socket.inet_pton(socket.AF_INET6, interface)
except OSError:
log.warning('Unable to verify IPv6 Address with socket.')

return False
except ImportError:
import socket

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 8f4d18e

Please sign in to comment.