Skip to content
Snippets Groups Projects
Commit fa6dd8ba authored by Richard T. Carback III's avatar Richard T. Carback III
Browse files

Refactor dumpRounds

parent 08b2f22b
No related branches found
No related tags found
2 merge requests!510Release,!304pickup subcommand
...@@ -11,16 +11,19 @@ package cmd ...@@ -11,16 +11,19 @@ package cmd
import ( import (
"encoding/base64" "encoding/base64"
"fmt" "fmt"
"github.com/spf13/viper"
"strconv" "strconv"
"time" "time"
"github.com/spf13/viper"
"github.com/spf13/cobra" "github.com/spf13/cobra"
jww "github.com/spf13/jwalterweatherman" jww "github.com/spf13/jwalterweatherman"
"gitlab.com/elixxir/client/cmix/rounds" "gitlab.com/elixxir/client/cmix/rounds"
"gitlab.com/elixxir/client/xxdk"
"gitlab.com/xx_network/comms/signature" "gitlab.com/xx_network/comms/signature"
"gitlab.com/xx_network/crypto/signature/ec" "gitlab.com/xx_network/crypto/signature/ec"
"gitlab.com/xx_network/primitives/id" "gitlab.com/xx_network/primitives/id"
"gitlab.com/xx_network/primitives/ndf"
) )
// dumpRoundsCmd allows the user to view network information about a specific // dumpRoundsCmd allows the user to view network information about a specific
...@@ -48,22 +51,22 @@ var dumpRoundsCmd = &cobra.Command{ ...@@ -48,22 +51,22 @@ var dumpRoundsCmd = &cobra.Command{
}) })
waitUntilConnected(connected) waitUntilConnected(connected)
numRequests := len(roundIDs) roundInfos := dumpRounds(roundIDs, user)
requestCh := make(chan bool, numRequests)
registration := user.GetStorage().GetNDF().Registration ndf := user.GetStorage().GetNDF()
ecp := registration.EllipticPubKey
pubkey, err := ec.LoadPublicKey(ecp) for i := range roundInfos {
if err != nil { printRoundInfo(roundInfos[i])
jww.FATAL.Panicf("%+v", err) printAndVerifyRoundSig(roundInfos[i], ndf)
}
},
} }
fmt.Printf("registration pubkey: %s\n\n", pubkey.MarshalText())
rcb := func(round rounds.Round, success bool) { func init() {
if !success { rootCmd.AddCommand(dumpRoundsCmd)
fmt.Printf("round %v lookup failed", round.ID)
} }
func printRoundInfo(round rounds.Round) {
fmt.Printf("Round %v:", round.ID) fmt.Printf("Round %v:", round.ID)
fmt.Printf("\n\tBatch size: %v, State: %v", fmt.Printf("\n\tBatch size: %v, State: %v",
round.BatchSize, round.State) round.BatchSize, round.State)
...@@ -97,6 +100,16 @@ var dumpRoundsCmd = &cobra.Command{ ...@@ -97,6 +100,16 @@ var dumpRoundsCmd = &cobra.Command{
base64.StdEncoding.EncodeToString( base64.StdEncoding.EncodeToString(
ce.Source)) ce.Source))
} }
}
func printAndVerifyRoundSig(round rounds.Round, ndf *ndf.NetworkDefinition) {
registration := ndf.Registration
ecp := registration.EllipticPubKey
pubkey, err := ec.LoadPublicKey(ecp)
if err != nil {
jww.FATAL.Panicf("%+v", err)
}
fmt.Printf("registration pubkey: %s\n\n", pubkey.MarshalText())
ri := round.Raw ri := round.Raw
err = signature.VerifyEddsa(ri, pubkey) err = signature.VerifyEddsa(ri, pubkey)
...@@ -118,8 +131,17 @@ var dumpRoundsCmd = &cobra.Command{ ...@@ -118,8 +131,17 @@ var dumpRoundsCmd = &cobra.Command{
// } else { // } else {
// fmt.Printf("RSA signature succeeded!") // fmt.Printf("RSA signature succeeded!")
// } // }
}
func dumpRounds(roundIDs []id.Round, user *xxdk.E2e) []rounds.Round {
numRequests := len(roundIDs)
requestCh := make(chan rounds.Round, numRequests)
requestCh <- success rcb := func(round rounds.Round, success bool) {
if !success {
fmt.Printf("round %v lookup failed", round.ID)
}
requestCh <- round
} }
for i := range roundIDs { for i := range roundIDs {
...@@ -130,15 +152,13 @@ var dumpRoundsCmd = &cobra.Command{ ...@@ -130,15 +152,13 @@ var dumpRoundsCmd = &cobra.Command{
} }
} }
roundInfos := make([]rounds.Round, 0)
for done := 0; done < numRequests; done++ { for done := 0; done < numRequests; done++ {
res := <-requestCh res := <-requestCh
roundInfos = append(roundInfos, res)
fmt.Printf("request complete: %v", res) fmt.Printf("request complete: %v", res)
} }
}, return roundInfos
}
func init() {
rootCmd.AddCommand(dumpRoundsCmd)
} }
func parseRoundIDs(roundStrs []string) []id.Round { func parseRoundIDs(roundStrs []string) []id.Round {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment