Skip to content

Commit 2de21e5

Browse files
ulopepalango
authored andcommitted
Service Registry: Query PFS info endpoint instead of shelling out to ping
The service_registry CLI tool used to shell out to ping to check if a given service URL is reachable. This is problematic on multiple levels: - The `ping` binary may not be available (as has happened in the RSB containers) - A server operator my block ICMP requests for whatever reason This replaces the ping check with a direct request to the PFS API `info` endpoint.
1 parent 3f548f7 commit 2de21e5

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/raiden_libs/service_registry.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
# pylint: disable=too-many-arguments,too-many-locals,too-many-statements
2-
import subprocess
32
import sys
43
import textwrap
54
from datetime import datetime
65
from math import floor, log10
76
from typing import Any, Callable, Dict, List, Optional
7+
from urllib.parse import urljoin, urlparse
88

99
import click
1010
import gevent
11+
import requests
1112
import structlog
1213
from eth_typing import HexStr
1314
from eth_utils import event_abi_to_log_topic, to_canonical_address, to_checksum_address, to_hex
1415
from hexbytes import HexBytes
16+
from requests import RequestException
1517
from web3 import Web3
1618
from web3.contract import Contract, ContractFunction
1719
from web3.logs import DISCARD
@@ -435,12 +437,18 @@ def maybe_prompt(query: str) -> None:
435437

436438
if service_url and service_url != current_url:
437439
click.secho(f'\nNew Url to be registered "{service_url}"')
438-
hostname = service_url.split("//")[1]
439-
reachable = not subprocess.run(
440-
["ping", "-c", "1", hostname], capture_output=True, check=False
441-
).returncode
440+
try:
441+
response = requests.get(urljoin(service_url, "/api/v2/info"), timeout=2)
442+
reachable = 199 < response.status_code < 300
443+
except RequestException:
444+
reachable = False
442445
if not reachable:
443-
click.secho(f"`ping {hostname}` fails. Are you sure the URL is correct?", fg="yellow")
446+
hostname = urlparse(service_url).netloc
447+
click.secho(
448+
f"The PFS at `{hostname}` doesn't appear to respond. "
449+
f"Are you sure the URL is correct?",
450+
fg="yellow",
451+
)
444452
maybe_prompt("I have checked the URL and it is correct")
445453

446454
checked_transact(

0 commit comments

Comments
 (0)