mirror of https://gitlab.com/litecord/litecord.git
Compare commits
No commits in common. "c1a6d9a53a6b0f9f11cd01349e959bf20c8d41d0" and "7d8488adc7ea2d9b5d268f3e51ec10426d806edf" have entirely different histories.
c1a6d9a53a
...
7d8488adc7
|
|
@ -66,9 +66,6 @@ class Config:
|
||||||
#: Postgres credentials
|
#: Postgres credentials
|
||||||
POSTGRES = {}
|
POSTGRES = {}
|
||||||
|
|
||||||
#: Shared secret for LVSP
|
|
||||||
LVSP_SECRET = ""
|
|
||||||
|
|
||||||
|
|
||||||
class Development(Config):
|
class Development(Config):
|
||||||
DEBUG = True
|
DEBUG = True
|
||||||
|
|
|
||||||
|
|
@ -24,9 +24,6 @@ from typing import Dict
|
||||||
import websockets
|
import websockets
|
||||||
from logbook import Logger
|
from logbook import Logger
|
||||||
|
|
||||||
import hmac
|
|
||||||
import hashlib
|
|
||||||
|
|
||||||
from litecord.voice.lvsp_opcodes import OPCodes as OP, InfoTable, InfoReverse
|
from litecord.voice.lvsp_opcodes import OPCodes as OP, InfoTable, InfoReverse
|
||||||
|
|
||||||
log = Logger(__name__)
|
log = Logger(__name__)
|
||||||
|
|
@ -62,7 +59,7 @@ class LVSPConnection:
|
||||||
"""Receive a payload."""
|
"""Receive a payload."""
|
||||||
assert self.conn is not None
|
assert self.conn is not None
|
||||||
msg = await self.conn.recv()
|
msg = await self.conn.recv()
|
||||||
msg = json.loads(msg)
|
msg = json.dumps(msg)
|
||||||
return msg
|
return msg
|
||||||
|
|
||||||
async def send_op(self, opcode: int, data: dict):
|
async def send_op(self, opcode: int, data: dict):
|
||||||
|
|
@ -103,15 +100,10 @@ class LVSPConnection:
|
||||||
"""Handle HELLO message."""
|
"""Handle HELLO message."""
|
||||||
data = msg["d"]
|
data = msg["d"]
|
||||||
|
|
||||||
|
# nonce = data['nonce']
|
||||||
self._hb_interval = data["heartbeat_interval"]
|
self._hb_interval = data["heartbeat_interval"]
|
||||||
|
|
||||||
token = hmac.new(
|
# TODO: send identify
|
||||||
self.app.config.get("LVSP_SECRET").encode(),
|
|
||||||
data["nonce"].encode(),
|
|
||||||
hashlib.sha256,
|
|
||||||
).hexdigest()
|
|
||||||
|
|
||||||
await self.send_op(OP.identify, {"token": token})
|
|
||||||
|
|
||||||
async def _update_health(self, new_health: float):
|
async def _update_health(self, new_health: float):
|
||||||
"""Update the health value of a given voice server."""
|
"""Update the health value of a given voice server."""
|
||||||
|
|
@ -120,7 +112,7 @@ class LVSPConnection:
|
||||||
await self.app.db.execute(
|
await self.app.db.execute(
|
||||||
"""
|
"""
|
||||||
UPDATE voice_servers
|
UPDATE voice_servers
|
||||||
SET last_health = $1
|
SET health = $1
|
||||||
WHERE hostname = $2
|
WHERE hostname = $2
|
||||||
""",
|
""",
|
||||||
new_health,
|
new_health,
|
||||||
|
|
@ -132,17 +124,13 @@ class LVSPConnection:
|
||||||
|
|
||||||
We only start heartbeating after READY.
|
We only start heartbeating after READY.
|
||||||
"""
|
"""
|
||||||
data = msg["d"]
|
await self._update_health(msg["health"])
|
||||||
|
|
||||||
await self._update_health(data["health"])
|
|
||||||
self._start_hb()
|
self._start_hb()
|
||||||
|
|
||||||
async def _handle_5(self, msg):
|
async def _handle_5(self, msg):
|
||||||
"""Handle HEARTBEAT_ACK."""
|
"""Handle HEARTBEAT_ACK."""
|
||||||
self._stop_hb()
|
self._stop_hb()
|
||||||
data = msg["d"]
|
await self._update_health(msg["health"])
|
||||||
|
|
||||||
await self._update_health(data["health"])
|
|
||||||
self._start_hb()
|
self._start_hb()
|
||||||
|
|
||||||
async def _handle_6(self, msg):
|
async def _handle_6(self, msg):
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue