hivesolutions / netius

Readable, simple and fast asynchronous non-blocking network apps
http://netius.hive.pt
Apache License 2.0
118 stars 5 forks source link

Protocols support 🚀 #23

Open joamag opened 6 years ago

joamag commented 6 years ago

Description

Since the inception of the asyncio library in Python 3.5, the Python network world has changed, and a lot of "scalability" emerged from that.

As Netius was created before the arrival of asyncio, the tech approach to network diverged. Although both strategies represent nonblocking asyncio event-loop-based solutions overall, they have different approaches and abstractions for server and client implementation.

The objective of this issue is to merge (via compatibility layer) both approaches, making it possible for the following scenarios:

Meaning full bi-directional compatibility between Netius's way of working and the asyncio one.

Implementation

Architecture

Change ideas

Command-based client

We must rethink what a command-based client (e.g., SMTP, IMAP, etc.) is, as their session is currently very hard-coded. It must be much more similar to a command-based server, kind of like a bot-based server (more similar to the FTP server). And their state machine should be more flexible.

Migration strategy

This is the overall idea of how to migrate a client.

HTTPConnection -> HTTPProtocol

Principles

Testing

To test that both strategies are working, one can use the ASYNCIO=1 env variable to run in the asyncio event loop. The COMPAT=1 mode will ensure that Netius's services and clients run the compatibility layer, meaning that they should be able to run with the asyncio API behavior expectations, calling the proper protocol callbacks, etc.

Reference

Transports and protocols (callback-based API) aiohttp server

joamag commented 6 years ago

It's important to make support for a simple server like this one echos_tcp.py as soon as possible.