diff options
| author | Chris Ball <chris@printf.net> | 2015-05-26 22:08:47 -0400 |
|---|---|---|
| committer | Chris Ball <chris@printf.net> | 2015-05-26 22:08:47 -0400 |
| commit | fdb0c652127c3865d4ef9dd4567f410de7466d24 (patch) | |
| tree | 9116f6a08a3aad95728a6fbc332705fb584bd379 | |
| parent | 62575ab19c870d8925ae0e896aa55eaf1f7b0bd1 (diff) | |
Create keyfile if it doesn't already exist
| -rwxr-xr-x | gitswarmd | 17 |
1 files changed, 13 insertions, 4 deletions
@@ -24,10 +24,20 @@ dht.listen(6882) var announcedRefs = {} var announcedRepos = {} -var key = read_keyfile() -console.log(key) +var key = create_or_read_keyfile() -function read_keyfile () { +function create_or_read_keyfile () { + var filename = 'ed25519.key' + if (!fs.existsSync(filename)) { + var keypair = new EC('ed25519').genKeyPair() + var key = { + pub: keypair.getPublic('hex'), + priv: keypair.getPrivate('hex') + } + fs.writeFileSync(filename, JSON.stringify(key)) + } + + // Okay, now the file exists, whether created here or not. var key = JSON.parse(fs.readFileSync('ed25519.key').toString()) return ed25519.keyPair({ priv: key.priv, @@ -47,7 +57,6 @@ function bpad (n, buf) { } } -console.log(key) dht.on('ready', function () { // Spider all */.git dirs and announce all refs. var repos = glob.sync('*/.git/git-daemon-export-ok') |
