websockets: only allow connections to identify once
Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
parent
cbc02d625c
commit
da864ab391
|
@ -380,6 +380,10 @@ class WebsocketManager(APITransport):
|
||||||
ws: WebSocket,
|
ws: WebSocket,
|
||||||
**kwargs
|
**kwargs
|
||||||
) -> Dict[str, int]:
|
) -> Dict[str, int]:
|
||||||
|
if ws.identified:
|
||||||
|
raise self.server.error(
|
||||||
|
f"Connection already identified: {ws.client_data}"
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
name = str(kwargs["client_name"])
|
name = str(kwargs["client_name"])
|
||||||
version = str(kwargs["version"])
|
version = str(kwargs["version"])
|
||||||
|
@ -500,6 +504,7 @@ class WebSocket(WebSocketHandler, Subscribable):
|
||||||
self.message_buf: List[Union[str, Dict[str, Any]]] = []
|
self.message_buf: List[Union[str, Dict[str, Any]]] = []
|
||||||
self.last_pong_time: float = self.event_loop.get_loop_time()
|
self.last_pong_time: float = self.event_loop.get_loop_time()
|
||||||
self._connected_time: float = 0.
|
self._connected_time: float = 0.
|
||||||
|
self._identified: bool = False
|
||||||
self._client_data: Dict[str, str] = {
|
self._client_data: Dict[str, str] = {
|
||||||
"name": "unknown",
|
"name": "unknown",
|
||||||
"version": "",
|
"version": "",
|
||||||
|
@ -519,6 +524,10 @@ class WebSocket(WebSocketHandler, Subscribable):
|
||||||
def start_time(self) -> float:
|
def start_time(self) -> float:
|
||||||
return self._connected_time
|
return self._connected_time
|
||||||
|
|
||||||
|
@property
|
||||||
|
def identified(self) -> bool:
|
||||||
|
return self._identified
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def client_data(self) -> Dict[str, str]:
|
def client_data(self) -> Dict[str, str]:
|
||||||
return self._client_data
|
return self._client_data
|
||||||
|
@ -526,6 +535,7 @@ class WebSocket(WebSocketHandler, Subscribable):
|
||||||
@client_data.setter
|
@client_data.setter
|
||||||
def client_data(self, data: Dict[str, str]) -> None:
|
def client_data(self, data: Dict[str, str]) -> None:
|
||||||
self._client_data = data
|
self._client_data = data
|
||||||
|
self._identified = True
|
||||||
|
|
||||||
def open(self, *args, **kwargs) -> None:
|
def open(self, *args, **kwargs) -> None:
|
||||||
self.set_nodelay(True)
|
self.set_nodelay(True)
|
||||||
|
|
Loading…
Reference in New Issue