mirror of
https://github.com/status-im/status-go.git
synced 2026-08-31 17:11:23 +00:00
* fix(waku): Avoid peer reconnection storm (#7447) * fix(waku): Avoid peer reconnection storm This commit is fixing 2 issues in waku: 1. Unnecesary disconnect/reconnects 2. dns failure at startup will silently give up - no retries - filter connection changes and forward the signal only when a change happened - dnsDiscovery: retry on failure with exponential backoff * chore: bump logos-delivery Include https://github.com/logos-messaging/logos-delivery-go/pull/1302 * chore: add usds to mandatory tokens (#7455) * feat(preferences): add secure storage for app settings (#7460) * Should replace QSettings that are stored in files refs status-im/status-app#20922 --------- Co-authored-by: Alex Jbanca <47811206+alexjba@users.noreply.github.com> Co-authored-by: Andrey Bocharnikov <andrey.bocharnikov@gmail.com>
72 lines
2.1 KiB
Go
72 lines
2.1 KiB
Go
package datasync
|
|
|
|
import (
|
|
"crypto/ecdsa"
|
|
"errors"
|
|
"sync/atomic"
|
|
|
|
"github.com/golang/protobuf/proto"
|
|
datasyncnode "github.com/status-im/mvds/node"
|
|
"github.com/status-im/mvds/protobuf"
|
|
datasynctransport "github.com/status-im/mvds/transport"
|
|
"go.uber.org/zap"
|
|
|
|
datasyncpeer "github.com/status-im/status-go/pkg/messaging/layers/reliability/datasync/peer"
|
|
)
|
|
|
|
type DataSync struct {
|
|
*datasyncnode.Node
|
|
// NodeTransport is the implementation of the datasync transport interface.
|
|
*NodeTransport
|
|
logger *zap.Logger
|
|
sendingEnabled atomic.Bool
|
|
}
|
|
|
|
func New(node *datasyncnode.Node, transport *NodeTransport, sendingEnabled bool, logger *zap.Logger) *DataSync {
|
|
d := &DataSync{Node: node, NodeTransport: transport, logger: logger}
|
|
d.sendingEnabled.Store(sendingEnabled)
|
|
return d
|
|
}
|
|
|
|
// Unwrap tries to unwrap datasync message and passes back the message to datasync in order to acknowledge any potential message and mark messages as acknowledged
|
|
func (d *DataSync) Unwrap(sender *ecdsa.PublicKey, payload []byte) (*protobuf.Payload, error) {
|
|
logger := d.logger.With(zap.String("site", "Handle"))
|
|
|
|
datasyncMessage, err := unwrap(payload)
|
|
// If it failed to decode is not a protobuf message, if it successfully decoded but body is empty, is likedly a protobuf wrapped message
|
|
if err != nil {
|
|
logger.Debug("Unwrapping datasync message failed", zap.Error(err))
|
|
return nil, err
|
|
} else if !datasyncMessage.IsValid() {
|
|
return nil, errors.New("handling non-datasync message")
|
|
} else {
|
|
logger.Debug("handling datasync message")
|
|
if d.sendingEnabled.Load() {
|
|
d.add(sender, &datasyncMessage)
|
|
}
|
|
}
|
|
|
|
return &datasyncMessage, nil
|
|
}
|
|
|
|
func (d *DataSync) Stop() {
|
|
d.Node.Stop()
|
|
}
|
|
|
|
func (d *DataSync) SetSendingEnabled(v bool) {
|
|
d.sendingEnabled.Store(v)
|
|
}
|
|
|
|
func (d *DataSync) add(publicKey *ecdsa.PublicKey, datasyncMessage *protobuf.Payload) {
|
|
packet := datasynctransport.Packet{
|
|
Sender: datasyncpeer.PublicKeyToPeerID(*publicKey),
|
|
Payload: datasyncMessage,
|
|
}
|
|
d.NodeTransport.AddPacket(packet)
|
|
}
|
|
|
|
func unwrap(payload []byte) (datasyncPayload protobuf.Payload, err error) {
|
|
err = proto.Unmarshal(payload, &datasyncPayload)
|
|
return
|
|
}
|