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.

59 lines
1.5 KiB

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