From 1634f137be90eed8e7da7ce3964d45b7f0cc0651 Mon Sep 17 00:00:00 2001 From: Itamar Turner-Trauring Date: Tue, 12 Apr 2022 12:54:16 -0400 Subject: [PATCH] Use sets more widely in the schema. --- docs/proposed/http-storage-node-protocol.rst | 3 +++ src/allmydata/storage/http_client.py | 7 ++++--- src/allmydata/storage/http_server.py | 2 +- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/docs/proposed/http-storage-node-protocol.rst b/docs/proposed/http-storage-node-protocol.rst index 2ceb3c03a..be543abb2 100644 --- a/docs/proposed/http-storage-node-protocol.rst +++ b/docs/proposed/http-storage-node-protocol.rst @@ -350,6 +350,9 @@ Because of the simple types used throughout and the equivalence described in `RFC 7049`_ these examples should be representative regardless of which of these two encodings is chosen. +For CBOR messages, any sequence that is semantically a set (i.e. no repeated values allowed, order doesn't matter, and is hashable in Python) should be sent as a set. +Tag 6.258 is used to indicate sets in CBOR. + HTTP Design ~~~~~~~~~~~ diff --git a/src/allmydata/storage/http_client.py b/src/allmydata/storage/http_client.py index 3a758e592..e735a6369 100644 --- a/src/allmydata/storage/http_client.py +++ b/src/allmydata/storage/http_client.py @@ -39,8 +39,9 @@ class ClientException(Exception): # Schemas for server responses. # -# TODO usage of sets is inconsistent. Either use everywhere (and document in -# spec document) or use nowhere. +# Tags are of the form #6.nnn, where the number is documented at +# https://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml. Notably, #6.258 +# indicates a set. _SCHEMAS = { "get_version": Schema( """ @@ -74,7 +75,7 @@ _SCHEMAS = { ), "list_shares": Schema( """ - message = [* uint] + message = #6.258([* uint]) """ ), } diff --git a/src/allmydata/storage/http_server.py b/src/allmydata/storage/http_server.py index 3876409b0..54e60f913 100644 --- a/src/allmydata/storage/http_server.py +++ b/src/allmydata/storage/http_server.py @@ -436,7 +436,7 @@ class HTTPServer(object): """ List shares for the given storage index. """ - share_numbers = list(self._storage_server.get_buckets(storage_index).keys()) + share_numbers = set(self._storage_server.get_buckets(storage_index).keys()) return self._send_encoded(request, share_numbers) @_authorized_route(