stuff from I don't know when

This commit is contained in:
Ehmry - 2018-12-12 17:56:44 +01:00
parent be35d47ad3
commit c6fcfecd1d
4 changed files with 45 additions and 21 deletions

View File

@ -6,7 +6,7 @@ description = "A simple content addressed file-system"
license = "GPLv3"
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"]
skipFiles = @["dagfs_repl.nim"]

View File

@ -207,21 +207,9 @@ componentConstructHook = proc(env: GenodeEnv) =
policies.setLen 0
configXml.findAll("policy", policies)
proc processSessions(rom: RomClient) =
update rom
proc createSessions(rom: RomClient): bool =
## Return true on progress
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":
let policy = policies.lookupPolicy label
if policy.isNil:
@ -232,10 +220,17 @@ componentConstructHook = proc(env: GenodeEnv) =
let role = policy.attr("role")
case role
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)
frontends[id] = fend
session = fend
of "backend":
if backends.contains id:
continue
var prio = 1
try: prio = policy.attr("prio").parseInt
except: discard
@ -253,6 +248,28 @@ componentConstructHook = proc(env: GenodeEnv) =
importcpp: "#->parent().deliver_session_cap(Genode::Parent::Server::Id{#}, #)".}
env.deliverSession(id, cap)
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
sessionsRom = env.newRomHandler("session_requests", processSessions)

View File

@ -1,5 +1,5 @@
import std/hashes, std/streams, std/strutils
import base58/bitcoin, cbor
import base58/bitcoin, cbor, siphash
import ./dagfs/priv/hex, ./dagfs/priv/blake2
const
@ -37,8 +37,10 @@ proc `==`*(cbor: CborNode; cid: Cid): bool =
return false
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.
var zeroKey: Key
result = cast[Hash](sipHash(cid.digest, zeroKey))
proc toCbor*(cid: Cid): CborNode = newCborBytes cid.digest
## Generate a CBOR representation of a CID.

View File

@ -19,6 +19,7 @@ type
case kind: AtomKind
of atomPath:
path: string
name: string
of atomCid:
cid: Cid
of atomString:
@ -71,7 +72,7 @@ proc newAtomError(msg: string): Atom =
proc newAtomPath(s: string): Atom =
try:
let path = expandFilename s
Atom(kind: atomPath, path: path)
Atom(kind: atomPath, path: path, name: extractFilename(s))
except OSError:
newAtomError("invalid path '$1'" % s)
@ -134,6 +135,10 @@ proc append(list: NodeRef; n: NodeObj) =
p[] = n
list.append p
template returnError(n: NodeObj) =
if n.atom.kind == atomError:
return n.atom.newNode
proc getFile(env: Env; path: string): FsNode =
result = env.paths.getOrDefault path
if result.isNil:
@ -368,17 +373,17 @@ proc globFunc(env: Env; args: NodeObj): NodeRef =
proc ingestFunc(env: Env; args: NodeObj): NodeRef =
var root = newFsRoot()
for n in args.walk:
returnError n
let
a = n.atom
name = a.path.extractFilename
info = a.path.getFileInfo
case info.kind
of pcFile, pcLinkToFile:
let file = env.getFile a.path
root.add(name, file)
root.add(a.name, file)
of pcDir, pcLinkToDir:
let dir = env.getDir a.path
root.add(name, dir)
root.add(a.name, dir)
let
cid = env.store.putDag(root.toCbor)
cid.newAtom.newNode