Skip to content

Commit

Permalink
Return PFS broadcast room id in info response
Browse files Browse the repository at this point in the history
This is necessary after
- raiden-network/raiden-service-bundle#187
- raiden-network/raiden#6442

With those PRs the set of federation servers can become disjunct between
different Raiden client versions. Therefore we can't rely on the
previous check in the Raiden client if the PFS' server is in the known
servers set.

The RoomID is uniquely identifying a specific broadcasting room and can
therefore be used as a better information source for this check.
  • Loading branch information
ulope committed Sep 15, 2020
1 parent e120059 commit 2cac33d
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
14 changes: 14 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[tool.black]
line-length = 99
target-version = ['py37']
include = '\.pyi?$'
exclude = '''
/(
\.git
| \.mypy_cache
| \.tox
| \.venv
| build
| dist
)/
'''
6 changes: 5 additions & 1 deletion src/pathfinding_service/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ def get(self) -> Tuple[dict, int]:
"payment_address": to_checksum_address(self.pathfinding_service.address),
"UTC": datetime.utcnow().isoformat(),
"matrix_server": self.api.pathfinding_service.matrix_listener.base_url,
"matrix_room_id": self.api.pathfinding_service.matrix_listener.broadcast_room_id,
}
return info, 200

Expand Down Expand Up @@ -445,7 +446,10 @@ def get(self, token_network_address: str) -> Tuple[List[Dict[str, Any]], int]:

class DebugPathResource(PathfinderResource):
def get( # pylint: disable=no-self-use
self, token_network_address: str, source_address: str, target_address: Optional[str] = None
self,
token_network_address: str,
source_address: str,
target_address: Optional[str] = None,
) -> Tuple[dict, int]:
request_count = 0
responses = []
Expand Down
12 changes: 5 additions & 7 deletions src/raiden_libs/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
from raiden.storage.serialization.serializer import MessageSerializer
from raiden.utils.cli import get_matrix_servers
from raiden.utils.signer import LocalSigner
from raiden.utils.typing import Address, ChainID
from raiden.utils.typing import Address, ChainID, RoomID
from raiden_contracts.utils.type_aliases import PrivateKey

log = structlog.get_logger(__name__)
Expand Down Expand Up @@ -162,6 +162,7 @@ def __init__(
http_retry_timeout=40,
http_retry_delay=matrix_http_retry_delay,
)
self.broadcast_room_id: Optional[RoomID] = None
self._broadcast_room: Optional[Room] = None
self._displayname_cache = DisplayNameCache()
self.base_url = self._client.api.base_url
Expand Down Expand Up @@ -205,10 +206,7 @@ def _start_client(self) -> None:
try:
self.user_manager.start()

login(
self._client,
signer=LocalSigner(private_key=self.private_key),
)
login(self._client, signer=LocalSigner(private_key=self.private_key))
except (MatrixRequestError, ValueError):
raise ConnectionError("Could not login/register to matrix.")

Expand All @@ -219,6 +217,7 @@ def _start_client(self) -> None:
self._broadcast_room = join_broadcast_room(
client=self._client, broadcast_room_alias=room_alias
)
self.broadcast_room_id = self._broadcast_room.room_id

sync_filter_id = self._client.create_sync_filter(rooms=[self._broadcast_room])
self._client.set_sync_filter_id(sync_filter_id)
Expand All @@ -231,8 +230,7 @@ def follow_address_presence(self, address: Address, refresh: bool = False) -> No
if refresh:
self.user_manager.populate_userids_for_address(address)
self.user_manager.track_address_presence(
address=address,
user_ids=self.user_manager.get_userids_for_address(address),
address=address, user_ids=self.user_manager.get_userids_for_address(address)
)

log.debug(
Expand Down

0 comments on commit 2cac33d

Please sign in to comment.