Skip to content

Commit

Permalink
Merge pull request #2 from JarbasHiveMind/release-0.0.2a1
Browse files Browse the repository at this point in the history
Release 0.0.2a1
  • Loading branch information
JarbasAl authored Dec 29, 2024
2 parents 3c7f576 + 711d001 commit 9ba21ca
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Changelog

## [0.0.2a1](https://github.com/JarbasHiveMind/hivemind-websocket-protocol/tree/0.0.2a1) (2024-12-29)

[Full Changelog](https://github.com/JarbasHiveMind/hivemind-websocket-protocol/compare/0.0.1...0.0.2a1)

**Merged pull requests:**

- fix:dataclass [\#1](https://github.com/JarbasHiveMind/hivemind-websocket-protocol/pull/1) ([JarbasAl](https://github.com/JarbasAl))



\* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
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
4 changes: 2 additions & 2 deletions hivemind_websocket_protocol/version.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# START_VERSION_BLOCK
VERSION_MAJOR = 0
VERSION_MINOR = 0
VERSION_BUILD = 1
VERSION_ALPHA = 0
VERSION_BUILD = 2
VERSION_ALPHA = 1
# END_VERSION_BLOCK
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ def required(requirements_file):
if pkg.strip() and not pkg.startswith("#")]


PLUGIN_ENTRY_POINT = 'hivemind-websocket-plugin=hivemind_websocket_protocol:HiveMindWebsocketProtocol'

setup(
name='hivemind-websocket-protocol',
Expand All @@ -48,6 +49,7 @@ def required(requirements_file):
license='Apache-2.0',
author='jarbasAi',
install_requires=required("requirements.txt"),
entry_points={'hivemind.network.protocol': PLUGIN_ENTRY_POINT},
author_email='[email protected]',
description='websocket network protocol for hivemind-core'
)

0 comments on commit 9ba21ca

Please sign in to comment.