-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Grzegorz Leszczyński
committed
Oct 30, 2024
1 parent
6d96fec
commit 6ea94cb
Showing
11 changed files
with
216 additions
and
223 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.