Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] Multiple Cabals Continuation #89

Merged
merged 45 commits into from
Nov 16, 2018
Merged
Show file tree
Hide file tree
Changes from 34 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
7d84c98
Initial implementation of multiple cabals :D
nikolaiwarner Oct 28, 2018
42cfbfe
Fix ctrl-p in cabals list
nikolaiwarner Oct 28, 2018
c5880cb
Update .cabal.yml-example
cblgh Oct 28, 2018
d1cca36
Use os for detecting homedir
nikolaiwarner Oct 28, 2018
eed7e4d
Add a few style improvements
nikolaiwarner Oct 28, 2018
a535128
Look for config file as config.yml in ~/.cabal dir by default
nikolaiwarner Oct 28, 2018
cf3f2fa
reintroduce day changed message
cblgh Nov 1, 2018
44e2fcf
reintroduce nick highlighting
cblgh Nov 1, 2018
be77795
Merge branch 'misc-features' into multicabal
cblgh Nov 1, 2018
3a7c66c
fix typo with self.state.cabal.client.messages
cblgh Nov 1, 2018
e13c9e1
fix more goofs in my feature merge
cblgh Nov 1, 2018
0048df5
fix day changed message
cblgh Nov 1, 2018
60d267e
refactor: self.state.cabal.client -> self.client
cblgh Nov 1, 2018
506db67
fix bug on first start with user=unknown
cblgh Nov 1, 2018
18066be
reintroduce --nick to set nickname at start
cblgh Nov 1, 2018
9413cfd
add protocol verison
cblgh Nov 1, 2018
02785a6
add --new to create a new cabal, remove --db
cblgh Nov 6, 2018
51672b9
add key to publishSingleMessage
cblgh Nov 6, 2018
cffa01f
Merge branch 'master' into multi-cabal-protocol-version
cblgh Nov 6, 2018
49162b6
bump cabal-core dep
cblgh Nov 6, 2018
dfb3e61
fix merge issue with MOTD
cblgh Nov 6, 2018
7735dee
fix merge
cblgh Nov 6, 2018
629e00b
refactor: use ctrl+j to tab between cabals & chans
cblgh Nov 6, 2018
3a03043
refactor: alt-n changes between panes instead
cblgh Nov 6, 2018
2b67983
fix horizontal display of motd
cblgh Nov 6, 2018
92b04d8
update help with new pane changing key
cblgh Nov 6, 2018
a843f45
improve help copy
cblgh Nov 6, 2018
5989fa8
revert self.client shortcut as it caused a few bugs
cblgh Nov 6, 2018
d1c0325
update readme
cblgh Nov 6, 2018
e3a8868
Add /add cabal feature and save change to config file
nikolaiwarner Nov 7, 2018
bb07285
refactor --new, make use of hypercore-crypto
cblgh Nov 8, 2018
3880a04
add hypercore-crypto as dep
cblgh Nov 8, 2018
6462e30
5.0.1
cblgh Nov 8, 2018
2e83bd0
add /exit, an alias for /quit
cblgh Nov 9, 2018
2e16401
add --alias, use databaseVersion
cblgh Nov 14, 2018
502147b
add --experimental flag
cblgh Nov 14, 2018
dcf5958
revert version bump
cblgh Nov 14, 2018
8738a9e
add --aliases
cblgh Nov 14, 2018
253c00e
standard
cblgh Nov 14, 2018
aadfdc7
standard for real
cblgh Nov 14, 2018
8ce6dab
add --clear and --forget
cblgh Nov 14, 2018
fb008b6
fix bug when no config and running argless
cblgh Nov 14, 2018
d4a55a5
`cabal` now joins the most recently joined cabal
cblgh Nov 14, 2018
7b66cfd
cleanup
cblgh Nov 16, 2018
c6b2a01
remove package lock lol
cblgh Nov 16, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .cabal.yml-example
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
cabals:
- cabal://bd45fde0ad866d4069af490f0ca9b07110808307872d4b659a4ff7a4ef85315a
- 22f7763be0e939160dd04137b66aaac8f2179350eec740e57a656dfdf1f4dc29
- cbl://3d45fde0ad866d4069af490f0ca9b07110808307872d4b659a4ff7a4ef853132
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ config.js
*.pdf
archives

# Cabal config files
.cabal.yml

#################
## Eclipse
#################
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ $ cabal --key cabal://0c6247a6378074257854a66ea5bc90fd6268a0eb5f0d896e55e59e2c3c
## Usage
#### Start a new instance:
```
cabal --db <file path>
cabal --new
cblgh marked this conversation as resolved.
Show resolved Hide resolved
```

#### Connect to an existing instance:
Expand Down Expand Up @@ -90,3 +90,5 @@ cabal --key <key> --seeder
&nbsp;&nbsp;&nbsp;&nbsp;scroll down through backlog
`alt-[1,9]`
&nbsp;&nbsp;&nbsp;&nbsp;select channels 1-9
`alt-n`
&nbsp;&nbsp;&nbsp;&nbsp;tab between the cabals & channels panes
125 changes: 93 additions & 32 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,34 @@
var Cabal = require('cabal-core')
var swarm = require('cabal-core/swarm.js')
var minimist = require('minimist')
var os = require('os')
var fs = require('fs')
var yaml = require('js-yaml')
var mkdirp = require('mkdirp')
var frontend = require('./neat-screen.js')
var crypto = require('hypercore-crypto')

var args = minimist(process.argv.slice(2))

var homedir = process.env.HOME || process.env.HOMEPATH || process.env.USERPROFILE
var rootdir = args.dir || (homedir + '/.cabal/archives/')
var protocolMajorVersion = Cabal.protocolVersion.split('.')[0]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

an implication of this is that if we make any protocol / network change, everyone in the cabalverse will use a new directory and have to generate a new private key (and lose all things associated to that identity. right now that's just "nick", but in the future it could be display pic or other things)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my feeling is to version this separately, or to not even version it at all. this is to try and escape from the vestigial hypercores, right? if our understanding of it is right, we should never have to do this again.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, that only happens if we make a breaking change (major version). and if we make a breaking change, i think we should be free to rid ourselves of the headache of old configs and make the best of the breaking change.

this is definitely to try to pin down our issues. we should never need to do this, but if we do it then we can exclude for certain that old clients are screwing things up.

i am fine with trying out this approach for a while (after this pr is stable and merged) and then reverting to not using a protocol version if it still feels really bad

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're saying the same things:

  • I agree with this change (using a new dir to escape the vestigial hypercore issue)
  • I don't like it being tied to protocol version though, since this is more like a database version bump
  • If we conflate protocol and db versioning, then every time we do a major protocol change we'll be essentially deleting (hiding) users' private keys needlessly by creating a new cabal directory

var homedir = os.homedir()
var rootdir = args.dir || (homedir + `/.cabal/v${protocolMajorVersion}`)
var archivesdir = `${rootdir}/archives/`

var usage = `Usage

cabal --key cabal://key

OR

cabal --db /path/to/db
cabal --new

Options:

--seed Start a headless seed for the specified cabal key

--nick Your nickname
--new Start a new cabal
--message Publish a single message; then quit after \`timeout\`
--channel Channel name to publish to for \`message\` option; default: "default"
--timeout Delay in milliseconds to wait on swarm before quitting for \`message\` option; default: 5000
Expand All @@ -29,57 +38,109 @@ var usage = `Usage
Work in progress! Learn more at github.com/cabal-club
`

var cabalKeys = []

// Attempt to load local or homedir config file
try {
var config
var configFilePath
var configFilename = 'config.yml'
var currentDirConfigFilename = '.cabal.yml'
mkdirp.sync(rootdir)
if (args.config && fs.existsSync(args.config)) {
configFilePath = args.config
} else if (fs.existsSync(currentDirConfigFilename)) {
configFilePath = currentDirConfigFilename
} else if (fs.existsSync(rootdir + '/' + configFilename)) {
configFilePath = rootdir + '/' + configFilename
}
if (configFilePath) {
config = yaml.safeLoad(fs.readFileSync(configFilePath, 'utf8'))
if (config && config.cabals) {
cabalKeys = config.cabals
}
}
} catch (e) {
console.log(e)
}

if (args.key) {
args.key = args.key.replace('cabal://', '').replace('cbl://', '').replace('dat://', '').replace(/\//g, '')
args.db = rootdir + args.key
// If a key is provided, place it at the top of the list
cabalKeys.unshift(args.key)
}

var cabal = Cabal(args.db, args.key)
if (args.new) {
cblgh marked this conversation as resolved.
Show resolved Hide resolved
var key = crypto.keyPair().publicKey.toString('hex')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👌

var db = archivesdir + key
var cabal = Cabal(db, key)
cabal.db.ready(function () {
start(args.key)
if (!args.seed) {
start([cabal])
}
})
} else {
cabal = Cabal(args.db, null)
cabal.db.ready(function () {
cabal.getLocalKey(function (err, key) {
if (err) throw err
start(key)
} else if (cabalKeys.length) {
Promise.all(cabalKeys.map((key) => {
key = key.replace('cabal://', '').replace('cbl://', '').replace('dat://', '').replace(/\//g, '')
var db = archivesdir + key
var cabal = Cabal(db, key)
return new Promise((resolve) => {
cabal.db.ready(() => {
resolve(cabal)
})
})
})).then((cabals) => {
start(cabals)
})
}

if (!args.db) {
} else {
process.stderr.write(usage)
process.exit(1)
}

function start (key) {
function start (cabals) {
if (!args.seed) {
if (args.message) {
if (args.key && args.message) {
publishSingleMessage({
key: args.key,
channel: args.channel,
message: args.message,
messageType: args.type,
timeout: args.timeout
})
return
}
frontend(cabal)
setTimeout(function () { swarm(cabal) }, 300)
frontend({
archivesdir,
cabals,
configFilePath,
homedir,
protocolMajorVersion,
rootdir
})
setTimeout(() => {
cabals.forEach((cabal) => {
swarm(cabal)
})
}, 300)
} else {
console.log('Seeding', key)
swarm(cabal)
cabals.forEach((cabal) => {
console.log('Seeding', cabal.key)
swarm(cabal)
})
}
}

function publishSingleMessage ({channel, message, messageType, timeout}) {
console.log('Publishing message to channel - ' + channel + ': "' + message + '"...')
cabal.publish({
type: messageType || 'chat/text',
content: {
channel: channel || 'default',
text: message
}
function publishSingleMessage ({key, channel, message, messageType, timeout}) {
console.log(`Publishing message to channel - ${channel || 'default'}: ${message}`)
var cabal = Cabal(archivesdir + key, key)
cabal.db.ready(() => {
cabal.publish({
type: messageType || 'chat/text',
content: {
channel: channel || 'default',
text: message
}
})
swarm(cabal)
setTimeout(function () { process.exit(0) }, timeout || 5000)
})
swarm(cabal)
setTimeout(function () { process.exit(0) }, timeout || 5000)
}
24 changes: 23 additions & 1 deletion commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ function Commander (view, cabal) {

var self = this
this.commands = {
add: {
help: () => 'add a cabal',
call: (arg) => {
if (arg === '') {
self.view.writeLine('* Usage example: /add cabalkey')
return
}
self.channel = arg
self.view.addCabal(arg)
}
},
nick: {
help: () => 'change your display name',
call: (arg) => {
Expand Down Expand Up @@ -71,6 +82,10 @@ function Commander (view, cabal) {
self.view.writeLine.bind(self.view)(`/${key}`)
self.view.writeLine.bind(self.view)(` ${self.commands[key].help()}`)
}
self.view.writeLine.bind(self.view)(`alt-n`)
self.view.writeLine.bind(self.view)(` move between channels/cabals panes`)
self.view.writeLine.bind(self.view)(`ctrl+{n,p}`)
self.view.writeLine.bind(self.view)(` move up/down channels/cabals`)
}
},
debug: {
Expand All @@ -91,6 +106,12 @@ function Commander (view, cabal) {
process.exit(0)
}
},
exit: {
help: () => 'exit the cabal process',
call: (arg) => {
process.exit(0)
}
},
topic: {
help: () => 'set the topic/description/`message of the day` for a channel',
call: (arg) => {
Expand All @@ -99,9 +120,10 @@ function Commander (view, cabal) {
}
}
// add aliases to commands
this.alias('add', 'cabal')
this.alias('emote', 'me')
this.alias('join', 'j')
this.alias('nick', 'n')
this.alias('emote', 'me')
this.alias('topic', 'motd')
}

Expand Down
Loading