diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6d6b5f5 --- /dev/null +++ b/Makefile @@ -0,0 +1,35 @@ +BIN := bin/allmende +REGION ?= u1j# Bonn; several are allowed: make run REGION="u1j u1h" (u1h is Cologne) +DATA ?= +FLAGS := $(if $(DATA),--data $(DATA)) + +.PHONY: help build run init test vet web web-test check clean + +help: ## list the targets + @grep -E '^[a-z-]+:.*## ' $(MAKEFILE_LIST) | awk -F':.*## ' '{printf " %-10s %s\n", $$1, $$2}' + +build: ## build the node into bin/allmende (the UI is already embedded) + go build -o $(BIN) ./cmd/allmende + +init: build ## create your identity (once): make init [DATA=dir] + $(BIN) init $(FLAGS) + +run: build ## run a node (default region Bonn): make run [REGION=u1j] [DATA=dir] + $(BIN) run $(FLAGS) $(foreach r,$(REGION),--region $(r)) + +vet: ## go vet + go vet ./... + +test: ## Go tests with the race detector + go test -race ./... + +web: ## rebuild web/dist after changing web/src (needs Node.js) + cd web && npm ci && npm run build + +web-test: ## type-check and test the web UI (needs Node.js) + cd web && npm ci && npm run typecheck && npm test + +check: vet test web-test ## everything: vet, Go tests, web checks + +clean: ## remove built binaries + rm -rf bin diff --git a/README.md b/README.md index dcd99d7..d95f759 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,9 @@ server and no cost. See [docs/PROTOCOL.md](docs/PROTOCOL.md). ## Try it ``` -go build -o bin/node ./cmd/node -bin/node init # shows your 12-word recovery phrase once -bin/node run --region u1x # u1x = Hamburg area; UI and API on http://127.0.0.1:8080 +go build -o bin/allmende ./cmd/allmende +bin/allmende init # shows your 12-word recovery phrase once +bin/allmende run --region u1x # u1x = Hamburg area; UI and API on http://127.0.0.1:8080 ``` Open http://127.0.0.1:8080 to search. Your browser checks every listing's @@ -20,7 +20,7 @@ pre-built and embedded; Node.js is only needed to change it 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 (`node run` prints a sign-in link; open it to get "My listings") +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. Owners publish from the same screen: "New listing" takes a title, price and diff --git a/cmd/node/init.go b/cmd/allmende/init.go similarity index 93% rename from cmd/node/init.go rename to cmd/allmende/init.go index 9e6a708..0fb275e 100644 --- a/cmd/node/init.go +++ b/cmd/allmende/init.go @@ -24,7 +24,7 @@ func cmdInit(args []string) error { fs.Parse(args) if _, err := os.Stat(filepath.Join(*data, "device.key")); err == nil { - return fmt.Errorf("%s is already set up. To get access back after losing this machine, use 'node recover'", *data) + return fmt.Errorf("%s is already set up. To get access back after losing this machine, use 'allmende recover'", *data) } root, phrase, err := identity.NewRoot() @@ -59,7 +59,7 @@ func cmdInit(args []string) error { fmt.Printf("\nDone. This machine is set up as a device of identity %s…\n", dev.Cert.Author[:12]) fmt.Printf("Your device certificate is valid until %s.\n\n", time.Unix(dev.Cert.ExpiresAt, 0).Format("2006-01-02")) - fmt.Printf("Next: node run --region --data %s\n", *data) + fmt.Printf("Next: allmende run --region --data %s\n", *data) fmt.Printf("The admin token for publishing is in %s\n", filepath.Join(*data, tokenFile)) return nil } @@ -95,7 +95,7 @@ func confirmPhrase(in *bufio.Reader, words []string) error { fmt.Printf("Word number %d: ", i+1) line, err := in.ReadString('\n') if err != nil && (!errors.Is(err, io.EOF) || line == "") { - return errors.New("no input; run 'node init' again in a terminal") + return errors.New("no input; run 'allmende init' again in a terminal") } if strings.EqualFold(strings.TrimSpace(line), words[i]) { break diff --git a/cmd/node/login_test.go b/cmd/allmende/login_test.go similarity index 100% rename from cmd/node/login_test.go rename to cmd/allmende/login_test.go diff --git a/cmd/node/main.go b/cmd/allmende/main.go similarity index 78% rename from cmd/node/main.go rename to cmd/allmende/main.go index 2284f11..d1a1091 100644 --- a/cmd/node/main.go +++ b/cmd/allmende/main.go @@ -1,8 +1,8 @@ -// Command node runs an Allmende node. +// Command allmende runs an Allmende node. // -// node init first-time setup: creates your identity and shows your recovery phrase -// node run run the node (replicates listings, serves the HTTP API) -// node recover restore from the recovery phrase after a lost or compromised machine +// allmende init first-time setup: creates your identity and shows your recovery phrase +// allmende run run the node (replicates listings, serves the HTTP API) +// allmende recover restore from the recovery phrase after a lost or compromised machine package main import ( @@ -26,11 +26,11 @@ const ( const usage = `Allmende: a free, distributed marketplace for homes. Usage: - node init [--data DIR] create your identity (first run) - node run [--data DIR] --region u1x run the node - node recover [--data DIR] restore access using your recovery phrase + allmende init [--data DIR] create your identity (first run) + allmende run [--data DIR] --region u1x run the node + allmende recover [--data DIR] restore access using your recovery phrase -Run "node -h" for the options of a command. +Run "allmende -h" for the options of a command. ` func main() { diff --git a/cmd/node/recover.go b/cmd/allmende/recover.go similarity index 97% rename from cmd/node/recover.go rename to cmd/allmende/recover.go index 688d351..93de92a 100644 --- a/cmd/node/recover.go +++ b/cmd/allmende/recover.go @@ -103,7 +103,7 @@ func cmdRecover(args []string) error { time.Unix(dev.Cert.ExpiresAt, 0).Format("2006-01-02")) fmt.Printf(" - %d of your listings were re-signed from this device.\n", republished) fmt.Println(" - A new admin token was written; the old one no longer works.") - fmt.Println("\nStart the node with 'node run' so the revocation spreads through the network.") + fmt.Println("\nStart the node with 'allmende run' so the revocation spreads through the network.") return nil } diff --git a/cmd/node/run.go b/cmd/allmende/run.go similarity index 96% rename from cmd/node/run.go rename to cmd/allmende/run.go index 0eba632..4f0b588 100644 --- a/cmd/node/run.go +++ b/cmd/allmende/run.go @@ -53,17 +53,17 @@ func cmdRun(args []string) error { dev, err := identity.LoadDevice(*data) if err != nil { if errors.Is(err, os.ErrNotExist) { - return fmt.Errorf("%s is not set up yet: run 'node init' first", *data) + return fmt.Errorf("%s is not set up yet: run 'allmende init' first", *data) } return err } until := time.Until(time.Unix(dev.Cert.ExpiresAt, 0)) if until <= 0 { - return errors.New("this device's certificate has expired; run 'node recover' to renew it") + return errors.New("this device's certificate has expired; run 'allmende recover' to renew it") } log := slog.New(slog.NewTextHandler(os.Stderr, nil)) if until < certWarnBefore { - log.Warn("device certificate expires soon; run 'node recover' to renew it", + log.Warn("device certificate expires soon; run 'allmende recover' to renew it", "expires", time.Unix(dev.Cert.ExpiresAt, 0).Format("2006-01-02")) } diff --git a/docs/PROTOCOL.md b/docs/PROTOCOL.md index 006f3b8..ed07a01 100644 --- a/docs/PROTOCOL.md +++ b/docs/PROTOCOL.md @@ -44,7 +44,7 @@ revoked. There are no accounts. because on a new machine the owner has only the phrase and does not know the old device's key. The replacement device is enrolled at the same instant (`issued_at == revoked_at`), which stays valid. -- **Recovery** (`node recover`): phrase in, all-devices revocation out, fresh +- **Recovery** (`allmende recover`): phrase in, all-devices revocation out, fresh device enrolled, the node's own listings re-signed (`seq + 1`) from the new device. The same command renews the yearly certificate. - **Peer IDs change on recovery** because the device key is the libp2p @@ -321,7 +321,7 @@ text rules below are enforced by endpoints. carry `last_dir`, `needs_reply`, a text `preview` (empty for hidden messages), `effort` (proof-of-work bits of the first message) and `grant_until`. - **Owner login.** The page itself never contains the admin token (every node - serves the same page, including public gateways). `node run` prints a link + serves the same page, including public gateways). `allmende run` prints a link `http://127.0.0.1:8080/#/login/` to the terminal, not to its log. The token is in the URL fragment, which a browser never sends to a server; the page moves it into `sessionStorage` (so closing the tab signs out), removes it @@ -404,12 +404,12 @@ needed to change the UI (`cd web && npm ci && npm run build`). - The node mines the proof-of-work while the request is open, so the form shows a "publishing" state for a few seconds. -## Running a node (`cmd/node`) +## Running a node (`cmd/allmende`) ``` -node init # create identity, show the 12-word phrase (once) -node run --region u1x [--bootstrap ] # replicate a region, serve the API on 127.0.0.1:8080 -node recover # restore from the phrase; also yearly cert renewal +allmende init # create identity, show the 12-word phrase (once) +allmende run --region u1x [--bootstrap ] # replicate a region, serve the API on 127.0.0.1:8080 +allmende recover # restore from the phrase; also yearly cert renewal ``` ## Spam