-
Notifications
You must be signed in to change notification settings - Fork 115
/
daemon.go
56 lines (50 loc) · 1.4 KB
/
daemon.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"fmt"
"os"
"runtime"
"github.com/dedis/drand/core"
"github.com/dedis/drand/key"
"github.com/urfave/cli"
)
func startCmd(c *cli.Context) error {
conf := contextToConfig(c)
fs := key.NewFileStore(conf.ConfigFolder())
var drand *core.Drand
// determine if we already ran a DKG or not
_, errG := fs.LoadGroup()
_, errS := fs.LoadShare()
_, errD := fs.LoadDistPublic()
// XXX place that logic inside core/ directly with only one method
freshRun := errG != nil || errS != nil || errD != nil
var err error
if freshRun {
if exit := resetBeaconDB(conf); exit {
os.Exit(0)
}
fmt.Println("drand: will run as fresh install -> expect to run DKG.")
drand, err = core.NewDrand(fs, conf)
if err != nil {
fatal("drand: can't instantiate drand instance %s", err)
}
} else {
fmt.Print("drand: will already start running randomness beacon")
drand, err = core.LoadDrand(fs, conf)
if err != nil {
fatal("drand: can't load drand instance %s", err)
}
// XXX make it configurable so that new share holder can still start if
// nobody started.
if err := drand.StartBeacon(!c.Bool(pushFlag.Name)); err != nil {
fatal("drand: starting beacon failed: %s", err)
}
}
// wait indefinitely - XXX analyzes goroutine graphs to see if it actually
// makes sense
runtime.Goexit()
return nil
}
func stopDaemon(c *cli.Context) error {
// TODO
panic("not implemented yet")
}