forked from RunOnFlux/chainweb-node-docker
-
Notifications
You must be signed in to change notification settings - Fork 1
/
check-reachability.sh
71 lines (55 loc) · 1.72 KB
/
check-reachability.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env bash
# set -e
# ############################################################################ #
# PARAMETERS
HOST=$1
PORT=$2
CHAINWEB_NETWORK=${CHAINWEB_NETWORK:-mainnet01}
CHAINWEB_BOOTSTRAP_NODE=${CHAINWEB_BOOTSTRAP_NODE:-us-e1.chainweb.com}
# ############################################################################ #
# Temporary files
CERTFILE=$(mktemp)
KEYFILE=$(mktemp)
trap '{ kill $(jobs -pr); wait $(jobs -pr) 2>/dev/null ; rm -f -- "$CERTFILE" "$KEYFILE" ; }' EXIT
# ############################################################################ #
# Utils
function create-certificate {
openssl req \
-x509 \
-newkey rsa:4096 \
-keyout "$KEYFILE" \
-out "$CERTFILE" \
-days 1 \
-nodes \
-subj "/CN=$HOST" \
> /dev/null 2>&1
get-fingerprint < "$CERTFILE"
}
function get-fingerprint {
openssl x509 -fingerprint -noout -sha256 |
sed 's/://g' |
tail -c 65 |
xxd -r -p |
base64 |
tr -d '=' |
tr '/+' '_-'
}
function run-server {
openssl s_server -port "$PORT" -cert "$CERTFILE" -key "$KEYFILE" -www -quiet &
}
# ############################################################################ #
# Perform Check
# Create certificate
CERTID=$(create-certificate)
# start server in the background
run-server
# make request to chainweb bootstrap node
PEER_INFO="{\"address\": {\"hostname\": \"$HOST\", \"port\": $PORT}, \"id\": \"$CERTID\"}"
curl "https://$CHAINWEB_BOOTSTRAP_NODE/chainweb/0.0/$CHAINWEB_NETWORK/cut/peer" \
-sLk \
-XPUT \
-H 'content-type: application/json' \
-H 'X-Chainweb-Node-Version: 1.7' \
-v \
-d "$PEER_INFO" 2>&1 |
grep -q "< HTTP/2 204\|missing X-Chainweb-Node-Version header"