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,91 +51,13 @@ var dumpRoundsCmd = &cobra.Command{ ...@@ -48,91 +51,13 @@ 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)
if err != nil {
jww.FATAL.Panicf("%+v", err)
}
fmt.Printf("registration pubkey: %s\n\n", pubkey.MarshalText())
rcb := func(round rounds.Round, success bool) {
if !success {
fmt.Printf("round %v lookup failed", round.ID)
}
fmt.Printf("Round %v:", round.ID)
fmt.Printf("\n\tBatch size: %v, State: %v",
round.BatchSize, round.State)
fmt.Printf("\n\tUpdateID: %v, AddrSpaceSize: %v",
round.UpdateID, round.AddressSpaceSize)
fmt.Printf("\n\tTopology: ")
for i, nodeId := range round.Raw.Topology {
nidStr := base64.StdEncoding.EncodeToString(
nodeId)
fmt.Printf("\n\t\t%d\t-\t%s", i, nidStr)
}
fmt.Printf("\n\tTimestamps: ")
for state, ts := range round.Timestamps {
fmt.Printf("\n\t\t%v \t-\t%v", state, ts)
}
fmt.Printf("\n\tErrors (%d): ", len(round.Raw.Errors))
for i, err := range round.Raw.Errors {
fmt.Printf("\n\t\t%d - %v", i, err)
}
fmt.Printf("\n\tClientErrors (%d): ",
len(round.Raw.ClientErrors))
for _, ce := range round.Raw.ClientErrors {
fmt.Printf("\n\t\t%s - %v, Src: %v",
base64.StdEncoding.EncodeToString(
ce.ClientId),
ce.Error,
base64.StdEncoding.EncodeToString(
ce.Source))
}
ri := round.Raw
err = signature.VerifyEddsa(ri, pubkey)
if err != nil {
fmt.Printf("\n\tECC signature failed: %v", err)
fmt.Printf("\n\tuse trace logging for sig details")
} else {
fmt.Printf("\n\tECC signature succeeded!\n\n")
}
// fmt.Printf("Round Info RAW: %v\n\n", round)
// rsapubkey, _ := rsa.LoadPublicKeyFromPem([]byte(
// registration.TlsCertificate))
// signature.VerifyRsa(ri, rsapubkey)
// if err != nil {
// fmt.Printf("RSA signature failed: %v", err)
// fmt.Printf("use trace logging for sig details")
// } else {
// fmt.Printf("RSA signature succeeded!")
// }
requestCh <- success
}
for i := range roundIDs {
rid := roundIDs[i]
err := user.GetCmix().LookupHistoricalRound(rid, rcb)
if err != nil {
fmt.Printf("error on %v: %v", rid, err)
}
}
for done := 0; done < numRequests; done++ { for i := range roundInfos {
res := <-requestCh printRoundInfo(roundInfos[i])
fmt.Printf("request complete: %v", res) printAndVerifyRoundSig(roundInfos[i], ndf)
} }
}, },
} }
...@@ -141,6 +66,101 @@ func init() { ...@@ -141,6 +66,101 @@ func init() {
rootCmd.AddCommand(dumpRoundsCmd) rootCmd.AddCommand(dumpRoundsCmd)
} }
func printRoundInfo(round rounds.Round) {
fmt.Printf("Round %v:", round.ID)
fmt.Printf("\n\tBatch size: %v, State: %v",
round.BatchSize, round.State)
fmt.Printf("\n\tUpdateID: %v, AddrSpaceSize: %v",
round.UpdateID, round.AddressSpaceSize)
fmt.Printf("\n\tTopology: ")
for i, nodeId := range round.Raw.Topology {
nidStr := base64.StdEncoding.EncodeToString(
nodeId)
fmt.Printf("\n\t\t%d\t-\t%s", i, nidStr)
}
fmt.Printf("\n\tTimestamps: ")
for state, ts := range round.Timestamps {
fmt.Printf("\n\t\t%v \t-\t%v", state, ts)
}
fmt.Printf("\n\tErrors (%d): ", len(round.Raw.Errors))
for i, err := range round.Raw.Errors {
fmt.Printf("\n\t\t%d - %v", i, err)
}
fmt.Printf("\n\tClientErrors (%d): ",
len(round.Raw.ClientErrors))
for _, ce := range round.Raw.ClientErrors {
fmt.Printf("\n\t\t%s - %v, Src: %v",
base64.StdEncoding.EncodeToString(
ce.ClientId),
ce.Error,
base64.StdEncoding.EncodeToString(
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
err = signature.VerifyEddsa(ri, pubkey)
if err != nil {
fmt.Printf("\n\tECC signature failed: %v", err)
fmt.Printf("\n\tuse trace logging for sig details")
} else {
fmt.Printf("\n\tECC signature succeeded!\n\n")
}
// fmt.Printf("Round Info RAW: %v\n\n", round)
// rsapubkey, _ := rsa.LoadPublicKeyFromPem([]byte(
// registration.TlsCertificate))
// signature.VerifyRsa(ri, rsapubkey)
// if err != nil {
// fmt.Printf("RSA signature failed: %v", err)
// fmt.Printf("use trace logging for sig details")
// } else {
// fmt.Printf("RSA signature succeeded!")
// }
}
func dumpRounds(roundIDs []id.Round, user *xxdk.E2e) []rounds.Round {
numRequests := len(roundIDs)
requestCh := make(chan rounds.Round, numRequests)
rcb := func(round rounds.Round, success bool) {
if !success {
fmt.Printf("round %v lookup failed", round.ID)
}
requestCh <- round
}
for i := range roundIDs {
rid := roundIDs[i]
err := user.GetCmix().LookupHistoricalRound(rid, rcb)
if err != nil {
fmt.Printf("error on %v: %v", rid, err)
}
}
roundInfos := make([]rounds.Round, 0)
for done := 0; done < numRequests; done++ {
res := <-requestCh
roundInfos = append(roundInfos, res)
fmt.Printf("request complete: %v", res)
}
return roundInfos
}
func parseRoundIDs(roundStrs []string) []id.Round { func parseRoundIDs(roundStrs []string) []id.Round {
var roundIDs []id.Round var roundIDs []id.Round
for _, r := range roundStrs { for _, r := range roundStrs {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment