Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Create Makefile for churn
Put the churn update in the Makefile. As this required more previsible
behavior of the certificate and cache, most of the Makefile has been
rewritten.
  • Loading branch information
ineiti committed Oct 22, 2021
1 parent 27d616a commit 95ac5b5
Showing 1 changed file with 58 additions and 25 deletions.
83 changes: 58 additions & 25 deletions tools/Makefile
@@ -1,45 +1,78 @@
.PHONY: dirinfo check-password
.PHONY: churn clean clean_cert 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_cert:
rm -rf $(AUTH_DIR)

certificates: pip_install $(AUTH_ID) $(AUTH_SIGN) $(AUTH_CERT) $(AUTH_AUTH)
$(AUTH_DIR)/%:
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_DIR)/%: certificates
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_cert

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) > $@

0 comments on commit 95ac5b5

Please sign in to comment.