skip EventMsgDelete events in Status

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2019-10-15 11:55:18 +02:00
parent c668dba610
commit 768539255a
No known key found for this signature in database
GPG Key ID: 4EF064D0E6D63020
3 changed files with 35 additions and 21 deletions

View File

@ -1,8 +1,8 @@
package status
import (
"encoding/hex"
"crypto/ecdsa"
"encoding/hex"
crypto "github.com/ethereum/go-ethereum/crypto"
)

View File

@ -1,34 +1,34 @@
package status
import (
"fmt"
"time"
"context"
"strings"
"database/sql"
"crypto/ecdsa"
"database/sql"
"fmt"
"strings"
"time"
"go.uber.org/zap"
"github.com/pkg/errors"
"github.com/google/uuid"
"github.com/pkg/errors"
"go.uber.org/zap"
"github.com/42wim/matterbridge/bridge"
"github.com/42wim/matterbridge/bridge/config"
v1 "github.com/status-im/status-protocol-go/v1"
crypto "github.com/ethereum/go-ethereum/crypto"
status "github.com/status-im/status-protocol-go"
params "github.com/status-im/status-go/params"
gonode "github.com/status-im/status-go/node"
params "github.com/status-im/status-go/params"
status "github.com/status-im/status-protocol-go"
v1 "github.com/status-im/status-protocol-go/v1"
)
type Bstatus struct {
*bridge.Config
// message fetching loop controls
fetchInterval time.Duration
fetchTimeout time.Duration
fetchDone chan bool
fetchInterval time.Duration
fetchTimeout time.Duration
fetchDone chan bool
// Whisper node settings
whisperListenPort int
@ -43,14 +43,14 @@ type Bstatus struct {
func New(cfg *bridge.Config) bridge.Bridger {
return &Bstatus{
Config: cfg,
fetchDone: make(chan bool),
Config: cfg,
fetchDone: make(chan bool),
whisperListenPort: 30303,
whisperListenAddr: "0.0.0.0",
// TODO parametrize those
whisperDataDir: "/tmp/matterbridge-status-data",
fetchTimeout: 500 * time.Millisecond,
fetchInterval: 500 * time.Millisecond,
fetchTimeout: 500 * time.Millisecond,
fetchInterval: 500 * time.Millisecond,
}
}
@ -127,6 +127,10 @@ func (b *Bstatus) Send(msg config.Message) (string, error) {
if !b.Connected() {
return "", fmt.Errorf("bridge %s not connected, dropping message %#v to bridge", b.Account, msg)
}
if skipBridgeMessage(msg) {
return "", nil
}
b.Log.Infof("=> Sending message %#v", msg)
// Use a timeout for sending messages
@ -181,8 +185,7 @@ func (b *Bstatus) fetchMessagesLoop() {
continue
}
for _, msg := range msgs {
b.Log.Infof("MSG: %#v", msg)
if b.skipMessage(msg) {
if b.skipStatusMessage(msg) {
continue
}
b.propagateMessage(msg)
@ -215,8 +218,8 @@ func (b *Bstatus) propagateMessage(msg *v1.Message) {
}
}
// skipMessage skips messages that need to be skipped
func (b *Bstatus) skipMessage(msg *v1.Message) bool {
// skipStatusMessage defines which Status messages can be ignored
func (b *Bstatus) skipStatusMessage(msg *v1.Message) bool {
// skip messages from ourselves
if isPubKeyEqual(msg.SigPubKey, &b.privateKey.PublicKey) {
return true
@ -230,6 +233,15 @@ func (b *Bstatus) skipMessage(msg *v1.Message) bool {
return false
}
// skipBridgeMessage defines which messages from the bridge should be ignored
func skipBridgeMessage(msg config.Message) bool {
// skip delete messages
if msg.Event == config.EventMsgDelete {
return true
}
return false
}
func (b *Bstatus) withListenAddr() params.Option {
if addr := b.GetString("ListenAddr"); addr != "" {
b.whisperListenAddr = addr

2
go.mod
View File

@ -89,3 +89,5 @@ require (
replace github.com/bwmarrin/discordgo v0.19.0 => github.com/matterbridge/discordgo v0.0.0-20190818085008-57c6e0fc2f40
replace github.com/ethereum/go-ethereum v1.8.27 => github.com/status-im/go-ethereum v1.8.27-status.5
go 1.13