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.

56 lines
1.0 KiB

  1. package main
  2. import (
  3. "fmt"
  4. "os"
  5. "time"
  6. "github.com/ethereum/go-ethereum/log"
  7. swarm "github.com/vocdoni/go-dvote/net/swarm"
  8. )
  9. func main() {
  10. if len(os.Args) < 2 {
  11. fmt.Println("Use <sym|asym> <key>")
  12. return
  13. }
  14. sn := new(swarm.SwarmNet)
  15. err := sn.Init()
  16. if err != nil {
  17. fmt.Printf("%v\n", err)
  18. return
  19. }
  20. err = sn.SetLog("crit")
  21. if err != nil {
  22. fmt.Printf("Cannot set loglevel %v\n", err)
  23. }
  24. kind := os.Args[1]
  25. topic := "vocdoni_test"
  26. var key string
  27. if kind == "sym" || kind == "asym" {
  28. key = os.Args[2]
  29. sn.PssSub(kind, key, topic, "")
  30. defer sn.PssTopics[topic].Unregister()
  31. } else {
  32. fmt.Println("First parameter must be sym or asym")
  33. return
  34. }
  35. go func() {
  36. for {
  37. msg := <-sn.PssTopics[topic].Delivery
  38. fmt.Printf("<- Pss received: %s\n", msg)
  39. }
  40. }()
  41. hostname, _ := os.Hostname()
  42. for {
  43. fmt.Printf("-> Sending %s pss to [%s]\n", kind, key)
  44. err := sn.PssPub(kind, key, topic, fmt.Sprintf("Hello world from %s", hostname), "")
  45. log.Info("pss sent", "err", err)
  46. time.Sleep(10 * time.Second)
  47. }
  48. }