add basic config
This commit is contained in:
parent
15a3b710a0
commit
9da64ef251
|
@ -523,6 +523,9 @@ type ShhextConfig struct {
|
||||||
VerifyENSContractAddress string
|
VerifyENSContractAddress string
|
||||||
|
|
||||||
VerifyTransactionChainID int64
|
VerifyTransactionChainID int64
|
||||||
|
|
||||||
|
// PushNotificationServerEnabled indicates whether a push notification server should be started
|
||||||
|
PushNotificationServerEnabled bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate validates the ShhextConfig struct and returns an error if inconsistent values are found
|
// Validate validates the ShhextConfig struct and returns an error if inconsistent values are found
|
||||||
|
|
|
@ -3,7 +3,6 @@ package protocol
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
"database/sql"
|
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"os"
|
"os"
|
||||||
|
@ -26,6 +25,7 @@ import (
|
||||||
"github.com/status-im/status-go/protocol/images"
|
"github.com/status-im/status-go/protocol/images"
|
||||||
"github.com/status-im/status-go/protocol/protobuf"
|
"github.com/status-im/status-go/protocol/protobuf"
|
||||||
"github.com/status-im/status-go/protocol/push_notification_client"
|
"github.com/status-im/status-go/protocol/push_notification_client"
|
||||||
|
"github.com/status-im/status-go/protocol/push_notification_server"
|
||||||
"github.com/status-im/status-go/protocol/sqlite"
|
"github.com/status-im/status-go/protocol/sqlite"
|
||||||
"github.com/status-im/status-go/protocol/transport"
|
"github.com/status-im/status-go/protocol/transport"
|
||||||
wakutransp "github.com/status-im/status-go/protocol/transport/waku"
|
wakutransp "github.com/status-im/status-go/protocol/transport/waku"
|
||||||
|
@ -59,6 +59,7 @@ type Messenger struct {
|
||||||
processor *messageProcessor
|
processor *messageProcessor
|
||||||
handler *MessageHandler
|
handler *MessageHandler
|
||||||
pushNotificationClient *push_notification_client.Client
|
pushNotificationClient *push_notification_client.Client
|
||||||
|
pushNotificationServer *push_notification_server.Server
|
||||||
logger *zap.Logger
|
logger *zap.Logger
|
||||||
verifyTransactionClient EthClient
|
verifyTransactionClient EthClient
|
||||||
featureFlags featureFlags
|
featureFlags featureFlags
|
||||||
|
@ -102,99 +103,6 @@ type dbConfig struct {
|
||||||
dbKey string
|
dbKey string
|
||||||
}
|
}
|
||||||
|
|
||||||
type config struct {
|
|
||||||
// This needs to be exposed until we move here mailserver logic
|
|
||||||
// as otherwise the client is not notified of a new filter and
|
|
||||||
// won't be pulling messages from mailservers until it reloads the chats/filters
|
|
||||||
onNegotiatedFilters func([]*transport.Filter)
|
|
||||||
// DEPRECATED: no need to expose it
|
|
||||||
onSendContactCodeHandler func(*encryption.ProtocolMessageSpec)
|
|
||||||
|
|
||||||
// systemMessagesTranslations holds translations for system-messages
|
|
||||||
systemMessagesTranslations map[protobuf.MembershipUpdateEvent_EventType]string
|
|
||||||
// Config for the envelopes monitor
|
|
||||||
envelopesMonitorConfig *transport.EnvelopesMonitorConfig
|
|
||||||
|
|
||||||
messagesPersistenceEnabled bool
|
|
||||||
featureFlags featureFlags
|
|
||||||
|
|
||||||
// A path to a database or a database instance is required.
|
|
||||||
// The database instance has a higher priority.
|
|
||||||
dbConfig dbConfig
|
|
||||||
db *sql.DB
|
|
||||||
|
|
||||||
verifyTransactionClient EthClient
|
|
||||||
|
|
||||||
logger *zap.Logger
|
|
||||||
}
|
|
||||||
|
|
||||||
type Option func(*config) error
|
|
||||||
|
|
||||||
// WithSystemMessagesTranslations is required for Group Chats which are currently disabled.
|
|
||||||
// nolint: unused
|
|
||||||
func WithSystemMessagesTranslations(t map[protobuf.MembershipUpdateEvent_EventType]string) Option {
|
|
||||||
return func(c *config) error {
|
|
||||||
c.systemMessagesTranslations = t
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func WithOnNegotiatedFilters(h func([]*transport.Filter)) Option {
|
|
||||||
return func(c *config) error {
|
|
||||||
c.onNegotiatedFilters = h
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func WithCustomLogger(logger *zap.Logger) Option {
|
|
||||||
return func(c *config) error {
|
|
||||||
c.logger = logger
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func WithMessagesPersistenceEnabled() Option {
|
|
||||||
return func(c *config) error {
|
|
||||||
c.messagesPersistenceEnabled = true
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func WithDatabaseConfig(dbPath, dbKey string) Option {
|
|
||||||
return func(c *config) error {
|
|
||||||
c.dbConfig = dbConfig{dbPath: dbPath, dbKey: dbKey}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func WithVerifyTransactionClient(client EthClient) Option {
|
|
||||||
return func(c *config) error {
|
|
||||||
c.verifyTransactionClient = client
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func WithDatabase(db *sql.DB) Option {
|
|
||||||
return func(c *config) error {
|
|
||||||
c.db = db
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func WithDatasync() func(c *config) error {
|
|
||||||
return func(c *config) error {
|
|
||||||
c.featureFlags.datasync = true
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func WithEnvelopesMonitorConfig(emc *transport.EnvelopesMonitorConfig) Option {
|
|
||||||
return func(c *config) error {
|
|
||||||
c.envelopesMonitorConfig = emc
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func NewMessenger(
|
func NewMessenger(
|
||||||
identity *ecdsa.PrivateKey,
|
identity *ecdsa.PrivateKey,
|
||||||
node types.Node,
|
node types.Node,
|
||||||
|
@ -333,6 +241,12 @@ func NewMessenger(
|
||||||
pushNotificationClientPersistence := push_notification_client.NewPersistence(database)
|
pushNotificationClientPersistence := push_notification_client.NewPersistence(database)
|
||||||
pushNotificationClient := push_notification_client.New(pushNotificationClientPersistence)
|
pushNotificationClient := push_notification_client.New(pushNotificationClientPersistence)
|
||||||
|
|
||||||
|
var pushNotificationServer *push_notification_server.Server
|
||||||
|
if c.pushNotificationServerConfig != nil {
|
||||||
|
pushNotificationServerPersistence := push_notification_server.NewSQLitePersistence(database)
|
||||||
|
pushNotificationServer = push_notification_server.New(c.pushNotificationServerConfig, pushNotificationServerPersistence)
|
||||||
|
}
|
||||||
|
|
||||||
processor, err := newMessageProcessor(
|
processor, err := newMessageProcessor(
|
||||||
identity,
|
identity,
|
||||||
database,
|
database,
|
||||||
|
@ -357,6 +271,7 @@ func NewMessenger(
|
||||||
processor: processor,
|
processor: processor,
|
||||||
handler: handler,
|
handler: handler,
|
||||||
pushNotificationClient: pushNotificationClient,
|
pushNotificationClient: pushNotificationClient,
|
||||||
|
pushNotificationServer: pushNotificationServer,
|
||||||
featureFlags: c.featureFlags,
|
featureFlags: c.featureFlags,
|
||||||
systemMessagesTranslations: c.systemMessagesTranslations,
|
systemMessagesTranslations: c.systemMessagesTranslations,
|
||||||
allChats: make(map[string]*Chat),
|
allChats: make(map[string]*Chat),
|
||||||
|
|
|
@ -0,0 +1,112 @@
|
||||||
|
package protocol
|
||||||
|
|
||||||
|
import (
|
||||||
|
"database/sql"
|
||||||
|
"github.com/status-im/status-go/protocol/encryption"
|
||||||
|
"github.com/status-im/status-go/protocol/protobuf"
|
||||||
|
"github.com/status-im/status-go/protocol/push_notification_server"
|
||||||
|
"github.com/status-im/status-go/protocol/transport"
|
||||||
|
"go.uber.org/zap"
|
||||||
|
)
|
||||||
|
|
||||||
|
type config struct {
|
||||||
|
// This needs to be exposed until we move here mailserver logic
|
||||||
|
// as otherwise the client is not notified of a new filter and
|
||||||
|
// won't be pulling messages from mailservers until it reloads the chats/filters
|
||||||
|
onNegotiatedFilters func([]*transport.Filter)
|
||||||
|
// DEPRECATED: no need to expose it
|
||||||
|
onSendContactCodeHandler func(*encryption.ProtocolMessageSpec)
|
||||||
|
|
||||||
|
// systemMessagesTranslations holds translations for system-messages
|
||||||
|
systemMessagesTranslations map[protobuf.MembershipUpdateEvent_EventType]string
|
||||||
|
// Config for the envelopes monitor
|
||||||
|
envelopesMonitorConfig *transport.EnvelopesMonitorConfig
|
||||||
|
|
||||||
|
messagesPersistenceEnabled bool
|
||||||
|
featureFlags featureFlags
|
||||||
|
|
||||||
|
// A path to a database or a database instance is required.
|
||||||
|
// The database instance has a higher priority.
|
||||||
|
dbConfig dbConfig
|
||||||
|
db *sql.DB
|
||||||
|
|
||||||
|
verifyTransactionClient EthClient
|
||||||
|
|
||||||
|
pushNotificationServerConfig *push_notification_server.Config
|
||||||
|
|
||||||
|
logger *zap.Logger
|
||||||
|
}
|
||||||
|
|
||||||
|
type Option func(*config) error
|
||||||
|
|
||||||
|
// WithSystemMessagesTranslations is required for Group Chats which are currently disabled.
|
||||||
|
// nolint: unused
|
||||||
|
func WithSystemMessagesTranslations(t map[protobuf.MembershipUpdateEvent_EventType]string) Option {
|
||||||
|
return func(c *config) error {
|
||||||
|
c.systemMessagesTranslations = t
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithOnNegotiatedFilters(h func([]*transport.Filter)) Option {
|
||||||
|
return func(c *config) error {
|
||||||
|
c.onNegotiatedFilters = h
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithCustomLogger(logger *zap.Logger) Option {
|
||||||
|
return func(c *config) error {
|
||||||
|
c.logger = logger
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithMessagesPersistenceEnabled() Option {
|
||||||
|
return func(c *config) error {
|
||||||
|
c.messagesPersistenceEnabled = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithDatabaseConfig(dbPath, dbKey string) Option {
|
||||||
|
return func(c *config) error {
|
||||||
|
c.dbConfig = dbConfig{dbPath: dbPath, dbKey: dbKey}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithVerifyTransactionClient(client EthClient) Option {
|
||||||
|
return func(c *config) error {
|
||||||
|
c.verifyTransactionClient = client
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithDatabase(db *sql.DB) Option {
|
||||||
|
return func(c *config) error {
|
||||||
|
c.db = db
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithPushNotificationServerConfig(pushNotificationServerConfig *push_notification_server.Config) Option {
|
||||||
|
return func(c *config) error {
|
||||||
|
c.pushNotificationServerConfig = pushNotificationServerConfig
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithDatasync() func(c *config) error {
|
||||||
|
return func(c *config) error {
|
||||||
|
c.featureFlags.datasync = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WithEnvelopesMonitorConfig(emc *transport.EnvelopesMonitorConfig) Option {
|
||||||
|
return func(c *config) error {
|
||||||
|
c.envelopesMonitorConfig = emc
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,6 +9,7 @@ import (
|
||||||
|
|
||||||
"github.com/status-im/status-go/eth-node/crypto/ecies"
|
"github.com/status-im/status-go/eth-node/crypto/ecies"
|
||||||
"github.com/status-im/status-go/protocol/protobuf"
|
"github.com/status-im/status-go/protocol/protobuf"
|
||||||
|
"go.uber.org/zap"
|
||||||
)
|
)
|
||||||
|
|
||||||
const encryptedPayloadKeyLength = 16
|
const encryptedPayloadKeyLength = 16
|
||||||
|
@ -19,6 +20,8 @@ type Config struct {
|
||||||
Identity *ecdsa.PrivateKey
|
Identity *ecdsa.PrivateKey
|
||||||
// GorushUrl is the url for the gorush service
|
// GorushUrl is the url for the gorush service
|
||||||
GorushURL string
|
GorushURL string
|
||||||
|
|
||||||
|
Logger *zap.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
type Server struct {
|
type Server struct {
|
||||||
|
|
|
@ -37,6 +37,9 @@ type StatusMessage struct {
|
||||||
// Hash is the transport layer hash
|
// Hash is the transport layer hash
|
||||||
Hash []byte `json:"-"`
|
Hash []byte `json:"-"`
|
||||||
|
|
||||||
|
// Dst is the targeted public key
|
||||||
|
Dst *ecdsa.PublicKey
|
||||||
|
|
||||||
// TransportLayerSigPubKey contains the public key provided by the transport layer
|
// TransportLayerSigPubKey contains the public key provided by the transport layer
|
||||||
TransportLayerSigPubKey *ecdsa.PublicKey `json:"-"`
|
TransportLayerSigPubKey *ecdsa.PublicKey `json:"-"`
|
||||||
// ApplicationMetadataLayerPubKey contains the public key provided by the application metadata layer
|
// ApplicationMetadataLayerPubKey contains the public key provided by the application metadata layer
|
||||||
|
@ -87,6 +90,14 @@ func (m *StatusMessage) HandleTransport(shhMessage *types.Message) error {
|
||||||
m.TransportLayerSigPubKey = publicKey
|
m.TransportLayerSigPubKey = publicKey
|
||||||
m.TransportPayload = shhMessage.Payload
|
m.TransportPayload = shhMessage.Payload
|
||||||
|
|
||||||
|
if shhMessage.Dst != nil {
|
||||||
|
publicKey, err := crypto.UnmarshalPubkey(shhMessage.Dst)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
m.Dst = publicKey
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,6 +33,7 @@ import (
|
||||||
coretypes "github.com/status-im/status-go/eth-node/core/types"
|
coretypes "github.com/status-im/status-go/eth-node/core/types"
|
||||||
"github.com/status-im/status-go/eth-node/types"
|
"github.com/status-im/status-go/eth-node/types"
|
||||||
"github.com/status-im/status-go/protocol"
|
"github.com/status-im/status-go/protocol"
|
||||||
|
"github.com/status-im/status-go/protocol/push_notification_server"
|
||||||
"github.com/status-im/status-go/protocol/transport"
|
"github.com/status-im/status-go/protocol/transport"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -144,7 +145,7 @@ func (s *Service) InitProtocol(identity *ecdsa.PrivateKey, db *sql.DB, logger *z
|
||||||
EnvelopeEventsHandler: EnvelopeSignalHandler{},
|
EnvelopeEventsHandler: EnvelopeSignalHandler{},
|
||||||
Logger: logger,
|
Logger: logger,
|
||||||
}
|
}
|
||||||
options := buildMessengerOptions(s.config, db, envelopesMonitorConfig, logger)
|
options := buildMessengerOptions(s.config, identity, db, envelopesMonitorConfig, logger)
|
||||||
|
|
||||||
messenger, err := protocol.NewMessenger(
|
messenger, err := protocol.NewMessenger(
|
||||||
identity,
|
identity,
|
||||||
|
@ -439,6 +440,7 @@ func onNegotiatedFilters(filters []*transport.Filter) {
|
||||||
|
|
||||||
func buildMessengerOptions(
|
func buildMessengerOptions(
|
||||||
config params.ShhextConfig,
|
config params.ShhextConfig,
|
||||||
|
identity *ecdsa.PrivateKey,
|
||||||
db *sql.DB,
|
db *sql.DB,
|
||||||
envelopesMonitorConfig *transport.EnvelopesMonitorConfig,
|
envelopesMonitorConfig *transport.EnvelopesMonitorConfig,
|
||||||
logger *zap.Logger,
|
logger *zap.Logger,
|
||||||
|
@ -454,6 +456,16 @@ func buildMessengerOptions(
|
||||||
options = append(options, protocol.WithDatasync())
|
options = append(options, protocol.WithDatasync())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// For now build with default/hardcoded options.
|
||||||
|
if config.PushNotificationServerEnabled {
|
||||||
|
config := &push_notification_server.Config{
|
||||||
|
Identity: identity,
|
||||||
|
Logger: logger,
|
||||||
|
GorushURL: "https://gorush.status.im",
|
||||||
|
}
|
||||||
|
options = append(options, protocol.WithPushNotificationServerConfig(config))
|
||||||
|
}
|
||||||
|
|
||||||
if config.VerifyTransactionURL != "" {
|
if config.VerifyTransactionURL != "" {
|
||||||
client := &verifyTransactionClient{
|
client := &verifyTransactionClient{
|
||||||
url: config.VerifyTransactionURL,
|
url: config.VerifyTransactionURL,
|
||||||
|
|
Loading…
Reference in New Issue