Skip to content

Commit

Permalink
fix:dataclass
Browse files Browse the repository at this point in the history
  • Loading branch information
JarbasAl authored Dec 29, 2024
1 parent 3c7f576 commit 32f8b93
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions hivemind_websocket_protocol/__init__.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import asyncio
import dataclasses
import os
import os.path
import random
from os import makedirs
from os.path import exists, join
from socket import gethostname
from typing import Optional, Tuple
from typing import Dict, Any, Optional, Tuple

import pybase64
from OpenSSL import crypto
Expand All @@ -25,19 +26,23 @@
HiveMindClientConnection,
HiveMindNodeType
)
from hivemind_plugin_manager.protocols import ClientCallbacks


@dataclasses.dataclass
class HiveMindWebsocketProtocol(NetworkProtocol):
"""
WebSocket handler for managing HiveMind client connections.
Attributes:
hm_protocol (Optional[HiveMindListenerProtocol]): The protocol instance for handling HiveMind messages.
"""
config: Dict[str, Any] = dataclasses.field(default_factory=dict)
hm_protocol: Optional[HiveMindListenerProtocol] = None
callbacks: ClientCallbacks = dataclasses.field(default_factory=ClientCallbacks)

def run(self):

LOG.debug(f"websocket server config: {self.config}")
asyncio.set_event_loop_policy(AnyThreadEventLoopPolicy())
HiveMindTornadoWebSocket.loop = ioloop.IOLoop.current()
HiveMindTornadoWebSocket.hm_protocol = self.hm_protocol
Expand Down Expand Up @@ -84,13 +89,13 @@ def create_self_signed_cert(
Returns:
Tuple[str, str]: The paths to the created certificate and key files.
"""
CERT_FILE = name + ".crt"
KEY_FILE = name + ".key"
cert_path = join(cert_dir, CERT_FILE)
key_path = join(cert_dir, KEY_FILE)
cert_file = name + ".crt"
key_file = name + ".key"
cert_path = join(cert_dir, cert_file)
key_path = join(cert_dir, key_file)
makedirs(cert_dir, exist_ok=True)

if not exists(join(cert_dir, CERT_FILE)) or not exists(join(cert_dir, KEY_FILE)):
if not exists(join(cert_dir, cert_file)) or not exists(join(cert_dir, key_file)):
# create a key pair
k = crypto.PKey()
k.generate_key(crypto.TYPE_RSA, 2048)
Expand Down

0 comments on commit 32f8b93

Please sign in to comment.