|
@ -265,8 +265,7 @@ func strAddress(addr string) pss.PssAddress { |
|
|
func (sn *SwarmNet) PssSub(subType, key, topic, address string) error { |
|
|
func (sn *SwarmNet) PssSub(subType, key, topic, address string) error { |
|
|
pssTopic := strTopic(topic) |
|
|
pssTopic := strTopic(topic) |
|
|
pssAddress := strAddress(address) |
|
|
pssAddress := strAddress(address) |
|
|
switch subType { |
|
|
|
|
|
case "sym": |
|
|
|
|
|
|
|
|
if subType == "sym" { |
|
|
_, err := sn.Pss.SetSymmetricKey(strSymKey(key), pssTopic, pssAddress, true) |
|
|
_, err := sn.Pss.SetSymmetricKey(strSymKey(key), pssTopic, pssAddress, true) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return err |
|
|
return err |
|
@ -278,14 +277,17 @@ func (sn *SwarmNet) PssSub(subType, key, topic, address string) error { |
|
|
sn.PssTopics[topic].Delivery = make(chan []byte) |
|
|
sn.PssTopics[topic].Delivery = make(chan []byte) |
|
|
|
|
|
|
|
|
var pssHandler pss.HandlerFunc = func(msg []byte, peer *p2p.Peer, asym bool, keyid string) error { |
|
|
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 |
|
|
sn.PssTopics[topic].Delivery <- msg |
|
|
return nil |
|
|
return nil |
|
|
} |
|
|
} |
|
|
topicHandler := pss.NewHandler(pssHandler) |
|
|
topicHandler := pss.NewHandler(pssHandler) |
|
|
|
|
|
if subType == "raw" { |
|
|
|
|
|
topicHandler = topicHandler.WithProxBin().WithRaw() |
|
|
|
|
|
} |
|
|
sn.PssTopics[topic].Unregister = sn.Pss.Register(&pssTopic, topicHandler) |
|
|
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 |
|
|
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)) |
|
|
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(address), dstTopic, hexutil.Bytes(msg)) |
|
|
} |
|
|
} |
|
|
if subType == "asym" { |
|
|
if subType == "asym" { |
|
|
// add 0x prefix if not present
|
|
|
// add 0x prefix if not present
|
|
|