stuff from I don't know when
This commit is contained in:
parent
be35d47ad3
commit
c6fcfecd1d
|
@ -6,7 +6,7 @@ description = "A simple content addressed file-system"
|
||||||
license = "GPLv3"
|
license = "GPLv3"
|
||||||
srcDir = "src"
|
srcDir = "src"
|
||||||
|
|
||||||
requires "nim >= 0.18.0", "base58", "cbor >= 0.5.1"
|
requires "nim >= 0.18.0", "base58", "cbor >= 0.5.1", "siphash"
|
||||||
|
|
||||||
bin = @["dagfs_repl"]
|
bin = @["dagfs_repl"]
|
||||||
skipFiles = @["dagfs_repl.nim"]
|
skipFiles = @["dagfs_repl.nim"]
|
||||||
|
|
|
@ -207,21 +207,9 @@ componentConstructHook = proc(env: GenodeEnv) =
|
||||||
policies.setLen 0
|
policies.setLen 0
|
||||||
configXml.findAll("policy", policies)
|
configXml.findAll("policy", policies)
|
||||||
|
|
||||||
proc processSessions(rom: RomClient) =
|
proc createSessions(rom: RomClient): bool =
|
||||||
update rom
|
## Return true on progress
|
||||||
var requests = initSessionRequestsParser(rom)
|
var requests = initSessionRequestsParser(rom)
|
||||||
|
|
||||||
for id in requests.close:
|
|
||||||
var s: Session
|
|
||||||
if frontends.contains id:
|
|
||||||
s = frontends[id]
|
|
||||||
frontends.del id
|
|
||||||
elif backends.contains id:
|
|
||||||
s = backends[id]
|
|
||||||
backends.del id
|
|
||||||
env.ep.dissolve s
|
|
||||||
env.parent.sessionResponseClose(id)
|
|
||||||
|
|
||||||
for id, label, args in requests.create "Dagfs":
|
for id, label, args in requests.create "Dagfs":
|
||||||
let policy = policies.lookupPolicy label
|
let policy = policies.lookupPolicy label
|
||||||
if policy.isNil:
|
if policy.isNil:
|
||||||
|
@ -232,10 +220,17 @@ componentConstructHook = proc(env: GenodeEnv) =
|
||||||
let role = policy.attr("role")
|
let role = policy.attr("role")
|
||||||
case role
|
case role
|
||||||
of "frontend":
|
of "frontend":
|
||||||
|
if frontends.contains id:
|
||||||
|
continue
|
||||||
|
if backends.len < 1:
|
||||||
|
echo "defering ", label, " until backends are available"
|
||||||
|
continue
|
||||||
let fend = newFrontend(env, backends, args, label)
|
let fend = newFrontend(env, backends, args, label)
|
||||||
frontends[id] = fend
|
frontends[id] = fend
|
||||||
session = fend
|
session = fend
|
||||||
of "backend":
|
of "backend":
|
||||||
|
if backends.contains id:
|
||||||
|
continue
|
||||||
var prio = 1
|
var prio = 1
|
||||||
try: prio = policy.attr("prio").parseInt
|
try: prio = policy.attr("prio").parseInt
|
||||||
except: discard
|
except: discard
|
||||||
|
@ -253,6 +248,28 @@ componentConstructHook = proc(env: GenodeEnv) =
|
||||||
importcpp: "#->parent().deliver_session_cap(Genode::Parent::Server::Id{#}, #)".}
|
importcpp: "#->parent().deliver_session_cap(Genode::Parent::Server::Id{#}, #)".}
|
||||||
env.deliverSession(id, cap)
|
env.deliverSession(id, cap)
|
||||||
echo "session opened for ", label
|
echo "session opened for ", label
|
||||||
|
result = true
|
||||||
|
|
||||||
|
proc processSessions(rom: RomClient) =
|
||||||
|
update rom
|
||||||
|
var requests = initSessionRequestsParser(rom)
|
||||||
|
|
||||||
|
for id in requests.close:
|
||||||
|
var s: Session
|
||||||
|
if frontends.contains id:
|
||||||
|
s = frontends[id]
|
||||||
|
frontends.del id
|
||||||
|
elif backends.contains id:
|
||||||
|
s = backends[id]
|
||||||
|
backends.del id
|
||||||
|
env.ep.dissolve s
|
||||||
|
env.parent.sessionResponseClose(id)
|
||||||
|
|
||||||
|
while rom.createSessions():
|
||||||
|
update rom
|
||||||
|
# Process the session requests repeatedly to ensure
|
||||||
|
# that frontend sessions waiting for backends are
|
||||||
|
# processed regardless to the order of requests.
|
||||||
|
|
||||||
let
|
let
|
||||||
sessionsRom = env.newRomHandler("session_requests", processSessions)
|
sessionsRom = env.newRomHandler("session_requests", processSessions)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import std/hashes, std/streams, std/strutils
|
import std/hashes, std/streams, std/strutils
|
||||||
import base58/bitcoin, cbor
|
import base58/bitcoin, cbor, siphash
|
||||||
import ./dagfs/priv/hex, ./dagfs/priv/blake2
|
import ./dagfs/priv/hex, ./dagfs/priv/blake2
|
||||||
|
|
||||||
const
|
const
|
||||||
|
@ -37,8 +37,10 @@ proc `==`*(cbor: CborNode; cid: Cid): bool =
|
||||||
return false
|
return false
|
||||||
result = true
|
result = true
|
||||||
|
|
||||||
proc hash*(cid: Cid): Hash = hash cid.digest
|
proc hash*(cid: Cid): Hash =
|
||||||
## Reduce a CID into an integer for use in tables.
|
## Reduce a CID into an integer for use in tables.
|
||||||
|
var zeroKey: Key
|
||||||
|
result = cast[Hash](sipHash(cid.digest, zeroKey))
|
||||||
|
|
||||||
proc toCbor*(cid: Cid): CborNode = newCborBytes cid.digest
|
proc toCbor*(cid: Cid): CborNode = newCborBytes cid.digest
|
||||||
## Generate a CBOR representation of a CID.
|
## Generate a CBOR representation of a CID.
|
||||||
|
|
|
@ -19,6 +19,7 @@ type
|
||||||
case kind: AtomKind
|
case kind: AtomKind
|
||||||
of atomPath:
|
of atomPath:
|
||||||
path: string
|
path: string
|
||||||
|
name: string
|
||||||
of atomCid:
|
of atomCid:
|
||||||
cid: Cid
|
cid: Cid
|
||||||
of atomString:
|
of atomString:
|
||||||
|
@ -71,7 +72,7 @@ proc newAtomError(msg: string): Atom =
|
||||||
proc newAtomPath(s: string): Atom =
|
proc newAtomPath(s: string): Atom =
|
||||||
try:
|
try:
|
||||||
let path = expandFilename s
|
let path = expandFilename s
|
||||||
Atom(kind: atomPath, path: path)
|
Atom(kind: atomPath, path: path, name: extractFilename(s))
|
||||||
except OSError:
|
except OSError:
|
||||||
newAtomError("invalid path '$1'" % s)
|
newAtomError("invalid path '$1'" % s)
|
||||||
|
|
||||||
|
@ -134,6 +135,10 @@ proc append(list: NodeRef; n: NodeObj) =
|
||||||
p[] = n
|
p[] = n
|
||||||
list.append p
|
list.append p
|
||||||
|
|
||||||
|
template returnError(n: NodeObj) =
|
||||||
|
if n.atom.kind == atomError:
|
||||||
|
return n.atom.newNode
|
||||||
|
|
||||||
proc getFile(env: Env; path: string): FsNode =
|
proc getFile(env: Env; path: string): FsNode =
|
||||||
result = env.paths.getOrDefault path
|
result = env.paths.getOrDefault path
|
||||||
if result.isNil:
|
if result.isNil:
|
||||||
|
@ -368,17 +373,17 @@ proc globFunc(env: Env; args: NodeObj): NodeRef =
|
||||||
proc ingestFunc(env: Env; args: NodeObj): NodeRef =
|
proc ingestFunc(env: Env; args: NodeObj): NodeRef =
|
||||||
var root = newFsRoot()
|
var root = newFsRoot()
|
||||||
for n in args.walk:
|
for n in args.walk:
|
||||||
|
returnError n
|
||||||
let
|
let
|
||||||
a = n.atom
|
a = n.atom
|
||||||
name = a.path.extractFilename
|
|
||||||
info = a.path.getFileInfo
|
info = a.path.getFileInfo
|
||||||
case info.kind
|
case info.kind
|
||||||
of pcFile, pcLinkToFile:
|
of pcFile, pcLinkToFile:
|
||||||
let file = env.getFile a.path
|
let file = env.getFile a.path
|
||||||
root.add(name, file)
|
root.add(a.name, file)
|
||||||
of pcDir, pcLinkToDir:
|
of pcDir, pcLinkToDir:
|
||||||
let dir = env.getDir a.path
|
let dir = env.getDir a.path
|
||||||
root.add(name, dir)
|
root.add(a.name, dir)
|
||||||
let
|
let
|
||||||
cid = env.store.putDag(root.toCbor)
|
cid = env.store.putDag(root.toCbor)
|
||||||
cid.newAtom.newNode
|
cid.newAtom.newNode
|
||||||
|
|
Loading…
Reference in New Issue
Block a user