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.2 KiB

  1. package main
  2. import (
  3. swarm "github.com/vocdoni/go-dvote/net/swarm"
  4. "os"
  5. "fmt"
  6. "time"
  7. "github.com/ethereum/go-ethereum/log"
  8. )
  9. func main() {
  10. if len(os.Args) < 2 {
  11. fmt.Println("Use <sym|asym> <key>")
  12. return
  13. }
  14. sn := new(swarm.SimplePss)
  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. key := ""
  27. if kind == "sym" || kind == "asym" || kind == "raw" {
  28. if kind != "raw" {
  29. key = os.Args[2]
  30. }
  31. sn.PssSub(kind, key, topic, "")
  32. defer sn.PssTopics[topic].Unregister()
  33. } else {
  34. fmt.Println("First parameter must be sym or asym")
  35. return
  36. }
  37. fmt.Printf("My PSS pubKey is %s\n", sn.PssPubKey)
  38. go func() {
  39. for {
  40. pmsg := <-sn.PssTopics[topic].Delivery
  41. fmt.Printf("<- Pss received msg:{%s}\n", pmsg.Msg)
  42. }
  43. }()
  44. hostname, _ := os.Hostname()
  45. for {
  46. fmt.Printf("-> Sending %s pss to [%s]\n", kind, key)
  47. currentTime := int64(time.Now().Unix())
  48. err := sn.PssPub(kind, key, topic, fmt.Sprintf("Hello world from %s at %d", hostname, currentTime), "")
  49. log.Info("pss send", "err", err)
  50. time.Sleep(10 * time.Second)
  51. }
  52. }