Skip to content

Commit

Permalink
Merge pull request #98 from tomeshnet/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
benhylau committed Nov 2, 2017
2 parents 960398d + 5da6ae4 commit 5fc3ee1
Show file tree
Hide file tree
Showing 17 changed files with 230 additions and 72 deletions.
39 changes: 22 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@

[![Build Status](https://travis-ci.org/tomeshnet/prototype-cjdns-pi.svg?branch=master)](https://travis-ci.org/tomeshnet/prototype-cjdns-pi)

The following instructions will help you set up an encrypted mesh network on Raspberry Pi's. It takes about 5 minutes to set up a node with the Pi 3. Obviously, to have a mesh you will need more than one node.
The following instructions will help you set up an encrypted mesh network on Raspberry Pi's. It takes about 15 minutes to set up a node with the Pi 3. Obviously, to have a mesh you will need more than one node.

Many models of Orange Pi hardware running [Armbian](https://www.armbian.com/) are also supported. The same installation steps can be followed, except you would flash the SD card with Armbian instead of Raspbian. See [Hardware Table](#hardware-table) for the full list of supported hardware.

## Set Up
(Note: Latest version is based on Stretch and is currently a WIP. Please continue to use Jessie)

1. Make sure you have the following items:

* A Raspberry Pi Zero, 1, 2, or 3 (Pi 3 recommended)
* Raspberry Pi Zero, 1, 2, 3 (Pi 3 recommended), or for advanced users other [compatible hardware](#hardware-table)
* An SD card that works with the Pi
* **Optional:** A USB WiFi adapter with [802.11s Mesh Point](https://github.com/o11s/open80211s/wiki/HOWTO) support, such as the [TP-LINK TL-WN722N](http://www.tp-link.com/en/products/details/TL-WN722N.html) or [Toplinkst TOP-GS07](https://github.com/tomeshnet/documents/blob/master/technical/20170208_mesh-point-with-topgs07-rt5572.md)

1. Flash the SD card with [Raspbian Jessie Lite](https://downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2017-07-05/2017-07-05-raspbian-jessie-lite.zip)
1. Flash the SD card with [Raspbian Stretch Lite](https://www.raspberrypi.org/downloads/raspbian/).

1. Create an empty file named **ssh** to enable SSH when the Pi boots:

Expand All @@ -38,7 +39,7 @@ The following instructions will help you set up an encrypted mesh network on Ras
The installation script can also install many optional features such as distributed applications and network analysis tools that are useful but non-essential to run a node. You can use flags to selectively enable them, or use the following command to install all optional features:

```
$ wget https://raw.githubusercontent.com/tomeshnet/prototype-cjdns-pi/master/scripts/install && chmod +x install && WITH_MESH_POINT=true WITH_WIFI_AP=true WITH_IPFS=true WITH_PROMETHEUS_NODE_EXPORTER=true WITH_PROMETHEUS_SERVER=true WITH_GRAFANA=true WITH_EXTRA_TOOLS=true ./install
$ wget https://raw.githubusercontent.com/tomeshnet/prototype-cjdns-pi/master/scripts/install && chmod +x install && WITH_MESH_POINT=true WITH_WIFI_AP=true WITH_IPFS=true WITH_PROMETHEUS_NODE_EXPORTER=true WITH_PROMETHEUS_SERVER=true WITH_GRAFANA=true WITH_H_DNS=true WITH_H_NTP=true WITH_FAKE_HWCLOCK=true WITH_EXTRA_TOOLS=true ./install
```

## Optional Features
Expand All @@ -51,6 +52,9 @@ The following instructions will help you set up an encrypted mesh network on Ras
| `WITH_PROMETHEUS_NODE_EXPORTER` | **9100**: Node Exporter UI | Set to `true` if you want to install [Prometheus Node Exporter](https://github.com/prometheus/node_exporter) to report network metrics. |
| `WITH_PROMETHEUS_SERVER` | **9090**: Prometheus Server UI | Set to `true` if you want to install [Prometheus Server](https://github.com/prometheus/prometheus) to collect network metrics. *Requires Prometheus Node Exporter.* |
| `WITH_GRAFANA` | **3000**: Grafana UI (login: admin/admin) | Set to `true` if you want to install [Grafana](https://grafana.com) to display network metrics. *Requires Prometheus Server.* |
| `WITH_H_DNS` | None | Set to `true` if you want to use Hyperboria-compatible DNS servers: `fc4d:c8e5:9efe:9ac2:8e72:fcf7:6ce8:39dc` and `fc6e:691e:dfaa:b992:a10a:7b49:5a1a:5e09` |
| `WITH_H_NTP` | None | Set to `true` if you want to use a Hyperboria-compatible NTP server: `fc4d:c8e5:9efe:9ac2:8e72:fcf7:6ce8:39dc` |
| `WITH_FAKE_HWCLOCK` | None | Set to `true` if you want to force hwclock to store its time every 5 minutes. |
| `WITH_EXTRA_TOOLS` | None | Set to `true` if you want to install non-essential tools useful for network analysis: vim socat oping bmon iperf3 |

If you are connected to the WiFi Access Point, all HTTP services are available via `http://10.0.0.1:PORT` as well as the cjdns IPv6. To connect with the cjdns address, first note your node's fc00::/8 address from `status`, then navigate to `http://[fcaa:bbbb:cccc:dddd:eeee:0000:1111:2222]:PORT` from your browser.
Expand Down Expand Up @@ -83,18 +87,19 @@ We are adding support for [Orange Pi](http://www.orangepi.org/) boards and have

## Hardware Table

Following is a list of hardware tested with the install.

| Hardware | Base OS | CJDNS Bench~ | USB | Ethernet| Notes |
| :-------------------------|:----------------|:--------------|:-----|:--------|:-----------------|
| Raspberry Pi 1 A+ | [Raspbian Jessie Lite](https://www.raspberrypi.org/downloads/raspbian/) | 35K | 1 | None | |
| Raspberry Pi 1 B+ | [Raspbian Jessie Lite](https://www.raspberrypi.org/downloads/raspbian/) | 35K | 2 | 10/100 | |
| Raspberry Pi 3 | [Raspbian Jessie Lite](https://www.raspberrypi.org/downloads/raspbian/) | | 2 | 10/100 | |
| Raspberry Pi Zero | [Raspbian Jessie Lite](https://www.raspberrypi.org/downloads/raspbian/) | | 1 | 10/100 | |
| Orange Pi Lite | [Armbian Nightly](https://dl.armbian.com/orangepilite/nightly/) | 126K | 2 | None | |
| Orange Pi One | [Armbian Nightly](https://dl.armbian.com/orangepione/nightly/) | 131K | 1 | 10/100 | |
| Orange Pi Zero | [Armbian Nightly](https://dl.armbian.com/orangepizero/nightly/) | 70K | 1(+2*) | 10/100 | *Additional USB available via headers |
| Orange Pi Zero Plus 2 H5 | [Armbian Nightly](https://dl.armbian.com/orangepizeroplus2-h5/nightly/) | 142K | 0(+2*) | None | *USB available via headers |
List of tested hardware:

| Hardware | Base OS | [CJDNS Benchmark](https://github.com/phillymesh/cjdns-optimizations) (salsa20/poly1305, switching) | USB | Ethernet | Notes |
| :-------------------------|:----------------|:---------------------------------------------------------------------------------------------------|:----|:---------|:---------|
| Raspberry Pi 3 | [Raspbian Lite](https://www.raspberrypi.org/downloads/raspbian/) | 350k, 100k | 2 | 10/100 | |
| Raspberry Pi 2 | [Raspbian Lite](https://www.raspberrypi.org/downloads/raspbian/) | 150k, 50k | 2 | 10/100 | |
| Raspberry Pi 1 A+ | [Raspbian Lite](https://www.raspberrypi.org/downloads/raspbian/) | 35k, - | 1 | None | |
| Raspberry Pi 1 B+ | [Raspbian Lite](https://www.raspberrypi.org/downloads/raspbian/) | 35k, - | 2 | 10/100 | |
| Raspberry Pi Zero | [Raspbian Lite](https://www.raspberrypi.org/downloads/raspbian/) | 68k, 30k | 1* | None | *Need OTG Cable |
| Orange Pi Lite | [Armbian Nightly](https://dl.armbian.com/orangepilite/nightly/) | 198k, 76k | 2 | None | |
| Orange Pi One | [Armbian Nightly](https://dl.armbian.com/orangepione/nightly/) | 198k, 76k | 1 | 10/100 | |
| Orange Pi Zero | [Armbian Nightly](https://dl.armbian.com/orangepizero/nightly/) | 148k, 56k | 1 (+2*) | 10/100 | *Additional USB available via headers |
| Orange Pi Zero Plus 2 H5 | [Armbian Nightly](https://dl.armbian.com/orangepizeroplus2-h5/nightly/) | 142k, 92K | 0 (+2*) | None | *USB available via headers |

## Development

Expand Down
14 changes: 14 additions & 0 deletions scripts/fake-hwclock/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bash

set -e

BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# Install fake-hwclock
if [ ! -x "$(command -v fake-hwclock)" ]; then
sudo apt-get install fake-hwclock -y
fi

# Configure crontab to run fake-hwclock every 5 minutes
sudo sed -i '/fake-hwclock/d' /etc/crontab
echo "*/5 * * * * root fake-hwclock" | sudo tee --append /etc/crontab > /dev/null
5 changes: 5 additions & 0 deletions scripts/fake-hwclock/uninstall
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

set -e

sudo sed -i '/fake-hwclock/d' /etc/crontab
13 changes: 13 additions & 0 deletions scripts/h-dns/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/usr/bin/env bash

set -e

H_DNS_SERVER_0="fc4d:c8e5:9efe:9ac2:8e72:fcf7:6ce8:39dc"
H_DNS_SERVER_1="fc6e:691e:dfaa:b992:a10a:7b49:5a1a:5e09"

BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# Configure Hyperboria DNS
sudo sed -i '/dns-nameservers /d' /etc/network/interfaces
echo "" | sudo tee --append /etc/network/interfaces > /dev/null
echo "dns-nameservers ${H_DNS_SERVER_0} ${H_DNS_SERVER_1}" | sudo tee --append /etc/network/interfaces > /dev/null
5 changes: 5 additions & 0 deletions scripts/h-dns/uninstall
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

set -e

sudo sed -i '/dns-nameservers /d' /etc/network/interfaces
16 changes: 16 additions & 0 deletions scripts/h-ntp/install
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

set -e

H_NTP_SERVER="fc4d:c8e5:9efe:9ac2:8e72:fcf7:6ce8:39dc"

BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# Install NTP
if [ ! -x "$(command -v ntpd)" ]; then
sudo apt-get install ntp -y
fi

# Configure Hyperboria NTP
sudo sed -i '/pool /d' /etc/ntp.conf
echo "pool -6 ${H_NTP_SERVER} iburst" | sudo tee --append /etc/ntp.conf > /dev/null
5 changes: 5 additions & 0 deletions scripts/h-ntp/uninstall
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

set -e

sudo sed -i '/pool /d' /etc/ntp.conf
1 change: 1 addition & 0 deletions scripts/hostapd/dnsmasq.conf
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
interface=wlan0
dhcp-range=10.0.0.2,10.0.0.127,255.255.255.0,12h
bind-interfaces
48 changes: 35 additions & 13 deletions scripts/hostapd/install
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@ set -e

BASE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

# Install hostapd and dnsmasq to run IEEE 802.11 Access Point
if ! [ "$(which hostapd)" ] || ! [ "$(which dnsmasq)" ]; then
sudo apt-get install hostapd dnsmasq radvd -y
# Create radvd.conf before installing radvd, installation fails without it
if ! [ -f /etc/radvd.conf ]; then
sudo cp "$BASE_DIR/radvd.conf" /etc/radvd.conf
fi

# Install packages to run IEEE 802.11 Access Point
sudo apt-get install hostapd radvd dnsmasq iptables -y

# Configure wlan0 interface
sudo cp /etc/network/interfaces /etc/network/interfaces.backup
START=$(grep -n "allow-hotplug wlan0" /etc/network/interfaces | awk '{ print $1 }' FS=':')
END=$(expr $START + 3)
sudo sed -i "${START},${END}d" /etc/network/interfaces
sudo mv /etc/network/interfaces /etc/network/interfaces.bak
sudo touch /etc/network/interfaces

echo "source-directory /etc/network/interfaces.d" | sudo tee --append /etc/network/interfaces > /dev/null
echo "" | sudo tee --append /etc/network/interfaces > /dev/null
echo "auto lo" | sudo tee --append /etc/network/interfaces > /dev/null
echo "iface lo inet loopback" | sudo tee --append /etc/network/interfaces > /dev/null
echo "" | sudo tee --append /etc/network/interfaces > /dev/null
echo "allow-hotplug wlan0" | sudo tee --append /etc/network/interfaces > /dev/null
echo "iface wlan0 inet static" | sudo tee --append /etc/network/interfaces > /dev/null
Expand All @@ -24,9 +30,12 @@ echo " broadcast 10.0.0.255" | sudo tee --append /etc/network/interfaces > /d
echo "iface wlan0 inet6 static" | sudo tee --append /etc/network/interfaces > /dev/null
echo " address fdfc::2" | sudo tee --append /etc/network/interfaces > /dev/null
echo " netmask 64" | sudo tee --append /etc/network/interfaces > /dev/null
echo "" | sudo tee --append /etc/network/interfaces > /dev/null
echo "allow-hotplug eth0" | sudo tee --append /etc/network/interfaces > /dev/null
echo "iface eth0 inet dhcp" | sudo tee --append /etc/network/interfaces > /dev/null

# Enable packet forwarding
sudo cp /etc/sysctl.conf /etc/sysctl.conf.backup
sudo cp /etc/sysctl.conf /etc/sysctl.conf.bak
sudo sed -i 's/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/' /etc/sysctl.conf
sudo sed -i 's/#net.ipv6.conf.all.forwarding=1/net.ipv6.conf.all.forwarding=1/' /etc/sysctl.conf

Expand Down Expand Up @@ -71,17 +80,30 @@ else
fi

# Configure DHCP with dnsmasq
sudo cp /etc/dnsmasq.conf /etc/dnsmasq.conf.backup
if [ -f /etc/dnsmasq.conf ]; then
sudo cp /etc/dnsmasq.conf /etc/dnsmasq.conf.bak
fi
sudo cp "$BASE_DIR/dnsmasq.conf" /etc/dnsmasq.conf
sudo cp /etc/dhcpcd.conf /etc/dhcpcd.conf.backup
sudo echo "" | sudo tee --append /etc/dhcpcd.conf > /dev/null
sudo echo "denyinterfaces wlan0" | sudo tee --append /etc/dhcpcd.conf > /dev/null

if [ -f /etc/dhcpcd.conf ]; then
sudo cp /etc/dhcpcd.conf /etc/dhcpcd.conf.bak
sudo echo "" | sudo tee --append /etc/dhcpcd.conf > /dev/null
sudo echo "denyinterfaces wlan0" | sudo tee --append /etc/dhcpcd.conf > /dev/null
fi

# Configure IPv6 router advertisement with radvd
sudo cp "$BASE_DIR/radvd.conf" /etc/radvd.conf
sudo systemctl daemon-reload
sudo systemctl enable radvd.service
sudo systemctl start radvd.service

# Enable hostapd service
if [ -f /etc/default/hostapd ]; then
sed '\?^DAEMON_CONF?d' /etc/default/hostapd | sudo tee /etc/default/hostapd > /dev/null
sudo echo DAEMON_CONF="/etc/hostapd.conf" | sudo tee --append /etc/default/hostapd > /dev/null
fi

sudo cp "$BASE_DIR/hostapd.service" /etc/systemd/system/hostapd.service
sudo systemctl daemon-reload
sudo systemctl enable hostapd.service
sudo systemctl start hostapd.service
sudo systemctl start hostapd.service
16 changes: 8 additions & 8 deletions scripts/hostapd/uninstall
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ set -e
sudo systemctl disable hostapd.service 2>/dev/null || true
sudo systemctl stop hostapd.service 2>/dev/null || true
sudo systemctl daemon-reload
if [ -f "/etc/network/interfaces.backup" ]; then
sudo mv /etc/network/interfaces.backup /etc/network/interfaces
if [ -f "/etc/network/interfaces.bak" ]; then
sudo mv /etc/network/interfaces.bak /etc/network/interfaces
fi
if [ -f "/etc/sysctl.conf.backup" ]; then
sudo mv /etc/sysctl.conf.backup /etc/sysctl.conf
if [ -f "/etc/sysctl.conf.bak" ]; then
sudo mv /etc/sysctl.conf.bak /etc/sysctl.conf
fi
if [ -f "/etc/dnsmasq.conf.backup" ]; then
sudo mv /etc/dnsmasq.conf.backup /etc/dnsmasq.conf
if [ -f "/etc/dnsmasq.conf.bak" ]; then
sudo mv /etc/dnsmasq.conf.bak /etc/dnsmasq.conf
fi
if [ -f "/etc/dhcpcd.conf.backup" ]; then
sudo mv /etc/dhcpcd.conf.backup /etc/dhcpcd.conf
if [ -f "/etc/dhcpcd.conf.bak" ]; then
sudo mv /etc/dhcpcd.conf.bak /etc/dhcpcd.conf
fi
sudo rm -f /etc/radvd.conf
sudo rm -f /etc/hostapd/hostapd.conf
Expand Down
2 changes: 1 addition & 1 deletion scripts/hostapd/wpa-eap/hostapd.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
interface=wlan0
hw_mode=g
channel=10
channel=11
auth_algs=1
wpa=3
wpa_key_mgmt=WPA-EAP
Expand Down
2 changes: 1 addition & 1 deletion scripts/hostapd/wpa-psk/hostapd.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
interface=wlan0
hw_mode=g
channel=10
channel=11
auth_algs=1
wpa=2
wpa_key_mgmt=WPA-PSK
Expand Down
2 changes: 1 addition & 1 deletion scripts/install
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ if [ -z "$TAG_PROTOTYPE_CJDNS_PI" ]; then
TAG_PROTOTYPE_CJDNS_PI=master
fi

if ! [ -z "`ps xa | grep dpkg | grep -v grep`" ]; then
if ! [ -z "`ps xa | awk '{print $5}' | grep dpkg | grep -v grep`" ]; then
echo -e "\e[1;31mDPKG is running in the background.\e[0m"
read -p "Would you like to KILL it to continue (Y/n)? " -n 1 -r
echo ""
Expand Down
Loading

0 comments on commit 5fc3ee1

Please sign in to comment.