Update for Nim-2.0.0

This commit is contained in:
Emery Hemingway 2023-08-16 10:57:14 +01:00
parent 58280baabe
commit ef38792970
6 changed files with 30 additions and 25 deletions

View File

@ -2,4 +2,4 @@ let
syndicate = builtins.getFlake "syndicate";
pkgs =
import <nixpkgs> { overlays = builtins.attrValues syndicate.overlays; };
in pkgs.nimPackages.syndicate_utils
in pkgs.nim2Packages.syndicate_utils

View File

@ -9,17 +9,20 @@ proc unixSocketPath: Unix =
if result.path == "":
result.path = getEnv("XDG_RUNTIME_DIR", "/run/user/1000") / "dataspace"
proc envStep: Preserve[Ref] =
proc envStep: Assertion =
var s = getEnv("SYNDICATE_STEP")
if s != "": parsePreserves(s, Ref)
else: capabilities.mint().toPreserve(Ref)
if s != "": parsePreserves(s, Cap)
else: capabilities.mint().toPreserve(Cap)
proc main =
let label = getAppFilename().extractFilename
discard bootDataspace(label) do (root: Ref; turn: var Turn):
let step = envStep()
connect(turn, unixSocketPath(), step) do (turn: var Turn; ds: Ref):
message(turn, ds, initRecord(label, map(commandLineParams(), parsePreserves)))
let
step = envStep()
label = getAppFilename().extractFilename
data = map(commandLineParams(), parsePreserves)
discard bootDataspace(label) do (root: Cap; turn: var Turn):
connect(turn, unixSocketPath(), step) do (turn: var Turn; ds: Cap):
message(turn, ds, initRecord(label, data))
for _ in 1..4: poll()
quit()

View File

@ -3,15 +3,12 @@
## A ping utility for Syndicate.
import std/[asyncdispatch, asyncnet, math, monotimes, nativesockets, net, os, strutils, tables, times]
import std/[asyncdispatch, asyncnet, monotimes, nativesockets, net, os, strutils, tables, times]
import preserves
import syndicate, syndicate/patterns
import ./schema/net_mapper
type ListenOn* {.preservesRecord: "listen-on".} = ref object
dataspace: Preserve[Ref]
#[
var
SOL_IP {.importc, nodecl, header: "<sys/socket.h>".}: int
@ -71,7 +68,7 @@ proc match(a, b: IcmpEchoFields): bool =
type
Pinger = ref object
facet: Facet
ds: Ref
ds: Cap
rtt: RoundTripTime
rttHandle: Handle
sum: Duration
@ -82,7 +79,7 @@ type
sadLen: SockLen
interval: Duration
proc newPinger(address: IpAddress; facet: Facet; ds: Ref): Pinger =
proc newPinger(address: IpAddress; facet: Facet; ds: Cap): Pinger =
result = Pinger(
facet: facet,
ds: ds,
@ -138,10 +135,11 @@ proc exchangeEcho(ping: Pinger) {.async.} =
else:
stderr.writeLine "reply data has a bad length ", data.len
proc kick(ping: Pinger) =
proc kick(ping: Pinger) {.gcsafe.} =
if not ping.socket.isClosed:
addTimer(ping.interval.inMilliseconds.int, oneshot = true) do (fd: AsyncFD) -> bool:
exchangeEcho(ping).addCallback do (fut: Future[void]):
let fut = exchangeEcho(ping)
fut.addCallback do ():
if fut.failed and ping.rttHandle != Handle(0):
ping.facet.run do (turn: var Turn):
retract(turn, ping.rttHandle)
@ -153,13 +151,13 @@ proc kick(ping: Pinger) =
ping.interval = ping.interval * 2
kick(ping)
type RefArgs {.preservesDictionary.} = object
dataspace: Ref
type Args {.preservesDictionary.} = object
dataspace: Cap
runActor("main") do (root: Ref; turn: var Turn):
runActor("net_mapper") do (root: Cap; turn: var Turn):
connectStdio(root, turn)
let rttObserver = ?Observe(pattern: !RoundTripTime) ?? {0: grabLit()}
during(turn, root, ?RefArgs) do (ds: Ref):
during(turn, root, ?Args) do (ds: Cap):
during(turn, ds, rttObserver) do (address: IpAddress):
var ping: Pinger
if address.family == IpAddressFamily.IPv4:

1
src/nim.cfg Normal file
View File

@ -0,0 +1 @@
threads:off

View File

@ -107,14 +107,17 @@ setControlCHook:
quit()
proc main =
let pat = inputPattern()
let
unix = unixSocketPath()
step = envStep()
pat = inputPattern()
if stdout.is_a_TTY:
illwillInit()
hideCursor()
discard bootDataspace("syndex_card") do (ds: Cap; turn: var Turn):
connect(turn, unixSocketPath(), envStep()) do (turn: var Turn; ds: Cap):
connect(turn, unix, step) do (turn: var Turn; ds: Cap):
var termBuf = newTerminalBuffer(terminalWidth(), terminalHeight())
termBuf.write(1, 1, $pat, styleBright)
termBuf.drawHorizLine(1, termBuf.width(), 2)
@ -132,7 +135,7 @@ proc main =
else:
let entity = DumpEntity()
runActor("syndex_card") do (root: Cap; turn: var Turn):
connect(turn, unixSocketPath(), envStep()) do (turn: var Turn; ds: Cap):
connect(turn, unix, step) do (turn: var Turn; ds: Cap):
discard observe(turn, ds, pat, entity)
main()

View File

@ -1,6 +1,6 @@
# Package
version = "20230801"
version = "20230816"
author = "Emery Hemingway"
description = "Utilites for Syndicated Actors and Synit"
license = "unlicense"