From cd4435749606f5ef957362bf47e4c04db927dea9 Mon Sep 17 00:00:00 2001 From: Pranav Jerry Date: Sun, 14 Nov 2021 19:32:34 +0530 Subject: [PATCH 1/9] updated version I accidentally pushed the previous commit to master instead of this branch. This should revert things --- naxalnet/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/naxalnet/__init__.py b/naxalnet/__init__.py index 69ce491..ca60229 100644 --- a/naxalnet/__init__.py +++ b/naxalnet/__init__.py @@ -42,4 +42,4 @@ given below. # # In case you forgot to change the version, skip the number # and put the next number in the next commit. -__version__ = "0.5.1" +__version__ = "0.5.1a0.dev2" From caeb0426126148f72c578a9bbcbcb321fd2d3f58 Mon Sep 17 00:00:00 2001 From: Pranav Jerry Date: Sun, 14 Nov 2021 19:46:04 +0530 Subject: [PATCH 2/9] implemented NetworkLoop call in scripts.py See any_interface_is_routable() --- naxalnet/__init__.py | 2 +- naxalnet/scripts.py | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/naxalnet/__init__.py b/naxalnet/__init__.py index ca60229..623d2e4 100644 --- a/naxalnet/__init__.py +++ b/naxalnet/__init__.py @@ -42,4 +42,4 @@ given below. # # In case you forgot to change the version, skip the number # and put the next number in the next commit. -__version__ = "0.5.1a0.dev2" +__version__ = "0.5.1a0.dev3" diff --git a/naxalnet/scripts.py b/naxalnet/scripts.py index 89dd382..4dbcd20 100644 --- a/naxalnet/scripts.py +++ b/naxalnet/scripts.py @@ -37,7 +37,7 @@ from naxalnet.log import logger from naxalnet.iwd import Adapter, Device, IWD from naxalnet.config import args from naxalnet.daemon import Daemon -from naxalnet.network import NetworkD +from naxalnet.network import NetworkD, NetworkLoop def get_sorted_glob(directory: str, glob: str) -> list: @@ -56,17 +56,14 @@ def get_sorted_glob(directory: str, glob: str) -> list: def any_interface_is_routable(): """returns true if any of the interfaces is routable""" - networkd = NetworkD(runtime_dir=args.networkd_runtime_dir) + networkd = NetworkLoop(runtime_dir=args.networkd_runtime_dir) # First, add the temporary configs to networkd. for i in get_sorted_glob(args.networkd_config_dir, TMP_NET_GLOB): logger.debug("Adding temporary config %s", i) networkd.add_config(i) - # Then, wait for some time to setup the network. - # This can probably be replaced by a d-bus wait-for-signal - # function that timeouts after 10 seconds. - time.sleep(10) - routable = networkd.is_routable() + + routable = networkd.wait_until_routable() networkd.remove_all_configs() return routable From 183ce16eca46bec56916a78ef3dc0c79cd3bb1d4 Mon Sep 17 00:00:00 2001 From: Pranav Jerry Date: Sun, 14 Nov 2021 19:57:35 +0530 Subject: [PATCH 3/9] added timeout This doesn't work yet --- naxalnet/__init__.py | 2 +- naxalnet/network.py | 12 ++++++++++-- naxalnet/scripts.py | 3 ++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/naxalnet/__init__.py b/naxalnet/__init__.py index 623d2e4..2a38d30 100644 --- a/naxalnet/__init__.py +++ b/naxalnet/__init__.py @@ -42,4 +42,4 @@ given below. # # In case you forgot to change the version, skip the number # and put the next number in the next commit. -__version__ = "0.5.1a0.dev3" +__version__ = "0.5.1a0.dev4" diff --git a/naxalnet/network.py b/naxalnet/network.py index caa1e80..d1787f0 100644 --- a/naxalnet/network.py +++ b/naxalnet/network.py @@ -29,6 +29,7 @@ examples. import subprocess from pathlib import Path +from gi.repository import GObject from dasbus.connection import SystemMessageBus from dasbus.loop import EventLoop @@ -145,10 +146,12 @@ class NetworkLoop(NetworkD): def wait_until_routable(self, timeout=0): """ - wait until timeout in milliseconds and returns True when any - network interface is shown routable by networkd + Wait until timeout in milliseconds and returns True when any + network interface is shown routable by networkd. Does not wait + for timeout if timeout==0 """ self.wait_for_change("AddressState", self.on_addressstate_change) + self.setup_timeout(timeout) return self.is_routable() def wait_for_change(self, name, function): @@ -167,6 +170,11 @@ class NetworkLoop(NetworkD): if self.waitfor in data: return self.wait_function() + def setup_timeout(self, timeout): + """setup a timeout""" + if timeout != 0: + GObject.timeout_add(timeout, self.on_timeout) + def on_timeout(self): """called by dasbus when a timeout occurs""" self.loop.quit() diff --git a/naxalnet/scripts.py b/naxalnet/scripts.py index 4dbcd20..64ec06d 100644 --- a/naxalnet/scripts.py +++ b/naxalnet/scripts.py @@ -63,7 +63,8 @@ def any_interface_is_routable(): logger.debug("Adding temporary config %s", i) networkd.add_config(i) - routable = networkd.wait_until_routable() + # timeout = 10 seconds + routable = networkd.wait_until_routable(10 * 1000) networkd.remove_all_configs() return routable From d7a84d8ccca4c4c90f2bcbf3195ea63fa72291a5 Mon Sep 17 00:00:00 2001 From: Pranav Jerry Date: Tue, 16 Nov 2021 22:00:00 +0530 Subject: [PATCH 4/9] replaced GObject with GLib in network.py See the previous commit. And the one preceding that. And the one before that. Keep going until /dev/brain0 gets symlinked to /dev/urandom --- naxalnet/__init__.py | 2 +- naxalnet/network.py | 19 ++++++++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/naxalnet/__init__.py b/naxalnet/__init__.py index 2a38d30..1d5eb43 100644 --- a/naxalnet/__init__.py +++ b/naxalnet/__init__.py @@ -42,4 +42,4 @@ given below. # # In case you forgot to change the version, skip the number # and put the next number in the next commit. -__version__ = "0.5.1a0.dev4" +__version__ = "0.5.1a0.dev5" diff --git a/naxalnet/network.py b/naxalnet/network.py index d1787f0..f0f6899 100644 --- a/naxalnet/network.py +++ b/naxalnet/network.py @@ -29,9 +29,8 @@ examples. import subprocess from pathlib import Path -from gi.repository import GObject from dasbus.connection import SystemMessageBus -from dasbus.loop import EventLoop +from dasbus.loop import EventLoop, GLib NETWORKD_BUS = "org.freedesktop.network1" @@ -46,6 +45,7 @@ class NetworkD: """ def __init__(self, runtime_dir="/run/systemd/network", bus=SystemMessageBus()): + print("NetworkD init") self._bus = bus self.proxy_reload() @@ -122,6 +122,9 @@ class NetworkD: self.remove_config(i.name) +# TODO: remove all calls to print() before merging to master + + class NetworkLoop(NetworkD): """Used to wait until a condition is met @@ -133,6 +136,7 @@ class NetworkLoop(NetworkD): """ def __init__(self, *args, **kwargs): + print("NetworkLoop init") # first, initialise the parent object super().__init__(*args, **kwargs) self.waitfor = None @@ -141,6 +145,9 @@ class NetworkLoop(NetworkD): def start_loop(self): """start the dasbus loop""" + print("start loop") + print("waitfor", self.waitfor) + print("waitfor func", self.wait_function) self.proxy.PropertiesChanged.connect(self.on_properties_changed) self.loop.run() @@ -150,31 +157,37 @@ class NetworkLoop(NetworkD): network interface is shown routable by networkd. Does not wait for timeout if timeout==0 """ + print("wait until routable") self.wait_for_change("AddressState", self.on_addressstate_change) self.setup_timeout(timeout) return self.is_routable() def wait_for_change(self, name, function): """used by the public functions""" + print("wait for change") self.waitfor = name self.wait_function = function self.start_loop() def on_addressstate_change(self): """quit the loop if the network is routable""" + print("on addrstate change") if self.is_routable(): self.loop.quit() def on_properties_changed(self, bus_interface, data, blah): """give this function some documentation""" + print("on properties changed") if self.waitfor in data: return self.wait_function() def setup_timeout(self, timeout): """setup a timeout""" + print("setup timeout") if timeout != 0: - GObject.timeout_add(timeout, self.on_timeout) + GLib.timeout_add(timeout, self.on_timeout) def on_timeout(self): """called by dasbus when a timeout occurs""" + print("on timeout") self.loop.quit() From 5e58df0b711614aca67cfb5d34d245a82f7729f2 Mon Sep 17 00:00:00 2001 From: Pranav Jerry Date: Mon, 29 Nov 2021 14:36:59 +0530 Subject: [PATCH 5/9] temporary fix for #25 Uses multithreading.Process instead of GLib.timeout_add() The moment I finished writing this part, I found out the only problem with my previous commit was that I had setup the timeout _after_ calling the blocking function wait_for_change instead of before it. Although this version (with Process) works, I'm reverting to the previous version and swapping the two lines (which I had tested and found to work) And in case you have read upto the previous line you should also know I fixed some code in the README TL;DR: I have proven once again I am an idiot --- README.md | 7 ++++--- naxalnet/__init__.py | 2 +- naxalnet/network.py | 31 ++++++++++++++++++++----------- naxalnet/scripts.py | 3 +-- pyproject.toml | 1 + setup.cfg | 5 ++++- 6 files changed, 31 insertions(+), 18 deletions(-) diff --git a/README.md b/README.md index 0511620..59444cf 100644 --- a/README.md +++ b/README.md @@ -136,7 +136,7 @@ uname -r python3 --version # Check for IBSS (ad-hoc) support in your WiFi firmware or driver -iw phy | grep -iq ibss && echo "IBSS is supported" || echo "IBSS not supported" +iw phy | grep -q join_ibss && echo "IBSS is supported" || echo "IBSS not supported" ``` Clone the naxalnet repo and cd into it. @@ -300,8 +300,9 @@ systemd-networkd configures the network. ### Online class -naxalnet can be used to share connections to join online classes. -You need at least one device with internet access if you are not using a program like [Jami][]. +naxalnet can be used to share connections to join online classes. You need +at least one device with internet access if you are not using a program +like [Jami][].