mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-06-19 07:48:11 +00:00
Add working HTTP support.
This commit is contained in:
@ -64,7 +64,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 import node
|
from allmydata import node
|
||||||
from .protocol_switch import FoolscapOrHttp
|
from .protocol_switch import update_foolscap_or_http_class
|
||||||
|
|
||||||
|
|
||||||
KiB=1024
|
KiB=1024
|
||||||
@ -820,11 +820,7 @@ class _Client(node.Node, pollmixin.PollMixin):
|
|||||||
furl_file = self.config.get_private_path("storage.furl").encode(get_filesystem_encoding())
|
furl_file = self.config.get_private_path("storage.furl").encode(get_filesystem_encoding())
|
||||||
furl = self.tub.registerReference(FoolscapStorageServer(ss), furlFile=furl_file)
|
furl = self.tub.registerReference(FoolscapStorageServer(ss), furlFile=furl_file)
|
||||||
(_, _, swissnum) = furl.rpartition("/")
|
(_, _, swissnum) = furl.rpartition("/")
|
||||||
class FoolscapOrHttpWithCert(FoolscapOrHttp):
|
update_foolscap_or_http_class(self.tub.negotiationClass, self.tub.myCertificate, ss, swissnum.encode("ascii"))
|
||||||
certificate = self.tub.myCertificate
|
|
||||||
storage_server = ss
|
|
||||||
swissnum = swissnum
|
|
||||||
self.tub.negotiationClass = FoolscapOrHttpWithCert
|
|
||||||
|
|
||||||
announcement["anonymous-storage-FURL"] = furl
|
announcement["anonymous-storage-FURL"] = furl
|
||||||
|
|
||||||
|
@ -55,6 +55,8 @@ from allmydata.util.yamlutil import (
|
|||||||
from . import (
|
from . import (
|
||||||
__full_version__,
|
__full_version__,
|
||||||
)
|
)
|
||||||
|
from .protocol_switch import create_foolscap_or_http_class
|
||||||
|
|
||||||
|
|
||||||
def _common_valid_config():
|
def _common_valid_config():
|
||||||
return configutil.ValidConfiguration({
|
return configutil.ValidConfiguration({
|
||||||
@ -707,6 +709,7 @@ def create_tub(tub_options, default_connection_handlers, foolscap_connection_han
|
|||||||
the new Tub via `Tub.setOption`
|
the new Tub via `Tub.setOption`
|
||||||
"""
|
"""
|
||||||
tub = Tub(**kwargs)
|
tub = Tub(**kwargs)
|
||||||
|
tub.negotiationClass = create_foolscap_or_http_class()
|
||||||
for (name, value) in list(tub_options.items()):
|
for (name, value) in list(tub_options.items()):
|
||||||
tub.setOption(name, value)
|
tub.setOption(name, value)
|
||||||
handlers = default_connection_handlers.copy()
|
handlers = default_connection_handlers.copy()
|
||||||
|
@ -14,6 +14,7 @@ from twisted.protocols.tls import TLSMemoryBIOFactory
|
|||||||
from foolscap.negotiate import Negotiation
|
from foolscap.negotiate import Negotiation
|
||||||
|
|
||||||
from .storage.http_server import HTTPServer
|
from .storage.http_server import HTTPServer
|
||||||
|
from .storage.server import StorageServer
|
||||||
|
|
||||||
|
|
||||||
class ProtocolMode(Enum):
|
class ProtocolMode(Enum):
|
||||||
@ -38,6 +39,11 @@ class FoolscapOrHttp(Protocol, metaclass=PretendToBeNegotiation):
|
|||||||
Pretends to be a ``foolscap.negotiate.Negotiation`` instance.
|
Pretends to be a ``foolscap.negotiate.Negotiation`` instance.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# These three will be set by a subclass
|
||||||
|
swissnum: bytes
|
||||||
|
certificate = None # TODO figure out type
|
||||||
|
storage_server: StorageServer
|
||||||
|
|
||||||
_foolscap: Optional[Negotiation] = None
|
_foolscap: Optional[Negotiation] = None
|
||||||
_protocol_mode: ProtocolMode = ProtocolMode.UNDECIDED
|
_protocol_mode: ProtocolMode = ProtocolMode.UNDECIDED
|
||||||
_buffer: bytes = b""
|
_buffer: bytes = b""
|
||||||
@ -113,3 +119,16 @@ class FoolscapOrHttp(Protocol, metaclass=PretendToBeNegotiation):
|
|||||||
def connectionLost(self, reason: Failure) -> None:
|
def connectionLost(self, reason: Failure) -> None:
|
||||||
if self._protocol_mode == ProtocolMode.FOOLSCAP:
|
if self._protocol_mode == ProtocolMode.FOOLSCAP:
|
||||||
return self._foolscap.connectionLost(reason)
|
return self._foolscap.connectionLost(reason)
|
||||||
|
|
||||||
|
|
||||||
|
def create_foolscap_or_http_class():
|
||||||
|
class FoolscapOrHttpWithCert(FoolscapOrHttp):
|
||||||
|
pass
|
||||||
|
|
||||||
|
return FoolscapOrHttpWithCert
|
||||||
|
|
||||||
|
|
||||||
|
def update_foolscap_or_http_class(cls, certificate, storage_server, swissnum):
|
||||||
|
cls.certificate = certificate
|
||||||
|
cls.storage_server = storage_server
|
||||||
|
cls.swissnum = swissnum
|
||||||
|
Reference in New Issue
Block a user