Browse Source

Consolidate raw

feature/pss_raw
p4u 5 years ago
parent
commit
cd19d5b044
2 changed files with 10 additions and 6 deletions
  1. +3
    -1
      cmd/pssTest/psstest.go
  2. +7
    -5
      net/swarm/swarm.go

+ 3
- 1
cmd/pssTest/psstest.go

@ -49,9 +49,11 @@ func main() {
}()
hostname, _ := os.Hostname()
for {
fmt.Printf("-> Sending %s pss to [%s]\n", kind, key)
err := sn.PssPub(kind, key, topic, fmt.Sprintf("Hello world from %s", hostname), "")
currentTime := int64(time.Now().Unix())
err := sn.PssPub(kind, key, topic, fmt.Sprintf("Hello world from %s at %d", hostname, currentTime), "")
log.Info("pss sent", "err", err)
time.Sleep(10 * time.Second)
}

+ 7
- 5
net/swarm/swarm.go

@ -265,8 +265,7 @@ func strAddress(addr string) pss.PssAddress {
func (sn *SwarmNet) PssSub(subType, key, topic, address string) error {
pssTopic := strTopic(topic)
pssAddress := strAddress(address)
switch subType {
case "sym":
if subType == "sym" {
_, err := sn.Pss.SetSymmetricKey(strSymKey(key), pssTopic, pssAddress, true)
if err != nil {
return err
@ -278,14 +277,17 @@ func (sn *SwarmNet) PssSub(subType, key, topic, address string) error {
sn.PssTopics[topic].Delivery = make(chan []byte)
var pssHandler pss.HandlerFunc = func(msg []byte, peer *p2p.Peer, asym bool, keyid string) error {
//log.Info("pss received", "msg", fmt.Sprintf("%s", msg), "keyid", fmt.Sprintf("%s", keyid))
log.Debug("pss received", "msg", fmt.Sprintf("%s", msg), "keyid", fmt.Sprintf("%s", keyid))
sn.PssTopics[topic].Delivery <- msg
return nil
}
topicHandler := pss.NewHandler(pssHandler)
if subType == "raw" {
topicHandler = topicHandler.WithProxBin().WithRaw()
}
sn.PssTopics[topic].Unregister = sn.Pss.Register(&pssTopic, topicHandler)
log.Info(fmt.Sprintf("Subscribed to topic %s", pssTopic.String()))
log.Info(fmt.Sprintf("Subscribed to [%s] topic %s", subType, pssTopic.String()))
return nil
}
@ -302,7 +304,7 @@ func (sn *SwarmNet) PssPub(subType, key, topic, msg, address string) error {
err = sn.Pss.SendSym(symKeyId, strTopic(topic), hexutil.Bytes(msg))
}
if subType == "raw" {
err = sn.Pss.SendRaw(hexutil.Bytes(dstAddr), dstTopic, hexutil.Bytes(msg))
err = sn.Pss.SendRaw(hexutil.Bytes(address), dstTopic, hexutil.Bytes(msg))
}
if subType == "asym" {
// add 0x prefix if not present

Loading…
Cancel
Save