# Allmende
A free, distributed marketplace for buying, selling and renting. Listings are
replicated across the nodes of everyone who participates, so there is no central
server and no cost. See [docs/PROTOCOL.md](docs/PROTOCOL.md).
## How to run it
You need Go (see `go.mod` for the version). Node.js is not needed to run a node.
**1. Build**
```
git clone ssh://git@git.stinnesbeck.com:2222/nils/allmende.git && cd allmende
go build -o bin/allmende ./cmd/allmende # or: make build
```
**2. Create your identity (once)**
```
bin/allmende init # or: make init
```
This prints your 12-word recovery phrase **once**. Write it down: it is the only
way to get your identity and listings back if the machine is lost
(`allmende recover`). Keys and the database live in the data directory,
`~/.local/share/allmende` by default (change it with `--data
` or the
`ALLMENDE_DATA` environment variable). Besides the numbered list, `init` prints the
words as one plain line you can triple-click and paste into a password manager.
**3. Start the node**
```
bin/allmende run # or: make run
```
The UI and API are on http://127.0.0.1:8080. Leave it running: a node has to stay
up to receive messages and keep your listings alive. Stop it with Ctrl+C.
**4. Sign in and choose a region**
`run` prints an "Owner login" link in the terminal. Open it in your browser. A new
node follows no region yet, so you land on the region picker: type a place name
(Bonn, Köln, München, ...), add the cells you want and save. It applies at once.
To start with regions instead, pass them on the command line, by code or by name:
```
bin/allmende run --region u1j --region "Köln"
```
**5. Use it**
- Open http://127.0.0.1:8080 to search listings, and write to an owner from a listing.
- In the browser, "My listings" > "New listing" publishes one. Listings last up to
30 days; renew them there (the terminal reminds you when 5 days are left).
- Answers to your listings show up under "My listings", and the terminal says
when a message arrives.
Useful flags for `run`: `--http ` (default `127.0.0.1:8080`),
`--listen ` (libp2p port), `--bootstrap `, `--no-mdns`,
`--data `. `bin/allmende help` lists them all. To run it for real, in Docker
or on NixOS, see below.
Open http://127.0.0.1:8080 to search. Your browser checks every listing's
signature itself, so you don't have to trust the node it talks to. The UI is
pre-built and embedded; Node.js is only needed to change it
(`cd web && npm ci && npm run build && npm test`).
Buyers can write to an owner straight from a listing, without an account.
Messages are end-to-end encrypted in the browser and relayed through the
network, so a node only ever sees ciphertext. The owner reads and answers
in the browser (`allmende run` prints a sign-in link; open it to get "My listings")
and can release the exact address as a signed message. When a message arrives the
node says so on its terminal (listing, link to the conversation, never the text).
Owners publish from the same screen: "New listing" takes a title, price and
pasted coordinates (only a ~1 km area is published, never the address), and
listings can be edited, renewed (30 days, manually) or deleted there. Renewing is
manual on purpose, so abandoned listings lapse; the node reminds you on its
terminal, once a day, about every listing with 5 days or less left.
**Regions** are the areas a node keeps listings for (3-character geohash cells,
about 100 to 150 km wide). A new node follows none: the owner chooses them in the
browser, "My listings", then "Regions", or `--region` sets them at the first start:
a region code (`--region u1j`) or a place name (`--region Bonn --region "Köln"`;
the node says which cells a name became). Search a place
by name (Bonn, Cologne, München, …); the page offers the place's own cell and any
cell within about 40 km, and the change applies at once, without a restart. The
choice is kept in `regions.json` in the data directory and wins over `--region`
from then on (delete the file to go back to the flag).
Nodes find each other through a bootstrap list in DNS (`allmende.stinnesbeck.com`),
the peers they met last time, a DHT per region, and mDNS on the local network.
Add your own bootstrap peers with `--bootstrap /ip4//tcp//p2p/`
(or `/dnsaddr/`), or turn the built-in one off with `--no-default-bootstrap`.
**Running a bootstrap node** helps everyone else connect, and nodes behind a home
router use it as a relay. It needs a public address:
```
allmende run --public --listen /ip4/0.0.0.0/tcp/4001 --listen /ip4/0.0.0.0/udp/4001/quic-v1
```
It prints the DNS TXT records to publish at `_dnsaddr.allmende.stinnesbeck.com`
(`dnsaddr=/ip4//tcp/4001/p2p/`, one per address). With a few such
nodes on different networks, the network no longer depends on any one of them.
In Docker replace the command (see the end of the `Dockerfile`) and add `--public`;
the NixOS module has `services.allmende.public = true`.
## Running a node for real
A node needs to stay up to receive messages and keep your listings alive. Make
targets: `make build run test check e2e docker` (`make help` lists them).
**Docker**
```
docker build -t allmende . # or: make docker
docker run --rm -it -v allmende-data:/data allmende init # once; write down the phrase
docker run -d --name allmende -v allmende-data:/data \
-p 127.0.0.1:8080:8080 -p 4001:4001 -p 4001:4001/udp allmende # then choose regions in the browser
docker logs allmende | grep -A1 'Owner login' # the sign-in link
```
The image runs as a non-root user and keeps its data in the `/data` volume.
Regions are chosen in the browser and kept in the volume. To start with some
or to add peers, replace the command (see the end of the `Dockerfile`). Publish port 8080 on `127.0.0.1` only: it also serves the owner
API. For public use put a TLS reverse proxy in front.
**NixOS** (flake)
```nix
{
inputs.allmende.url = "git+ssh://git@git.stinnesbeck.com:2222/nils/allmende.git";
outputs = { nixpkgs, allmende, ... }: {
nixosConfigurations.myhost = nixpkgs.lib.nixosSystem {
modules = [
allmende.nixosModules.default
{ services.allmende = { enable = true; openFirewall = true; }; } # regions: choose in the browser, or regions = [ "u1j" ]
];
};
};
}
```
After `nixos-rebuild switch`, do the one-time setup (it shows the recovery
phrase, so it is not part of the service): `sudo allmende-admin init && sudo
systemctl start allmende`. The sign-in link is in `journalctl -u allmende`.
Without NixOS, from a checkout: `nix run . -- run --region u1j`, or
`nix develop` for a shell with Go, Node.js and the other tools `make check`
needs. `nix flake check` builds the package and boots a NixOS VM that tests the
module. After changing `go.mod`, update `vendorHash` in `nix/package.nix`.
Licensed under the [GNU AGPL-3.0](LICENSE): free for everyone, and it stays free.
## Third-party data
The place names the region picker searches (`web/static/places.tsv`) come from
[GeoNames](https://www.geonames.org/) (cities with more than 15,000 inhabitants),
licensed [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/), with a few
German names added by hand. `web/scripts/places.mjs` rebuilds the file from
GeoNames' `cities15000.txt`. The page credits GeoNames wherever places are searched.