You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.4 KiB

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