mirror of
https://github.com/arnaucube/go-dvote.git
synced 2026-02-28 05:26:46 +01:00
Testing asymetric messages
This commit is contained in:
@@ -16,19 +16,20 @@ func main() {
|
|||||||
fmt.Printf("%v\n", err)
|
fmt.Printf("%v\n", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
key := "randomkey0"
|
key := os.Args[1]
|
||||||
sn.PssSub("sym", key, "vocdoni_test", "")
|
topic := "vocdoni_test"
|
||||||
|
|
||||||
|
sn.PssSub("asym", key, topic, "")
|
||||||
go func() {
|
go func() {
|
||||||
for {
|
for {
|
||||||
msg := <-sn.PssTopics["vocdoni_test"].Delivery
|
msg := <-sn.PssTopics[topic].Delivery
|
||||||
fmt.Printf("Pss received: %s\n", msg)
|
fmt.Printf("Pss received: %s\n", msg)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
hostname, _ := os.Hostname()
|
hostname, _ := os.Hostname()
|
||||||
for {
|
for {
|
||||||
err := sn.PssPub("sym", key, "vocdoni_test", fmt.Sprintf("Hello world from %s", hostname), "")
|
err := sn.PssPub("asym", key, topic, fmt.Sprintf("Hello world from %s", hostname), "")
|
||||||
log.Info("pss sent", "err", err)
|
log.Info("pss sent", "err", err)
|
||||||
time.Sleep(10 * time.Second)
|
time.Sleep(10 * time.Second)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package swarm
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
|
"encoding/hex"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
@@ -299,7 +300,11 @@ func (sn *SwarmNet) PssPub(subType, key, topic, msg, address string) error {
|
|||||||
err = sn.Pss.SendRaw(hexutil.Bytes(dstAddr), dstTopic, hexutil.Bytes(msg))
|
err = sn.Pss.SendRaw(hexutil.Bytes(dstAddr), dstTopic, hexutil.Bytes(msg))
|
||||||
}
|
}
|
||||||
if subType == "asym" {
|
if subType == "asym" {
|
||||||
err = sn.Pss.SetPeerPublicKey(hexutil.Bytes(key), dstTopic, dstAddr)
|
pubKeyBytes, err := hex.DecodeString(key)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = sn.Pss.SetPeerPublicKey(pubKeyBytes, dstTopic, dstAddr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user