mirror of
https://github.com/arnaucube/go-dvote.git
synced 2026-02-28 05:26:46 +01:00
Testing raw
This commit is contained in:
@@ -28,10 +28,12 @@ func main() {
|
|||||||
|
|
||||||
kind := os.Args[1]
|
kind := os.Args[1]
|
||||||
topic := "vocdoni_test"
|
topic := "vocdoni_test"
|
||||||
var key string
|
key := ""
|
||||||
|
|
||||||
if kind == "sym" || kind == "asym" {
|
if kind == "sym" || kind == "asym" || kind == "raw" {
|
||||||
key = os.Args[2]
|
if kind != "raw" {
|
||||||
|
key = os.Args[2]
|
||||||
|
}
|
||||||
sn.PssSub(kind, key, topic, "")
|
sn.PssSub(kind, key, topic, "")
|
||||||
defer sn.PssTopics[topic].Unregister()
|
defer sn.PssTopics[topic].Unregister()
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -298,27 +298,21 @@ func (sn *SwarmNet) PssPub(subType, key, topic, msg, address string) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
// send symetric message
|
||||||
err = sn.Pss.SendSym(symKeyId, strTopic(topic), hexutil.Bytes(msg))
|
err = sn.Pss.SendSym(symKeyId, strTopic(topic), hexutil.Bytes(msg))
|
||||||
}
|
}
|
||||||
if subType == "raw" {
|
if subType == "raw" {
|
||||||
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" {
|
||||||
|
// add 0x prefix if not present
|
||||||
if hasHexPrefix := strings.HasPrefix(key, "0x"); !hasHexPrefix {
|
if hasHexPrefix := strings.HasPrefix(key, "0x"); !hasHexPrefix {
|
||||||
key = "0x" + key
|
key = "0x" + key
|
||||||
}
|
}
|
||||||
topics, addresses, err := sn.Pss.GetPublickeyPeers(key)
|
|
||||||
|
// check if topic+address is already set for a pubKey
|
||||||
|
_, err := sn.Pss.GetPeerAddress(key, dstTopic)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
|
||||||
}
|
|
||||||
topicFound := false
|
|
||||||
for i, t := range topics {
|
|
||||||
if dstTopic == t && fmt.Sprintf("%x", addresses[i]) == fmt.Sprintf("%x", dstAddr) {
|
|
||||||
topicFound = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if !topicFound {
|
|
||||||
pubKeyBytes, err := hexutil.Decode(key)
|
pubKeyBytes, err := hexutil.Decode(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -329,25 +323,8 @@ func (sn *SwarmNet) PssPub(subType, key, topic, msg, address string) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// send asymetric message
|
||||||
err = sn.Pss.SendAsym(key, dstTopic, hexutil.Bytes(msg))
|
err = sn.Pss.SendAsym(key, dstTopic, hexutil.Bytes(msg))
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sn *SwarmNet) Test() error {
|
|
||||||
sn.PssSub("sym", "vocdoni", "vocdoni_test", "")
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
for {
|
|
||||||
msg := <-sn.PssTopics["vocdoni_test"].Delivery
|
|
||||||
fmt.Printf("Pss received: %s\n", msg)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
hostname, _ := os.Hostname()
|
|
||||||
for {
|
|
||||||
err := sn.PssPub("sym", "vocdoni", "vocdoni_test", fmt.Sprintf("Hello world from %s", hostname), "")
|
|
||||||
log.Info("pss sent", "err", err)
|
|
||||||
time.Sleep(10 * time.Second)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user