Use sets more widely in the schema.

This commit is contained in:
Itamar Turner-Trauring 2022-04-12 12:54:16 -04:00
parent 4b20b67ce6
commit 1634f137be
3 changed files with 8 additions and 4 deletions

View File

@ -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
~~~~~~~~~~~

View File

@ -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])
"""
),
}

View File

@ -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(