Browse Source

Extend pss delivery chan type

feature/pss
p4u 5 years ago
parent
commit
1c45bd6bc2
2 changed files with 15 additions and 6 deletions
  1. +3
    -3
      cmd/pssTest/psstest.go
  2. +12
    -3
      net/swarm/swarm.go

+ 3
- 3
cmd/pssTest/psstest.go

@ -40,11 +40,11 @@ func main() {
fmt.Println("First parameter must be sym or asym")
return
}
fmt.Printf("My PSS pubKey is %s\n", sn.PssPubKey)
go func() {
for {
msg := <-sn.PssTopics[topic].Delivery
fmt.Printf("<- Pss received: %s\n", msg)
pmsg := <-sn.PssTopics[topic].Delivery
fmt.Printf("<- Pss received msg:{%s}\n", pmsg.Msg)
}
}()

+ 12
- 3
net/swarm/swarm.go

@ -112,9 +112,16 @@ func NewSwarmPorts() *swarmPorts {
return sp
}
type pssMsg struct {
Msg []byte
Peer *p2p.Peer
Asym bool
Keyid string
}
type pssSub struct {
Unregister func()
Delivery (chan []byte)
Delivery (chan pssMsg)
Address string
}
@ -274,11 +281,12 @@ func (sn *SwarmNet) PssSub(subType, key, topic, address string) error {
sn.PssTopics[topic] = new(pssSub)
sn.PssTopics[topic].Address = address
sn.PssTopics[topic].Delivery = make(chan []byte)
sn.PssTopics[topic].Delivery = make(chan pssMsg)
var pssHandler pss.HandlerFunc = func(msg []byte, peer *p2p.Peer, asym bool, keyid string) error {
log.Debug("pss received", "msg", fmt.Sprintf("%s", msg), "keyid", fmt.Sprintf("%s", keyid))
sn.PssTopics[topic].Delivery <- msg
sn.PssTopics[topic].Delivery <- pssMsg{Msg: msg, Peer: peer, Asym: asym, Keyid: keyid}
return nil
}
topicHandler := pss.NewHandler(pssHandler)
@ -304,6 +312,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" {
// sed raw message
err = sn.Pss.SendRaw(hexutil.Bytes(address), dstTopic, hexutil.Bytes(msg))
}
if subType == "asym" {

Loading…
Cancel
Save