mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-02-01 16:58:10 +00:00
Add a timeout.
This commit is contained in:
parent
0c99a9f7b0
commit
eb1e48bcc3
@ -2,13 +2,14 @@
|
||||
Support for listening with both HTTP and Foolscap on the same port.
|
||||
"""
|
||||
|
||||
from typing import Optional, Tuple
|
||||
from typing import Optional
|
||||
|
||||
from twisted.internet.protocol import Protocol
|
||||
from twisted.internet.interfaces import ITransport
|
||||
from twisted.internet.interfaces import IDelayedCall
|
||||
from twisted.internet.ssl import CertificateOptions, PrivateCertificate
|
||||
from twisted.web.server import Site
|
||||
from twisted.protocols.tls import TLSMemoryBIOFactory
|
||||
from twisted.internet import reactor
|
||||
|
||||
from foolscap.negotiate import Negotiation
|
||||
|
||||
@ -36,6 +37,8 @@ class FoolscapOrHttp(Protocol, metaclass=PretendToBeNegotiation):
|
||||
certificate: PrivateCertificate
|
||||
storage_server: StorageServer
|
||||
|
||||
_timeout: IDelayedCall
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self._foolscap: Negotiation = Negotiation(*args, **kwargs)
|
||||
self._buffer: bytes = b""
|
||||
@ -69,6 +72,9 @@ class FoolscapOrHttp(Protocol, metaclass=PretendToBeNegotiation):
|
||||
self._convert_to_negotiation()
|
||||
return self.initClient(*args, **kwargs)
|
||||
|
||||
def connectionMade(self):
|
||||
self._timeout = reactor.callLater(30, self.transport.abortConnection)
|
||||
|
||||
def dataReceived(self, data: bytes) -> None:
|
||||
"""Handle incoming data.
|
||||
|
||||
@ -80,7 +86,8 @@ class FoolscapOrHttp(Protocol, metaclass=PretendToBeNegotiation):
|
||||
return
|
||||
|
||||
# Check if it looks like a Foolscap request. If so, it can handle this
|
||||
# and later data:
|
||||
# and later data, otherwise assume HTTPS.
|
||||
self._timeout.cancel()
|
||||
if self._buffer.startswith(b"GET /id/"):
|
||||
transport = self.transport
|
||||
buf = self._buffer
|
||||
|
Loading…
x
Reference in New Issue
Block a user