Ensure sent event is received from a mailserver (#1304)
In previous change i used same filtering for a handler that processes confirmations. But if we are connected with peers that do not support confirmations on whisper level, whisper may send "Sent" event when envelope is written to a socket. This is our old behaviour. So, this PR allows to use confirmations from a mail servers and ensure that transition between multiple version of peers will be smooth.
This commit is contained in:
parent
a609b468fe
commit
d51761f83e
|
@ -333,6 +333,7 @@ func activateShhService(stack *node.Node, config *params.NodeConfig, db *leveldb
|
||||||
InstallationID: config.InstallationID,
|
InstallationID: config.InstallationID,
|
||||||
Debug: config.DebugAPIEnabled,
|
Debug: config.DebugAPIEnabled,
|
||||||
PFSEnabled: config.PFSEnabled,
|
PFSEnabled: config.PFSEnabled,
|
||||||
|
MailServerConfirmations: config.MailServerConfirmations,
|
||||||
}
|
}
|
||||||
|
|
||||||
svc := shhext.New(whisper, shhext.EnvelopeSignalHandler{}, db, config)
|
svc := shhext.New(whisper, shhext.EnvelopeSignalHandler{}, db, config)
|
||||||
|
|
|
@ -303,6 +303,9 @@ type NodeConfig struct {
|
||||||
|
|
||||||
// MailServerRegistryAddress is the MailServerRegistry contract address
|
// MailServerRegistryAddress is the MailServerRegistry contract address
|
||||||
MailServerRegistryAddress string
|
MailServerRegistryAddress string
|
||||||
|
|
||||||
|
// MailServerConfirmations should be true if client wants to receive confirmatons only from a selected mail servers.
|
||||||
|
MailServerConfirmations bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Option is an additional setting when creating a NodeConfig
|
// Option is an additional setting when creating a NodeConfig
|
||||||
|
|
|
@ -107,6 +107,12 @@ func (t *tracker) handleEvent(event whisper.EnvelopeEvent) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *tracker) handleEventEnvelopeSent(event whisper.EnvelopeEvent) {
|
func (t *tracker) handleEventEnvelopeSent(event whisper.EnvelopeEvent) {
|
||||||
|
if t.mailServerConfirmation {
|
||||||
|
if !t.isMailserver(event.Peer) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
t.mu.Lock()
|
t.mu.Lock()
|
||||||
defer t.mu.Unlock()
|
defer t.mu.Unlock()
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,6 @@ func (s *TrackerSuite) SetupTest() {
|
||||||
cache: map[common.Hash]EnvelopeState{},
|
cache: map[common.Hash]EnvelopeState{},
|
||||||
batches: map[common.Hash]map[common.Hash]struct{}{},
|
batches: map[common.Hash]map[common.Hash]struct{}{},
|
||||||
mailPeers: mailservers.NewPeerStore(),
|
mailPeers: mailservers.NewPeerStore(),
|
||||||
mailServerConfirmation: true,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,3 +141,15 @@ func (s *TrackerSuite) TestRequestExpiration() {
|
||||||
s.Fail("timed out while waiting for request expiration")
|
s.Fail("timed out while waiting for request expiration")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *TrackerSuite) TestIgnoreNotFromMailserver() {
|
||||||
|
// enables filter in the tracker to drop confirmations from non-mailserver peers
|
||||||
|
s.tracker.mailServerConfirmation = true
|
||||||
|
s.tracker.Add(testHash)
|
||||||
|
s.tracker.handleEvent(whisper.EnvelopeEvent{
|
||||||
|
Event: whisper.EventEnvelopeSent,
|
||||||
|
Hash: testHash,
|
||||||
|
Peer: enode.ID{1}, // could be empty, doesn't impact test behaviour
|
||||||
|
})
|
||||||
|
s.Require().Equal(EnvelopePosted, s.tracker.GetState(testHash))
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue