github.com/DFWallet/tendermint-cosmos@v0.0.2/test/fuzz/p2p/addrbook/init-corpus/main.go (about) 1 // nolint: gosec 2 package main 3 4 import ( 5 "encoding/json" 6 "flag" 7 "fmt" 8 "io/ioutil" 9 "log" 10 "net" 11 "os" 12 "path/filepath" 13 14 "github.com/DFWallet/tendermint-cosmos/crypto/ed25519" 15 "github.com/DFWallet/tendermint-cosmos/p2p" 16 ) 17 18 func main() { 19 baseDir := flag.String("base", ".", `where the "corpus" directory will live`) 20 flag.Parse() 21 22 initCorpus(*baseDir) 23 } 24 25 func initCorpus(baseDir string) { 26 log.SetFlags(0) 27 28 // create "corpus" directory 29 corpusDir := filepath.Join(baseDir, "corpus") 30 if err := os.MkdirAll(corpusDir, 0755); err != nil { 31 log.Fatalf("Creating %q err: %v", corpusDir, err) 32 } 33 34 // create corpus 35 privKey := ed25519.GenPrivKey() 36 addrs := []*p2p.NetAddress{ 37 {ID: p2p.PubKeyToID(privKey.PubKey()), IP: net.IPv4(0, 0, 0, 0), Port: 0}, 38 {ID: p2p.PubKeyToID(privKey.PubKey()), IP: net.IPv4(127, 0, 0, 0), Port: 80}, 39 {ID: p2p.PubKeyToID(privKey.PubKey()), IP: net.IPv4(213, 87, 10, 200), Port: 8808}, 40 {ID: p2p.PubKeyToID(privKey.PubKey()), IP: net.IPv4(111, 111, 111, 111), Port: 26656}, 41 {ID: p2p.PubKeyToID(privKey.PubKey()), IP: net.ParseIP("2001:db8::68"), Port: 26656}, 42 } 43 44 for i, addr := range addrs { 45 filename := filepath.Join(corpusDir, fmt.Sprintf("%d.json", i)) 46 47 bz, err := json.Marshal(addr) 48 if err != nil { 49 log.Fatalf("can't marshal %v: %v", addr, err) 50 } 51 52 if err := ioutil.WriteFile(filename, bz, 0644); err != nil { 53 log.Fatalf("can't write %v to %q: %v", addr, filename, err) 54 } 55 56 log.Printf("wrote %q", filename) 57 } 58 }