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:
Dmitry Shulyak 2018-12-06 11:30:57 +02:00 committed by Andrea Maria Piana
parent a609b468fe
commit d51761f83e
4 changed files with 29 additions and 8 deletions

View File

@ -329,10 +329,11 @@ func activateShhService(stack *node.Node, config *params.NodeConfig, db *leveldb
}
config := &shhext.ServiceConfig{
DataDir: config.BackupDisabledDataDir,
InstallationID: config.InstallationID,
Debug: config.DebugAPIEnabled,
PFSEnabled: config.PFSEnabled,
DataDir: config.BackupDisabledDataDir,
InstallationID: config.InstallationID,
Debug: config.DebugAPIEnabled,
PFSEnabled: config.PFSEnabled,
MailServerConfirmations: config.MailServerConfirmations,
}
svc := shhext.New(whisper, shhext.EnvelopeSignalHandler{}, db, config)

View File

@ -303,6 +303,9 @@ type NodeConfig struct {
// MailServerRegistryAddress is the MailServerRegistry contract address
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

View File

@ -107,6 +107,12 @@ func (t *tracker) handleEvent(event whisper.EnvelopeEvent) {
}
func (t *tracker) handleEventEnvelopeSent(event whisper.EnvelopeEvent) {
if t.mailServerConfirmation {
if !t.isMailserver(event.Peer) {
return
}
}
t.mu.Lock()
defer t.mu.Unlock()

View File

@ -29,10 +29,9 @@ type TrackerSuite struct {
func (s *TrackerSuite) SetupTest() {
s.tracker = &tracker{
cache: map[common.Hash]EnvelopeState{},
batches: map[common.Hash]map[common.Hash]struct{}{},
mailPeers: mailservers.NewPeerStore(),
mailServerConfirmation: true,
cache: map[common.Hash]EnvelopeState{},
batches: map[common.Hash]map[common.Hash]struct{}{},
mailPeers: mailservers.NewPeerStore(),
}
}
@ -142,3 +141,15 @@ func (s *TrackerSuite) TestRequestExpiration() {
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))
}