mHash validation helper. Ability to block a peer
This commit is contained in:
parent
c1fa1c77fc
commit
b2979b9474
|
@ -69,8 +69,9 @@ var peerBlockCmd = &cobra.Command{
|
||||||
Use: "block",
|
Use: "block",
|
||||||
Short: "Block a peer from your local node.",
|
Short: "Block a peer from your local node.",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
mhash := args[0]
|
mHash := validateMhash(args[0])
|
||||||
fmt.Printf("TODO: Validate this input string %s\n", mhash)
|
addPeer(mHash, blocked)
|
||||||
|
fmt.Printf("Blocked %s\n", mHash)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,8 @@
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"log"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type testCase struct {
|
type testCase struct {
|
||||||
|
@ -14,9 +15,22 @@ type testCase struct {
|
||||||
func B32Decode(input string) []byte {
|
func B32Decode(input string) []byte {
|
||||||
output, error := encoder.DecodeString(input)
|
output, error := encoder.DecodeString(input)
|
||||||
if error != nil {
|
if error != nil {
|
||||||
msg := fmt.Sprintf("Error decoding Base32 string %s", input)
|
log.Fatalf("Error decoding Base32 string %s", input)
|
||||||
panic(msg)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return output
|
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
|
||||||
|
}
|
||||||
|
|
|
@ -39,7 +39,7 @@ func addPeer(mHash string, status PeerStatus) {
|
||||||
}
|
}
|
||||||
_, err2 := tx.Exec(createPeer, mHash, status)
|
_, err2 := tx.Exec(createPeer, mHash, status)
|
||||||
if err2 != nil {
|
if err2 != nil {
|
||||||
log.Fatalf("Failed to addPeer (1): %s", err2)
|
log.Fatalf("Failure. Possible duplicate peer?: %s", err2)
|
||||||
}
|
}
|
||||||
err1 := tx.Commit()
|
err1 := tx.Commit()
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
|
|
Loading…
Reference in New Issue