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