diff --git a/project/cli.go b/project/cli.go index 099c93a..f825b04 100644 --- a/project/cli.go +++ b/project/cli.go @@ -69,8 +69,9 @@ var peerBlockCmd = &cobra.Command{ Use: "block", Short: "Block a peer from your local node.", Run: func(cmd *cobra.Command, args []string) { - mhash := args[0] - fmt.Printf("TODO: Validate this input string %s\n", mhash) + mHash := validateMhash(args[0]) + addPeer(mHash, blocked) + fmt.Printf("Blocked %s\n", mHash) }, } diff --git a/project/decoders.go b/project/decoders.go index ebb54de..ea8f0fb 100644 --- a/project/decoders.go +++ b/project/decoders.go @@ -1,7 +1,8 @@ package main import ( - "fmt" + "log" + "strings" ) type testCase struct { @@ -14,9 +15,22 @@ type testCase struct { func B32Decode(input string) []byte { output, error := encoder.DecodeString(input) if error != nil { - msg := fmt.Sprintf("Error decoding Base32 string %s", input) - panic(msg) + log.Fatalf("Error decoding Base32 string %s", input) } return output } + +func validateMhash(input string) string { + arry := strings.Split(input, ".") + if len(arry) != 2 { + log.Fatalf("Expected '%s' to be an mHash", input) + } + switch arry[0] + "." { + case BlobSigil, MessageSigil, PeerSigil: + return input + } + msg := "Expected left side of Mhash dot to be one of %s, %s, %s. Got: %s" + log.Fatalf(msg, BlobSigil, MessageSigil, PeerSigil, arry[0]) + return input +} diff --git a/project/peers.go b/project/peers.go index b81c650..68c6340 100644 --- a/project/peers.go +++ b/project/peers.go @@ -39,7 +39,7 @@ func addPeer(mHash string, status PeerStatus) { } _, err2 := tx.Exec(createPeer, mHash, status) if err2 != nil { - log.Fatalf("Failed to addPeer (1): %s", err2) + log.Fatalf("Failure. Possible duplicate peer?: %s", err2) } err1 := tx.Commit() if err1 != nil {