Skip to content

Commit

Permalink
Merge pull request #122
Browse files Browse the repository at this point in the history
Release v0.5.4
  • Loading branch information
bsrinivas8687 authored Mar 1, 2023
2 parents d45365a + 8c18e05 commit 296d292
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 26 deletions.
39 changes: 32 additions & 7 deletions scripts/runner.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#!/usr/bin/env bash

set -euo pipefail

CONTAINER_NAME=sentinelnode
NODE_DIR="${HOME}/.sentinelnode"
TOOLS_DIR="${NODE_DIR}/tools"
NODE_IMAGE=ghcr.io/sentinel-official/dvpn-node:latest

function stop {
Expand Down Expand Up @@ -83,6 +85,16 @@ function cmd_init {
}

function cmd_init_config {
function query_min_price {
"${TOOLS_DIR}/buf" curl \
--data '{"subspace":"vpn/node","key":"MinPrice"}' \
--http2-prior-knowledge \
--protocol grpc \
http://grpc.sentinel.co:9090/cosmos.params.v1beta1.Query/Params |
jq -r '.param.value' | jq -s '.[] | sort_by(.denom) | .[] | .amount + .denom' |
sed -e 's/"//g' | sed -z 's/\n/,/g' | sed 's/.$//'
}

function cmd_help {
echo "Usage: ${0} init config COMMAND OPTIONS"
echo ""
Expand Down Expand Up @@ -117,7 +129,7 @@ function cmd_init {
local node_ipv4_address=
local node_listen_on="0.0.0.0:${PORTS[0]}"
local node_moniker=
local node_price=
local node_price && node_price=$(query_min_price)
local node_provider=
local node_remote_url="https://${PUBLIC_IP}:${PORTS[0]}"
local node_type="${NODE_TYPE}"
Expand All @@ -141,15 +153,15 @@ function cmd_init {
if [[ -n "${input}" ]]; then node_ipv4_address="${input}"; fi
config_set "node.ipv4_address" "${node_ipv4_address}"

read -p "Enter node_listen_on[${node_listen_on}]:" -r input
read -p "Enter node_listen_on [${node_listen_on}]:" -r input
if [[ -n "${input}" ]]; then node_listen_on="${input}"; fi
config_set "node.listen_on" "${node_listen_on}"

read -p "Enter node_moniker:" -r input
if [[ -n "${input}" ]]; then node_moniker="${input}"; fi
config_set "node.moniker" "${node_moniker}"

read -p "Enter node_price:" -r input
read -p "Enter node_price [${node_price}]:" -r input
if [[ -n "${input}" ]]; then node_price="${input}"; fi
config_set "node.price" "${node_price}"

Expand Down Expand Up @@ -341,6 +353,18 @@ function cmd_setup {
DEBIAN_FRONTEND=noninteractive apt-get install --yes "${@}"
}

function install_tools {
function install_buf {
if [[ ! -f "${TOOLS_DIR}/buf" ]]; then
curl -fsSL "https://github.com/bufbuild/buf/releases/download/v1.14.0/buf-$(uname -s)-$(uname -m)" -o "${TOOLS_DIR}/buf"
chmod +x "${TOOLS_DIR}/buf"
fi
}

mkdir -p "${TOOLS_DIR}"
install_buf
}

function setup_docker {
function install {
if ! command -v docker &>/dev/null; then
Expand Down Expand Up @@ -370,7 +394,7 @@ EOF
ip6tables-save >/etc/iptables/rules.v6
}

function generate_tls {
function setup_tls {
openssl req -new \
-newkey ec \
-pkeyopt ec_paramgen_curve:prime256v1 \
Expand All @@ -379,15 +403,16 @@ EOF
-sha256 \
-days 365 \
-nodes \
-out "${1}/tls.crt" \
-keyout "${1}/tls.key"
-out "${NODE_DIR}/tls.crt" \
-keyout "${NODE_DIR}/tls.key"
}

apt-get update
install_packages curl git openssl
install_tools
setup_docker
setup_iptables
mkdir -p "${NODE_DIR}" && generate_tls "${NODE_DIR}"
setup_tls
docker pull "${NODE_IMAGE}"
}

Expand Down
27 changes: 8 additions & 19 deletions utils/geoip.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package utils
import (
"encoding/json"
"net/http"
"strconv"
"time"

"github.com/sentinel-official/dvpn-node/types"
Expand All @@ -12,7 +11,7 @@ import (
func FetchGeoIPLocation() (*types.GeoIPLocation, error) {
var (
client = &http.Client{Timeout: 15 * time.Second}
path = "https://ipv4.geojs.io/v1/ip/geo.json"
path = "http://ip-api.com/json"
)

resp, err := client.Get(path)
Expand All @@ -27,32 +26,22 @@ func FetchGeoIPLocation() (*types.GeoIPLocation, error) {
}()

var body struct {
City string `json:"city"`
Country string `json:"country"`
IP string `json:"ip"`
Latitude string `json:"latitude"`
Longitude string `json:"longitude"`
City string `json:"city"`
Country string `json:"country"`
IP string `json:"query"`
Latitude float64 `json:"lat"`
Longitude float64 `json:"lon"`
}

if err = json.NewDecoder(resp.Body).Decode(&body); err != nil {
return nil, err
}

latitude, err := strconv.ParseFloat(body.Latitude, 64)
if err != nil {
return nil, err
}

longitude, err := strconv.ParseFloat(body.Longitude, 64)
if err != nil {
return nil, err
}

return &types.GeoIPLocation{
City: body.City,
Country: body.Country,
IP: body.IP,
Latitude: latitude,
Longitude: longitude,
Latitude: body.Latitude,
Longitude: body.Longitude,
}, nil
}

0 comments on commit 296d292

Please sign in to comment.