mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2024-12-22 06:17:50 +00:00
A unit test, and some cleanups and fixes.
This commit is contained in:
parent
dc4d215683
commit
4ea005d653
@ -60,6 +60,7 @@ from allmydata.interfaces import (
|
|||||||
from allmydata.nodemaker import NodeMaker
|
from allmydata.nodemaker import NodeMaker
|
||||||
from allmydata.blacklist import Blacklist
|
from allmydata.blacklist import Blacklist
|
||||||
from allmydata.node import _Config
|
from allmydata.node import _Config
|
||||||
|
from allmydata.storage.http_common import ANONYMOUS_STORAGE_NURLS
|
||||||
|
|
||||||
KiB=1024
|
KiB=1024
|
||||||
MiB=1024*KiB
|
MiB=1024*KiB
|
||||||
@ -838,7 +839,7 @@ class _Client(node.Node, pollmixin.PollMixin):
|
|||||||
if hasattr(self.tub.negotiationClass, "add_storage_server"):
|
if hasattr(self.tub.negotiationClass, "add_storage_server"):
|
||||||
nurls = self.tub.negotiationClass.add_storage_server(ss, swissnum.encode("ascii"))
|
nurls = self.tub.negotiationClass.add_storage_server(ss, swissnum.encode("ascii"))
|
||||||
self.storage_nurls = nurls
|
self.storage_nurls = nurls
|
||||||
announcement[storage_client.ANONYMOUS_STORAGE_NURLS] = [n.to_text() for n in nurls]
|
announcement[ANONYMOUS_STORAGE_NURLS] = [n.to_text() for n in nurls]
|
||||||
# Tell Foolscap server about the nurls so it can send them out
|
# Tell Foolscap server about the nurls so it can send them out
|
||||||
# to clients, allowing them to auto-upgrade.
|
# to clients, allowing them to auto-upgrade.
|
||||||
foolscap_server.set_nurls(nurls)
|
foolscap_server.set_nurls(nurls)
|
||||||
|
@ -16,6 +16,10 @@ from twisted.web.iweb import IResponse
|
|||||||
|
|
||||||
CBOR_MIME_TYPE = "application/cbor"
|
CBOR_MIME_TYPE = "application/cbor"
|
||||||
|
|
||||||
|
# Key used in introducer announcements and Foolscap storage server version for
|
||||||
|
# HTTP storage NURLs:
|
||||||
|
ANONYMOUS_STORAGE_NURLS = "anonymous-storage-NURLs"
|
||||||
|
|
||||||
|
|
||||||
def get_content_type(headers: Headers) -> Optional[str]:
|
def get_content_type(headers: Headers) -> Optional[str]:
|
||||||
"""
|
"""
|
||||||
|
@ -31,7 +31,7 @@ from allmydata.storage.immutable import (
|
|||||||
)
|
)
|
||||||
from allmydata.storage.crawler import BucketCountingCrawler
|
from allmydata.storage.crawler import BucketCountingCrawler
|
||||||
from allmydata.storage.expirer import LeaseCheckingCrawler
|
from allmydata.storage.expirer import LeaseCheckingCrawler
|
||||||
from ..storage_client import ANONYMOUS_STORAGE_NURLS
|
from .http_common import ANONYMOUS_STORAGE_NURLS
|
||||||
|
|
||||||
# storage/
|
# storage/
|
||||||
# storage/shares/incoming
|
# storage/shares/incoming
|
||||||
@ -834,7 +834,7 @@ class FoolscapStorageServer(Referenceable): # type: ignore # warner/foolscap#78
|
|||||||
|
|
||||||
# The HTTP storage NURLs for this server. We include them in version
|
# The HTTP storage NURLs for this server. We include them in version
|
||||||
# messages so clients can upgrade from Foolscap to HTTP.
|
# messages so clients can upgrade from Foolscap to HTTP.
|
||||||
self._nurls : list[str] = []
|
self._nurls : list[bytes] = []
|
||||||
|
|
||||||
def _bucket_writer_closed(self, bw):
|
def _bucket_writer_closed(self, bw):
|
||||||
if bw in self._bucket_writer_disconnect_markers:
|
if bw in self._bucket_writer_disconnect_markers:
|
||||||
@ -843,13 +843,14 @@ class FoolscapStorageServer(Referenceable): # type: ignore # warner/foolscap#78
|
|||||||
|
|
||||||
def set_nurls(self, nurls: list[DecodedURL]) -> None:
|
def set_nurls(self, nurls: list[DecodedURL]) -> None:
|
||||||
"""Set the HTTP NURLs for this server."""
|
"""Set the HTTP NURLs for this server."""
|
||||||
self._nurls = [n.to_text() for n in nurls]
|
self._nurls = [n.to_text().encode("utf-8") for n in nurls]
|
||||||
|
|
||||||
def remote_get_version(self):
|
def remote_get_version(self):
|
||||||
result = self._server.get_version()
|
result = self._server.get_version()
|
||||||
if self._nurls:
|
if self._nurls:
|
||||||
|
# Tell clients how to upgrade to HTTP protocol:
|
||||||
result[b"http://allmydata.org/tahoe/protocols/storage/v2"] = {
|
result[b"http://allmydata.org/tahoe/protocols/storage/v2"] = {
|
||||||
ANONYMOUS_STORAGE_NURLS: self._nurls
|
ANONYMOUS_STORAGE_NURLS.encode("ascii"): self._nurls
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@ -93,10 +93,9 @@ from allmydata.storage.http_client import (
|
|||||||
ReadVector, TestWriteVectors, WriteVector, TestVector, ClientException,
|
ReadVector, TestWriteVectors, WriteVector, TestVector, ClientException,
|
||||||
StorageClientFactory
|
StorageClientFactory
|
||||||
)
|
)
|
||||||
|
from .storage.http_common import ANONYMOUS_STORAGE_NURLS
|
||||||
from .node import _Config
|
from .node import _Config
|
||||||
|
|
||||||
ANONYMOUS_STORAGE_NURLS = "anonymous-storage-NURLs"
|
|
||||||
|
|
||||||
|
|
||||||
# who is responsible for de-duplication?
|
# who is responsible for de-duplication?
|
||||||
# both?
|
# both?
|
||||||
@ -333,6 +332,8 @@ class StorageFarmBroker(service.MultiService):
|
|||||||
return s
|
return s
|
||||||
|
|
||||||
handler_overrides = server.get("connections", {})
|
handler_overrides = server.get("connections", {})
|
||||||
|
# TODO connect and get version; if it has HTTP and we support HTTP, do
|
||||||
|
# HTTPNativeStorageServer instead.
|
||||||
s = NativeStorageServer(
|
s = NativeStorageServer(
|
||||||
server_id,
|
server_id,
|
||||||
server["ann"],
|
server["ann"],
|
||||||
|
@ -33,6 +33,7 @@ from twisted.trial import unittest
|
|||||||
from twisted.internet import defer
|
from twisted.internet import defer
|
||||||
from twisted.internet.task import Clock
|
from twisted.internet.task import Clock
|
||||||
|
|
||||||
|
from hyperlink import DecodedURL
|
||||||
from hypothesis import given, strategies, example
|
from hypothesis import given, strategies, example
|
||||||
|
|
||||||
import itertools
|
import itertools
|
||||||
@ -583,6 +584,19 @@ class Server(AsyncTestCase):
|
|||||||
sv1 = ver[b'http://allmydata.org/tahoe/protocols/storage/v1']
|
sv1 = ver[b'http://allmydata.org/tahoe/protocols/storage/v1']
|
||||||
self.assertTrue(sv1.get(b'prevents-read-past-end-of-share-data'), sv1)
|
self.assertTrue(sv1.get(b'prevents-read-past-end-of-share-data'), sv1)
|
||||||
|
|
||||||
|
def test_get_version_can_expose_nurls(self):
|
||||||
|
"""
|
||||||
|
``FoolscapStorageServer.remote_get_version()`` includes NURLs if set.
|
||||||
|
"""
|
||||||
|
ss = FoolscapStorageServer(self.create("test_get_version_can_expose_nurls"))
|
||||||
|
v2 = b'http://allmydata.org/tahoe/protocols/storage/v2'
|
||||||
|
self.assertNotIn(v2, ss.remote_get_version())
|
||||||
|
ss.set_nurls([DecodedURL.from_text("pb://blah"), DecodedURL.from_text("pb://baz")])
|
||||||
|
self.assertEqual(
|
||||||
|
ss.remote_get_version()[v2],
|
||||||
|
{b"anonymous-storage-NURLs": [b"pb://blah", b"pb://baz"]}
|
||||||
|
)
|
||||||
|
|
||||||
def test_declares_maximum_share_sizes(self):
|
def test_declares_maximum_share_sizes(self):
|
||||||
ss = self.create("test_declares_maximum_share_sizes")
|
ss = self.create("test_declares_maximum_share_sizes")
|
||||||
ver = ss.get_version()
|
ver = ss.get_version()
|
||||||
|
Loading…
Reference in New Issue
Block a user