Compare commits

...

19 Commits

Author SHA1 Message Date
Pranav Jerry fad2591b9f
new version -- 0.5.2 2021-12-10 20:16:34 +05:30
Pranav Jerry 05b91e7721 Merge pull request 'Fix for issue #25' (#26) from fix-issue-25 into master
Reviewed-on: pranav/naxalnet#26
2021-12-02 14:13:31 +00:00
Pranav Jerry 4d4e5e15d7
Merge branch 'master' into fix-issue-25
Things should be working fine now
2021-12-02 19:40:49 +05:30
Pranav Jerry 6bca6149b7
ready to merge 2021-12-02 19:29:19 +05:30
Pranav Jerry 710da18af9
moved naxalnet.service to the main directory 2021-12-01 21:34:40 +05:30
Pranav Jerry 888fdf3856
removed all print() calls from network.py
Updated CHANGELOG.md. We (another word for 'me') can push after moving
naxalnet.service out of service/. I am told the unit file is having a
rather dull time coping with per lonely life.
2021-12-01 21:27:27 +05:30
Pranav Jerry fc1f3d4216
another fix for #25
Or, to be more precise, a fix for the fix preceding the current fix for
issue #25 that just didn't fix things right. If your head spins, see the
previous commit, or call an ambulance (that is, if you are privileged
enough to access a phone and know your local helpline number)
2021-11-29 14:47:59 +05:30
Pranav Jerry 5e58df0b71
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
2021-11-29 14:36:59 +05:30
Pranav Jerry d7a84d8ccc
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
2021-11-16 22:00:00 +05:30
Pranav Jerry 183ce16eca
added timeout
This doesn't work yet
2021-11-14 19:57:35 +05:30
Pranav Jerry caeb042612
implemented NetworkLoop call in scripts.py
See any_interface_is_routable()
2021-11-14 19:46:04 +05:30
Pranav Jerry f657146eb3 Revert "added class to wait until routable"
This reverts commit fbf518e14c.
2021-11-14 19:39:51 +05:30
Pranav Jerry cd44357496
updated version
I accidentally pushed the previous commit to master instead of this
branch. This should revert things
2021-11-14 19:32:34 +05:30
Pranav Jerry fbf518e14c
added class to wait until routable
I haven't tested this properly yet
2021-11-14 19:00:10 +05:30
Pranav Jerry 28de9570b5
updated minimum debian version in README.md
I have added a comment on #20 about this
2021-11-08 21:20:24 +05:30
Pranav Jerry 009f6364cd
add xmpp channel to README.md and HACKING.md 2021-10-31 20:18:56 +05:30
Pranav Jerry a09ababd06
removed telegram group
We could use something else instead
2021-10-30 21:57:41 +05:30
Pranav Jerry 9749cf0c00
added telegram group and something else in README
Added Briar to the list in internet shutdown
2021-10-30 21:54:43 +05:30
Pranav Jerry 542347eac7 Updated use cases in README.md 2021-10-30 13:06:13 +00:00
9 changed files with 125 additions and 40 deletions

View File

@ -1,5 +1,9 @@
# Changelog
## [v0.5.2][] - 2021-12-10
- Optimised auto gateway mode selection (#25)
## [v0.5.1][] - 2021-10-22
- Fixed stopping at boot when GNOME starts location service (#21)
@ -47,7 +51,8 @@ used to do. The shell script was not given a version.
- Closed #1 and #3
[unreleased]: https://git.disroot.org/pranav/naxalnet/compare/v0.5.1...HEAD
[unreleased]: https://git.disroot.org/pranav/naxalnet/compare/v0.5.2...HEAD
[v0.5.2]: https://git.disroot.org/pranav/naxalnet/compare/v0.5.1...v0.5.2
[v0.5.1]: https://git.disroot.org/pranav/naxalnet/compare/v0.5.0...v0.5.1
[v0.5.0]: https://git.disroot.org/pranav/naxalnet/compare/v0.4.0...v0.5.0
[v0.4.0]: https://git.disroot.org/pranav/naxalnet/compare/v0.3.0...v0.4.0

View File

@ -2,35 +2,39 @@
Everyone can [hack][] naxalnet. See below for how to hack.
## 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.
<!-- And send your hate 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

View File

@ -78,9 +78,10 @@ naxalnet][startnx] when you need it.
### Debian or Ubuntu
naxalnet is not packaged for Debian or Ubuntu, so you will have to build
and install it manually. Currently, only Debian experimental and Ubuntu
21.10 comes with the required version of systemd. Therefore, naxalnet
requires **Debian experimental** or **Ubuntu 21.10 or greater** to work.
and install it manually. Currently, only Debian bookworm (testing) and
Ubuntu 21.10 comes with the required version of systemd. Therefore,
naxalnet requires **Debian testing** or **Ubuntu 21.10 or greater** to
work.
Install the requirements from the repositories:
@ -135,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.
@ -272,7 +273,9 @@ naxalnet --help
## Contributing or reporting bugs
See [HACKING.md](HACKING.md)
Join the XMPP channel <xmpp:naxalnet@chat.disroot.org> to talk about
anything related to this program or about mesh networks in general. See
[HACKING.md](HACKING.md) to contribute to the repo.
## How it works
@ -297,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.
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][].
<!--
@ -311,12 +315,12 @@ Withheld due to national security reasons.
### Internet shutdown
You can communicate with neighbouring devices running naxalnet, using
services like [IPFS][], [Jami][], [Secure Scuttlebutt][ssb] and others
which can work on an intranet. They should be installed on your machine
_before_ your friendly democratic government announces an [internet
shutdown][], since you cannot download and install them during a shutdown.
When a shutdown occurs, [enable naxalnet][enablenx] and use the installed
software to communicate with anyone within range.
services like [IPFS][], [Jami][], [Briar][] [Secure Scuttlebutt][ssb] or
similar software which can work on an intranet. They should be installed
on your machine _before_ your friendly democratic government announces an
[internet shutdown][], since you cannot download and install them during a
shutdown. When a shutdown occurs, [enable naxalnet][enablenx] and use the
installed software to communicate with anyone within range.
## Uninstalling
@ -360,6 +364,7 @@ See [LICENSE](LICENSE) for the complete version of the license.
[ipfs]: https://ipfs.io "InterPlanetary File System"
[jami]: https://jami.net "Peer to peer video calls"
[ssb]: https://scuttlebutt.nz "Secure Scuttlebutt"
[briar]: https://briarproject.org/
[dasbus]: https://github.com/rhinstaller/dasbus "A python D-Bus library"
[aur]: https://aur.archlinux.org/packages/naxalnet
[aur-devel]: https://aur.archlinux.org/packages/naxalnet-git

View File

@ -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.2"

View File

@ -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()

View File

@ -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"]:

View File

@ -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"

View File

@ -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 =