|
| 1 | +# zre |
| 2 | + |
| 3 | +[](https://github.com/sorki/haskell-zre/actions/workflows/ci.yaml) |
| 4 | +[](https://hackage.haskell.org/package/zre) |
| 5 | +[](https://packdeps.haskellers.com/feed?needle=zre) |
| 6 | + |
| 7 | +ZRE protocol implementation https://rfc.zeromq.org/spec:36/ZRE/ |
| 8 | + |
| 9 | +Peer-to-peer local area networking with reliable group messaging |
| 10 | +and automatic peer discovery. |
| 11 | + |
| 12 | +## Usage |
| 13 | + |
| 14 | +Dependencies: |
| 15 | + |
| 16 | +``` |
| 17 | +zeromq4 |
| 18 | +``` |
| 19 | + |
| 20 | +Clone and test |
| 21 | + |
| 22 | +```sh |
| 23 | +git clone https://github.com/sorki/haskell-zre/ |
| 24 | +cd haskell-zre |
| 25 | +nix-build |
| 26 | +./result/bin/zre |
| 27 | +# in another terminal or networked computer |
| 28 | +./result/bin/zre |
| 29 | +``` |
| 30 | + |
| 31 | +Two zre peers should find each other and be able to send message between each other. |
| 32 | +Firewall needs to allow traffic on UDP port 5670 and TCP port range 41000-41100. |
| 33 | +Application picks random port from this range and advertises it to network. |
| 34 | + |
| 35 | +## Applications |
| 36 | + |
| 37 | +Few applications are provided to get you started: |
| 38 | + |
| 39 | + - zre - interact and dump events |
| 40 | + - zrecat <group> - cat messages for group |
| 41 | + |
| 42 | +These can be installed locally using `pkgs.haskellPackage.zre`. |
| 43 | + |
| 44 | +Try running multiple copies of `zre` and `zrecat` on |
| 45 | +the same computer or computers on the local network |
| 46 | + |
| 47 | +```sh |
| 48 | +zre |
| 49 | +# another terminal |
| 50 | +zrecat test |
| 51 | +# now in original terminal you can join testgroup with |
| 52 | +> /join test |
| 53 | +# or send messages to it |
| 54 | +> /shout test msg |
| 55 | +``` |
| 56 | + |
| 57 | +Send uptime periodically to uptime group |
| 58 | + |
| 59 | +```sh |
| 60 | +( while true; do uptime; sleep 1; done ) | zrecat uptime |
| 61 | +``` |
| 62 | + |
| 63 | +Cat file to group |
| 64 | + |
| 65 | +```sh |
| 66 | +cat /etc/os-release | zrecat test |
| 67 | +``` |
| 68 | + |
| 69 | +Interact manually |
| 70 | + |
| 71 | +```sh |
| 72 | +zre |
| 73 | +# in zre shell following commands are supported: |
| 74 | +> /join time |
| 75 | +> /shout time test! |
| 76 | +> /leave time |
| 77 | +> /join uptime |
| 78 | +> /whisper <uuid> message |
| 79 | +``` |
| 80 | + |
| 81 | +## ZGossip |
| 82 | + |
| 83 | +Implementation of gossip protocol is included in form of key value TTL server. |
| 84 | +This allows connecting peers from different networks (or subnets) not reachable via multicast |
| 85 | +beacon. This service requires TCP port 31337 and can be started with `zgossip-server` binary. |
| 86 | + |
| 87 | +Run server |
| 88 | + |
| 89 | +```sh |
| 90 | +zgossip_server |
| 91 | +``` |
| 92 | + |
| 93 | +Pass gossip endpoint to apps with |
| 94 | + |
| 95 | +```sh |
| 96 | +zre -g <gossip_ip>:31337 |
| 97 | +``` |
| 98 | + |
| 99 | +## Configuration |
| 100 | + |
| 101 | +ZRE applications using `runZre` will automatically try to load configuration |
| 102 | +file if `ZRECFG` environment variable points to it. See `zre.conf` for configuration |
| 103 | +example:: |
| 104 | + |
| 105 | +```sh |
| 106 | +ZRECFG=./zre.conf zrecat test |
| 107 | +``` |
| 108 | + |
| 109 | +To be able to use one config for multiple apps and still be able to distinguish between |
| 110 | +them you can also set `ZRENAME` environment variable which overrides name |
| 111 | +from config or default config if `ZRECFG` is not used:: |
| 112 | + |
| 113 | +```sh |
| 114 | +ZRENAME=zrenode1 zrecat test |
| 115 | +``` |
| 116 | + |
| 117 | +## Demos |
| 118 | + |
| 119 | +* https://asciinema.org/a/106340 |
0 commit comments