From 0ee56e12b05cc77ddbf8fdc699f702eeed29607a Mon Sep 17 00:00:00 2001 From: Brian Warner Date: Sun, 22 May 2016 11:01:44 -0700 Subject: [PATCH] change 'list' protocol, make room for nameplate attributes --- src/wormhole/server/rendezvous_websocket.py | 7 +++++-- src/wormhole/test/test_server.py | 7 ++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/wormhole/server/rendezvous_websocket.py b/src/wormhole/server/rendezvous_websocket.py index 2a7e82f..153b037 100644 --- a/src/wormhole/server/rendezvous_websocket.py +++ b/src/wormhole/server/rendezvous_websocket.py @@ -54,7 +54,7 @@ from .rendezvous import CrowdedError, SidedMessage # -> {type: "bind", appid:, side:} # # -> {type: "list"} -> nameplates -# <- {type: "nameplates", nameplates: [str..]} +# <- {type: "nameplates", nameplates: [{id: str,..},..]} # -> {type: "allocate"} -> nameplate, mailbox # <- {type: "allocated", nameplate: str} # -> {type: "claim", nameplate: str} -> mailbox @@ -152,7 +152,10 @@ class WebSocketRendezvous(websocket.WebSocketServerProtocol): def handle_list(self): nameplate_ids = sorted(self._app.get_nameplate_ids()) - self.send("nameplates", nameplates=nameplate_ids) + # provide room to add nameplate attributes later (like which wordlist + # is used for each, maybe how many words) + nameplates = [{"id": nid} for nid in nameplate_ids] + self.send("nameplates", nameplates=nameplates) def handle_allocate(self, server_rx): if self._did_allocate: diff --git a/src/wormhole/test/test_server.py b/src/wormhole/test/test_server.py index 4d78bf4..90c03eb 100644 --- a/src/wormhole/test/test_server.py +++ b/src/wormhole/test/test_server.py @@ -539,7 +539,12 @@ class WebSocketAPI(ServerBase, unittest.TestCase): c1.send(u"list") m = yield c1.next_non_ack() self.assertEqual(m[u"type"], u"nameplates") - self.assertEqual(set(m[u"nameplates"]), set([nameplate_id1, u"np2"])) + nids = set() + for n in m[u"nameplates"]: + self.assertEqual(type(n), dict) + self.assertEqual(list(n.keys()), [u"id"]) + nids.add(n[u"id"]) + self.assertEqual(nids, set([nameplate_id1, u"np2"])) @inlineCallbacks def test_allocate(self):