Attenuate and sync
This commit is contained in:
parent
b8c1bec9cf
commit
a014362292
|
@ -144,7 +144,7 @@ proc `$`*(actor: Actor): string =
|
|||
proc `$`*(t: Turn): string =
|
||||
"<Turn:" & $t.desc.id & ">"
|
||||
|
||||
proc attenuate(r: Cap; a: Attenuation): Cap =
|
||||
proc attenuate*(r: Cap; a: Attenuation): Cap =
|
||||
if a.len == 0: result = r
|
||||
else: result = Cap(
|
||||
target: r.target,
|
||||
|
@ -530,10 +530,12 @@ proc spawnLink*(name: string; turn: var Turn; bootProc: TurnAction; initialAsser
|
|||
halfLink(turn.facet, result.root)
|
||||
halfLink(result.root, turn.facet)
|
||||
|
||||
var inertActor {.threadvar.}: Actor
|
||||
|
||||
proc newInertCap*(): Cap =
|
||||
new result
|
||||
let a = bootActor("inert") do (turn: Turn): turn.stop()
|
||||
Cap(relay: a.root)
|
||||
if inertActor.isNil:
|
||||
inertActor = bootActor("inert") do (turn: var Turn): turn.stop()
|
||||
Cap(relay: inertActor.root)
|
||||
|
||||
proc atExit*(actor; action) = actor.exitHooks.add action
|
||||
|
||||
|
|
|
@ -158,8 +158,8 @@ using
|
|||
|
||||
proc lookupLocal(relay; oid: Oid): Cap =
|
||||
let sym = relay.exported.grab oid
|
||||
if sym.isNil: newInertCap()
|
||||
else: sym.cap
|
||||
if not sym.isNil:
|
||||
result = sym.cap
|
||||
|
||||
proc isInert(r: Cap): bool =
|
||||
r.target.isNil
|
||||
|
@ -177,9 +177,11 @@ proc rewriteCapIn(relay; facet; n: WireRef, imported: var seq[WireSymbol]): Cap
|
|||
imported.add e
|
||||
result = e.cap
|
||||
of WireRefKind.yours:
|
||||
let r = relay.lookupLocal(n.yours.oid)
|
||||
if n.yours.attenuation.len == 0 or r.isInert: result = r
|
||||
else: raiseAssert "attenuation not implemented"
|
||||
result = relay.lookupLocal(n.yours.oid)
|
||||
if result.isNil:
|
||||
result = newInertCap()
|
||||
elif n.yours.attenuation.len > 0:
|
||||
result = attenuate(result, n.yours.attenuation)
|
||||
|
||||
proc rewriteIn(relay; facet; v: Value):
|
||||
tuple[rewritten: Assertion; imported: seq[WireSymbol]] =
|
||||
|
@ -212,14 +214,13 @@ proc dispatch(relay: Relay; turn: var Turn; cap: Cap; event: Event) =
|
|||
turn.message(cap, a)
|
||||
|
||||
of EventKind.Sync:
|
||||
discard # TODO
|
||||
#[
|
||||
var imported: seq[WireSymbol]
|
||||
let k = relay.rewriteCapIn(turn, evenr.sync.peer, imported)
|
||||
turn.sync(cap) do (turn: var Turn):
|
||||
turn.message(k, true)
|
||||
for e in imported: relay.imported.del e
|
||||
]#
|
||||
var
|
||||
(v, imported) = rewriteIn(relay, turn.facet, event.sync.peer)
|
||||
peer = unembed(v, Cap)
|
||||
if peer.isSome:
|
||||
turn.message(get peer, true)
|
||||
for e in imported: relay.imported.drop e
|
||||
|
||||
proc dispatch(relay: Relay; v: Value) =
|
||||
trace "S: ", v
|
||||
|
@ -231,10 +232,8 @@ proc dispatch(relay: Relay; v: Value) =
|
|||
# https://synit.org/book/protocol.html#turn-packets
|
||||
for te in pkt.turn:
|
||||
let r = lookupLocal(relay, te.oid.Oid)
|
||||
if not r.isInert:
|
||||
if not r.isNil:
|
||||
dispatch(relay, t, r, te.event)
|
||||
else:
|
||||
stderr.writeLine("discarding event for unknown Cap; ", te.event)
|
||||
of PacketKind.Error:
|
||||
# https://synit.org/book/protocol.html#error-packets
|
||||
when defined(posix):
|
||||
|
|
Loading…
Reference in New Issue