diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index f3a6a9a..f59f897 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -29,7 +29,6 @@ jobs: env: DIR_AUTH_PASSWORD: dummy run: | - make dirinfo make churn - uses: actions-rs/toolchain@v1 @@ -74,5 +73,5 @@ jobs: env: DIR_AUTH_PASSWORD: dummy run: | - make dirinfo + make cache python -m pytest diff --git a/tools/Makefile b/tools/Makefile index 149c711..b8feeb2 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -1,45 +1,80 @@ -.PHONY: dirinfo check-password +.PHONY: churn clean clean_auth clean_cache secrets_authority update_cache_churn AUTH_DIR=authority-private -DIR_CACHE=directory-cache +AUTH_ID=$(AUTH_DIR)/authority_identity_key +AUTH_SIGN=$(AUTH_DIR)/authority_signing_key +AUTH_CERT=$(AUTH_DIR)/certificate.txt +AUTH_AUTH=$(AUTH_DIR)/authority.txt +CACHE_DIR=directory-cache +CACHE_CERT=$(CACHE_DIR)/certificate.txt +CACHE_AUTH=$(CACHE_DIR)/authority.txt +CACHE_CONS=$(CACHE_DIR)/consensus.txt +CACHE_MICRO=$(CACHE_DIR)/microdescriptors.txt -all: dirinfo +all: update_cache -$(AUTH_DIR): pip_install check-password +clean_auth: + rm -rf $(AUTH_DIR) + +authority: pip_install $(AUTH_ID) $(AUTH_SIGN) $(AUTH_CERT) $(AUTH_AUTH) +$(AUTH_ID) $(AUTH_SIGN) $(AUTH_CERT) $(AUTH_AUTH): +ifeq ($(DIR_AUTH_PASSWORD), ) + $(error Environment variable DIR_AUTH_PASSWORD is undefined or invalid.) +endif mkdir -p $(AUTH_DIR) - mkdir -p $(DIR_CACHE) ./gen_fresh_dirinfo.py generate-certificate \ - --authority-identity-key $(AUTH_DIR)/authority_identity_key \ - --authority-signing-key $(AUTH_DIR)/authority_signing_key \ - --authority-certificate $(DIR_CACHE)/certificate.txt \ - --authority-v3ident $(DIR_CACHE)/authority.txt + --authority-identity-key $(AUTH_ID) \ + --authority-signing-key $(AUTH_SIGN) \ + --authority-certificate $(AUTH_CERT) \ + --authority-v3ident $(AUTH_AUTH) + +clean_cache: + rm -rf $(CACHE_DIR) + +update_cache: clean_cache cache -dirinfo: $(AUTH_DIR) +cache: $(CACHE_CERT) $(CACHE_AUTH) $(CACHE_CONS) $(CACHE_MICRO) +$(CACHE_CERT) $(CACHE_AUTH) $(CACHE_CONS) $(CACHE_MICRO): + $(MAKE) authority + mkdir -p $(CACHE_DIR) + cp $(AUTH_CERT) $(AUTH_AUTH) $(CACHE_DIR) ./gen_fresh_dirinfo.py generate-dirinfo \ - --authority-signing-key $(AUTH_DIR)/authority_signing_key \ - --authority-certificate $(DIR_CACHE)/certificate.txt \ - --consensus $(DIR_CACHE)/consensus.txt \ - --microdescriptors $(DIR_CACHE)/microdescriptors.txt + --authority-signing-key $(AUTH_SIGN) \ + --authority-certificate $(CACHE_CERT) \ + --consensus $(CACHE_CONS) \ + --microdescriptors $(CACHE_MICRO) -churn: $(DIR_CACHE)/consensus.txt +churn: cache ./gen_fresh_dirinfo.py compute-churn \ - --consensus $(DIR_CACHE)/consensus.txt \ - --churn $(DIR_CACHE)/churn.txt + --consensus $(CACHE_DIR)/consensus.txt \ + --churn $(CACHE_DIR)/churn.txt pip_install: requirements.txt pip3 install -qr requirements.txt touch pip_install -clean: - rm -rf $(AUTH_DIR) $(DIR_CACHE) - -check-password: -ifeq ($(DIR_AUTH_PASSWORD), ) - $(error Environment variable DIR_AUTH_PASSWORD is undefined or invalid.) -endif +clean: clean_cache clean_auth secrets_authority: $(AUTH_DIR) - tar cjf auth.tgz $(AUTH_DIR) $(DIR_CACHE)/{certificate.txt,authority.txt} + tar cjf auth.tgz $(AUTH_DIR) $(CACHE_DIR)/{certificate.txt,authority.txt} base64 -i auth.tgz rm auth.tgz echo $$DIR_AUTH_PASSWORD + +# This updates the CACHE_DIR directory: +# - fully every Monday or if the consensus is missing +# - creating a new churn.txt on every day +# It supposes that the +CHURN_WEEK_FILE = $(CACHE_DIR)/churn_week +CHURN_WEEK := $(shell date +%Y_%W) +update_cache_churn: $(CHURN_WEEK_FILE) + if grep -v $(CHURN_WEEK) $(CHURN_WEEK_FILE); then \ + rm -f $(CACHE_DIR)/*; \ + fi + if [ $$( date +%w ) = 1 ]; then \ + rm -f $(CACHE_DIR)/*; \ + fi + $(MAKE) churn $(CHURN_WEEK_FILE) + +$(CHURN_WEEK_FILE): + echo $(CHURN_WEEK) > $@ diff --git a/tools/README.md b/tools/README.md index d8decd6..ca1485f 100644 --- a/tools/README.md +++ b/tools/README.md @@ -59,7 +59,7 @@ directory authority are written to the sub-directory `authority-private`. To generate an updated custom consensus containing fresh directory information, run: ``` -make dirinfo +make update_cache ``` The Makefile writes the resulting files to the `directory-cache/` directory. Lightarti-rest relies on the files in this directory for its operation. Apps should download this directory and supply it as the `cache_dir` argument.