0.2.5-snapshot native support for tcp client/server
This commit is contained in:
1 parent
26d1f3522f
commit
ffcdcf7350
16 files changed
+524
-580
No files matched your search
@@ -1,31 +1,36 @@
|
||||
# Kiloparsec
|
||||
|
||||
The new generation of __PARanoid SECurity__ protocol, advanced, faster, more secure. It also allows connecting any "block device" transport to the same local interface. Out if the box it
|
||||
The new generation of __PARanoid SECurity__ protocol, advanced, faster, more secure. It also allows connecting any "
|
||||
block device" transport to the same local interface. Out if the box it
|
||||
provides the following transports:
|
||||
|
||||
| name | JVM | JS | native |
|
||||
|----------------|-----|----|--------|
|
||||
| TCP/IP server | * | | |
|
||||
| TCP/IP client | * | | |
|
||||
| Websock server | * | | |
|
||||
| Websock client | * | * | * |
|
||||
|
||||
At the moment we're working on supporting TCP/IP on most native targets. This feature is planned to rach public beta in August and production in early september 2024.
|
||||
| name | JVM | JS | native |
|
||||
|----------------|-----|----|-------------------|
|
||||
| TCP/IP server | ✓ | | β @0.2.5-SNAPSHOT |
|
||||
| TCP/IP client | ✓ | | β @0.2.5-SNAPSHOT |
|
||||
| Websock server | ✓ | | |
|
||||
| Websock client | ✓ | ✓ | ✓ |
|
||||
|
||||
At the moment we're working on supporting TCP/IP on most native targets. This feature is planned to rach public beta in
|
||||
August and production in early september 2024.
|
||||
|
||||
## TCP/IP transport
|
||||
|
||||
It is the fastest. JVM implementation uses nio2 async sockets and optimizes TCP socket to play
|
||||
well with blocks (smart NO_DELAY mode). It is multiplatform, nut lacks of async TCP/IP support
|
||||
on natvic targetm this is where I need help having little time. I'd prefer to use something asyn like UV on native targets.
|
||||
on natvic targetm this is where I need help having little time. I'd prefer to use something asyn like UV on native
|
||||
targets.
|
||||
|
||||
I know no existing way to implement it in KotlinJS for the modern browsers.
|
||||
|
||||
## Websock server
|
||||
|
||||
While it is much slower than pure TCP, it is still faster than any http-based transport. It uses binary frames based on the Ktor server framework to easily integrate with web services. We recommend using it instead of a classic HTTP API as it beats it in terms of speed and server load even with HTTP/2.
|
||||
While it is much slower than pure TCP, it is still faster than any http-based transport. It uses binary frames based on
|
||||
the Ktor server framework to easily integrate with web services. We recommend using it instead of a classic HTTP API as
|
||||
it beats it in terms of speed and server load even with HTTP/2.
|
||||
|
||||
We recommend to create the `KiloInterface<S>` instance and connect it to the websock and tcp servers in real applications to get easy access from anywhere.
|
||||
We recommend to create the `KiloInterface<S>` instance and connect it to the websock and tcp servers in real
|
||||
applications to get easy access from anywhere.
|
||||
|
||||
# Usage
|
||||
|
||||
@@ -64,16 +69,16 @@ and functions available, like:
|
||||
// Api.kt
|
||||
|
||||
@Serializable
|
||||
class FooArgs(val text: String,val number: Int = 42)
|
||||
class FooArgs(val text: String, val number: Int = 42)
|
||||
|
||||
// Server-side interface
|
||||
val cmdSetFoo by command<FooArgs,Unit>()
|
||||
val cmdGetFoo by command<Unit,FooArgs>()
|
||||
val cmdPing by command<String,String>()
|
||||
val cmdCheckConnected by command<Unit,Boolean>()
|
||||
val cmdSetFoo by command<FooArgs, Unit>()
|
||||
val cmdGetFoo by command<Unit, FooArgs>()
|
||||
val cmdPing by command<String, String>()
|
||||
val cmdCheckConnected by command<Unit, Boolean>()
|
||||
|
||||
// client-side interface (called from the server)
|
||||
val cmdPushClient by command<String,Unit>()
|
||||
val cmdPushClient by command<String, Unit>()
|
||||
```
|
||||
|
||||
## Call it from the client:
|
||||
@@ -93,7 +98,7 @@ val client = websocketClient<Unit>("wss://your.host.com/kp") {
|
||||
// If we want to collect connected state changes (this is optional)
|
||||
launch {
|
||||
client.connectedStateFlow.collect {
|
||||
if( it )
|
||||
if (it)
|
||||
println("I am connected")
|
||||
else
|
||||
println("trying to connect...")
|
||||
@@ -113,13 +118,13 @@ the protocol. With KILOPARSEC it is rather basic operation:\
|
||||
|
||||
~~~kotlin
|
||||
// Our session just keeps Foo for cmd{Get|Set}Foo:
|
||||
data class Session(var fooState: FooArgs?=null)
|
||||
data class Session(var fooState: FooArgs? = null)
|
||||
|
||||
// Let's now provide interface we export, it will be used on each connection automatically:
|
||||
|
||||
// Note server interface uses Session:
|
||||
val serverInterface = KiloInterface<Session>().apply {
|
||||
onConnected {
|
||||
onConnected {
|
||||
// Do some initialization
|
||||
session.fooState = null
|
||||
}
|
||||
@@ -136,6 +141,7 @@ val ns: NettyApplicationEngine = embeddedServer(Netty, port = 8080, host = "0.0.
|
||||
|
||||
|
||||
~~~
|
||||
|
||||
# Details
|
||||
|
||||
It is not compatible with parsec family and no more based on an Universa crypto library. To better fit
|
||||
@@ -144,12 +150,14 @@ and every connection (while parsec caches session keys to avoid time-consuming k
|
||||
keys cryptography for session is shifted to use ed25519 curves which are supposed to provide agreeable strength with
|
||||
enough speed to protect every connection with a unique new keys. Also, we completely get rid of SHA2.
|
||||
|
||||
Kiloparsec also uses a denser binary format [bipack](https://gitea.sergeych.net/SergeychWorks/mp_bintools), no more key-values,
|
||||
which reveals much less on the inner data structure, providing advanced
|
||||
typed RPC interfaces with kotlinx.serialization. There is also Rust implementation [bipack_ru](https://gitea.sergeych.net/DiWAN/bipack_ru).
|
||||
Kiloparsec also uses a denser binary format [bipack](https://gitea.sergeych.net/SergeychWorks/mp_bintools), no more
|
||||
key-values,
|
||||
which reveals much less on the inner data structure, providing advanced
|
||||
typed RPC interfaces with kotlinx.serialization. There is also Rust
|
||||
implementation [bipack_ru](https://gitea.sergeych.net/DiWAN/bipack_ru).
|
||||
The architecture allows connecting same functional interfaces to several various type channels at once.
|
||||
|
||||
Also, the difference from parsecs is that there are no more unencrypted layer commands available to users.
|
||||
Also, the difference from parsecs is that there are no more unencrypted layer commands available to users.
|
||||
All RPC is performed over the encrypted connection.
|
||||
|
||||
# Technical description
|
||||
@@ -163,7 +171,9 @@ Integrated tools to prevent MITM attacks include also non-transferred independen
|
||||
independently on the ends and is never transferred with the network. Comparing it somehow (visually, with QR code, etc)
|
||||
could add a very robust guarantee of the connection safety and ingenuity.
|
||||
|
||||
Kiloparsec has built-in completely asynchronous (coroutine based top-down) transport layer based on TCP (JVM only as for now) and the same async Websocket-based transport based on KTOR. Websocket client is multiplatform, though the server is JVM only insofar.
|
||||
Kiloparsec has built-in completely asynchronous (coroutine based top-down) transport layer based on TCP (JVM only as for
|
||||
now) and the same async Websocket-based transport based on KTOR. Websocket client is multiplatform, though the server is
|
||||
JVM only insofar.
|
||||
|
||||
# Licensing
|
||||
|
||||
|
||||
Reference in new issue
Block a user