Skip to content

Commit

Permalink
dump registered relays: quote dns names.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbgi committed Oct 26, 2021
1 parent e1d138b commit 6ea8cbc
Showing 1 changed file with 11 additions and 16 deletions.
27 changes: 11 additions & 16 deletions roles/explorer.nix
Expand Up @@ -174,15 +174,6 @@ in {

systemd.services.dump-registered-relays-topology = let
excludedPools = lib.concatStringsSep ", " (map (hash: "'${hash}'") globals.static.poolsExcludeList);
get_latest_synced_block = writeText "extract_relays.sql" ''
select array_to_json(array_agg(row_to_json(t))) from (
select COALESCE(ipv4, dns_name) as addr, port from (
select min(update_id) as update_id, ipv4, dns_name, port from pool_relay inner join pool_update ON pool_update.id = pool_relay.update_id inner join pool_hash ON pool_update.hash_id = pool_hash.id where ${lib.optionalString (globals.static.poolsExcludeList != []) "pool_hash.view not in (${excludedPools}) and "}(
(ipv4 is null and dns_name NOT LIKE '% %') or ipv4 !~ '(^0\.)|(^10\.)|(^100\.6[4-9]\.)|(^100\.[7-9]\d\.)|(^100\.1[0-1]\d\.)|(^100\.12[0-7]\.)|(^127\.)|(^169\.254\.)|(^172\.1[6-9]\.)|(^172\.2[0-9]\.)|(^172\.3[0-1]\.)|(^192\.0\.0\.)|(^192\.0\.2\.)|(^192\.88\.99\.)|(^192\.168\.)|(^198\.1[8-9]\.)|(^198\.51\.100\.)|(^203.0\.113\.)|(^22[4-9]\.)|(^23[0-9]\.)|(^24[0-9]\.)|(^25[0-5]\.)')
group by ipv4, dns_name, port order by update_id
) t
) t;
'';
extract_relays_sql = writeText "extract_relays.sql" ''
select array_to_json(array_agg(row_to_json(t))) from (
select COALESCE(ipv4, dns_name) as addr, port from (
Expand All @@ -204,14 +195,14 @@ in {
index=$1
addr=$2
port=$3
allAddresses=$(dig +nocookie +short $addr A)
allAddresses=$(dig +nocookie +short -q "$addr" A)
if [ -z "$allAddresses" ]; then
allAddresses=$addr
fi
while IFS= read -r ip; do
set +e
PING="$(timeout 7s cardano-ping -h $ip -p $port -m $NETWORK_MAGIC -c 1 -q --json)"
PING="$(timeout 7s cardano-ping -h "$ip" -p "$port" -m $NETWORK_MAGIC -c 1 -q --json)"
res=$?
if [ $res -eq 0 ]; then
echo $PING | jq -c > /dev/null 2>&1
Expand All @@ -232,8 +223,11 @@ in {
else
state=$country_code
fi
echo $r | jq -c --arg continent "$continent" \
--arg state "$state" '. + {continent: $continent, state: $state}' > $index-relay.json
jq -c --arg addr "$addr" --arg port "$port" \
--arg continent "$continent" --arg state "$state" \
'{addr: $addr, port: $port, continent: $continent, state: $state}' \
<<< '{}' \
> $index-relay.json
break
else
>&2 echo "Failed to retrieved goip info for $ip"
Expand Down Expand Up @@ -261,12 +255,12 @@ in {
for r in $(psql -t < ${extract_relays_sql} | jq -c '.[]'); do
addr=$(echo "$r" | jq -r '.addr')
port=$(echo "$r" | jq -r '.port')
allAddresses=$addr$'\n'$(dig +nocookie +short $addr A)
allAddresses=$addr$'\n'$(dig +nocookie +short -q "$addr" A)
excludedAddresses=$(comm -12 <(echo "$allAddresses" | sort) <(echo "$excludeList"))
nbExcludedAddresses=$(echo $excludedAddresses | wc -w)
if [[ $nbExcludedAddresses == 0 ]]; then
((i+=1))
pingAddr $i $addr $port &
pingAddr $i "$addr" "$port" &
sleep 0.5
else
>&2 echo "$addr excluded due to dns name or IPs being in exclude list:\n$excludedAddresses"
Expand All @@ -293,7 +287,8 @@ in {
sleep 3600
done
'';
startLimitIntervalSec = 1800;
# 3 failures at max within 24h:
startLimitIntervalSec = 24 * 60 * 60;
serviceConfig = {
User = cfg.user;
StateDirectory = "registered-relays-dump";
Expand Down

0 comments on commit 6ea8cbc

Please sign in to comment.