Compare commits

...

39 Commits
v0.5.0 ... main

Author SHA1 Message Date
Pranav Jerry
566f562d33 Merge pull request 'fixed typo in README' (#30) from fix-readme-typo into main
Reviewed-on: https://git.disroot.org/pranav/pybatmesh/pulls/30
2024-08-13 09:51:40 +02:00
1106945732
fixed typo in README
Added a space between two words in License section of README
2024-08-13 11:00:32 +05:30
Pranav Jerry
d45ac72442 Merge pull request 'Updated installation instructions for debian' (#29) from update-debian-installation-instructions into main
Reviewed-on: https://git.disroot.org/pranav/pybatmesh/pulls/29
2022-09-13 04:52:02 +00:00
3354584045
updated installation instructions for debian
dasbus is now in debian repos. We no longer need to install it with pip
2022-09-13 10:12:04 +05:30
0c6bdea4a8
updated CHANGELOG.md
I'm renaming the project to pybatmesh. Added instructions to update via
the command-line on the CHANGELOG
2022-08-03 11:08:41 +05:30
Pranav Jerry
9123224de0 Merge pull request 'Rename to pybatmesh' (#27) from rename-to-pybatmesh into main
Reviewed-on: https://git.disroot.org/pranav/naxalnet/pulls/27
2022-08-03 05:23:03 +00:00
396fe9af7e
updated version and minor changes
Removed some more traces of the previous name.
Removed an unused import and updated CHANGELOG.md
2022-08-03 10:39:26 +05:30
72dda12d7b
renaming to pybatmesh
pybatmesh better describes the project and does not attract the
attention of caged investigation agencies, like it probably would have
before. I probably left traces of the original name somewhere, so this
commit will likely be followed by other commits to erase all traces of
the previous name
2022-07-23 15:58:32 +05:30
38d0aa8ab5
not maintained anymore
If anyone is interested to takeover naxalnet, see #8
2022-02-04 12:51:07 +05:30
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: https://git.disroot.org/pranav/naxalnet/pulls/26
2021-12-02 14:13:31 +00:00
4d4e5e15d7
Merge branch 'master' into fix-issue-25
Things should be working fine now
2021-12-02 19:40:49 +05:30
6bca6149b7
ready to merge 2021-12-02 19:29:19 +05:30
710da18af9
moved naxalnet.service to the main directory 2021-12-01 21:34:40 +05:30
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
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
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
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
183ce16eca
added timeout
This doesn't work yet
2021-11-14 19:57:35 +05:30
caeb042612
implemented NetworkLoop call in scripts.py
See any_interface_is_routable()
2021-11-14 19:46:04 +05:30
f657146eb3 Revert "added class to wait until routable"
This reverts commit fbf518e14cb59caad3c459a04be7de35215eb52c.
2021-11-14 19:39:51 +05:30
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
fbf518e14c
added class to wait until routable
I haven't tested this properly yet
2021-11-14 19:00:10 +05:30
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
009f6364cd
add xmpp channel to README.md and HACKING.md 2021-10-31 20:18:56 +05:30
a09ababd06
removed telegram group
We could use something else instead
2021-10-30 21:57:41 +05:30
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
a5ba99ca2a
Version 0.5.1
Fixed issue #21
2021-10-22 13:28:16 +05:30
Pranav Jerry
0d5d3c5cc6 Merge pull request 'fix for issue #21' (#22) from geoclue-fix into master
Reviewed-on: https://git.disroot.org/pranav/naxalnet/pulls/22
2021-10-22 07:53:45 +00:00
26a907d907
updated readme, changelog
prepare to merge to master
2021-10-22 13:20:09 +05:30
704fe646f8
renamed systemd-networkd/ to network/
Nothing big. And naxalnet needs a new maintainer or I will keep screwing
up things.
2021-10-22 13:09:15 +05:30
aa079c7c29
reverted the changes
Instead, removed the wpa_supplicant "conflicts" line from naxalnet.service
2021-10-22 13:05:37 +05:30
295fde3f0b
added override service for wpa_supplicant
This probably isn't working like we want
2021-10-22 12:54:52 +05:30
270db3cf90
added hack to fix #21 2021-10-22 12:06:17 +05:30
6fbebc51bb
almost fixed things 2021-10-22 11:58:41 +05:30
1f8be50dd6
moved systemd service to a dir
This is to add another service file alongside naxalnet.service
2021-10-22 11:11:11 +05:30
c4933378ff
quick fix for #21
Added a couple of lines in the README until #21 is closed.
2021-10-22 11:02:53 +05:30
0a85c465ee
added features section in README.md
And added some more info on adding bug reports.
See issue #20.
2021-10-15 16:05:06 +05:30
25 changed files with 312 additions and 238 deletions

View File

@ -1,5 +1,29 @@
# Changelog # Changelog
## [v0.5.3][] - 2022-08-03
- Renamed to pybatmesh, to be more clear what the program does
- code cleanup
To update via the repo, do the following:
```sh
git remote set-url origin git@git.disroot.org:pranav/pybatmesh.git
# or
git remote set-url origin https://git.disroot.org/pranav/pybatmesh.git
# remove naxlnet and install pybatmesh
git pull && git checkout 38d0aa8ab5dd60f2febffda335df6df1ea143ab3 && make clean && sudo make purge && git checkout main && make && sudo make install
```
## [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)
- Changes in directory structure
## [v0.5.0][] - 2021-10-10 ## [v0.5.0][] - 2021-10-10
- Better error messages - Better error messages
@ -42,9 +66,12 @@ used to do. The shell script was not given a version.
- Closed #1 and #3 - Closed #1 and #3
[unreleased]: https://git.disroot.org/pranav/naxalnet/compare/v0.5.0...HEAD [unreleased]: https://git.disroot.org/pranav/pybatmesh/compare/v0.5.3...HEAD
[v0.5.0]: https://git.disroot.org/pranav/naxalnet/compare/v0.4.0...v0.5.0 [v0.5.3]: https://git.disroot.org/pranav/pybatmesh/compare/v0.5.2...v0.5.3
[v0.4.0]: https://git.disroot.org/pranav/naxalnet/compare/v0.3.0...v0.4.0 [v0.5.2]: https://git.disroot.org/pranav/pybatmesh/compare/v0.5.1...v0.5.2
[v0.3.0]: https://git.disroot.org/pranav/naxalnet/compare/v0.2.0...v0.3.0 [v0.5.1]: https://git.disroot.org/pranav/pybatmesh/compare/v0.5.0...v0.5.1
[v0.2.0]: https://git.disroot.org/pranav/naxalnet/compare/v0.1.0...v0.2.0 [v0.5.0]: https://git.disroot.org/pranav/pybatmesh/compare/v0.4.0...v0.5.0
[v0.1.0]: https://git.disroot.org/pranav/naxalnet/releases/tag/v0.1.0 [v0.4.0]: https://git.disroot.org/pranav/pybatmesh/compare/v0.3.0...v0.4.0
[v0.3.0]: https://git.disroot.org/pranav/pybatmesh/compare/v0.2.0...v0.3.0
[v0.2.0]: https://git.disroot.org/pranav/pybatmesh/compare/v0.1.0...v0.2.0
[v0.1.0]: https://git.disroot.org/pranav/pybatmesh/releases/tag/v0.1.0

View File

@ -1,30 +1,33 @@
# Hacking # Hacking
Everyone can [hack][] naxalnet. See below for how to hack. Everyone can [hack][] pybatmesh. See below for how to hack.
## Reporting issues and suggesting ideas ## Reporting issues and suggesting ideas
To report a bug or suggest an idea, create a new issue at To report a bug or suggest an idea, create a new issue at
<https://git.disroot.org/pranav/naxalnet/issues> <https://git.disroot.org/pranav/pybatmesh/issues>
While reporting a bug, you can add the debug messages to provide more
data. Run `journalctl -fu pybatmesh` on a terminal emulator (this could
take some time on some machines). Now on another one, type `sudo systemctl start pybatmesh.service` or whatever caused the error. Now copy the error
messages and paste it in the issue body along with the description.
## Improving documentation ## Improving documentation
The README and HACKING.md needs to be more beginner friendly. The README and HACKING.md needs to be more beginner friendly. See #20.
See #20.
## Contribute code ## Contribute code
To push to this repo, you need your username to be in the To push to this repo, you need your username to be in the contributors
contributors list. Add your username to issue #8 to add you list. Add your username to issue #8 to add you as a contributor. Before
as a contributor. Before each commit, update the CHANGELOG.md each commit, update the CHANGELOG.md and `__version__` in
and `__version__` in `naxalnet/__init__.py` `pybatmesh/__init__.py`
## Packaging ## Packaging
Currently this program is only packaged for Arch Linux. Currently this program is only packaged for Arch Linux. pybatmesh needs
naxalnet needs packages in GNU+Linux+systemd packages in GNU+Linux+systemd distributions such as Debian, Fedora,
distributions such as Debian, Fedora, openSUSE, openSUSE, and nixos. If you know/like to package it in your distro, post a
and nixos. If you know/like to package it in your distro, message to issue #6.
post a message to issue #6.
[hack]: https://catb.org/jargon/html/H/hack.html [hack]: https://catb.org/jargon/html/H/hack.html

View File

@ -10,19 +10,19 @@ DESTDIR:= /
all: build all: build
# Build only when naxalnet/__init__.py changes. We assume here that anyone # Build only when pybatmesh/__init__.py changes. We assume here that anyone
# creating a new commit will first update the __version__ in # creating a new commit will first update the __version__ in
# naxalnet/__init__.py # pybatmesh/__init__.py
build: naxalnet/__init__.py build: pybatmesh/__init__.py
$(PYTHON) setup.py build $(PYTHON) setup.py build
install: install:
$(PYTHON) setup.py install --root="$(DESTDIR)" --optimize=1 --skip-build $(PYTHON) setup.py install --root="$(DESTDIR)" --optimize=1 --skip-build
uninstall: uninstall:
$(PIP) uninstall -y naxalnet $(PIP) uninstall -y pybatmesh
rm -rf /usr/share/naxalnet /usr/lib/systemd/system/naxalnet.service rm -rf /usr/share/pybatmesh /usr/lib/systemd/system/pybatmesh.service
@echo "make uninstall will not remove anything in /etc/naxalnet" && \ @echo "make uninstall will not remove anything in /etc/pybatmesh" && \
echo "Do 'sudo make purge' to remove it." echo "Do 'sudo make purge' to remove it."
rpm: rpm:
@ -31,7 +31,7 @@ rpm:
# Remove config files, like apt purge. Purge should first do what # Remove config files, like apt purge. Purge should first do what
# uninstall does, so we add uninstall as a dependency to this rule. # uninstall does, so we add uninstall as a dependency to this rule.
purge: uninstall purge: uninstall
rm -rf /etc/naxalnet rm -rf /etc/pybatmesh
clean: clean:
rm -rf build *.egg-info **/__pycache__ dist rm -rf build *.egg-info **/__pycache__ dist

184
README.md
View File

@ -1,47 +1,30 @@
# naxalnet # pybatmesh
**naxalnet** is a program to create a wireless mesh network for **pybatmesh** is a program to create a wireless mesh network for
communicating with each other. It can be useful during an [internet communicating with each other. It can be useful during an [internet
shutdown](#internet-shutdown), or to join [online classes](#online-class) shutdown](#internet-shutdown), or to join [online classes](#online-class)
with a group of laptops. It uses [B.A.T.M.A.N. Advanced][batman-adv], an with a group of laptops. It uses [B.A.T.M.A.N. Advanced][batman-adv], an
implementation of the B.A.T.M.A.N. routing protocol to communicate with implementation of the B.A.T.M.A.N. routing protocol to communicate with
peers. The name naxal comes from Naxalbari, a village in Darjeeling, West peers.
Bengal.
**WARNING**: This program uses an **unencrypted** network. This means you do **WARNING**: This program uses an **unencrypted** network. This means you do
not get any more privacy or security than with an open WiFi network. not get any more privacy or security than with an open WiFi network.
<!-- NOTE TO ACTIVISTS ## Features
Running this program in the world's largest (partly-free) democracy - Select best network when multiple nodes have internet access (gateway
may result in you getting arrested under the Act Which Must Not Be Named, mode)
and not getting bail because of false evidence planted in your phone by - Detect insertion and removal of wifi adapters and reconfigure them
Pegasus, or by a forensic lab in Gujarat. - Readable logs
- Supports rfkill
The author, much like the GoI, does not wish to take responsibility in your
well-being if you get arrested under a draconian national security law.
-->
<!-- UNCOMMENT WHEN NECESSARY
**Disclaimer**: In case you are either 1: a complete idiot; or 2: a member
of the saffron brigade; or 3: both, please be aware that this project is
not affiliated with any human rights defenders or with anyone currently at
risk of death in overcrowded prisons.
Using the name naxal in a program will not shake the foundations of
democracy nor affect the soverignty, unity or integrity of any
nation-state. .
-->
## Requirements ## Requirements
- [systemd-networkd v248 or greater][batman-systemd] - [systemd-networkd v248 or greater][batman-systemd]
- Linux kernel with [batman-adv v2021.0][batman-systemd] or greater - Linux kernel with [batman-adv v2021.0][batman-systemd] or greater
- [iwd][] for controlling the WiFi adapter - [iwd][] for controlling the WiFi adapter
- python (tested only on 3.9) - python (tested on 3.9 and 3.10)
- python setuptools, for building and installing naxalnet - python setuptools, for building and installing pybatmesh
- [python-systemd][], for logging to systemd journal - [python-systemd][], for logging to systemd journal
- [dasbus][], for communicating with iwd - [dasbus][], for communicating with iwd
- two or more machines with a WiFi adapter having ibss support, called - two or more machines with a WiFi adapter having ibss support, called
@ -56,30 +39,29 @@ distributions will have to build manually.
### Arch Linux ### Arch Linux
Install [naxalnet][aur] (or [naxalnet-git][aur-devel] for the Install [pybatmesh][aur] (or [pybatmesh-git][aur-devel] for the
development version) from the AUR with your favourite helper: development version) from the AUR with your favourite helper:
```sh ```sh
yay -S naxalnet yay -S pybatmesh
``` ```
Optionally, [setup systemd-resolved][arch-resolved] for DNS. [Start Optionally, [setup systemd-resolved][arch-resolved] for DNS. [Start
naxalnet][startnx] when you need it. pybatmesh][startnx] when you need it.
### Debian or Ubuntu ### Debian or Ubuntu
naxalnet is not packaged for Debian or Ubuntu, so you will have to build pybatmesh is not packaged for Debian or Ubuntu, so you will have to build
and install it manually. Currently, only Debian experimental and Ubuntu and install it manually. Currently, only Debian bookworm (testing) and
21.10 comes with the required version of systemd. Therefore, naxalnet Ubuntu 21.10 comes with the required version of systemd. Therefore,
requires **Debian experimental** or **Ubuntu 21.10 or greater** to work. pybatmesh requires **Debian testing** or **Ubuntu 21.10 or greater** to
work.
Install the requirements from the repositories: Install the requirements from the repositories:
```sh ```sh
# batctl is optional # batctl is optional
sudo apt install python3-pip python3-systemd iwd batctl build-essential sudo apt install python3-pip python3-systemd python3-dasbus iwd batctl
# Now, install dasbus with pip
sudo pip3 install dasbus
``` ```
Now follow the instructions in the Now follow the instructions in the
@ -87,25 +69,25 @@ Now follow the instructions in the
### Fedora ### Fedora
naxalnet is not packaged for Fedora, so it should be installed manually. pybatmesh is not packaged for Fedora, so it should be installed manually.
naxalnet requires atleast systemd v248, which is only available on **Fedora pybatmesh requires at least systemd v248, which is only available on
34 and above**. python-setuptools support building rpms, which are the **Fedora 34 and above**. python-setuptools support building rpms, which
preferred way of installing software in Fedora. Follow the steps to are the preferred way of installing software in Fedora. Follow the steps
install naxalnet on Fedora: to install pybatmesh on Fedora:
```sh ```sh
# Install the build requirements # Install the build requirements
sudo dnf install python3-setuptools make git sudo dnf install python3-setuptools make git
# Clone the repo # Clone the repo
git clone https://git.disroot.org/pranav/naxalnet.git git clone https://git.disroot.org/pranav/pybatmesh.git
cd naxalnet cd pybatmesh
# Create an installable rpm from the source code # Create an installable rpm from the source code
make rpm make rpm
# Now install it. This will also install the requirements # Now install it. This will also install the requirements
sudo dnf install dist/naxalnet-$(python3 -m setup --version)-1.noarch.rpm sudo dnf install dist/pybatmesh-$(python3 -m setup --version)-1.noarch.rpm
``` ```
### Manually ### Manually
@ -126,17 +108,17 @@ uname -r
python3 --version python3 --version
# Check for IBSS (ad-hoc) support in your WiFi firmware or driver # 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. Clone the pybatmesh repo and cd into it.
```sh ```sh
git clone https://git.disroot.org/pranav/naxalnet.git git clone https://git.disroot.org/pranav/pybatmesh.git
cd naxalnet cd pybatmesh
``` ```
Now, build and install naxalnet: Now, build and install pybatmesh:
```sh ```sh
make make
@ -164,16 +146,16 @@ This will keep the configuration files.
## How to use ## How to use
You need more than one machine running naxalnet for the connection to work. You need more than one machine running pybatmesh for the connection to work.
### Start naxalnet ### Start pybatmesh
Though naxalnet can run from the command line, it was designed to be Though pybatmesh can run from the command line, it was designed to be
run as a systemd service. run as a systemd service.
To start naxalnet, do the command on all the nodes: To start pybatmesh, do the command on all the nodes:
```sh ```sh
sudo systemctl start naxalnet.service sudo systemctl start pybatmesh.service
``` ```
This will start a mesh network and connect to all nodes. To test if it This will start a mesh network and connect to all nodes. To test if it
@ -183,32 +165,32 @@ your network is up. Press Ctrl+C to stop `batctl`.
### Getting internet access ### Getting internet access
Connect an ethernet cable from a router to any of the nodes. Now restart Connect an ethernet cable from a router to any of the nodes. Now restart
naxalnet on the node to set `gateway_mode` to `server`. Other nodes will pybatmesh on the node to set `gateway_mode` to `server`. Other nodes will
take a minute or more to renew DHCP. You can optionally do this manually take a minute or more to renew DHCP. You can optionally do this manually
if you don't want the delay. To do this, type if you don't want the delay. To do this, type
`sudo networkctl renew bridge0` on all nodes. `sudo networkctl renew bridge0` on all nodes.
### Tethering via WiFi AP ### Tethering via WiFi AP
If there are two adapters in a peer, naxalnet will start a If there are two adapters in a peer, pybatmesh will start a
WiFi ap (also called WiFi hotspot) on one of them. WiFi ap (also called WiFi hotspot) on one of them.
Connect two WiFi adapters on a node. Connect two WiFi adapters on a node.
Now an AP will be started on one of the adapters. Now an AP will be started on one of the adapters.
Type `naxalnet --print-wifi` to get the WiFi SSID and password. Type `pybatmesh --print-wifi` to get the WiFi SSID and password.
If you had set up internet access on one of the nodes, internet If you had set up internet access on one of the nodes, internet
can be accessed from the AP. can be accessed from the AP.
### Running at boot ### Running at boot
To run naxalnet at boot, enable the service on all the nodes: To run pybatmesh at boot, enable the service on all the nodes:
```sh ```sh
sudo systemctl enable naxalnet.service sudo systemctl enable pybatmesh.service
``` ```
Now naxalnet will start a mesh on every boot. Now pybatmesh will start a mesh on every boot.
If you have NetworkManager enabled, which is the default in Ubuntu and If you have NetworkManager enabled, which is the default in Ubuntu and
Fedora, it should be disabled: Fedora, it should be disabled:
@ -217,10 +199,10 @@ Fedora, it should be disabled:
sudo systemctl disable NetworkManager.service sudo systemctl disable NetworkManager.service
``` ```
To stop running at boot, you should disable `naxalnet.service`: To stop running at boot, you should disable `pybatmesh.service`:
```sh ```sh
sudo systemctl disable naxalnet.service sudo systemctl disable pybatmesh.service
``` ```
If you had disabled `NetworkManager` before, enable it: If you had disabled `NetworkManager` before, enable it:
@ -232,10 +214,10 @@ sudo systemctl enable NetworkManager.service
### Stopping the service ### Stopping the service
```sh ```sh
sudo systemctl stop naxalnet iwd systemd-networkd systemd-resolved sudo systemctl stop pybatmesh iwd systemd-networkd systemd-resolved
``` ```
If your distribution uses NetworkManager, starting `naxalnet.service` If your distribution uses NetworkManager, starting `pybatmesh.service`
will have stopped it. Start NetworkManager again: will have stopped it. Start NetworkManager again:
```sh ```sh
@ -244,21 +226,21 @@ sudo systemctl start NetworkManager.service
### Configuration ### Configuration
naxalnet comes with a sample configuration file pybatmesh comes with a sample configuration file
`/etc/naxalnet/naxalnet.conf.example`. To change how the program `/etc/pybatmesh/pybatmesh.conf.example`. To change how the program
behaves, copy it to /etc/naxalnet/naxalnet.conf and edit it: behaves, copy it to /etc/pybatmesh/pybatmesh.conf and edit it:
```sh ```sh
sudo cp /etc/naxalnet/naxalnet.conf{.example,} sudo cp /etc/pybatmesh/pybatmesh.conf{.example,}
# Now edit the file with your favourite editor as root # Now edit the file with your favourite editor as root
gedit admin:/etc/naxalnet/naxalnet.conf gedit admin:/etc/pybatmesh/pybatmesh.conf
``` ```
Also, you can change its behaviour every time you run it using Also, you can change its behaviour every time you run it using
arguments: arguments:
```sh ```sh
naxalnet --help pybatmesh --help
``` ```
## Contributing or reporting bugs ## Contributing or reporting bugs
@ -272,47 +254,40 @@ hotspot), `station` (for joining WiFi networks) and `ad-hoc` (or ibss, for
decentralised networks). There are other modes supported by some WiFi decentralised networks). There are other modes supported by some WiFi
adapters too, like `p2p` (WiFi direct), but this program doesn't use them. adapters too, like `p2p` (WiFi direct), but this program doesn't use them.
naxalnet uses two modes - `ad-hoc` and `ap`, for connecting to the pybatmesh uses two modes - `ad-hoc` and `ap`, for connecting to the
mesh. naxalnet uses iwd to start an `ad-hoc` network and configures mesh. pybatmesh uses iwd to start an `ad-hoc` network and configures
systemd-networkd to setup a BATMAN Advanced network. systemd-networkd to setup a BATMAN Advanced network.
If there are two WiFi adapters connected to the machine, If there are two WiFi adapters connected to the machine,
naxalnet starts an ad-hoc on one of them and an ap on the other. pybatmesh starts an ad-hoc on one of them and an ap on the other.
You can use the ap for connecting mobile phones and other devices You can use the ap for connecting mobile phones and other devices
to the mesh network. to the mesh network.
Read the code and the documentation in the code to learn the details. Read the code and the documentation in the code to learn the details.
See the directory [systemd-networkd](systemd-networkd) to see how See the directory [network](network) to see how
systemd-networkd configures the network. systemd-networkd configures the network.
## Use cases ## Use cases
### Online class ### Online class
naxalnet can be used to share connections to join online classes. pybatmesh can be used to share connections to join online classes. You need
You need at least one device with internet access. at least one device with internet access if you are not using a program
like [Jami][] (see below).
<!--
### Malign democracies and well-established institutions
Withheld due to national security reasons.
-->
### Internet shutdown ### Internet shutdown
You can communicate with neighbouring devices running naxalnet, using You can communicate with neighbouring devices running pybatmesh, using
services like [IPFS][], [Jami][], [Secure Scuttlebutt][ssb] and others services like [IPFS][], [Jami][], [Briar][] [Secure Scuttlebutt][ssb] or
which can work on an intranet. They should be installed on your machine similar software which can work on an intranet. They should be installed
_before_ your friendly democratic government announces an [internet on your machine _before_ your friendly democratic government announces an
shutdown][], since you cannot download and install them during a shutdown. [internet shutdown][], since you cannot download and install them during a
When a shutdown occurs, [enable naxalnet][enablenx] and use the installed shutdown. When a shutdown occurs, [enable pybatmesh][enable-pybatmesh] and use the
software to communicate with anyone within range. installed software to communicate with anyone within range.
## Uninstalling ## Uninstalling
If you installed naxalnet manually, use make uninstall to remove If you installed pybatmesh manually, use make uninstall to remove
naxalnet and its data files. This requires python pip to be installed. pybatmesh and its data files. This requires python pip to be installed.
```sh ```sh
# Uninstall the program, keeping the config files # Uninstall the program, keeping the config files
@ -325,24 +300,24 @@ sudo make purge
Many projects make setting up B.A.T.M.A.N. Advanced mesh networks with Many projects make setting up B.A.T.M.A.N. Advanced mesh networks with
WiFi routers easier. They are easier to setup and are more WiFi routers easier. They are easier to setup and are more
configurable. But naxalnet is different from them. It simplifies configurable. But pybatmesh is different from them. It simplifies
setting up mesh networks with _laptops or computers_, and was not setting up mesh networks with _laptops or computers_, and was not
made to work with routers. made to work with routers.
The following projects does something similar to naxalnet, but The following projects does something similar to pybatmesh, but
requires special devices or routers to work. If you live in an area requires special devices or routers to work. If you live in an area
where the materials are easily available, consider using them instead where the materials are easily available, consider using them instead
of naxalnet. of pybatmesh.
- [LibreMesh][]: framework for OpenWrt-based firmwares - [LibreMesh][]: framework for OpenWrt-based firmwares
- [disaster.radio][]: solar-powered communications network - [disaster.radio][]: solar-powered communications network
## License ## License
naxalnet is [free/libre/swatantra][free-sw] and open source software; pybatmesh is [free/libre/swatantra][free-sw] and open source software;
you can redistribute it and/or modify it under the terms of the GNU you can redistribute it and/or modify it under the terms of the GNU
General Public License as published by the Free Software Foundation, General Public License as published by the Free Software Foundation,
eitherversion 3 of the License, or (at your option) any later version. either version 3 of the License, or (at your option) any later version.
See [LICENSE](LICENSE) for the complete version of the license. See [LICENSE](LICENSE) for the complete version of the license.
@ -351,17 +326,18 @@ See [LICENSE](LICENSE) for the complete version of the license.
[ipfs]: https://ipfs.io "InterPlanetary File System" [ipfs]: https://ipfs.io "InterPlanetary File System"
[jami]: https://jami.net "Peer to peer video calls" [jami]: https://jami.net "Peer to peer video calls"
[ssb]: https://scuttlebutt.nz "Secure Scuttlebutt" [ssb]: https://scuttlebutt.nz "Secure Scuttlebutt"
[briar]: https://briarproject.org/
[dasbus]: https://github.com/rhinstaller/dasbus "A python D-Bus library" [dasbus]: https://github.com/rhinstaller/dasbus "A python D-Bus library"
[aur]: https://aur.archlinux.org/packages/naxalnet [aur]: https://aur.archlinux.org/packages/pybatmesh
[aur-devel]: https://aur.archlinux.org/packages/naxalnet-git [aur-devel]: https://aur.archlinux.org/packages/pybatmesh-git
[arch-resolved]: https://wiki.archlinux.org/title/Systemd-resolved#DNS "systemd-resolved on ArchWiki" [arch-resolved]: https://wiki.archlinux.org/title/Systemd-resolved#DNS "systemd-resolved on ArchWiki"
[batman-systemd]: https://www.open-mesh.org/news/101 "systemd v248 brings support for batman advanced" [batman-systemd]: https://www.open-mesh.org/news/101 "systemd v248 brings support for batman advanced"
[libremesh]: https://libremesh.org [libremesh]: https://libremesh.org
[disaster.radio]: https://disaster.radio [disaster.radio]: https://disaster.radio
[startnx]: #start-naxalnet [startnx]: #start-pybatmesh
[iwd]: https://iwd.wiki.kernel.org "WiFi daemon" [iwd]: https://iwd.wiki.kernel.org "WiFi daemon"
[free-sw]: https://gnu.org/philosophy/free-sw.html "What is free software?" [free-sw]: https://gnu.org/philosophy/free-sw.html "What is free software?"
[enablenx]: #running-at-boot [enable-pybatmesh]: #running-at-boot
[requirements]: #requirements [requirements]: #requirements
[install-manual]: #manually [install-manual]: #manually
[python-systemd]: https://github.com/systemd/python-systemd [python-systemd]: https://github.com/systemd/python-systemd

View File

@ -1,7 +1,7 @@
# This file links any interface in ap mode # This file links any interface in ap mode
# to the bridge we created earlier. # to the bridge we created earlier.
# To start an AP, connect two adapters to the computer # To start an AP, connect two adapters to the computer
# before starting naxalnet.service # before starting pybatmesh.service
# This file won't do anything if an ap interface is not found. # This file won't do anything if an ap interface is not found.
[Match] [Match]

View File

@ -1,12 +1,12 @@
# This configuration file is part of naxalnet. # This configuration file is part of pybatmesh.
# To configure this program, rename this file # To configure this program, rename this file
# to naxalnet.conf and edit it. # to pybatmesh.conf and edit it.
# The values given here are defaults. # The values given here are defaults.
[networkd] [networkd]
# systemd-networkd configuration files bundled with naxalnet. # systemd-networkd configuration files bundled with pybatmesh.
# THese will be copied to runtimedir at runtime. # THese will be copied to runtimedir at runtime.
confdir = /usr/share/naxalnet/networkd confdir = /usr/share/pybatmesh/networkd
# systemd-networkd runtime configuration directory. # systemd-networkd runtime configuration directory.
# See man:systemd.network(5) # See man:systemd.network(5)
runtimedir = /run/systemd/network runtimedir = /run/systemd/network
@ -26,10 +26,10 @@ mode=auto
[adhoc] [adhoc]
# All your nodes should have the same name # All your nodes should have the same name
name = NxMesh name = pybatmesh
[ap] [ap]
# An AP is started if your machine has more than one WiFi adapter. # An AP is started if your machine has more than one WiFi adapter.
ssid = MeshWiFi ssid = BatWiFi
# Note the spelling. It's passwd, not password. # Note the spelling. It's passwd, not password.
passwd = naxalnet256 passwd = pybatmesh256

View File

@ -1,4 +1,4 @@
# The naxalnet systemd service # The pybatmesh systemd service
# See man:systemd.service(5) and man:systemd.unit(5) # See man:systemd.service(5) and man:systemd.unit(5)
# before editing this file. # before editing this file.
[Unit] [Unit]
@ -9,21 +9,19 @@ Wants=systemd-resolved.service
After=iwd.service After=iwd.service
After=systemd-networkd.service After=systemd-networkd.service
After=systemd-resolved.service After=systemd-resolved.service
# Stops NetworkManager and wpa_supplicant if already running # Stops NetworkManager if already running
Conflicts=NetworkManager.service Conflicts=NetworkManager.service
Conflicts=wpa_supplicant.service # This stops NetworkManager when pybatmesh is enabled
# This stops networkmanager and wpa_supplicant when naxalnet is enabled
After=NetworkManager.service After=NetworkManager.service
After=wpa_supplicant.service
[Service] [Service]
Type=notify Type=notify
NotifyAccess=all NotifyAccess=all
Restart=on-failure Restart=on-failure
RestartSec=2sec RestartSec=2sec
ExecStart=naxalnet --systemd ExecStart=pybatmesh --systemd
KillSignal=SIGINT KillSignal=SIGINT
# naxalnet already logs to systemd journal so we don't need # pybatmesh already logs to systemd journal so we don't need
# stdout and stderr. # stdout and stderr.
StandardOutput=null StandardOutput=null
StandardError=null StandardError=null

View File

@ -1,5 +1,5 @@
# This file is part of naxalnet. # This file is part of pybatmesh.
# Copyright (C) 2021 The naxalnet Authors # Copyright (C) 2021 The pybatmesh Authors
# This program is free software: you can redistribute it and/or modify it # This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the # under the terms of the GNU General Public License as published by the
@ -15,7 +15,7 @@
# with this program. If not, see <http://www.gnu.org/licenses/>. # with this program. If not, see <http://www.gnu.org/licenses/>.
""" """
naxalnet pybatmesh
======== ========
Create mesh networks with batman-adv, systemd-networkd and iwd. Create mesh networks with batman-adv, systemd-networkd and iwd.
@ -24,8 +24,8 @@ See README.md and the docstrings for documentation. You can read
documentaion in the python interpretor using something like the example documentaion in the python interpretor using something like the example
given below. given below.
>>> help("naxalnet") >>> help("pybatmesh")
>>> help("naxalnet.config") >>> help("pybatmesh.config")
""" """
@ -42,4 +42,4 @@ given below.
# #
# In case you forgot to change the version, skip the number # In case you forgot to change the version, skip the number
# and put the next number in the next commit. # and put the next number in the next commit.
__version__ = "0.5.0" __version__ = "0.5.3"

View File

@ -1,5 +1,5 @@
# This file is part of naxalnet. # This file is part of pybatmesh.
# Copyright (C) 2021 The naxalnet Authors # Copyright (C) 2021 The pybatmesh Authors
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -19,16 +19,12 @@
__main__.py __main__.py
----------- -----------
If called as python -m naxalnet, this file makes naxalnet run like If called as python -m pybatmesh, this file makes pybatmesh run like
it was called from the commandline. Try: it was called from the commandline. Try:
python -m naxalnet --help python -m pybatmesh --help
WARNING: Using naxalnet might threaten the soverignity and integrity of
your nation-state. The authors are not responsible for any damage caused
while using this software.
""" """
from naxalnet.scripts import main from pybatmesh.scripts import main
if __name__ == "__main__": if __name__ == "__main__":
main() main()

View File

@ -1,5 +1,5 @@
# This file is part of naxalnet. # This file is part of pybatmesh.
# Copyright (C) 2021 The naxalnet Authors # Copyright (C) 2021 The pybatmesh Authors
# This program is free software: you can redistribute it and/or modify it # This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the # under the terms of the GNU General Public License as published by the
@ -22,20 +22,20 @@ This file contains functions to parse configuration files and arguments.
Most of these functions are meant to be used by parse_args() internally, Most of these functions are meant to be used by parse_args() internally,
so only parse_args() should be imported outside this file. so only parse_args() should be imported outside this file.
Some parts of naxalnet can be configured by configuration files and Some parts of pybatmesh can be configured by configuration files and
arguments in a specific order. First, the default values from default.py arguments in a specific order. First, the default values from default.py
is taken. Then, key-value pairs from the configuration files are read, if is taken. Then, key-value pairs from the configuration files are read, if
they exist, in the following order: they exist, in the following order:
- First it reads /usr/share/naxalnet/naxalnet.conf and then from - First it reads /usr/share/pybatmesh/pybatmesh.conf and then from
/usr/share/naxalnet/naxalnet.conf.d/*.conf where *.conf means any file /usr/share/pybatmesh/pybatmesh.conf.d/*.conf where *.conf means any file
with the name ending with ".conf". The files in this directory are with the name ending with ".conf". The files in this directory are
intended to be used by distribution and package maintainers. intended to be used by distribution and package maintainers.
- Next, it does the same with /usr/local/share/naxalnet - Next, it does the same with /usr/local/share/pybatmesh
- Then, it looks for the files naxalnet.conf and naxalnet.conf.d/*.conf - Then, it looks for the files pybatmesh.conf and pybatmesh.conf.d/*.conf
from the directory /etc/naxalnet, like it did up above. This directory from the directory /etc/pybatmesh, like it did up above. This directory
is where the user creates and stores the config file. is where the user creates and stores the config file.
- Then it parses the arguments from the commandline, storing the values in - Then it parses the arguments from the commandline, storing the values in
@ -56,7 +56,7 @@ is used.
from pathlib import Path from pathlib import Path
from configparser import ConfigParser from configparser import ConfigParser
from argparse import ArgumentParser, Namespace from argparse import ArgumentParser, Namespace
from naxalnet.default import CONFIG, CONFIG_FILES, CONFIG_DIRS from pybatmesh.default import CONFIG, CONFIG_FILES, CONFIG_DIRS
def get_config_files(): def get_config_files():
@ -96,7 +96,7 @@ def parse_args() -> Namespace:
""" """
Parse all arguments and return ArgumentParser.parse_args(), Parse all arguments and return ArgumentParser.parse_args(),
with values in config files as fallback. Ideally, only this with values in config files as fallback. Ideally, only this
function should be used by naxalnet to get arguments and function should be used by pybatmesh to get arguments and
configuration. configuration.
""" """
config = parse_config() config = parse_config()

View File

@ -1,5 +1,5 @@
# This file is part of naxalnet. # This file is part of pybatmesh.
# Copyright (C) 2021 The naxalnet Authors # Copyright (C) 2021 The pybatmesh Authors
# This program is free software: you can redistribute it and/or modify it # This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the # under the terms of the GNU General Public License as published by the
@ -23,8 +23,8 @@ is plugged in, or it is removed.
""" """
from dasbus.loop import EventLoop from dasbus.loop import EventLoop
from naxalnet.iwd import IWD, IWD_DEVICE_INTERFACE from pybatmesh.iwd import IWD, IWD_DEVICE_INTERFACE
from naxalnet.log import logger from pybatmesh.log import logger
class Daemon: class Daemon:

View File

@ -1,5 +1,5 @@
# This file is part of naxalnet. # This file is part of pybatmesh.
# Copyright (C) 2021 The naxalnet Authors # Copyright (C) 2021 The pybatmesh Authors
# This program is free software: you can redistribute it and/or modify it # This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the # under the terms of the GNU General Public License as published by the
@ -21,26 +21,30 @@ default.py
This file contains default values for configuration. This is taken as This file contains default values for configuration. This is taken as
fallback data by config.py if no configuration files were found, or if a fallback data by config.py if no configuration files were found, or if a
key-value pair was not present in the config file. The data will be key-value pair was not present in the config file. The data will be
further changed by arguments if naxalnet is called from the commandline. further changed by arguments if pybatmesh is called from the commandline.
See config.py for more info. See config.py for more info.
""" """
CONFIG = { CONFIG = {
"networkd": { "networkd": {
"confdir": "/usr/share/naxalnet/networkd", "confdir": "/usr/share/pybatmesh/networkd",
"runtimedir": "/run/systemd/network", "runtimedir": "/run/systemd/network",
}, },
"device": {"batman": "bat0", "bridge": "bridge0"}, "device": {"batman": "bat0", "bridge": "bridge0"},
"adhoc": {"name": "NxMesh"}, "adhoc": {"name": "pybatmesh"},
"ap": {"ssid": "MeshWiFi", "passwd": "naxalnet256"}, "ap": {"ssid": "BatWiFi", "passwd": "pybatmesh256"},
"gateway": {"mode": "auto"}, "gateway": {"mode": "auto"},
} }
# glob # glob
CONFIG_FILES = ["naxalnet.conf", "naxalnet.conf.d/*.conf"] CONFIG_FILES = ["pybatmesh.conf", "pybatmesh.conf.d/*.conf"]
CONFIG_DIRS = ["/usr/share/naxalnet", "/usr/local/share/naxalnet", "/etc/naxalnet"] CONFIG_DIRS = ["/usr/share/pybatmesh", "/usr/local/share/pybatmesh", "/etc/pybatmesh"]
MESH_GLOB = "mesh.*" MESH_GLOB = "mesh.*"
TMP_NET_GLOB = "tmp.*" TMP_NET_GLOB = "tmp.*"
ISSUE_URL = "https://git.disroot.org/pranav/naxalnet/issues" ISSUE_URL = "https://git.disroot.org/pranav/pybatmesh/issues"
REPORT_BUG_INFO = "If you think this is a bug, report it to " + ISSUE_URL REPORT_BUG_INFO = "If you think this is a bug, report it to " + ISSUE_URL
# Changing this constant will alter not just the behaviour of pybatmesh,
# but affect the meaning of Life, the Universe and Everthing
ANSWER = 42

View File

@ -1,5 +1,5 @@
# This file is part of naxalnet. # This file is part of pybatmesh.
# Copyright (C) 2021 The naxalnet Authors # Copyright (C) 2021 The pybatmesh Authors
# This program is free software: you can redistribute it and/or modify it # This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the # under the terms of the GNU General Public License as published by the
@ -29,11 +29,11 @@ terms and what they mean:
network, where there is no central point of failure. network, where there is no central point of failure.
- ap: a mode used to start a central access point so that other machines - ap: a mode used to start a central access point so that other machines
without naxalnet can connect to the mesh. AP is also known as WiFi without pybatmesh can connect to the mesh. AP is also known as WiFi
hotspot. hotspot.
- station: this is the mode most WiFi adapters use by default. This mode - station: this is the mode most WiFi adapters use by default. This mode
is used to connect to an ap. naxalnet DOES NOT use this mode. is used to connect to an ap. pybatmesh DOES NOT use this mode.
- adapter: a physical WiFi chip or something similar that is present - adapter: a physical WiFi chip or something similar that is present
inside most laptops and phones or can be connected via USB to a inside most laptops and phones or can be connected via USB to a
@ -47,12 +47,12 @@ terms and what they mean:
- machine: Since iwd uses the term device for a WiFi interface, we use the - machine: Since iwd uses the term device for a WiFi interface, we use the
word machine to refer to a computer, or a laptop, or a phone. word machine to refer to a computer, or a laptop, or a phone.
- node: a machine that runs naxalnet and is therefore connected to the - node: a machine that runs pybatmesh and is therefore connected to the
mesh. mesh.
""" """
from dasbus.connection import SystemMessageBus from dasbus.connection import SystemMessageBus
from naxalnet.log import logger from pybatmesh.log import logger
IWD_BUS = "net.connman.iwd" IWD_BUS = "net.connman.iwd"
IWD_ROOT_PATH = "/" IWD_ROOT_PATH = "/"

View File

@ -1,5 +1,5 @@
# This file is part of naxalnet. # This file is part of pybatmesh.
# Copyright (C) 2021 The naxalnet Authors # Copyright (C) 2021 The pybatmesh Authors
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -19,22 +19,22 @@ log.py
------ ------
Initialise the logger for other submodules to import. Do not import any Initialise the logger for other submodules to import. Do not import any
submodules here other than naxallnet.config, which is needed to set the submodules here other than pybatmesh.config, which is needed to set the
loglevel and to add the systemd journal handler loglevel and to add the systemd journal handler
""" """
import logging import logging
from systemd.journal import JournalHandler from systemd.journal import JournalHandler
from naxalnet.config import args from pybatmesh.config import args
def get_logger(): def get_logger():
""" """
Initialise the logger and return it. Initialise the logger and return it.
This function is meant to be used only by naxalnet.log. This function is meant to be used only by pybatmesh.log.
If you want to import the logger, use: If you want to import the logger, use:
from naxalnet.log import logger from pybatmesh.log import logger
""" """
log = logging.getLogger("naxalnet") log = logging.getLogger("pybatmesh")
# --verbose # --verbose
if args.verbose >= 2: if args.verbose >= 2:
loglevel = logging.DEBUG loglevel = logging.DEBUG

View File

@ -1,5 +1,5 @@
# This file is part of naxalnet. # This file is part of pybatmesh.
# Copyright (C) 2021 The naxalnet Authors # Copyright (C) 2021 The pybatmesh Authors
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -30,6 +30,7 @@ examples.
import subprocess import subprocess
from pathlib import Path from pathlib import Path
from dasbus.connection import SystemMessageBus from dasbus.connection import SystemMessageBus
from dasbus.loop import EventLoop, GLib
NETWORKD_BUS = "org.freedesktop.network1" NETWORKD_BUS = "org.freedesktop.network1"
@ -39,11 +40,12 @@ NETWORKD_PATH = "/org/freedesktop/network1"
class NetworkD: class NetworkD:
""" """
Control systemd-networkd using configuration files. Since these Control systemd-networkd using configuration files. Since these
were made for use by naxalnet only, the class is not suitable for were made for use by pybatmesh only, the class is not suitable for
importing outside naxalnet. importing outside pybatmesh.
""" """
def __init__(self, runtime_dir="/run/systemd/network", bus=SystemMessageBus()): def __init__(self, runtime_dir="/run/systemd/network", bus=SystemMessageBus()):
print("NetworkD init")
self._bus = bus self._bus = bus
self.proxy_reload() self.proxy_reload()
@ -118,3 +120,68 @@ class NetworkD:
""" """
for i in self.runtime_path.iterdir(): for i in self.runtime_path.iterdir():
self.remove_config(i.name) 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

@ -1,5 +1,5 @@
# This file is part of naxalnet. # This file is part of pybatmesh.
# Copyright (C) 2021 The naxalnet Authors # Copyright (C) 2021 The pybatmesh Authors
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by # it under the terms of the GNU General Public License as published by
@ -22,22 +22,21 @@ The functions in this file is used for reading configs, args
and doing the things this program is supposed to do. and doing the things this program is supposed to do.
This file is named scripts.py because the original developer This file is named scripts.py because the original developer
of this program could not think of a better name that suits this file. of this program could not think of a better name that suits this file.
If you want to hack naxalnet, this is the right place to start. If you want to hack pybatmesh, this is the right place to start.
When run from the commandline, the function main() is called. When run from the commandline, the function main() is called.
""" """
import sys import sys
import time
from pathlib import Path from pathlib import Path
from dasbus.error import DBusError from dasbus.error import DBusError
from systemd.daemon import notify from systemd.daemon import notify
from naxalnet import __version__ from pybatmesh import __version__
from naxalnet.default import REPORT_BUG_INFO, MESH_GLOB, TMP_NET_GLOB from pybatmesh.default import REPORT_BUG_INFO, MESH_GLOB, TMP_NET_GLOB
from naxalnet.log import logger from pybatmesh.log import logger
from naxalnet.iwd import Adapter, Device, IWD from pybatmesh.iwd import Adapter, Device, IWD
from naxalnet.config import args from pybatmesh.config import args
from naxalnet.daemon import Daemon from pybatmesh.daemon import Daemon
from naxalnet.network import NetworkD from pybatmesh.network import NetworkD, NetworkLoop
def get_sorted_glob(directory: str, glob: str) -> list: def get_sorted_glob(directory: str, glob: str) -> list:
@ -56,17 +55,15 @@ def get_sorted_glob(directory: str, glob: str) -> list:
def any_interface_is_routable(): def any_interface_is_routable():
"""returns true if any of the interfaces 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. # First, add the temporary configs to networkd.
for i in get_sorted_glob(args.networkd_config_dir, TMP_NET_GLOB): for i in get_sorted_glob(args.networkd_config_dir, TMP_NET_GLOB):
logger.debug("Adding temporary config %s", i) logger.debug("Adding temporary config %s", i)
networkd.add_config(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 # timeout = 10 seconds
# function that timeouts after 10 seconds. routable = networkd.wait_until_routable(10 * 1000)
time.sleep(10)
routable = networkd.is_routable()
networkd.remove_all_configs() networkd.remove_all_configs()
return routable return routable
@ -161,7 +158,7 @@ def setup_devices():
if len(ap_devices) != 0: if len(ap_devices) != 0:
ap_device = Device(ap_devices.pop()) ap_device = Device(ap_devices.pop())
logger.info("Starting WiFi Access Point on %s", ap_device.name) logger.info("Starting WiFi Access Point on %s", ap_device.name)
logger.info("Use naxalnet --print-wifi to get password") logger.info("Use pybatmesh --print-wifi to get password")
# Turn on adapter if it is off # Turn on adapter if it is off
# See issue #9 # See issue #9
ap_adapter = Adapter(ap_device.adapter) ap_adapter = Adapter(ap_device.adapter)
@ -224,7 +221,7 @@ def main():
""" """
This is where the magic happens! This is where the magic happens!
This function is run every time you This function is run every time you
execute naxalnet from the commandline execute pybatmesh from the commandline
""" """
if args.print_wifi: if args.print_wifi:
@ -234,20 +231,22 @@ def main():
print_version() print_version()
sys.exit(0) sys.exit(0)
# Notify systemd that naxalnet is ready. # Notify systemd that pybatmesh is ready.
# see man:sd_notify(3) # see man:sd_notify(3)
notify("READY=1") notify("READY=1")
# Gateway mode comes in handy when many nodes have a DHCP server and # Gateway mode comes in handy when many nodes have a DHCP server and
# you want to prevent conflicts. It defaults to "auto" in naxalnet. # you want to prevent conflicts. It defaults to "auto" in pybatmesh.
# https://www.open-mesh.org/projects/batman-adv/wiki/Gateways # https://www.open-mesh.org/projects/batman-adv/wiki/Gateways
if args.gateway_mode == "auto": if args.gateway_mode == "auto":
logger.info("Checking for internet connection") logger.info("Checking for internet connection")
notify("STATUS=Checking for internet") notify("STATUS=Checking for internet")
# If any interface is routable, set gateway mode to server # If any interface is routable, set gateway mode to server
if any_interface_is_routable(): if any_interface_is_routable():
logger.info("Network is routable. Setting gw_mode to server")
gateway_mode = "server" gateway_mode = "server"
else: else:
logger.info("Network is not routable. Setting gw_mode to client")
gateway_mode = "client" gateway_mode = "client"
logger.info("gateway_mode set to %s", gateway_mode) logger.info("gateway_mode set to %s", gateway_mode)
elif args.gateway_mode in ["server", "client", "off"]: elif args.gateway_mode in ["server", "client", "off"]:

View File

@ -1,3 +1,4 @@
[build-system] [build-system]
# I don't know what this means, I just copied it from some setuptools tutorial
requires = ["setuptools", "wheel"] requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta" build-backend = "setuptools.build_meta"

View File

@ -1,10 +1,13 @@
# This program is not meant to be distributed through PyPi # This file is loosely based on the setup.cfg used in django.
# pybatmesh 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] [metadata]
name = naxalnet name = pybatmesh
version = attr: naxalnet.__version__ version = attr: pybatmesh.__version__
description = create mesh networks with batman-adv and systemd description = create mesh networks with batman-adv and systemd
long_description = file: README.md long_description = file: README.md
url = https://git.disroot.org/pranav/naxalnet url = https://git.disroot.org/pranav/pybatmesh
author = Pranav Jerry author = Pranav Jerry
author_email = libreinator@disroot.org author_email = libreinator@disroot.org
license = GPLv3 license = GPLv3
@ -29,21 +32,21 @@ install_requires =
[options.entry_points] [options.entry_points]
console_scripts = console_scripts =
naxalnet = naxalnet.scripts:main pybatmesh = pybatmesh.scripts:main
[options.data_files] [options.data_files]
lib/systemd/system = lib/systemd/system =
naxalnet.service pybatmesh.service
# If installing with pip, this file will be copied to some other place. # 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. # This is the reason we use setup.py instead of pip in the Makefile.
/etc/naxalnet = /etc/pybatmesh =
naxalnet.conf.example pybatmesh.conf.example
share/naxalnet/networkd = share/pybatmesh/networkd =
systemd-networkd/mesh.01-batman.netdev network/mesh.01-batman.netdev
systemd-networkd/mesh.02-bridge.netdev network/mesh.02-bridge.netdev
systemd-networkd/mesh.03-wireless-ad-hoc.network network/mesh.03-wireless-ad-hoc.network
systemd-networkd/mesh.04-batman.network network/mesh.04-batman.network
systemd-networkd/mesh.05-wireless-ap.network network/mesh.05-wireless-ap.network
systemd-networkd/mesh.06-eth.network network/mesh.06-eth.network
systemd-networkd/mesh.07-bridge.network network/mesh.07-bridge.network
systemd-networkd/tmp.01-eth.network network/tmp.01-eth.network