move self-publish check to pubsub

This commit is contained in:
vyzo 2020-03-27 20:56:03 +02:00
parent a1488680e7
commit ce3da3facd
2 changed files with 7 additions and 7 deletions

View File

@ -556,12 +556,6 @@ func (gs *GossipSubRouter) connector() {
} }
func (gs *GossipSubRouter) Publish(msg *Message) { func (gs *GossipSubRouter) Publish(msg *Message) {
self := gs.p.host.ID()
if peer.ID(msg.GetFrom()) == self && msg.ReceivedFrom != self {
// we don't forward messages claiming to be from us but not published by ourselves
return
}
gs.mcache.Put(msg.Message) gs.mcache.Put(msg.Message)
from := msg.ReceivedFrom from := msg.ReceivedFrom
@ -573,7 +567,7 @@ func (gs *GossipSubRouter) Publish(msg *Message) {
continue continue
} }
if gs.floodPublish && from == self { if gs.floodPublish && from == gs.p.host.ID() {
for p := range tmap { for p := range tmap {
if gs.score.Score(p) >= gs.publishThreshold { if gs.score.Score(p) >= gs.publishThreshold {
tosend[p] = struct{}{} tosend[p] = struct{}{}

View File

@ -849,6 +849,12 @@ func (p *PubSub) pushMsg(msg *Message) {
} }
func (p *PubSub) publishMessage(msg *Message) { func (p *PubSub) publishMessage(msg *Message) {
self := p.host.ID()
if peer.ID(msg.GetFrom()) == self && msg.ReceivedFrom != self {
// we don't publish messages claiming to be from us but not published by ourselves
return
}
p.tracer.DeliverMessage(msg) p.tracer.DeliverMessage(msg)
p.notifySubs(msg) p.notifySubs(msg)
p.rt.Publish(msg) p.rt.Publish(msg)