cabal-club / cabal-cli

Terminal client for Cabal, the p2p chat platform.

Home Page:https://cabal.chat

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add `--temp` option for debugging/etc

joehand opened this issue · comments

Feature request: add a --temp option to the command line to use an in-memory database. This is helpful for debugging to find out if its a local corruption issue or a network thingy.

I'm experimenting with adding a --temp flag to cabal as per this issue.

Since hypercore conforms to the random-access-storage spec, I figured I could easily swap in random-access-memory and get away with an easy win for cabal. Turns out that's not the case and what happens is I get the following error from multifeed when I pass in a random-access-memory object

/home/cblgh/code/cabal/node_modules/multifeed/index.js:33
      else return s(dir + '/' + name)
                  ^

TypeError: s is not a function
    at Storage.create (/home/cblgh/code/cabal/node_modules/multifeed/index.js:33:19)
    at Storage.openKey (/home/cblgh/code/cabal/node_modules/hypercore/lib/storage.js:209:34)
    at Storage.openKey (/home/cblgh/code/cabal/node_modules/hypercore/lib/storage.js:208:47)
    at Feed._open (/home/cblgh/code/cabal/node_modules/hypercore/index.js:225:17)
    at open (/home/cblgh/code/cabal/node_modules/hypercore/index.js:112:10)
    at run (/home/cblgh/code/cabal/node_modules/thunky/index.js:19:5)
    at Feed.thunk [as _ready] (/home/cblgh/code/cabal/node_modules/thunky/index.js:13:5)
    at new Feed (/home/cblgh/code/cabal/node_modules/hypercore/index.js:91:8)
    at Feed (/home/cblgh/code/cabal/node_modules/hypercore/index.js:30:39)
    at /home/cblgh/code/cabal/node_modules/multifeed/index.js

The cabal code:

    var storage = args.temp ? ram() : archivesdir + key
    return Cabal(storage, key, {maxFeeds: maxFeeds})

where Cabal is a cabal-core.


It's looking like you can't treat random-access-memory and random-access-file as interchangably as I'd thought, as the constructor for raf takes a file string, while ram takes a buffer.

I'm not really sure how to solve that particular problem, am I misusing ram?

Thoughts @noffle, @ralphtheninja?

@cblgh It looks like you should pass ram as is, e.g.

var storage = args.temp ? ram : archivesdir + key
return Cabal(storage, key, {maxFeeds: maxFeeds})

Since multifeed wants a function here:

this._storage = function (dir) {
    return function (name) {
      var s = storage
      if (typeof storage === 'string') return raf(path.join(storage, dir, name))
      else return s(dir + '/' + name)
    }
}

@ralphtheninja welllllll i guess that's what i get for coding at 2am huh? thanks! it works as intended when i pass ramas is :)

@joehand thanks for the suggestion - it looks like it works rather well :)