...
Page properties | ||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| ||||||||||||||||||||
|
Background
...
- Async I/O - as Iroha2 is heavily async and relies on executors for low-level thread management.
- A relatively small number of new dependencies - as new dependencies introduce potential security risks.
- Library rather than framework - as Iroha2 has already a rather specific structure and should not change its style to fit the framework.
- It should be possible to upgrade HTTP connection from HTTP library with WebSocket
- Free open license
- HTTP 1.1 support - as Substrate offchain workers do not support HTTP 2
Proposed Libraries
The proposed libraries are the following:
Protocol | Library | Description |
---|---|---|
HTTP | httphttparse | A general-purpose library of common HTTP types. This means that it will be needed to implement our own HTTP server with the use of this librarypush parser for the HTTP 1.x protocol. Avoids allocations. No copy. Fast. |
route-recognizer | Recognizes URL patterns with support for dynamic and glob segments. Can be easily replaced with our custom solution later. Used to speed up the development process. Also doesn't have any dependencies. | |
Web Socket | async-tungstenite | Asynchronous WebSockets for async-std, tokio, gio and any std Future s runtime. Based on tungstenite crate. |
The usage of these libraries would, in general, mean that we will implement our own web server based on TCP streams, but the messages will be parsed with the help of HTTP library. When the upgrade request for web socket will be received, then the connection manager will be passed to async-tangstenite tungstenite library.
Alternatives
Alternative | Description | Why not chosen | ||||
---|---|---|---|---|---|---|
tiny_http as HTTP server library | Low-level HTTP server library | No async support | ||||
http as HTTP type helper library | A general-purpose library of common HTTP types. | Does not support parsing from streams or raw bytes, which is a functionality that we might spend a lot of time writing if it is not supported out of the box. | ||||
async_h1 as HTTP server library | Asynchronous HTTP/1.1 parser. | Does not support WebSocket upgrade. | ||||
hyper as HTTP server library | A fast and correct HTTP implementation for Rust. Actually the fastest HTTP server library according to techempower. |
| ||||
h2 as HTTP server library | A Tokio aware, HTTP/2.0 client & server implementation for Rust. |
| ||||
http-service as HTTP server interface library | The crate http-service provides the necessary types and traits to implement your own HTTP Server. | The crate mainly provides the interface for the servers to implement the same methods, it might be good for architecture in general, but it is an additional dependency and our priority is to only add absolutely necessary ones. | ||||
tide as http server | A modular web framework built around async/await. |
In general it might have been a good choice if they had finished web socket support by now. | https://github.com/carllerche/h2 | Http 2.0 is not supported by the substrate | https://crates.io/crates/http-service | https://github.com/http-rs/tide |
actix / warp / rocket as web framework | Popular web frameworks with both warp and rocket being built on the hyper library, |
| ||||
Custom http and web socket libraries | It is possible to implement a fully custom solution. | There are already existing solutions which correctly implement the standards and are widely used. The team will be able to focus on our unique functionality. |
...