Add KMP networking backends

This commit is contained in:
sergeych committed 2026-04-02 19:23:46 +03:00
1 parent d409a4bb8b
commit 5346d15a9f
25 files changed
+1744 -75

No files matched your search

+13 -3
View File
@@ -153,10 +153,15 @@ val allowLocalOnly = object : HttpAccessPolicy {
override suspend fun check(op: HttpAccessOp, ctx: AccessContext): AccessDecision =
when (op) {
is HttpAccessOp.Request ->
if (op.url.startsWith("http://127.0.0.1:") || op.url.startsWith("http://localhost:"))
if (
op.url.startsWith("http://127.0.0.1:") ||
op.url.startsWith("https://127.0.0.1:") ||
op.url.startsWith("http://localhost:") ||
op.url.startsWith("https://localhost:")
)
AccessDecision(Decision.Allow)
else
AccessDecision(Decision.Deny, "only local HTTP requests are allowed")
AccessDecision(Decision.Deny, "only local HTTP/HTTPS requests are allowed")
}
}
```
@@ -166,4 +171,9 @@ val allowLocalOnly = object : HttpAccessPolicy {
#### Platform support
- **JVM:** supported
- **Other targets:** implementation may be added later; use `Http.isSupported()` before relying on it
- **Android:** supported via the Ktor CIO client backend
- **JS:** supported via the Ktor JS client backend
- **Linux native:** supported via the Ktor Curl client backend
- **Windows native:** supported via the Ktor WinHttp client backend
- **Apple native:** supported via the Ktor Darwin client backend
- **Other targets:** may report unsupported; use `Http.isSupported()` before relying on it
+4 -1
View File
@@ -1,6 +1,6 @@
### lyng.io.net — TCP and UDP sockets for Lyng scripts
This module provides minimal raw transport networking for Lyng scripts. It is implemented in `lyngio` and currently backed by Ktor sockets on the JVM.
This module provides minimal raw transport networking for Lyng scripts. It is implemented in `lyngio` and backed by Ktor sockets on the JVM and by Node networking APIs on JS/Node runtimes.
> **Note:** `lyngio` is a separate library module. It must be explicitly added as a dependency to your host application and initialized in your Lyng scopes.
@@ -161,4 +161,7 @@ The module uses `NetAccessPolicy` to authorize network operations before they ar
#### Platform support
- **JVM:** supported
- **Android:** supported via the Ktor CIO and Ktor sockets backends
- **JS/Node:** supported for `resolve`, TCP client/server, and UDP
- **JS/browser:** unsupported; capability checks report unavailable
- **Other targets:** currently report unsupported; use capability checks before relying on raw sockets
+34 -1
View File
@@ -107,9 +107,42 @@ The module uses `WsAccessPolicy` to authorize websocket operations.
- `WsAccessOp.Send(url, bytes, isText)`
- `WsAccessOp.Receive(url)`
Example restricted policy in Kotlin:
```kotlin
import net.sergeych.lyngio.fs.security.AccessContext
import net.sergeych.lyngio.fs.security.AccessDecision
import net.sergeych.lyngio.fs.security.Decision
import net.sergeych.lyngio.ws.security.WsAccessOp
import net.sergeych.lyngio.ws.security.WsAccessPolicy
val allowLocalOnly = object : WsAccessPolicy {
override suspend fun check(op: WsAccessOp, ctx: AccessContext): AccessDecision =
when (op) {
is WsAccessOp.Connect ->
if (
op.url.startsWith("ws://127.0.0.1:") ||
op.url.startsWith("wss://127.0.0.1:") ||
op.url.startsWith("ws://localhost:") ||
op.url.startsWith("wss://localhost:")
)
AccessDecision(Decision.Allow)
else
AccessDecision(Decision.Deny, "only local ws/wss connections are allowed")
else -> AccessDecision(Decision.Allow)
}
}
```
---
#### Platform support
- **JVM:** supported
- **Other targets:** currently report unsupported; use `Ws.isSupported()` before relying on websocket client access
- **Android:** supported via the Ktor CIO websocket client backend
- **JS:** supported via the Ktor JS websocket client backend
- **Linux native:** supported via the Ktor Curl websocket client backend
- **Windows native:** supported via the Ktor WinHttp websocket client backend
- **Apple native:** supported via the Ktor Darwin websocket client backend
- **Other targets:** may report unsupported; use `Ws.isSupported()` before relying on websocket client access