Skip to content

Commit

Permalink
merged with fix_group
Browse files Browse the repository at this point in the history
  • Loading branch information
PizzaWhisperer committed Jul 12, 2018
1 parent e3039ed commit 9c31270
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 4 deletions.
27 changes: 23 additions & 4 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 Down Expand Up @@ -145,7 +150,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 +197,21 @@ func keygenCmd(c *cli.Context) error {
if !args.Present() {
slog.Fatal("Missing drand address in argument (IPv4, dns)")
}
<<<<<<< HEAD
=======

addr := args.First()
var validID = regexp.MustCompile(`[:][0-9]+$`)
if !validID.MatchString(addr) {
slog.Print("No port given. Please, choose a port number (or ENTER for default port 8080): ")
var port string
fmt.Scanf("%s\n", &port)
if port == "" {
port = default_port
}
addr = addr + ":" + port
}
>>>>>>> 69c7b15... added group flag
var priv *key.Pair
if c.Bool("insecure") {
slog.Info("Generating private / public key pair in INSECURE mode (no TLS).")
Expand Down Expand Up @@ -322,8 +342,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 +464,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
18 changes: 18 additions & 0 deletions 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))
os.Args = []string{"drand", "run", "--group-init", groupPath}
os.Args = append(os.Args, names...)
main()
//TODO
}*/

func TestClientTLS(t *testing.T) {
tmpPath := path.Join(os.TempDir(), "drand")
os.Mkdir(tmpPath, 0777)
Expand Down

0 comments on commit 9c31270

Please sign in to comment.