mirror of
https://github.com/logos-messaging/go-libp2p-pubsub.git
synced 2026-01-07 15:23:08 +00:00
use the ID corresponding to signKey for published messages
This commit is contained in:
parent
b353ddca06
commit
bd15183543
@ -92,6 +92,8 @@ type PubSub struct {
|
|||||||
|
|
||||||
// key for signing messages; nil when signing is disabled (default for now)
|
// key for signing messages; nil when signing is disabled (default for now)
|
||||||
signKey crypto.PrivKey
|
signKey crypto.PrivKey
|
||||||
|
// source ID for signed messages; corresponds to signKey
|
||||||
|
signID peer.ID
|
||||||
// strict mode rejects all unsigned messages prior to validation
|
// strict mode rejects all unsigned messages prior to validation
|
||||||
signStrict bool
|
signStrict bool
|
||||||
|
|
||||||
@ -194,7 +196,8 @@ func WithValidateThrottle(n int) Option {
|
|||||||
|
|
||||||
func WithMessageSigning(strict bool) Option {
|
func WithMessageSigning(strict bool) Option {
|
||||||
return func(p *PubSub) error {
|
return func(p *PubSub) error {
|
||||||
p.signKey = p.host.Peerstore().PrivKey(p.host.ID())
|
p.signID = p.host.ID()
|
||||||
|
p.signKey = p.host.Peerstore().PrivKey(p.signID)
|
||||||
p.signStrict = strict
|
p.signStrict = strict
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@ -673,6 +676,7 @@ func (p *PubSub) Publish(topic string, data []byte) error {
|
|||||||
Seqno: seqno,
|
Seqno: seqno,
|
||||||
}
|
}
|
||||||
if p.signKey != nil {
|
if p.signKey != nil {
|
||||||
|
m.From = []byte(p.signID)
|
||||||
err := signMessage(p.signKey, m)
|
err := signMessage(p.signKey, m)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user