summaryrefslogtreecommitdiffstats
path: root/deluge/core/core.py
diff options
context:
space:
mode:
authortbkizle <tbkizle@gmail.com>2020-02-13 00:13:44 -0500
committerCalum Lind <calumlind+deluge@gmail.com>2022-01-30 16:13:27 +0000
commit540d557cb2163c41af894ee252cc677d01887376 (patch)
tree1e03424802944dde5d6cab4f2278173d39fff9ec /deluge/core/core.py
parentd8acadb085a8f20bce15193c4b6e946199ab263d (diff)
downloaddeluge-540d557cb2163c41af894ee252cc677d01887376.tar.gz
deluge-540d557cb2163c41af894ee252cc677d01887376.tar.bz2
deluge-540d557cb2163c41af894ee252cc677d01887376.zip
[Common] Add is_interface to validate network interfaces
Libtorrent now supports interface names instead of just IP address so add new common functions to validate user input. * Added is_interface that will verify if a libtorrent interface of name or IP address. * Added is_interface_name to verify that the name supplied is a valid network interface name in the operating system. On Windows sock.if_nameindex() is only supported on 3.8+ and does not return a uuid (required by libtorrent) so use ifaddr package. Using git commit version for ifaddr due to adapter name decode bug in v0.1.7. On other OSes attempt to use stdlib and fallback to ifaddr if installed otherwiser return True. * Added tests for is_interface & is_interface_name * Updated UIs with change from address to interface * Updated is_ipv6 and is_ipv4 to used inet_pton; now supported on Windows. Ref: https://github.com/pydron/ifaddr/pull/32 Closes: https://github.com/deluge-torrent/deluge/pull/338
Diffstat (limited to 'deluge/core/core.py')
-rw-r--r--deluge/core/core.py14
1 files changed, 10 insertions, 4 deletions
diff --git a/deluge/core/core.py b/deluge/core/core.py
index a763b8d2f..1090b0f2a 100644
--- a/deluge/core/core.py
+++ b/deluge/core/core.py
@@ -164,19 +164,25 @@ class Core(component.Component):
# store the one in the config so we can restore it on shutdown
self._old_listen_interface = None
if listen_interface:
- if deluge.common.is_ip(listen_interface):
+ if deluge.common.is_interface(listen_interface):
self._old_listen_interface = self.config['listen_interface']
self.config['listen_interface'] = listen_interface
else:
log.error(
- 'Invalid listen interface (must be IP Address): %s',
+ 'Invalid listen interface (must be IP Address or Interface Name): %s',
listen_interface,
)
self._old_outgoing_interface = None
if outgoing_interface:
- self._old_outgoing_interface = self.config['outgoing_interface']
- self.config['outgoing_interface'] = outgoing_interface
+ if deluge.common.is_interface(outgoing_interface):
+ self._old_outgoing_interface = self.config['outgoing_interface']
+ self.config['outgoing_interface'] = outgoing_interface
+ else:
+ log.error(
+ 'Invalid outgoing interface (must be IP Address or Interface Name): %s',
+ outgoing_interface,
+ )
# New release check information
self.__new_release = None