arnaucube
arnaucube/go-dvotePublic Self-hosted repository
go-dvote/cmd/pssTest/psstest.go
cmd/pssTest/psstest.goRaw
 1package main
 2
 3import (
 4	"fmt"
 5	"os"
 6	"time"
 7
 8	"github.com/ethereum/go-ethereum/log"
 9	swarm "github.com/vocdoni/go-dvote/net/swarm"
10)
11
12func main() {
13	sn := new(swarm.SwarmNet)
14	err := sn.Init()
15	if err != nil {
16		fmt.Printf("%v\n", err)
17		return
18	}
19	key := os.Args[1]
20	topic := "vocdoni_test"
21
22	sn.PssSub("asym", key, topic, "")
23	go func() {
24		for {
25			msg := <-sn.PssTopics[topic].Delivery
26			fmt.Printf("Pss received: %s\n", msg)
27		}
28	}()
29
30	hostname, _ := os.Hostname()
31	for {
32		err := sn.PssPub("asym", key, topic, fmt.Sprintf("Hello world from %s", hostname), "")
33		log.Info("pss sent", "err", err)
34		time.Sleep(10 * time.Second)
35	}
36}