make RelayV1Hint objects hashable/comparable
This commit is contained in:
parent
e1546bf03f
commit
80ae9236df
|
@ -139,6 +139,17 @@ class Hints(unittest.TestCase):
|
||||||
ep = c._endpoint_from_hint_obj("unknown:stuff:yowza:pivlor")
|
ep = c._endpoint_from_hint_obj("unknown:stuff:yowza:pivlor")
|
||||||
self.assertEqual(ep, None)
|
self.assertEqual(ep, None)
|
||||||
|
|
||||||
|
def test_comparable(self):
|
||||||
|
h1 = transit.DirectTCPV1Hint("hostname", "port1")
|
||||||
|
h1b = transit.DirectTCPV1Hint("hostname", "port1")
|
||||||
|
h2 = transit.DirectTCPV1Hint("hostname", "port2")
|
||||||
|
r1 = transit.RelayV1Hint(tuple(sorted([h1, h2])))
|
||||||
|
r2 = transit.RelayV1Hint(tuple(sorted([h2, h1])))
|
||||||
|
r3 = transit.RelayV1Hint(tuple(sorted([h1b, h2])))
|
||||||
|
self.assertEqual(r1, r2)
|
||||||
|
self.assertEqual(r2, r3)
|
||||||
|
self.assertEqual(len(set([r1, r2, r3])), 1)
|
||||||
|
|
||||||
|
|
||||||
class Basic(unittest.TestCase):
|
class Basic(unittest.TestCase):
|
||||||
@inlineCallbacks
|
@inlineCallbacks
|
||||||
|
|
|
@ -95,9 +95,10 @@ def build_sided_relay_handshake(key, side):
|
||||||
# * the rest of the connection contains transit data
|
# * the rest of the connection contains transit data
|
||||||
DirectTCPV1Hint = namedtuple("DirectTCPV1Hint", ["hostname", "port"])
|
DirectTCPV1Hint = namedtuple("DirectTCPV1Hint", ["hostname", "port"])
|
||||||
TorTCPV1Hint = namedtuple("TorTCPV1Hint", ["hostname", "port"])
|
TorTCPV1Hint = namedtuple("TorTCPV1Hint", ["hostname", "port"])
|
||||||
# RelayV1Hint contains a list of DirectTCPV1Hint and TorTCPV1Hint hints. For
|
# RelayV1Hint contains a tuple of DirectTCPV1Hint and TorTCPV1Hint hints (we
|
||||||
# each one, make the TCP connection, send the relay handshake, then complete
|
# use a tuple rather than a list so they'll be hashable into a set). For each
|
||||||
# the rest of the V1 protocol. Only one hint per relay is useful.
|
# one, make the TCP connection, send the relay handshake, then complete the
|
||||||
|
# rest of the V1 protocol. Only one hint per relay is useful.
|
||||||
RelayV1Hint = namedtuple("RelayV1Hint", ["hints"])
|
RelayV1Hint = namedtuple("RelayV1Hint", ["hints"])
|
||||||
|
|
||||||
def describe_hint_obj(hint):
|
def describe_hint_obj(hint):
|
||||||
|
@ -582,7 +583,9 @@ class Common:
|
||||||
if transit_relay:
|
if transit_relay:
|
||||||
if not isinstance(transit_relay, type(u"")):
|
if not isinstance(transit_relay, type(u"")):
|
||||||
raise InternalError
|
raise InternalError
|
||||||
relay = RelayV1Hint(hints=[parse_hint_argv(transit_relay)])
|
# TODO: allow multiple hints for a single relay
|
||||||
|
relay_hint = parse_hint_argv(transit_relay)
|
||||||
|
relay = RelayV1Hint(hints=(relay_hint,))
|
||||||
self._transit_relays = [relay]
|
self._transit_relays = [relay]
|
||||||
else:
|
else:
|
||||||
self._transit_relays = []
|
self._transit_relays = []
|
||||||
|
|
Loading…
Reference in New Issue
Block a user