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

Fix group #55

Merged
merged 15 commits into from
Jul 18, 2018
22 changes: 13 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,11 @@ func main() {
Usage: "indicates to use a non TLS server or connection",
}

groupFlag := cli.StringFlag{
Name: "group-init",
Usage: "the group file to use",
}

app.Commands = []cli.Command{
cli.Command{
Name: "keygen",
Expand All @@ -123,10 +128,9 @@ func main() {
},
},
cli.Command{
Name: "dkg",
Usage: "Run the DKG protocol",
ArgsUsage: "GROUP.TOML the group file listing all participant's identities",
Flags: toArray(leaderFlag, listenFlag, tlsCertFlag, tlsKeyFlag, certsDirFlag),
Name: "dkg",
Usage: "Run the DKG protocol",
Flags: toArray(leaderFlag, listenFlag, tlsCertFlag, tlsKeyFlag, certsDirFlag, groupFlag),
Action: func(c *cli.Context) error {
banner()
return dkgCmd(c)
Expand All @@ -145,7 +149,7 @@ func main() {
Name: "run",
Usage: "Run the daemon, first do the dkg if needed then run the beacon",
ArgsUsage: "<group file> is the group.toml generated with `group`. This argument is only needed if the DKG has NOT been run yet.",
Flags: toArray(leaderFlag, periodFlag, seedFlag, listenFlag, tlsCertFlag, tlsKeyFlag, certsDirFlag, insecureFlag),
Flags: toArray(leaderFlag, periodFlag, seedFlag, listenFlag, tlsCertFlag, tlsKeyFlag, certsDirFlag, insecureFlag, groupFlag),
Action: func(c *cli.Context) error {
banner()
return runCmd(c)
Expand Down Expand Up @@ -192,6 +196,7 @@ func keygenCmd(c *cli.Context) error {
if !args.Present() {
slog.Fatal("Missing drand address in argument (IPv4, dns)")
}

var priv *key.Pair
if c.Bool("insecure") {
slog.Info("Generating private / public key pair in INSECURE mode (no TLS).")
Expand Down Expand Up @@ -270,7 +275,7 @@ func groupCmd(c *cli.Context) error {
}

func dkgCmd(c *cli.Context) error {
if c.NArg() < 1 {
if !c.IsSet("group-init") {
slog.Fatal("dkg requires a group.toml file")
}
group := getGroup(c)
Expand Down Expand Up @@ -322,8 +327,7 @@ func runCmd(c *cli.Context) error {
fs := key.NewFileStore(conf.ConfigFolder())
var drand *core.Drand
var err error
if c.NArg() > 0 {
// we assume it is the group file
if c.IsSet("group-init") {
group := getGroup(c)
drand, err = core.NewDrand(fs, group, conf)
if err != nil {
Expand Down Expand Up @@ -445,7 +449,7 @@ func contextToConfig(c *cli.Context) *core.Config {

func getGroup(c *cli.Context) *key.Group {
g := &key.Group{}
if err := key.Load(c.Args().First(), g); err != nil {
if err := key.Load(c.String("group-init"), g); err != nil {
slog.Fatal(err)
}
slog.Infof("group file loaded with %d participants", g.Len())
Expand Down
20 changes: 19 additions & 1 deletion main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,24 @@ func TestGroupGen(t *testing.T) {
}
}

/*func TestRunGroupInit(t *testing.T) {
tmpPath := path.Join(os.TempDir(), "drand")
defer os.RemoveAll(tmpPath)

_, group := test.BatchTLSIdentities(5)
group.Nodes[0] = &key.IndexedPublic{
Identity: priv.Public,
Index: 0,
}
groupPath := path.Join(tmpPath, fmt.Sprintf("group.toml"))
require.NoError(t, key.Save(groupPath, group, false))

cmd := exec.Command("drand", "run", "--group-init", groupPath)
out, err := cmd.CombinedOutput()
fmt.Println(string(out))
require.NoError(t, err)
}*/

func TestClientTLS(t *testing.T) {
tmpPath := path.Join(os.TempDir(), "drand")
os.Mkdir(tmpPath, 0777)
Expand Down Expand Up @@ -121,7 +139,7 @@ func TestClientTLS(t *testing.T) {
groupPath := path.Join(tmpPath, fmt.Sprintf("group.toml"))
require.NoError(t, key.Save(groupPath, group, false))

os.Args = []string{"drand", "--config", tmpPath, "run", "--tls-cert", certPath, "--tls-key", keyPath, groupPath}
os.Args = []string{"drand", "--config", tmpPath, "run", "--tls-cert", certPath, "--tls-key", keyPath, "--group-init", groupPath}
go main()

installCmd := exec.Command("go", "install")
Expand Down