STS transmuting doesn't need the context of a server object
This commit is contained in:
parent
899d6f69d8
commit
feb71d5b14
2 changed files with 11 additions and 12 deletions
|
@ -75,6 +75,14 @@ def _cap_dict(s: str) -> Dict[str, str]:
|
|||
d[key] = value
|
||||
return d
|
||||
|
||||
async def sts_transmute(params: ConnectionParams):
|
||||
if not params.sts is None and not params.tls:
|
||||
now = time()
|
||||
since = (now-params.sts.created)
|
||||
if since <= params.sts.duration:
|
||||
params.port = params.sts.port
|
||||
params.tls = True
|
||||
|
||||
class CAPContext(ServerContext):
|
||||
async def on_ls(self, tokens: Dict[str, str]):
|
||||
caps = list(self.server.desired_caps)+CAPS
|
||||
|
@ -126,12 +134,3 @@ class CAPContext(ServerContext):
|
|||
|
||||
await self.on_ls(self.server.available_caps)
|
||||
await self.server.send(build("CAP", ["END"]))
|
||||
|
||||
class STSContext(ServerContext):
|
||||
async def transmute(self, params: ConnectionParams):
|
||||
if not params.sts is None and not params.tls:
|
||||
now = time()
|
||||
since = (now-params.sts.created)
|
||||
if since <= params.sts.duration:
|
||||
params.port = params.sts.port
|
||||
params.tls = True
|
||||
|
|
|
@ -8,8 +8,8 @@ from ircstates.numerics import *
|
|||
from ircstates.server import ServerDisconnectedException
|
||||
from irctokens import build, Line, tokenise
|
||||
|
||||
from .ircv3 import (CAPContext, STSContext, CAP_ECHO, CAP_SASL, CAP_LABEL,
|
||||
LABEL_TAG)
|
||||
from .ircv3 import (CAPContext, sts_transmute, CAP_ECHO, CAP_SASL,
|
||||
CAP_LABEL, LABEL_TAG)
|
||||
from .sasl import SASLContext, SASLResult
|
||||
from .join_info import WHOContext
|
||||
from .matching import ResponseOr, Responses, Response, ParamAny, ParamFolded
|
||||
|
@ -84,7 +84,7 @@ class Server(IServer):
|
|||
async def connect(self,
|
||||
transport: ITCPTransport,
|
||||
params: ConnectionParams):
|
||||
await STSContext(self).transmute(params)
|
||||
await sts_transmute(params)
|
||||
|
||||
reader, writer = await transport.connect(
|
||||
params.host,
|
||||
|
|
Loading…
Reference in a new issue