sign messages when a signing key is present

This commit is contained in:
vyzo 2018-08-26 13:26:44 +03:00
parent 7c1012c247
commit a6c349b6f0
3 changed files with 22 additions and 8 deletions

View File

@ -65,6 +65,12 @@
"hash": "QmdxUuburamoF6zF9qjeQC4WYcWGbWuRmdLacMEsW8ioD8",
"name": "gogo-protobuf",
"version": "0.0.0"
},
{
"author": "whyrusleeping",
"hash": "QmPvyPwuCgJ7pDmrKDxRtsScJgBaM5h4EpRL2qQJsmXf4n",
"name": "go-libp2p-crypto",
"version": "2.0.1"
}
],
"gxVersion": "0.9.0",

View File

@ -11,6 +11,7 @@ import (
pb "github.com/libp2p/go-floodsub/pb"
logging "github.com/ipfs/go-log"
crypto "github.com/libp2p/go-libp2p-crypto"
host "github.com/libp2p/go-libp2p-host"
inet "github.com/libp2p/go-libp2p-net"
peer "github.com/libp2p/go-libp2p-peer"
@ -89,6 +90,9 @@ type PubSub struct {
peers map[peer.ID]chan *RPC
seenMessages *timecache.TimeCache
// key for signing messages; nil when signing is disabled (default for now)
signKey crypto.PrivKey
ctx context.Context
}
@ -646,14 +650,16 @@ func (p *PubSub) GetTopics() []string {
// Publish publishes data under the given topic
func (p *PubSub) Publish(topic string, data []byte) error {
seqno := p.nextSeqno()
p.publish <- &Message{
&pb.Message{
Data: data,
TopicIDs: []string{topic},
From: []byte(p.host.ID()),
Seqno: seqno,
},
m := &pb.Message{
Data: data,
TopicIDs: []string{topic},
From: []byte(p.host.ID()),
Seqno: seqno,
}
if p.signKey != nil {
signMessage(p.signKey, m)
}
p.publish <- &Message{m}
return nil
}

View File

@ -2,12 +2,14 @@ package floodsub
import (
pb "github.com/libp2p/go-floodsub/pb"
crypto "github.com/libp2p/go-libp2p-crypto"
)
func verifyMessageSignature(m *pb.Message) error {
return nil
}
func signMessage(m *pb.Message) {
func signMessage(key crypto.PrivKey, m *pb.Message) {
}