Skip to content

Commit

Permalink
manage coma separated list of incoming interfaces
Browse files Browse the repository at this point in the history
  • Loading branch information
Strangelovian committed Aug 19, 2020
1 parent 23a48dd commit e821612
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 25 deletions.
28 changes: 22 additions & 6 deletions deluge/core/preferencesmanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from __future__ import unicode_literals

import ipaddress
import logging
import os
import platform
Expand Down Expand Up @@ -214,24 +215,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 ipaddress.ip_address(interface).version == 6
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 = [
'%s:%s' % (interface, port)
interface_port_list = [
'%s:%s' % (lib_interface, 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
8 changes: 4 additions & 4 deletions deluge/ui/gtk3/glade/preferences_dialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -2555,9 +2555,9 @@ used sparingly.</property>
<object class="GtkEntry" id="entry_interface">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="tooltip_text" translatable="yes">The IP address of the interface to listen for incoming bittorrent connections on. Leave this empty if you want to use the default.</property>
<property name="max_length">15</property>
<property name="width_chars">15</property>
<property name="tooltip_text" translatable="yes">Coma separated list of IP addresses / network interface names to be listened for incoming bittorrent connections. Leave this empty if you want to use the default.</property>
<property name="max_length">100</property>
<property name="width_chars">30</property>
<property name="truncate_multiline">True</property>
<property name="primary_icon_activatable">False</property>
<property name="secondary_icon_activatable">False</property>
Expand All @@ -2569,7 +2569,7 @@ used sparingly.</property>
<object class="GtkLabel" id="label110">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Incoming Address</property>
<property name="label" translatable="yes">Incoming Interfaces</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
Expand Down
4 changes: 2 additions & 2 deletions deluge/ui/gtk3/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -677,8 +677,8 @@ def set_config(self, hide=False):
'chk_random_outgoing_ports'
).get_active()
incoming_address = self.builder.get_object('entry_interface').get_text().strip()
if deluge.common.is_ip(incoming_address) or not incoming_address:
new_core_config['listen_interface'] = incoming_address

new_core_config['listen_interface'] = incoming_address
new_core_config['outgoing_interface'] = (
self.builder.get_object('entry_outgoing_interface').get_text().strip()
)
Expand Down
16 changes: 3 additions & 13 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: _('Listen 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 @@ -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 e821612

Please sign in to comment.