Meshenger is a Forban-inspired messaging software used for a speculative broadcast communication project. The starting point is an electronic messaging system running on a wireless mesh network. The messages propagate through the network when devices that come in contact with each other synchronize their content. It is non-hierarchical, every node receives, relays and broadcasts messages.
Using Meshenger, devices detect each other by continously broadcasting an identifier packet while listening to those of other nodes. As soon as two (or more) nodes detect each other they will try to synchronize the messages on each node.
The users of the network can interface with the nodes to send or receive messages by using the webbrowser of their smartphone or computer. The messages can be received and sent at any time, but they are only synchronized in the network when other nodes are encountered.
Meshenger is supposed to run on an Open-WRT router that has been configured to work in mesh networks (for a configuration how-to see below).
## Configuring a router for Open-WRT and Meshenger
### Flashing and preparing
Meshenger requires routers that both support Open-WRT and *have at least one USB port* [(List of Open-WRT routers here)](http://wiki.openwrt.org/toh/start).
We have used the following models: TP-Link MR-3020, TP-Link TP-WR703n and TP-WR842nd.
Open-WRT have a guide for each supported device that tells how to best flash your specific device with Open-WRT. [(Article on flashing)](http://wiki.openwrt.org/doc/howto/generic.flashing)
You are going to need to have an internet connection to your router, the easiest thing is to hook it up to the router.
Alternatively if you use OSX you can enable internet sharing (make sure to set your OSX machine as the gateway and DNS server for your router in /etc/config/network)
The next section is on how to set up the network interfaces to work with B.A.T.M.A.N the mesh networking protocol. It is more or less a summary of what's written [here.](http://www.open-mesh.org/projects/batman-adv/wiki/Batman-adv-openwrt-config)
For the front-end, the client user interface, we must have a captive portal running. These are the first steps in enableing another wireless interface for the hotspot
Add the following lines in the following config files and restart the network:
`$ vi /etc/config/network`
```
config interface 'hotspot'
option 'iface' 'radio0' #use your excisting wifi device (look in config/wireless below)
option 'proto' 'static'
option 'ipaddr' '192.168.2.1'
option 'netmask' '255.255.255.0'
option 'type' 'bridge'
```
`$ vi /etc/config/wireless`
```
config wifi-iface
option 'device' 'radio0' #use your excisting wifi device, look in the list above.
We want connecting clients to be redirected to our webapp, no matter what url they request. To do so we need to add some firewall rules, configure dhcp and dnsmasq.
Add the following firewall rules:
`$ vi /etc/config/firewall`
```
config 'rule'
option 'target' 'ACCEPT'
option 'src' 'hotspot' # guest wifi interface
option 'proto' 'tcp'
option '_name' 'Website' # this can maybe go?
option 'dest_port' '80'
config 'redirect'
option 'proto' 'tcp'
option '_name' 'Website' # this can maybe go?
option 'src' 'hotspot' # guest wifi interface
option 'src_dport' '80'
option 'dest_port' '80'
option 'dest_ip' '192.168.2.1' # ip of webserver
```
In the dnsmasq section of the dhcp config (first section) add the following line:
`$ vi /etc/config/dhcp`
```
list server '//192.168.2.1'
```
In the dnsmasq config (first section) add the following line(s):
`$ vi /etc/dnsmasq.conf`
```
# Redirect all dns requests to meshenger
address=/#/192.168.2.1
```
Restart dnsmasq to apply the changes:
`$ /etc/init.d/dnsmasq restart`
Now all http requests will be directed to Meshenger!
Alot of processes are started at boot, and we want to make sure our script runs after the system has booted completely. To find out the boot order, look in the rc.d folder:
```$ ls /etc/rc.d```
This will output a list of startup sctipts with prefixes like S10-, S20-, S30-. The numbers define the boot order, the higher, the later. Remember the highest 'S'(cript) number. We need to run our script after the last one.
Now we have to activate the script we just pasted and make it run as service, on every (re)boot.
```$ /etc/init.d/meshenger enable```
This creates a symlink in `/etc/rc.d` with the boot order number prefix you provided in the init.d script (S99-meshenger). You can also start and stop the service manually with:
```$ /etc/init.d/meshenger start```
```$ /etc/init.d/meshenger stop```
That's all, reboot and see if it works ( `$ ps | grep python` )!
If you want, you can hook your box up to the internet and manage it remotely. This is not in the scope of this project but I'll share the steps with you:
#### Configure your firewall
```
$ vi /etc/config/firewall
config 'rule'
option 'src' 'wan'
option 'dest_port' '22'
option 'target' 'ACCEPT'
option 'proto' 'tcp'
$ /etc/init.d/firewall restart
```
#### Configure open ssh service
Add the line below in your dropbear config
```
$ vi /etc/config/dropbear
option 'GatewayPorts' 'on'
$ /etc/init.d/dropbear restart
```
Now you can acces your router, via ssh, from the internet.