Removed dependency on netifaces.

This commit is contained in:
Mark Qvist 2023-05-04 23:19:43 +02:00
parent a3bee4baa9
commit 5e5d89cc92
9 changed files with 18 additions and 85 deletions

View File

@ -190,7 +190,6 @@ these dependencies, and when the `rns` package is installed with `pip`, they
will be downloaded and installed as well. will be downloaded and installed as well.
- [PyCA/cryptography](https://github.com/pyca/cryptography) - [PyCA/cryptography](https://github.com/pyca/cryptography)
- [netifaces](https://github.com/al45tair/netifaces)
- [pyserial](https://github.com/pyserial/pyserial) - [pyserial](https://github.com/pyserial/pyserial)
On more unusual systems, and in some rare cases, it might not be possible to On more unusual systems, and in some rare cases, it might not be possible to

View File

@ -408,25 +408,15 @@ class TCPServerInterface(Interface):
@staticmethod @staticmethod
def get_address_for_if(name): def get_address_for_if(name):
import importlib import RNS.vendor.ifaddr.niwrapper as netinfo
if importlib.util.find_spec('netifaces') != None: ifaddr = netinfo.ifaddresses(name)
import netifaces return ifaddr[netinfo.AF_INET][0]["addr"]
return netifaces.ifaddresses(name)[netifaces.AF_INET][0]['addr']
else:
RNS.log("Getting interface addresses from device names requires the netifaces module.", RNS.LOG_CRITICAL)
RNS.log("You can install it with the command: python3 -m pip install netifaces", RNS.LOG_CRITICAL)
RNS.panic()
@staticmethod @staticmethod
def get_broadcast_for_if(name): def get_broadcast_for_if(name):
import importlib import RNS.vendor.ifaddr.niwrapper as netinfo
if importlib.util.find_spec('netifaces') != None: ifaddr = netinfo.ifaddresses(name)
import netifaces return ifaddr[netinfo.AF_INET][0]["broadcast"]
return netifaces.ifaddresses(name)[netifaces.AF_INET][0]['broadcast']
else:
RNS.log("Getting interface addresses from device names requires the netifaces module.", RNS.LOG_CRITICAL)
RNS.log("You can install it with the command: python3 -m pip install netifaces", RNS.LOG_CRITICAL)
RNS.panic()
def __init__(self, owner, name, device=None, bindip=None, bindport=None, i2p_tunneled=False): def __init__(self, owner, name, device=None, bindip=None, bindport=None, i2p_tunneled=False):
self.rxb = 0 self.rxb = 0

View File

@ -34,25 +34,15 @@ class UDPInterface(Interface):
@staticmethod @staticmethod
def get_address_for_if(name): def get_address_for_if(name):
import importlib import RNS.vendor.ifaddr.niwrapper as netinfo
if importlib.util.find_spec('netifaces') != None: ifaddr = netinfo.ifaddresses(name)
import netifaces return ifaddr[netinfo.AF_INET][0]["addr"]
return netifaces.ifaddresses(name)[netifaces.AF_INET][0]['addr']
else:
RNS.log("Getting interface addresses from device names requires the netifaces module.", RNS.LOG_CRITICAL)
RNS.log("You can install it with the command: python3 -m pip install netifaces", RNS.LOG_CRITICAL)
RNS.panic()
@staticmethod @staticmethod
def get_broadcast_for_if(name): def get_broadcast_for_if(name):
import importlib import RNS.vendor.ifaddr.niwrapper as netinfo
if importlib.util.find_spec('netifaces') != None: ifaddr = netinfo.ifaddresses(name)
import netifaces return ifaddr[netinfo.AF_INET][0]["broadcast"]
return netifaces.ifaddresses(name)[netifaces.AF_INET][0]['broadcast']
else:
RNS.log("Getting interface addresses from device names requires the netifaces module.", RNS.LOG_CRITICAL)
RNS.log("You can install it with the command: python3 -m pip install netifaces", RNS.LOG_CRITICAL)
RNS.panic()
def __init__(self, owner, name, device=None, bindip=None, bindport=None, forwardip=None, forwardport=None): def __init__(self, owner, name, device=None, bindip=None, bindport=None, forwardip=None, forwardport=None):
self.rxb = 0 self.rxb = 0

View File

@ -1,5 +1,4 @@
# netifaces compatibility layer import ipaddress
import ifaddr import ifaddr
import socket import socket
@ -22,7 +21,10 @@ def ifaddresses(ifname) -> dict:
for ip in a.ips: for ip in a.ips:
t = {} t = {}
if ip.is_IPv4: if ip.is_IPv4:
net = ipaddress.ip_network(str(ip.ip)+"/"+str(ip.network_prefix), strict=False)
t["addr"] = ip.ip t["addr"] = ip.ip
t["prefix"] = ip.network_prefix
t["broadcast"] = str(net.broadcast_address)
ipv4s.append(t) ipv4s.append(t)
if ip.is_IPv6: if ip.is_IPv6:
t["addr"] = ip.ip[0] t["addr"] = ip.ip[0]

View File

@ -1,48 +0,0 @@
# Copyright (C) 2015 Stefan C. Mueller
import unittest
import pytest
import ifaddr
import ifaddr.netifaces
try:
import netifaces
except ImportError:
skip_netifaces = True
else:
skip_netifaces = False
class TestIfaddr(unittest.TestCase):
"""
Unittests for :mod:`ifaddr`.
There isn't much unit-testing that can be done without making assumptions
on the system or mocking of operating system APIs. So this just contains
a sanity check for the moment.
"""
def test_get_adapters_contains_localhost(self) -> None:
found = False
adapters = ifaddr.get_adapters()
for adapter in adapters:
for ip in adapter.ips:
if ip.ip == "127.0.0.1":
found = True
self.assertTrue(found, "No adapter has IP 127.0.0.1: %s" % str(adapters))
@pytest.mark.skipif(skip_netifaces, reason='netifaces not installed')
def test_netifaces_compatibility() -> None:
interfaces = ifaddr.netifaces.interfaces()
assert interfaces == netifaces.interfaces()
# TODO: implement those as well
# for interface in interfaces:
# print(interface)
# assert ifaddr.netifaces.ifaddresses(interface) == netifaces.ifaddresses(interface)
# assert ifaddr.netifaces.gateways() == netifaces.gateways()

View File

@ -38,7 +38,7 @@ These efforts are aimed at improving the ease of which Reticulum is understood,
- Update NomadNet screenshots - Update NomadNet screenshots
- Update Sideband screenshots - Update Sideband screenshots
- Installation - Installation
- Install docs for fedora, needs `python3-netifaces` - Remove references to netifaces
- Add a *Reticulum On Raspberry Pi* section - Add a *Reticulum On Raspberry Pi* section
- Update *Reticulum On Android* section if necessary - Update *Reticulum On Android* section if necessary
- Update Android install documentation. - Update Android install documentation.

Binary file not shown.

Binary file not shown.

View File

@ -20,7 +20,7 @@ if pure_python:
long_description = long_description.replace("</p>", "</p>"+pure_notice) long_description = long_description.replace("</p>", "</p>"+pure_notice)
else: else:
pkg_name = "rns" pkg_name = "rns"
requirements = ['cryptography>=3.4.7', 'pyserial>=3.5', 'netifaces'] requirements = ['cryptography>=3.4.7', 'pyserial>=3.5']
excluded_modules = exclude=["tests.*", "tests"] excluded_modules = exclude=["tests.*", "tests"]
packages = setuptools.find_packages(exclude=excluded_modules) packages = setuptools.find_packages(exclude=excluded_modules)