Skip to content

Commit

Permalink
fix: fixes after code review
Browse files Browse the repository at this point in the history
  • Loading branch information
Grzegorz Leszczyński committed Oct 30, 2024
1 parent 6d96fec commit 6ea94cb
Show file tree
Hide file tree
Showing 11 changed files with 216 additions and 223 deletions.
54 changes: 54 additions & 0 deletions bt_ddos_shield/address.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
from abc import ABC, abstractmethod
from enum import Enum


class AddressType(Enum):
"""
Possible types of address.
"""
IP = "ip" # IPv4 address
IPV6 = "ipv6" # IPv6 address
DOMAIN = "domain" # domain name


class Address(ABC):
"""
Class describing address, which redirects to original miner's server.
"""

def __init__(self, address_id, address_type: AddressType, address: str, port: int):
"""
Args:
address_id: Identifier (used by AddressManager) of the address. Type depends on the implementation.
address_type: Type of the address.
address: Address.
port: Port of the address.
"""
self.address_id = address_id
self.address_type = address_type
self.address = address
self.port = port

@abstractmethod
def encrypt(self) -> bytes:
"""
Encrypts address data.
Returns:
bytes: Encrypted address data.
"""
pass

@classmethod
@abstractmethod
def decrypt(cls, encrypted_data: bytes) -> Address:
"""
Create address from encrypted address data.
Args:
encrypted_data: Encrypted address data.
Returns:
Address: Created address.
"""
pass
57 changes: 57 additions & 0 deletions bt_ddos_shield/address_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
from abc import ABC, abstractmethod

from bt_ddos_shield.address import Address


class AbstractAddressManager(ABC):
"""
Abstract base class for manager handling public IP/domain addresses assigned to validators.
"""

def __init__(self, address_id):
"""
Args:
address_id: Identifier of the address of original miner's server. All created addresses for validators
should redirect to this address.
"""
self.address_id = address_id

@abstractmethod
def create_address(self) -> Address:
"""
Create a new address.
Returns:
Address: New address to be used by validator.
"""
pass

@abstractmethod
def remove_address(self, address_id):
"""
Remove address.
Args:
address_id: Identifier of the address to remove.
"""
pass

@abstractmethod
def address_exists(self, address_id) -> bool:
"""
Check if address exists.
Args:
address_id: Identifier of the address to check.
Returns:
bool: If address exists.
"""
pass

def hide_original_server(self):
"""
If method is implemented, it should hide the original server IP address from public access.
See auto_hide_original_server in MinerShield options.
"""
pass
14 changes: 6 additions & 8 deletions bt_ddos_shield/blockchain_manager.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
from abc import ABC, abstractmethod

class BlockchainManager(ABC):

class AbstractBlockchainManager(ABC):
"""
Abstract base class for manager handling publishing blocks to blockchain.
"""

def __init__(self):
pass

@abstractmethod
def publish(self, data: bytes):
"""
Puts data to blockchain.
Puts data to blockchain.
Args:
data: Data.
"""
Args:
data: Data.
"""
pass
52 changes: 0 additions & 52 deletions bt_ddos_shield/dns_manager.py

This file was deleted.

50 changes: 0 additions & 50 deletions bt_ddos_shield/domain.py

This file was deleted.

36 changes: 0 additions & 36 deletions bt_ddos_shield/event_manager.py

This file was deleted.

28 changes: 28 additions & 0 deletions bt_ddos_shield/event_processor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from abc import ABC, abstractmethod
from dataclasses import dataclass


@dataclass
class Event:
"""
Class describing event, which happened in the shield.
"""

event_description: str # Description of the event.
exception: Exception = None # Exception which caused the event.


class AbstractEventProcessor(ABC):
"""
Abstract base class for processor handling events generated by shield.
"""

@abstractmethod
def add_event(self, event: Event):
"""
Add new event to be handled by processor.
Args:
event: Event to add.
"""
pass
22 changes: 10 additions & 12 deletions bt_ddos_shield/manifest_manager.py
Original file line number Diff line number Diff line change
@@ -1,38 +1,36 @@
from abc import ABC, abstractmethod

from bt_ddos_shield.dns_manager import Domain
from bt_ddos_shield.address import Address
from bt_ddos_shield.miner_shield import Hotkey


class ManifestManager(ABC):
class AbstractManifestManager(ABC):
"""
Abstract base class for manager handling publishing manifest file containing encrypted domains for validators.
Abstract base class for manager handling publishing manifest file containing encrypted addresses for validators.
"""

def __init__(self):
pass

def add_mapping_file(self, domain_mapping: dict[str, Domain]) -> Domain:
def add_mapping_file(self, address_mapping: dict[Hotkey, Address]) -> Address:
"""
Adds a mapping as file with encrypted domains to the storage.
Adds a mapping as file with encrypted addresses to the storage.
Args:
domain_mapping: A dictionary containing the domain mapping (validator HotKey -> Domain).
address_mapping: A dictionary containing the address mapping (validator HotKey -> Address).
Returns:
Domain: Domain where file is put.
Address: Address where file is put.
"""
# TODO - add implementation (encrypt with EncryptionManager and call put_file)
pass

@abstractmethod
def put_file(self, data: str) -> Domain:
def _put_file(self, data: bytes) -> Address:
"""
Puts a file into the storage.
Args:
data: File contents.
Returns:
Domain: Domain where file is put.
Address: Address where file is put.
"""
pass
Loading

0 comments on commit 6ea94cb

Please sign in to comment.