From f8bbaf60a193df70c2741a9de91dacc2c4b8cad9 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Tue, 3 Sep 2019 13:28:18 -0700 Subject: [PATCH 1/2] Add more information to the peer mismatch exception --- libp2p/security/secio/transport.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/libp2p/security/secio/transport.py b/libp2p/security/secio/transport.py index 4c3dbc0..4e4ab50 100644 --- a/libp2p/security/secio/transport.py +++ b/libp2p/security/secio/transport.py @@ -245,7 +245,12 @@ async def _establish_session_parameters( if not remote_peer: remote_peer = remote_peer_from_proposal elif remote_peer != remote_peer_from_proposal: - raise PeerMismatchException() + raise PeerMismatchException( + { + "expected_remote_peer": remote_peer, + "received_remote_peer": remote_peer_from_proposal, + } + ) session_parameters.remote_peer = remote_peer curve_param, cipher_param, hash_param, order = _select_encryption_parameters( From bfd674e22cb76a1890367da300b53f1a87656949 Mon Sep 17 00:00:00 2001 From: Alex Stokes Date: Tue, 3 Sep 2019 13:28:31 -0700 Subject: [PATCH 2/2] Try all pairs of choices, not just a small subset via `zip` --- libp2p/security/secio/transport.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libp2p/security/secio/transport.py b/libp2p/security/secio/transport.py index 4e4ab50..7d9d7db 100644 --- a/libp2p/security/secio/transport.py +++ b/libp2p/security/secio/transport.py @@ -1,4 +1,5 @@ from dataclasses import dataclass +import itertools from typing import Optional, Tuple import multihash @@ -180,7 +181,7 @@ def _select_parameter_from_order( else: return supported_parameters.split(",")[0] - for first, second in zip(first_choices, second_choices): + for first, second in itertools.product(first_choices, second_choices): if first == second: return first raise IncompatibleChoices()