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"; syndicate = builtins.getFlake "syndicate";
pkgs = pkgs =
import <nixpkgs> { overlays = builtins.attrValues syndicate.overlays; }; 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 == "": if result.path == "":
result.path = getEnv("XDG_RUNTIME_DIR", "/run/user/1000") / "dataspace" result.path = getEnv("XDG_RUNTIME_DIR", "/run/user/1000") / "dataspace"
proc envStep: Preserve[Ref] = proc envStep: Assertion =
var s = getEnv("SYNDICATE_STEP") var s = getEnv("SYNDICATE_STEP")
if s != "": parsePreserves(s, Ref) if s != "": parsePreserves(s, Cap)
else: capabilities.mint().toPreserve(Ref) else: capabilities.mint().toPreserve(Cap)
proc main = proc main =
let label = getAppFilename().extractFilename let
discard bootDataspace(label) do (root: Ref; turn: var Turn): step = envStep()
let step = envStep() label = getAppFilename().extractFilename
connect(turn, unixSocketPath(), step) do (turn: var Turn; ds: Ref): data = map(commandLineParams(), parsePreserves)
message(turn, ds, initRecord(label, 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() for _ in 1..4: poll()
quit() quit()

View File

@ -3,15 +3,12 @@
## A ping utility for Syndicate. ## 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 preserves
import syndicate, syndicate/patterns import syndicate, syndicate/patterns
import ./schema/net_mapper import ./schema/net_mapper
type ListenOn* {.preservesRecord: "listen-on".} = ref object
dataspace: Preserve[Ref]
#[ #[
var var
SOL_IP {.importc, nodecl, header: "<sys/socket.h>".}: int SOL_IP {.importc, nodecl, header: "<sys/socket.h>".}: int
@ -71,7 +68,7 @@ proc match(a, b: IcmpEchoFields): bool =
type type
Pinger = ref object Pinger = ref object
facet: Facet facet: Facet
ds: Ref ds: Cap
rtt: RoundTripTime rtt: RoundTripTime
rttHandle: Handle rttHandle: Handle
sum: Duration sum: Duration
@ -82,7 +79,7 @@ type
sadLen: SockLen sadLen: SockLen
interval: Duration interval: Duration
proc newPinger(address: IpAddress; facet: Facet; ds: Ref): Pinger = proc newPinger(address: IpAddress; facet: Facet; ds: Cap): Pinger =
result = Pinger( result = Pinger(
facet: facet, facet: facet,
ds: ds, ds: ds,
@ -138,10 +135,11 @@ proc exchangeEcho(ping: Pinger) {.async.} =
else: else:
stderr.writeLine "reply data has a bad length ", data.len stderr.writeLine "reply data has a bad length ", data.len
proc kick(ping: Pinger) = proc kick(ping: Pinger) {.gcsafe.} =
if not ping.socket.isClosed: if not ping.socket.isClosed:
addTimer(ping.interval.inMilliseconds.int, oneshot = true) do (fd: AsyncFD) -> bool: 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): if fut.failed and ping.rttHandle != Handle(0):
ping.facet.run do (turn: var Turn): ping.facet.run do (turn: var Turn):
retract(turn, ping.rttHandle) retract(turn, ping.rttHandle)
@ -153,13 +151,13 @@ proc kick(ping: Pinger) =
ping.interval = ping.interval * 2 ping.interval = ping.interval * 2
kick(ping) kick(ping)
type RefArgs {.preservesDictionary.} = object type Args {.preservesDictionary.} = object
dataspace: Ref dataspace: Cap
runActor("main") do (root: Ref; turn: var Turn): runActor("net_mapper") do (root: Cap; turn: var Turn):
connectStdio(root, turn) connectStdio(root, turn)
let rttObserver = ?Observe(pattern: !RoundTripTime) ?? {0: grabLit()} 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): during(turn, ds, rttObserver) do (address: IpAddress):
var ping: Pinger var ping: Pinger
if address.family == IpAddressFamily.IPv4: 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() quit()
proc main = proc main =
let pat = inputPattern() let
unix = unixSocketPath()
step = envStep()
pat = inputPattern()
if stdout.is_a_TTY: if stdout.is_a_TTY:
illwillInit() illwillInit()
hideCursor() hideCursor()
discard bootDataspace("syndex_card") do (ds: Cap; turn: var Turn): 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()) var termBuf = newTerminalBuffer(terminalWidth(), terminalHeight())
termBuf.write(1, 1, $pat, styleBright) termBuf.write(1, 1, $pat, styleBright)
termBuf.drawHorizLine(1, termBuf.width(), 2) termBuf.drawHorizLine(1, termBuf.width(), 2)
@ -132,7 +135,7 @@ proc main =
else: else:
let entity = DumpEntity() let entity = DumpEntity()
runActor("syndex_card") do (root: Cap; turn: var Turn): 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) discard observe(turn, ds, pat, entity)
main() main()

View File

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