Skip to content

Commit 920f782

Browse files
committed
Split known servers
Depends-on: raiden-network/raiden-service-bundle#186 Related: raiden-network#6443, raiden-network#6212 This splits the known servers list into an 'active' and 'all' part. The 'active' part is read by the Raiden client and used to select a server to use. The 'all' part is used by the RSB as the federation whitelist. The purpose of this is to allow new servers to be added without making the Raiden client immediately try to use them while they are not yet ready.
1 parent 14164ec commit 920f782

File tree

3 files changed

+42
-17
lines changed

3 files changed

+42
-17
lines changed

raiden/constants.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ class Capabilities(Enum):
8686
WEBRTC = "webRTC"
8787

8888

89+
class ServerListType(Enum):
90+
ACTIVE_SERVERS = "active_servers"
91+
ALL_SERVERS = "all_servers"
92+
93+
8994
# Set at 64 since parity's default is 64 and Geth's default is 128
9095
# TODO: Make this configurable. Since in parity this is also a configurable value
9196
STATE_PRUNING_AFTER_BLOCKS = 64

raiden/settings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@
4545
DEFAULT_MATRIX_KNOWN_SERVERS = {
4646
Environment.PRODUCTION: (
4747
"https://raw.githubusercontent.com/raiden-network/raiden-service-bundle"
48-
"/master/known_servers/known_servers.alderaan.yaml"
48+
"/master/known_servers/known_servers-production-v1.2.0.json"
4949
),
5050
Environment.DEVELOPMENT: (
5151
"https://raw.githubusercontent.com/raiden-network/raiden-service-bundle"
52-
"/master/known_servers/known_servers.test.yaml"
52+
"/master/known_servers/known_servers-development-v1.2.0.json"
5353
),
5454
}
5555

raiden/utils/cli.py

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import errno
2+
import json
23
import os
34
import re
4-
import string
55
from enum import EnumMeta
66
from itertools import groupby
7+
from json.decoder import JSONDecodeError
78
from pathlib import Path
89
from string import Template
910
from typing import Any, Callable, Dict, List, MutableMapping, Union
@@ -16,6 +17,7 @@
1617
from toml import TomlDecodeError, load
1718
from web3.gas_strategies.time_based import fast_gas_price_strategy
1819

20+
from raiden.constants import ServerListType
1921
from raiden.exceptions import ConfigurationError, InvalidChecksummedAddress
2022
from raiden.network.rpc.middleware import faster_gas_price_strategy
2123
from raiden.utils.formatting import address_checksum_and_decode
@@ -423,13 +425,27 @@ def apply_config_file(
423425
cli_params[config_name_int] = config_value
424426

425427

426-
def get_matrix_servers(url: str) -> List[str]:
427-
"""Fetch a list of matrix servers from a text url
428+
def get_matrix_servers(
429+
url: str, server_list_type: ServerListType = ServerListType.ACTIVE_SERVERS
430+
) -> List[str]:
431+
"""Fetch a list of matrix servers from a URL
428432
429-
'-' prefixes (YAML list) are cleaned. Comment lines /^\\s*#/ are ignored
433+
The URL is expected to point to a JSON document of the following format::
430434
431-
url: url of a text file
432-
returns: list of urls, default schema is https
435+
{
436+
"active_servers": [
437+
"url1",
438+
"url2",
439+
...
440+
],
441+
"all_servers": [
442+
"url1",
443+
"url2",
444+
...
445+
]
446+
}
447+
448+
Which of the two lists is returned is controlled by the ``server_list_type`` argument.
433449
"""
434450
try:
435451
response = requests.get(url)
@@ -438,15 +454,19 @@ def get_matrix_servers(url: str) -> List[str]:
438454
except requests.RequestException as ex:
439455
raise RuntimeError(f"Could not fetch matrix servers list: {url!r} => {ex!r}") from ex
440456

441-
available_servers = []
442-
for line in response.text.splitlines():
443-
line = line.strip(string.whitespace + "-")
444-
if line.startswith("#") or not line:
445-
continue
446-
if not line.startswith("http"):
447-
line = "https://" + line # default schema
448-
available_servers.append(line)
449-
return available_servers
457+
try:
458+
known_servers: Dict[str, List[str]] = json.loads(response.text)
459+
msg = f"Unexpected format of known server list at {url}"
460+
assert {type_.value for type_ in ServerListType} == known_servers.keys(), msg
461+
active_servers = known_servers[server_list_type.value]
462+
except (JSONDecodeError, AssertionError) as ex:
463+
raise RuntimeError(
464+
f"Could not process list of known matrix servers: {url!r} => {ex!r}"
465+
) from ex
466+
return [
467+
f"https://{server}" if not server.startswith("http") else server
468+
for server in active_servers
469+
]
450470

451471

452472
ADDRESS_TYPE = AddressType()

0 commit comments

Comments
 (0)