NewAlpha


NameNewAlpha JSON
Version 1.1.1 PyPI version JSON
download
home_page
SummaryAn Easy to use Open-Source Virtual Networking Framework for Python. Including Switches and Clients/Servers.
upload_time2024-03-03 09:26:25
maintainer
docs_urlNone
authorNewAlpha-VNet
requires_python
license
keywords python iot networking socket virtual-machine server switch client framework
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ![](https://cdn.discordapp.com/attachments/810456487729168415/1213250618014044210/readme_newalpha_latest_logo2.png?ex=65f4cab0&is=65e255b0&hm=34c108a00794df248ad1b94c42900c6b7aff435e69f901ecd64e3eedcd7e5c09&)
<a href="https://badge.fury.io/py/NewAlpha"><img src="https://badge.fury.io/py/NewAlpha.svg" alt="PyPI version" height="18"></a>
<img alt="PyPI - Python Version" src="https://img.shields.io/pypi/pyversions/NewAlpha">
<img alt="GitHub License" src="https://img.shields.io/github/license/NewAlpha-VNet/NewAlpha">
<img alt="GitHub commits since latest release" src="https://img.shields.io/github/commits-since/NewAlpha-VNet/NewAlpha/latest">


***An Easy to use Open-Source Virtual Networking Framework for Python. Including Switches and Clients/Servers.***

> [!NOTE] 
> This framework is in early _Beta_ and may have malfunctions. In this case we would be happy to receive feedback.

## Solution
Offers a comprehensive networking solution designed to simplify the process of building and managing network infrastructures. With its user-friendly interface and pre-built infrastructure, NewAlpha eliminates the complexity of setting up networking systems. Whether for IoT applications or communication between virtual machines, NewAlpha provides a seamless experience, enabling users to easily change network configurations or manage logging systems for package tracing.

## How it works
NewAlpha is based on the Socket library, and simplifies its use. Create a virtual switch that contains a logging system to track or observe data packets. Clients are then able connect to the switch via sockets and can request/respond to other clients or servers. The data packets are structured as follows: `sender_port : message/parameter/commands : receiver_port` or as a concrete example: `25505:Hello World!:80880`. 

***Detailed:***

Each packet contains three main components: the sender's port number, the message, parameter, or command being transmitted, and the receiver's port number. This format ensures clear identification of both the source and destination of each packet, along with the content being conveyed. For instance, a typical packet might appear as follows: '25505:Hello World!:80880,' where '25505' represents the sender's port, 'Hello World!' denotes the message or payload, and '80880' signifies the receiver's port. Every virtual object communicates with such structure.

## Usage and implementation
Installing the latest version:
```cmd
pip install NewAlpha
```
```python
import NewAlpha
```
### Switch setup and traffic handling:
```python
switch = NewAlpha.AlphaSwitch()
switch.switchSetup(port=25505, address="Your IP-Address") #Change Port and IP
while True:
    switch.handleTraffic()
```
In this example, we first create an instance of the _switch_ class, then set up the switch's address data with port and address arguments. Subsequently, we run a loop to continuously handle client requests.

### Switch logging system:
The logging system is particularly useful when you want to track packets on the network or when troubleshooting with data transmission and cannot find the problem. These are the methods for managing the log:
```python
... #Previous switch setup

switch.startLog() #Starts recording the traffic
switch.stopLog() #Stops recording the traffic
log_str = switch.getNewestLog #Returns the newest log (datatype: str)
log_list_of_str = switch.getFullLog #Returns the entire logging list (datatype: list containing str)
```
It's good to know that the log is stored as/in RAM.

### Client/Server setup:
```python
client = NewAlpha.AlphaClient()
client.clientSetup(80880, "Your IP_Address") #Change Client's Port and IP
client.bridge(25505, "Switch IP_Address") #Enter the Switch Port and IP
client.registerSwitch()
```
As previously, we instantiate an object and then configure the address details of the client and the switch. We then register the client on the switch (optional but recommended).
### Client/Server response:
The virtual client/server has 3 types of response methods: _`frozenResponse()`_ , _`dynamicResponse()`_ and _`confirmationResponse`_.

***frozenResponse():***
```python
import threading

... #Previous client setup

def auto_respond():
  #key=request:value=response
  ruleset = {
  "Hi Flynn!":"Hi! How are you?" 
  }
  client.frozenResponse(ruleset)

auto_respond_thread = threading.Thread(target=auto_respond)
auto_respond_thread.start()
```
If you want to send messages while handling requests, you need threads. The _`frozenResponse()`_ method takes a set of rules as an argument to respond to a specific request with the correct answer. As the name suggests, the ruleset is frozen in a specific state, so there is no way to change it while the responding method processes it. However, it is possible to stop this thread and the response loop by setting a flag using the _`responseFlag()`_ method.

***dynamicResponse():***
```python
def auto_respond():
  while True:
    ... #Update ruleset for every new refresh/request
    client.dynamicResponse(ruleset=ruleset, refresh_time=1.0)

auto_respond_thread = threading.Thread(target=auto_respond)
auto_respond_thread.start()
```
Compared to the frozen response, the dynamic is able to change the ruleset every time the method is refreshed. Additionally, refresh_time requires a time argument, so the method waits for a specific amount of time for a request before it aborts. This is useful, for example, if you want to update the ruleset every second. _(Side info: the method additionally returns request, response, sender_port in exact that order)_

***confirmationResponse():***

```python
def auto_respond():
    while True:
        received_data, port = client.confirmationResponse("Got it, thanks!")
        print(received_data, port) #Can be used to build a chat-programm

auto_respond_thread = threading.Thread(target=auto_respond)
auto_respond_thread.start()
```
This method was specifically designed to enable dynamic context-based exchanges. What does that mean? In short, you could for example use it to create a chat application. If you want to respond to a request tailored to the message you receive, you can set up a system so you have enough time to respond. However, the method itself always responds with the save confirmation message.

### Client/Server request:
To request data packets, you can use either the _`request()`_ method or the _`generalRequest()`_ method. The only difference is that the general request method sends a message to all connected clients on the switch and the other method sends only a request to a specific connected client.

***request():***
```python
def send_package():
  encoded_message = client.encode_format("Hi Flynn!", 70770) #Message, ReceiverPort
  response, port, address = client.request(message=encoded_message)
```
Before sending a data packet, the message must be encoded/formatted using the encode_format() method. As mentioned before into the following form: `25505:Hi Flynn!:70770`. You don't always have to send it directly to the switch, you can also use it to transfer data to other networks (Then no encoding of the message is required).

***generalRequest():***
```python
response_list = client.generalRequest(message="Hi Flynn!")
```
The general request method does not require an encrypted message as an argument due to the different ports the client needs to send to. It is important to know that sending the request is done serially and not parallel with threads. Therefore it may take a while for the response to arrive.

## Benchmark
> Average Benchmark Results (for the constant package sending pause of 10ms).

| Clients-Amount | Package-Respond-Time | Latency-Drop-Time |
| :---:        |     :---:      |        :---:  |
| 5            | 13ms           |~700ms (<1s)   |
| 3            | 5ms            | ~670ms        |
| 2            | 1-2ms (<3ms)   | ~500ms        |

_Latency-Drop-Time explained: Worst case scenario when the switch has overlapping requests or is overloaded (Worst Package-Respond-Time)._

### Additional information:

`PackageMaxSize` = 4096 bytes of string (Maximum message size)

`PortsDigitsLength` = min/max 5 digits

`MaxPortsRange` = 10000 up to 65535 (Ports are only permitted in this range)

## Further configurations

### Blacklist toleration
During a data transaction, if a client that normally responds to requests is offline due to complications and the other ports are not informed and still send requests to that port, these clients will receive a 
"NoResponse" error. By default, this error occurs twice until the offline client is blacklisted. Therefore, no one can make a request to this machine. The client is removed from the blacklist when it communicates 
with the switch. Such tolerances can be changed using the _`setToleration()`_ method, which accepts an amount as an argument. (This type of response error can also occur when the client is overloaded with 
requests.)

### Byte size
By default, the maximum capacity of a message containing a string is 4096 bytes. For larger data transfers, you can change this byte size using the _`setByteSizeSwitch`_ or _`setByteSizeClient`_ method, which 
accepts an integer as an argument.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "NewAlpha",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "python,iot,networking,socket,virtual-machine,server,switch,client,framework",
    "author": "NewAlpha-VNet",
    "author_email": "<newalpha.help@gmx.net>",
    "download_url": "https://files.pythonhosted.org/packages/63/47/464be79d5c4c3e89e3b04bdfbe5863bfd8b346b4459eafa64eedc8f4a027/NewAlpha-1.1.1.tar.gz",
    "platform": null,
    "description": "![](https://cdn.discordapp.com/attachments/810456487729168415/1213250618014044210/readme_newalpha_latest_logo2.png?ex=65f4cab0&is=65e255b0&hm=34c108a00794df248ad1b94c42900c6b7aff435e69f901ecd64e3eedcd7e5c09&)\r\n<a href=\"https://badge.fury.io/py/NewAlpha\"><img src=\"https://badge.fury.io/py/NewAlpha.svg\" alt=\"PyPI version\" height=\"18\"></a>\r\n<img alt=\"PyPI - Python Version\" src=\"https://img.shields.io/pypi/pyversions/NewAlpha\">\r\n<img alt=\"GitHub License\" src=\"https://img.shields.io/github/license/NewAlpha-VNet/NewAlpha\">\r\n<img alt=\"GitHub commits since latest release\" src=\"https://img.shields.io/github/commits-since/NewAlpha-VNet/NewAlpha/latest\">\r\n\r\n\r\n***An Easy to use Open-Source Virtual Networking Framework for Python. Including Switches and Clients/Servers.***\r\n\r\n> [!NOTE] \r\n> This framework is in early _Beta_ and may have malfunctions. In this case we would be happy to receive feedback.\r\n\r\n## Solution\r\nOffers a comprehensive networking solution designed to simplify the process of building and managing network infrastructures. With its user-friendly interface and pre-built infrastructure, NewAlpha eliminates the complexity of setting up networking systems. Whether for IoT applications or communication between virtual machines, NewAlpha provides a seamless experience, enabling users to easily change network configurations or manage logging systems for package tracing.\r\n\r\n## How it works\r\nNewAlpha is based on the Socket library, and simplifies its use. Create a virtual switch that contains a logging system to track or observe data packets. Clients are then able connect to the switch via sockets and can request/respond to other clients or servers. The data packets are structured as follows: `sender_port : message/parameter/commands : receiver_port` or as a concrete example: `25505:Hello World!:80880`. \r\n\r\n***Detailed:***\r\n\r\nEach packet contains three main components: the sender's port number, the message, parameter, or command being transmitted, and the receiver's port number. This format ensures clear identification of both the source and destination of each packet, along with the content being conveyed. For instance, a typical packet might appear as follows: '25505:Hello World!:80880,' where '25505' represents the sender's port, 'Hello World!' denotes the message or payload, and '80880' signifies the receiver's port. Every virtual object communicates with such structure.\r\n\r\n## Usage and implementation\r\nInstalling the latest version:\r\n```cmd\r\npip install NewAlpha\r\n```\r\n```python\r\nimport NewAlpha\r\n```\r\n### Switch setup and traffic handling:\r\n```python\r\nswitch = NewAlpha.AlphaSwitch()\r\nswitch.switchSetup(port=25505, address=\"Your IP-Address\") #Change Port and IP\r\nwhile True:\r\n    switch.handleTraffic()\r\n```\r\nIn this example, we first create an instance of the _switch_ class, then set up the switch's address data with port and address arguments. Subsequently, we run a loop to continuously handle client requests.\r\n\r\n### Switch logging system:\r\nThe logging system is particularly useful when you want to track packets on the network or when troubleshooting with data transmission and cannot find the problem. These are the methods for managing the log:\r\n```python\r\n... #Previous switch setup\r\n\r\nswitch.startLog() #Starts recording the traffic\r\nswitch.stopLog() #Stops recording the traffic\r\nlog_str = switch.getNewestLog #Returns the newest log (datatype: str)\r\nlog_list_of_str = switch.getFullLog #Returns the entire logging list (datatype: list containing str)\r\n```\r\nIt's good to know that the log is stored as/in RAM.\r\n\r\n### Client/Server setup:\r\n```python\r\nclient = NewAlpha.AlphaClient()\r\nclient.clientSetup(80880, \"Your IP_Address\") #Change Client's Port and IP\r\nclient.bridge(25505, \"Switch IP_Address\") #Enter the Switch Port and IP\r\nclient.registerSwitch()\r\n```\r\nAs previously, we instantiate an object and then configure the address details of the client and the switch. We then register the client on the switch (optional but recommended).\r\n### Client/Server response:\r\nThe virtual client/server has 3 types of response methods: _`frozenResponse()`_ , _`dynamicResponse()`_ and _`confirmationResponse`_.\r\n\r\n***frozenResponse():***\r\n```python\r\nimport threading\r\n\r\n... #Previous client setup\r\n\r\ndef auto_respond():\r\n  #key=request:value=response\r\n  ruleset = {\r\n  \"Hi Flynn!\":\"Hi! How are you?\" \r\n  }\r\n  client.frozenResponse(ruleset)\r\n\r\nauto_respond_thread = threading.Thread(target=auto_respond)\r\nauto_respond_thread.start()\r\n```\r\nIf you want to send messages while handling requests, you need threads. The _`frozenResponse()`_ method takes a set of rules as an argument to respond to a specific request with the correct answer. As the name suggests, the ruleset is frozen in a specific state, so there is no way to change it while the responding method processes it. However, it is possible to stop this thread and the response loop by setting a flag using the _`responseFlag()`_ method.\r\n\r\n***dynamicResponse():***\r\n```python\r\ndef auto_respond():\r\n  while True:\r\n    ... #Update ruleset for every new refresh/request\r\n    client.dynamicResponse(ruleset=ruleset, refresh_time=1.0)\r\n\r\nauto_respond_thread = threading.Thread(target=auto_respond)\r\nauto_respond_thread.start()\r\n```\r\nCompared to the frozen response, the dynamic is able to change the ruleset every time the method is refreshed. Additionally, refresh_time requires a time argument, so the method waits for a specific amount of time for a request before it aborts. This is useful, for example, if you want to update the ruleset every second. _(Side info: the method additionally returns request, response, sender_port in exact that order)_\r\n\r\n***confirmationResponse():***\r\n\r\n```python\r\ndef auto_respond():\r\n    while True:\r\n        received_data, port = client.confirmationResponse(\"Got it, thanks!\")\r\n        print(received_data, port) #Can be used to build a chat-programm\r\n\r\nauto_respond_thread = threading.Thread(target=auto_respond)\r\nauto_respond_thread.start()\r\n```\r\nThis method was specifically designed to enable dynamic context-based exchanges. What does that mean? In short, you could for example use it to create a chat application. If you want to respond to a request tailored to the message you receive, you can set up a system so you have enough time to respond. However, the method itself always responds with the save confirmation message.\r\n\r\n### Client/Server request:\r\nTo request data packets, you can use either the _`request()`_ method or the _`generalRequest()`_ method. The only difference is that the general request method sends a message to all connected clients on the switch and the other method sends only a request to a specific connected client.\r\n\r\n***request():***\r\n```python\r\ndef send_package():\r\n  encoded_message = client.encode_format(\"Hi Flynn!\", 70770) #Message, ReceiverPort\r\n  response, port, address = client.request(message=encoded_message)\r\n```\r\nBefore sending a data packet, the message must be encoded/formatted using the encode_format() method. As mentioned before into the following form: `25505:Hi Flynn!:70770`. You don't always have to send it directly to the switch, you can also use it to transfer data to other networks (Then no encoding of the message is required).\r\n\r\n***generalRequest():***\r\n```python\r\nresponse_list = client.generalRequest(message=\"Hi Flynn!\")\r\n```\r\nThe general request method does not require an encrypted message as an argument due to the different ports the client needs to send to. It is important to know that sending the request is done serially and not parallel with threads. Therefore it may take a while for the response to arrive.\r\n\r\n## Benchmark\r\n> Average Benchmark Results (for the constant package sending pause of 10ms).\r\n\r\n| Clients-Amount | Package-Respond-Time | Latency-Drop-Time |\r\n| :---:        |     :---:      |        :---:  |\r\n| 5            | 13ms           |~700ms (<1s)   |\r\n| 3            | 5ms            | ~670ms        |\r\n| 2            | 1-2ms (<3ms)   | ~500ms        |\r\n\r\n_Latency-Drop-Time explained: Worst case scenario when the switch has overlapping requests or is overloaded (Worst Package-Respond-Time)._\r\n\r\n### Additional information:\r\n\r\n`PackageMaxSize` = 4096 bytes of string (Maximum message size)\r\n\r\n`PortsDigitsLength` = min/max 5 digits\r\n\r\n`MaxPortsRange` = 10000 up to 65535 (Ports are only permitted in this range)\r\n\r\n## Further configurations\r\n\r\n### Blacklist toleration\r\nDuring a data transaction, if a client that normally responds to requests is offline due to complications and the other ports are not informed and still send requests to that port, these clients will receive a \r\n\"NoResponse\" error. By default, this error occurs twice until the offline client is blacklisted. Therefore, no one can make a request to this machine. The client is removed from the blacklist when it communicates \r\nwith the switch. Such tolerances can be changed using the _`setToleration()`_ method, which accepts an amount as an argument. (This type of response error can also occur when the client is overloaded with \r\nrequests.)\r\n\r\n### Byte size\r\nBy default, the maximum capacity of a message containing a string is 4096 bytes. For larger data transfers, you can change this byte size using the _`setByteSizeSwitch`_ or _`setByteSizeClient`_ method, which \r\naccepts an integer as an argument.\r\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "An Easy to use Open-Source Virtual Networking Framework for Python. Including Switches and Clients/Servers.",
    "version": "1.1.1",
    "project_urls": null,
    "split_keywords": [
        "python",
        "iot",
        "networking",
        "socket",
        "virtual-machine",
        "server",
        "switch",
        "client",
        "framework"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3f1ec132463236fd4b7ac8d022e25670bb00d0633e8fc57d4e48dc2208bb7e70",
                "md5": "85daa26f3451160576373a16097dda78",
                "sha256": "46e63feeee7c55baa2790dab57a5697a4b87532c61e8790e396c597ac5d4df43"
            },
            "downloads": -1,
            "filename": "NewAlpha-1.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "85daa26f3451160576373a16097dda78",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 9956,
            "upload_time": "2024-03-03T09:26:24",
            "upload_time_iso_8601": "2024-03-03T09:26:24.175260Z",
            "url": "https://files.pythonhosted.org/packages/3f/1e/c132463236fd4b7ac8d022e25670bb00d0633e8fc57d4e48dc2208bb7e70/NewAlpha-1.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6347464be79d5c4c3e89e3b04bdfbe5863bfd8b346b4459eafa64eedc8f4a027",
                "md5": "66791b3faed1febe589571782a048836",
                "sha256": "db4dee3be97bbceb65a631d9f76e4c3f29b31f7565c6598b167f865932aa80e6"
            },
            "downloads": -1,
            "filename": "NewAlpha-1.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "66791b3faed1febe589571782a048836",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 9624,
            "upload_time": "2024-03-03T09:26:25",
            "upload_time_iso_8601": "2024-03-03T09:26:25.735467Z",
            "url": "https://files.pythonhosted.org/packages/63/47/464be79d5c4c3e89e3b04bdfbe5863bfd8b346b4459eafa64eedc8f4a027/NewAlpha-1.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-03 09:26:25",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "newalpha"
}
        
Elapsed time: 0.22949s