mirror of
https://git.disroot.org/pranav/pybatmesh.git
synced 2024-11-26 16:52:07 +05:30
Reviewed-on: https://git.disroot.org/pranav/naxalnet/pulls/26
This commit is contained in:
commit
05b91e7721
@ -1,5 +1,9 @@
|
||||
# Changelog
|
||||
|
||||
## [Unreleased][] - 2021-12-01
|
||||
|
||||
- Optimised auto gateway mode selection (#25)
|
||||
|
||||
## [v0.5.1][] - 2021-10-22
|
||||
|
||||
- Fixed stopping at boot when GNOME starts location service (#21)
|
||||
|
32
HACKING.md
32
HACKING.md
@ -2,41 +2,37 @@
|
||||
|
||||
Everyone can [hack][] naxalnet. See below for how to hack.
|
||||
|
||||
## Questions, answers and hate speech
|
||||
## Questions and answers
|
||||
|
||||
Join the XMPP channel <xmpp:naxalnet@chat.disroot.org> to talk about
|
||||
anything related to this program or about mesh networks in general.
|
||||
Redirect your hate messages to `/dev/null`
|
||||
|
||||
## Reporting issues and suggesting ideas
|
||||
|
||||
To report a bug or suggest an idea, create a new issue at
|
||||
<https://git.disroot.org/pranav/naxalnet/issues>
|
||||
|
||||
While reporting a bug, you need to add the debug messages too. Run
|
||||
`journalctl -fu naxalnet` on a terminal emulator (this could take some
|
||||
time). Now on another one, type `sudo systemctl start naxalnet.service` or
|
||||
whatever caused the error. Now copy the error messages and paste it in the
|
||||
issue body along with the description.
|
||||
While reporting a bug, you can add the debug messages to provide more
|
||||
data. Run `journalctl -fu naxalnet` on a terminal emulator (this could
|
||||
take some time on some machines). Now on another one, type `sudo systemctl start naxalnet.service` or whatever caused the error. Now copy the error
|
||||
messages and paste it in the issue body along with the description.
|
||||
|
||||
## Improving documentation
|
||||
|
||||
The README and HACKING.md needs to be more beginner friendly.
|
||||
See #20.
|
||||
The README and HACKING.md needs to be more beginner friendly. See #20.
|
||||
|
||||
## Contribute code
|
||||
|
||||
To push to this repo, you need your username to be in the
|
||||
contributors list. Add your username to issue #8 to add you
|
||||
as a contributor. Before each commit, update the CHANGELOG.md
|
||||
and `__version__` in `naxalnet/__init__.py`
|
||||
To push to this repo, you need your username to be in the contributors
|
||||
list. Add your username to issue #8 to add you as a contributor. Before
|
||||
each commit, update the CHANGELOG.md and `__version__` in
|
||||
`naxalnet/__init__.py`
|
||||
|
||||
## Packaging
|
||||
|
||||
Currently this program is only packaged for Arch Linux.
|
||||
naxalnet needs packages in GNU+Linux+systemd
|
||||
distributions such as Debian, Fedora, openSUSE,
|
||||
and nixos. If you know/like to package it in your distro,
|
||||
post a message to issue #6.
|
||||
Currently this program is only packaged for Arch Linux. naxalnet needs
|
||||
packages in GNU+Linux+systemd distributions such as Debian, Fedora,
|
||||
openSUSE, and nixos. If you know/like to package it in your distro, post a
|
||||
message to issue #6.
|
||||
|
||||
[hack]: https://catb.org/jargon/html/H/hack.html
|
||||
|
@ -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][].
|
||||
|
||||
<!--
|
||||
|
||||
|
@ -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.1a1"
|
||||
|
@ -30,6 +30,7 @@ examples.
|
||||
import subprocess
|
||||
from pathlib import Path
|
||||
from dasbus.connection import SystemMessageBus
|
||||
from dasbus.loop import EventLoop, GLib
|
||||
|
||||
|
||||
NETWORKD_BUS = "org.freedesktop.network1"
|
||||
@ -44,6 +45,7 @@ class NetworkD:
|
||||
"""
|
||||
|
||||
def __init__(self, runtime_dir="/run/systemd/network", bus=SystemMessageBus()):
|
||||
print("NetworkD init")
|
||||
self._bus = bus
|
||||
self.proxy_reload()
|
||||
|
||||
@ -118,3 +120,68 @@ class NetworkD:
|
||||
"""
|
||||
for i in self.runtime_path.iterdir():
|
||||
self.remove_config(i.name)
|
||||
|
||||
|
||||
class NetworkLoop(NetworkD):
|
||||
"""Used to wait until a condition is met
|
||||
|
||||
Available methods:
|
||||
|
||||
NetworkLoop.wait_until_routable(timeout=0):
|
||||
return true when the network is routable, or false when timed out
|
||||
|
||||
"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
# first, initialise the parent object
|
||||
super().__init__(*args, **kwargs)
|
||||
self.waitfor = None
|
||||
self.wait_function = None
|
||||
self.loop = EventLoop()
|
||||
|
||||
def start_loop(self):
|
||||
"""start the dasbus loop"""
|
||||
self.proxy.PropertiesChanged.connect(self.on_properties_changed)
|
||||
self.loop.run()
|
||||
|
||||
def wait_until_routable(self, timeout=0):
|
||||
"""
|
||||
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.setup_timeout(timeout)
|
||||
self.wait_for_change("AddressState", self.on_addressstate_change)
|
||||
|
||||
return self.is_routable()
|
||||
|
||||
def wait_for_change(self, name, function):
|
||||
"""
|
||||
Wait until the given property is changed and stop. If setup_timeout()
|
||||
is called before calling this function, the loop stops after the timeout
|
||||
or after the property is changed, whichever occurs first.
|
||||
"""
|
||||
self.waitfor = name
|
||||
self.wait_function = function
|
||||
self.start_loop()
|
||||
|
||||
def on_addressstate_change(self):
|
||||
"""quit the loop if the network is routable"""
|
||||
if self.is_routable():
|
||||
self.loop.quit()
|
||||
|
||||
def on_properties_changed(self, bus_interface, data, blah):
|
||||
"""called by dasbus everytime the configured property is changed"""
|
||||
if self.waitfor in data:
|
||||
return self.wait_function()
|
||||
# Just to shut up pylint
|
||||
return None
|
||||
|
||||
def setup_timeout(self, timeout):
|
||||
"""setup a timeout"""
|
||||
if timeout != 0:
|
||||
GLib.timeout_add(timeout, self.on_timeout)
|
||||
|
||||
def on_timeout(self):
|
||||
"""called by dasbus when a timeout occurs"""
|
||||
self.loop.quit()
|
||||
|
@ -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,15 @@ 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()
|
||||
|
||||
# timeout = 10 seconds
|
||||
routable = networkd.wait_until_routable(10 * 1000)
|
||||
networkd.remove_all_configs()
|
||||
|
||||
return routable
|
||||
@ -246,8 +244,10 @@ def main():
|
||||
notify("STATUS=Checking for internet")
|
||||
# If any interface is routable, set gateway mode to server
|
||||
if any_interface_is_routable():
|
||||
logger.info("Network is routable. Setting gw_mode to server")
|
||||
gateway_mode = "server"
|
||||
else:
|
||||
logger.info("Network is not routable. Setting gw_mode to client")
|
||||
gateway_mode = "client"
|
||||
logger.info("gateway_mode set to %s", gateway_mode)
|
||||
elif args.gateway_mode in ["server", "client", "off"]:
|
||||
|
@ -1,3 +1,4 @@
|
||||
[build-system]
|
||||
# I don't know what this means, I just copied it from some setuptools tutorial
|
||||
requires = ["setuptools", "wheel"]
|
||||
build-backend = "setuptools.build_meta"
|
||||
|
@ -1,4 +1,7 @@
|
||||
# This program is not meant to be distributed through PyPi
|
||||
# This file is loosely based on the setup.cfg used in django.
|
||||
# naxalnet is not meant to be distributed through PyPi. This program uses
|
||||
# a systemd service, and some other files whose path is hardcoded into the
|
||||
# module.
|
||||
[metadata]
|
||||
name = naxalnet
|
||||
version = attr: naxalnet.__version__
|
||||
@ -33,7 +36,7 @@ console_scripts =
|
||||
|
||||
[options.data_files]
|
||||
lib/systemd/system =
|
||||
service/naxalnet.service
|
||||
naxalnet.service
|
||||
# If installing with pip, this file will be copied to some other place.
|
||||
# This is the reason we use setup.py instead of pip in the Makefile.
|
||||
/etc/naxalnet =
|
||||
|
Loading…
Reference in New Issue
Block a user