Enabled push notifications by default and add fleet

This commit is contained in:
Andrea Maria Piana 2020-08-20 11:05:39 +02:00
parent 4e9928ab5f
commit 401d18e558
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
22 changed files with 349 additions and 114 deletions

View File

@ -1 +1 @@
0.57.2 0.58.0

View File

@ -511,8 +511,13 @@ func (b *GethStatusBackend) startNode(config *params.NodeConfig) (err error) {
} }
}() }()
b.log.Debug("starting node with config", "config", config)
// Update config with some defaults. // Update config with some defaults.
config.UpdateWithMobileDefaults() if err := config.UpdateWithDefaults(); err != nil {
return err
}
b.log.Debug("updated config with defaults", "config", config)
// Start by validating configuration // Start by validating configuration
if err := config.Validate(); err != nil { if err := config.Validate(); err != nil {

View File

@ -13,6 +13,8 @@
// 0006_appearance.up.sql (67B) // 0006_appearance.up.sql (67B)
// 0007_enable_waku_default.up.sql (38B) // 0007_enable_waku_default.up.sql (38B)
// 0008_add_push_notifications.up.sql (349B) // 0008_add_push_notifications.up.sql (349B)
// 0009_enable_sending_push_notifications.down.sql (49B)
// 0009_enable_sending_push_notifications.up.sql (49B)
// doc.go (74B) // doc.go (74B)
package migrations package migrations
@ -337,11 +339,51 @@ func _0008_add_push_notificationsUpSql() (*asset, error) {
return nil, err return nil, err
} }
info := bindataFileInfo{name: "0008_add_push_notifications.up.sql", size: 349, mode: os.FileMode(0644), modTime: time.Unix(1595840384, 0)} info := bindataFileInfo{name: "0008_add_push_notifications.up.sql", size: 349, mode: os.FileMode(0644), modTime: time.Unix(1596198373, 0)}
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x5a, 0x0, 0xbf, 0xd0, 0xdd, 0xcd, 0x73, 0xe0, 0x7c, 0x56, 0xef, 0xdc, 0x57, 0x61, 0x94, 0x64, 0x70, 0xb9, 0xfa, 0xa1, 0x2a, 0x36, 0xc, 0x2f, 0xf8, 0x95, 0xa, 0x57, 0x3e, 0x7a, 0xd7, 0x12}} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x5a, 0x0, 0xbf, 0xd0, 0xdd, 0xcd, 0x73, 0xe0, 0x7c, 0x56, 0xef, 0xdc, 0x57, 0x61, 0x94, 0x64, 0x70, 0xb9, 0xfa, 0xa1, 0x2a, 0x36, 0xc, 0x2f, 0xf8, 0x95, 0xa, 0x57, 0x3e, 0x7a, 0xd7, 0x12}}
return a, nil return a, nil
} }
var __0009_enable_sending_push_notificationsDownSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x0a\x0d\x70\x71\x0c\x71\x55\x28\x4e\x2d\x29\xc9\xcc\x4b\x2f\x56\x08\x76\x0d\x51\x28\x4e\xcd\x4b\x89\x2f\x28\x2d\xce\x88\xcf\xcb\x2f\xc9\x4c\xcb\x4c\x4e\x2c\xc9\xcc\xcf\x2b\x56\xb0\x55\x30\xb0\xe6\x02\x04\x00\x00\xff\xff\x57\x2d\xdb\x16\x31\x00\x00\x00")
func _0009_enable_sending_push_notificationsDownSqlBytes() ([]byte, error) {
return bindataRead(
__0009_enable_sending_push_notificationsDownSql,
"0009_enable_sending_push_notifications.down.sql",
)
}
func _0009_enable_sending_push_notificationsDownSql() (*asset, error) {
bytes, err := _0009_enable_sending_push_notificationsDownSqlBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "0009_enable_sending_push_notifications.down.sql", size: 49, mode: os.FileMode(0644), modTime: time.Unix(1597918101, 0)}
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xe9, 0xae, 0x1b, 0x41, 0xcb, 0x9c, 0x2c, 0x93, 0xc6, 0x2a, 0x77, 0x3, 0xb9, 0x51, 0xe0, 0x68, 0x68, 0x0, 0xf7, 0x5b, 0xb3, 0x1e, 0x94, 0x44, 0xba, 0x9c, 0xd0, 0x3b, 0x80, 0x21, 0x6f, 0xb5}}
return a, nil
}
var __0009_enable_sending_push_notificationsUpSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x0a\x0d\x70\x71\x0c\x71\x55\x28\x4e\x2d\x29\xc9\xcc\x4b\x2f\x56\x08\x76\x0d\x51\x28\x4e\xcd\x4b\x89\x2f\x28\x2d\xce\x88\xcf\xcb\x2f\xc9\x4c\xcb\x4c\x4e\x2c\xc9\xcc\xcf\x2b\x56\xb0\x55\x30\xb4\xe6\x02\x04\x00\x00\xff\xff\x60\x47\x19\x17\x31\x00\x00\x00")
func _0009_enable_sending_push_notificationsUpSqlBytes() ([]byte, error) {
return bindataRead(
__0009_enable_sending_push_notificationsUpSql,
"0009_enable_sending_push_notifications.up.sql",
)
}
func _0009_enable_sending_push_notificationsUpSql() (*asset, error) {
bytes, err := _0009_enable_sending_push_notificationsUpSqlBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "0009_enable_sending_push_notifications.up.sql", size: 49, mode: os.FileMode(0644), modTime: time.Unix(1597918090, 0)}
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x1b, 0x80, 0xe4, 0x9c, 0xc8, 0xb8, 0xd5, 0xef, 0xce, 0x74, 0x9b, 0x7b, 0xdd, 0xa, 0x99, 0x1e, 0xef, 0x7f, 0xb8, 0x99, 0x84, 0x4, 0x0, 0x6b, 0x1d, 0x2c, 0xa, 0xf8, 0x2c, 0x4f, 0xb5, 0x44}}
return a, nil
}
var _docGo = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x2c\xc9\xb1\x0d\xc4\x20\x0c\x05\xd0\x9e\x29\xfe\x02\xd8\xfd\x6d\xe3\x4b\xac\x2f\x44\x82\x09\x78\x7f\xa5\x49\xfd\xa6\x1d\xdd\xe8\xd8\xcf\x55\x8a\x2a\xe3\x47\x1f\xbe\x2c\x1d\x8c\xfa\x6f\xe3\xb4\x34\xd4\xd9\x89\xbb\x71\x59\xb6\x18\x1b\x35\x20\xa2\x9f\x0a\x03\xa2\xe5\x0d\x00\x00\xff\xff\x60\xcd\x06\xbe\x4a\x00\x00\x00") var _docGo = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x2c\xc9\xb1\x0d\xc4\x20\x0c\x05\xd0\x9e\x29\xfe\x02\xd8\xfd\x6d\xe3\x4b\xac\x2f\x44\x82\x09\x78\x7f\xa5\x49\xfd\xa6\x1d\xdd\xe8\xd8\xcf\x55\x8a\x2a\xe3\x47\x1f\xbe\x2c\x1d\x8c\xfa\x6f\xe3\xb4\x34\xd4\xd9\x89\xbb\x71\x59\xb6\x18\x1b\x35\x20\xa2\x9f\x0a\x03\xa2\xe5\x0d\x00\x00\xff\xff\x60\xcd\x06\xbe\x4a\x00\x00\x00")
func docGoBytes() ([]byte, error) { func docGoBytes() ([]byte, error) {
@ -479,6 +521,10 @@ var _bindata = map[string]func() (*asset, error){
"0008_add_push_notifications.up.sql": _0008_add_push_notificationsUpSql, "0008_add_push_notifications.up.sql": _0008_add_push_notificationsUpSql,
"0009_enable_sending_push_notifications.down.sql": _0009_enable_sending_push_notificationsDownSql,
"0009_enable_sending_push_notifications.up.sql": _0009_enable_sending_push_notificationsUpSql,
"doc.go": docGo, "doc.go": docGo,
} }
@ -523,20 +569,22 @@ type bintree struct {
} }
var _bintree = &bintree{nil, map[string]*bintree{ var _bintree = &bintree{nil, map[string]*bintree{
"0001_app.down.sql": &bintree{_0001_appDownSql, map[string]*bintree{}}, "0001_app.down.sql": &bintree{_0001_appDownSql, map[string]*bintree{}},
"0001_app.up.sql": &bintree{_0001_appUpSql, map[string]*bintree{}}, "0001_app.up.sql": &bintree{_0001_appUpSql, map[string]*bintree{}},
"0002_tokens.down.sql": &bintree{_0002_tokensDownSql, map[string]*bintree{}}, "0002_tokens.down.sql": &bintree{_0002_tokensDownSql, map[string]*bintree{}},
"0002_tokens.up.sql": &bintree{_0002_tokensUpSql, map[string]*bintree{}}, "0002_tokens.up.sql": &bintree{_0002_tokensUpSql, map[string]*bintree{}},
"0003_settings.down.sql": &bintree{_0003_settingsDownSql, map[string]*bintree{}}, "0003_settings.down.sql": &bintree{_0003_settingsDownSql, map[string]*bintree{}},
"0003_settings.up.sql": &bintree{_0003_settingsUpSql, map[string]*bintree{}}, "0003_settings.up.sql": &bintree{_0003_settingsUpSql, map[string]*bintree{}},
"0004_pending_stickers.down.sql": &bintree{_0004_pending_stickersDownSql, map[string]*bintree{}}, "0004_pending_stickers.down.sql": &bintree{_0004_pending_stickersDownSql, map[string]*bintree{}},
"0004_pending_stickers.up.sql": &bintree{_0004_pending_stickersUpSql, map[string]*bintree{}}, "0004_pending_stickers.up.sql": &bintree{_0004_pending_stickersUpSql, map[string]*bintree{}},
"0005_waku_mode.down.sql": &bintree{_0005_waku_modeDownSql, map[string]*bintree{}}, "0005_waku_mode.down.sql": &bintree{_0005_waku_modeDownSql, map[string]*bintree{}},
"0005_waku_mode.up.sql": &bintree{_0005_waku_modeUpSql, map[string]*bintree{}}, "0005_waku_mode.up.sql": &bintree{_0005_waku_modeUpSql, map[string]*bintree{}},
"0006_appearance.up.sql": &bintree{_0006_appearanceUpSql, map[string]*bintree{}}, "0006_appearance.up.sql": &bintree{_0006_appearanceUpSql, map[string]*bintree{}},
"0007_enable_waku_default.up.sql": &bintree{_0007_enable_waku_defaultUpSql, map[string]*bintree{}}, "0007_enable_waku_default.up.sql": &bintree{_0007_enable_waku_defaultUpSql, map[string]*bintree{}},
"0008_add_push_notifications.up.sql": &bintree{_0008_add_push_notificationsUpSql, map[string]*bintree{}}, "0008_add_push_notifications.up.sql": &bintree{_0008_add_push_notificationsUpSql, map[string]*bintree{}},
"doc.go": &bintree{docGo, map[string]*bintree{}}, "0009_enable_sending_push_notifications.down.sql": &bintree{_0009_enable_sending_push_notificationsDownSql, map[string]*bintree{}},
"0009_enable_sending_push_notifications.up.sql": &bintree{_0009_enable_sending_push_notificationsUpSql, map[string]*bintree{}},
"doc.go": &bintree{docGo, map[string]*bintree{}},
}} }}
// RestoreAsset restores an asset under the given directory. // RestoreAsset restores an asset under the given directory.

View File

@ -0,0 +1 @@
UPDATE settings SET send_push_notifications = 0;

View File

@ -0,0 +1 @@
UPDATE settings SET send_push_notifications = 1;

View File

@ -155,52 +155,6 @@ func main() {
return return
} }
if config.PushNotificationServerConfig.Enabled {
if config.NodeKey == "" {
logger.Error("node key needs to be set if running a push notification server")
return
}
identity, err := crypto.HexToECDSA(config.NodeKey)
if err != nil {
logger.Error("node key is invalid", "error", err)
return
}
// Generate installationID from public key, so it's always the same
installationID, err := uuid.FromBytes(crypto.CompressPubkey(&identity.PublicKey)[:16])
if err != nil {
logger.Error("cannot create installation id", "error", err)
return
}
db, err := appdatabase.InitializeDB(config.DataDir+"/"+installationID.String()+".db", "")
if err != nil {
logger.Error("failed to initialize app db", "error", err)
return
}
options := []protocol.Option{
protocol.WithPushNotifications(),
protocol.WithPushNotificationServerConfig(&config.PushNotificationServerConfig),
protocol.WithDatabase(db),
}
messenger, err := protocol.NewMessenger(identity, gethbridge.NewNodeBridge(backend.StatusNode().GethNode()), installationID.String(), options...)
if err != nil {
logger.Error("failed to create messenger", "error", err)
return
}
// This will start the push notification server as well as
// the config is set to Enabled
err = messenger.Start()
if err != nil {
logger.Error("failed to start messenger", "error", err)
return
}
}
err = sdnotify.Ready() err = sdnotify.Ready()
if err == sdnotify.ErrSdNotifyNoSocket { if err == sdnotify.ErrSdNotifyNoSocket {
logger.Debug("sd_notify socket not available") logger.Debug("sd_notify socket not available")
@ -242,6 +196,59 @@ func main() {
os.Exit(exitCode) os.Exit(exitCode)
} }
if config.PushNotificationServerConfig.Enabled {
if config.NodeKey == "" {
logger.Error("node key needs to be set if running a push notification server")
return
}
identity, err := crypto.HexToECDSA(config.NodeKey)
if err != nil {
logger.Error("node key is invalid", "error", err)
return
}
// Generate installationID from public key, so it's always the same
installationID, err := uuid.FromBytes(crypto.CompressPubkey(&identity.PublicKey)[:16])
if err != nil {
logger.Error("cannot create installation id", "error", err)
return
}
db, err := appdatabase.InitializeDB(config.DataDir+"/"+installationID.String()+".db", "")
if err != nil {
logger.Error("failed to initialize app db", "error", err)
return
}
options := []protocol.Option{
protocol.WithPushNotifications(),
protocol.WithPushNotificationServerConfig(&config.PushNotificationServerConfig),
protocol.WithDatabase(db),
}
messenger, err := protocol.NewMessenger(identity, gethbridge.NewNodeBridge(backend.StatusNode().GethNode()), installationID.String(), options...)
if err != nil {
logger.Error("failed to create messenger", "error", err)
return
}
err = messenger.Init()
if err != nil {
logger.Error("failed to init messenger", "error", err)
return
}
// This will start the push notification server as well as
// the config is set to Enabled
err = messenger.Start()
if err != nil {
logger.Error("failed to start messenger", "error", err)
return
}
go retrieveMessagesLoop(messenger, 300*time.Millisecond, interruptCh)
}
gethNode := backend.StatusNode().GethNode() gethNode := backend.StatusNode().GethNode()
if gethNode != nil { if gethNode != nil {
// wait till node has been stopped // wait till node has been stopped
@ -383,3 +390,22 @@ func haltOnInterruptSignal(statusNode *node.StatusNode) <-chan struct{} {
}() }()
return interruptCh return interruptCh
} }
// retrieveMessagesLoop fetches messages from a messenger so that they are processed
func retrieveMessagesLoop(messenger *protocol.Messenger, tick time.Duration, cancel <-chan struct{}) {
ticker := time.NewTicker(tick)
defer ticker.Stop()
for {
select {
case <-ticker.C:
_, err := messenger.RetrieveAll()
if err != nil {
logger.Error("failed to retrieve raw messages", "err", err)
continue
}
case <-cancel:
return
}
}
}

View File

@ -23,6 +23,17 @@
"enode://8a64b3c349a2e0ef4a32ea49609ed6eb3364be1110253c20adc17a3cebbc39a219e5d3e13b151c0eee5d8e0f9a8ba2cd026014e67b41a4ab7d1d5dd67ca27427@178.128.142.94:443", "enode://8a64b3c349a2e0ef4a32ea49609ed6eb3364be1110253c20adc17a3cebbc39a219e5d3e13b151c0eee5d8e0f9a8ba2cd026014e67b41a4ab7d1d5dd67ca27427@178.128.142.94:443",
"enode://44160e22e8b42bd32a06c1532165fa9e096eebedd7fa6d6e5f8bbef0440bc4a4591fe3651be68193a7ec029021cdb496cfe1d7f9f1dc69eb99226e6f39a7a5d4@35.225.221.245:443" "enode://44160e22e8b42bd32a06c1532165fa9e096eebedd7fa6d6e5f8bbef0440bc4a4591fe3651be68193a7ec029021cdb496cfe1d7f9f1dc69eb99226e6f39a7a5d4@35.225.221.245:443"
], ],
"PushNotificationsServers": [
"04606ae04a71e5db868a722c77a21c8244ae38f1bd6e81687cc6cfe88a3063fa1c245692232f64f45bd5408fed5133eab8ed78049332b04f9c110eac7f71c1b429",
"04c42f368a23fa98ee546fd247220759062323249ef657d26d357a777443aec04db1b29a3a22ef3e7c548e18493ddaf51a31b0aed6079bd6ebe5ae838fcfaf3a49",
"04ee2b53b0ace9692167a410514bca3024695dbf0e1a68e1dff9716da620efb195f04a4b9e873fb9b74ac84de801106c465b8e2b6c4f0d93b8749d1578bfcaf03e",
"042c8de3cbb27a3d30cbb5b3e003bc722b126f5aef82e2052aaef032ca94e0c7ad219e533ba88c70585ebd802de206693255335b100307645ab5170e88620d2a81",
"047aa648d6e855950b2e3d3bf220c496e0cae4adfddef3e1e6062e6b177aec93bc6cdcf1282cb40d1656932ebfdd565729da440368d7c4da7dbd4d004b1ac02bf8",
"0430211cbd81c25f07b03a0196d56e6ce4604bb13db773ff1c0ea2253547fafd6c06eae6ad3533e2ba39d59564cfbdbb5e2ce7c137a5ebb85e99dcfc7a75f99f55",
"04e85f1d4209f2f99da801af18db8716e584a28ad0bdc47fbdcd8f26af74dbd97fc279144680553ec7cd9092afe683ddea1e0f9fc571ebcb4b1d857c03a088853d",
"048a64b3c349a2e0ef4a32ea49609ed6eb3364be1110253c20adc17a3cebbc39a219e5d3e13b151c0eee5d8e0f9a8ba2cd026014e67b41a4ab7d1d5dd67ca27427",
"0444160e22e8b42bd32a06c1532165fa9e096eebedd7fa6d6e5f8bbef0440bc4a4591fe3651be68193a7ec029021cdb496cfe1d7f9f1dc69eb99226e6f39a7a5d4"
],
"StaticNodes": [ "StaticNodes": [
"enode://b77bffc29e2592f30180311dd81204ab845e5f78953b5ba0587c6631be9c0862963dea5eb64c90617cf0efd75308e22a42e30bc4eb3cd1bbddbd1da38ff6483e@47.75.10.177:443", "enode://b77bffc29e2592f30180311dd81204ab845e5f78953b5ba0587c6631be9c0862963dea5eb64c90617cf0efd75308e22a42e30bc4eb3cd1bbddbd1da38ff6483e@47.75.10.177:443",
"enode://a8bddfa24e1e92a82609b390766faa56cf7a5eef85b22a2b51e79b333c8aaeec84f7b4267e432edd1cf45b63a3ad0fc7d6c3a16f046aa6bc07ebe50e80b63b8c@178.128.141.249:443" "enode://a8bddfa24e1e92a82609b390766faa56cf7a5eef85b22a2b51e79b333c8aaeec84f7b4267e432edd1cf45b63a3ad0fc7d6c3a16f046aa6bc07ebe50e80b63b8c@178.128.141.249:443"

View File

@ -14,6 +14,12 @@
"enode://69f72baa7f1722d111a8c9c68c39a31430e9d567695f6108f31ccb6cd8f0adff4991e7fdca8fa770e75bc8a511a87d24690cbc80e008175f40c157d6f6788d48@206.189.240.16:443", "enode://69f72baa7f1722d111a8c9c68c39a31430e9d567695f6108f31ccb6cd8f0adff4991e7fdca8fa770e75bc8a511a87d24690cbc80e008175f40c157d6f6788d48@206.189.240.16:443",
"enode://e4fc10c1f65c8aed83ac26bc1bfb21a45cc1a8550a58077c8d2de2a0e0cd18e40fd40f7e6f7d02dc6cd06982b014ce88d6e468725ffe2c138e958788d0002a7f@35.239.193.41:443" "enode://e4fc10c1f65c8aed83ac26bc1bfb21a45cc1a8550a58077c8d2de2a0e0cd18e40fd40f7e6f7d02dc6cd06982b014ce88d6e468725ffe2c138e958788d0002a7f@35.239.193.41:443"
], ],
"PushNotificationsServers": [
"04b74859176c9751d314aeeffc26ec9f866a412752e7ddec91b19018a18e7cca8d637cfe2cedcb972f8eb64d816fbd5b4e89c7e8c7fd7df8a1329fa43db80b0bfe",
"0469f72baa7f1722d111a8c9c68c39a31430e9d567695f6108f31ccb6cd8f0adff4991e7fdca8fa770e75bc8a511a87d24690cbc80e008175f40c157d6f6788d48",
"04e4fc10c1f65c8aed83ac26bc1bfb21a45cc1a8550a58077c8d2de2a0e0cd18e40fd40f7e6f7d02dc6cd06982b014ce88d6e468725ffe2c138e958788d0002a7f"
],
"StaticNodes": [ "StaticNodes": [
"enode://914c0b30f27bab30c1dfd31dad7652a46fda9370542aee1b062498b1345ee0913614b8b9e3e84622e84a7203c5858ae1d9819f63aece13ee668e4f6668063989@167.99.19.148:443", "enode://914c0b30f27bab30c1dfd31dad7652a46fda9370542aee1b062498b1345ee0913614b8b9e3e84622e84a7203c5858ae1d9819f63aece13ee668e4f6668063989@167.99.19.148:443",
"enode://2d897c6e846949f9dcf10279f00e9b8325c18fe7fa52d658520ad7be9607c83008b42b06aefd97cfe1fdab571f33a2a9383ff97c5909ed51f63300834913237e@35.192.0.86:443" "enode://2d897c6e846949f9dcf10279f00e9b8325c18fe7fa52d658520ad7be9607c83008b42b06aefd97cfe1fdab571f33a2a9383ff97c5909ed51f63300834913237e@35.192.0.86:443"

View File

@ -14,6 +14,11 @@
"enode://e4865fe6c2a9c1a563a6447990d8e9ce672644ae3e08277ce38ec1f1b690eef6320c07a5d60c3b629f5d4494f93d6b86a745a0bf64ab295bbf6579017adc6ed8@206.189.243.161:443", "enode://e4865fe6c2a9c1a563a6447990d8e9ce672644ae3e08277ce38ec1f1b690eef6320c07a5d60c3b629f5d4494f93d6b86a745a0bf64ab295bbf6579017adc6ed8@206.189.243.161:443",
"enode://707e57453acd3e488c44b9d0e17975371e2f8fb67525eae5baca9b9c8e06c86cde7c794a6c2e36203bf9f56cae8b0e50f3b33c4c2b694a7baeea1754464ce4e3@35.192.229.172:443" "enode://707e57453acd3e488c44b9d0e17975371e2f8fb67525eae5baca9b9c8e06c86cde7c794a6c2e36203bf9f56cae8b0e50f3b33c4c2b694a7baeea1754464ce4e3@35.192.229.172:443"
], ],
"PushNotificationsServers": [
"04619dbb5dda12e85bf0eb5db40fb3de625609043242737c0e975f7dfd659d85dc6d9a84f9461a728c5ab68c072fed38ca6a53917ca24b8e93cc27bdef3a1e79ac",
"04e4865fe6c2a9c1a563a6447990d8e9ce672644ae3e08277ce38ec1f1b690eef6320c07a5d60c3b629f5d4494f93d6b86a745a0bf64ab295bbf6579017adc6ed8",
"04707e57453acd3e488c44b9d0e17975371e2f8fb67525eae5baca9b9c8e06c86cde7c794a6c2e36203bf9f56cae8b0e50f3b33c4c2b694a7baeea1754464ce4e3"
],
"StaticNodes": [ "StaticNodes": [
"enode://ad38f94030a846cc7005b7a1f3b6b01bf4ef59d34e8d3d6f4d12df23d14ba8656702a435d34cf4df3b412c0c1923df5adcce8461321a0d8ffb9435b26e572c2a@47.52.255.194:443", "enode://ad38f94030a846cc7005b7a1f3b6b01bf4ef59d34e8d3d6f4d12df23d14ba8656702a435d34cf4df3b412c0c1923df5adcce8461321a0d8ffb9435b26e572c2a@47.52.255.194:443",
"enode://1d193635e015918fb85bbaf774863d12f65d70c6977506187ef04420d74ec06c9e8f0dcb57ea042f85df87433dab17a1260ed8dde1bdf9d6d5d2de4b7bf8e993@206.189.243.163:443" "enode://1d193635e015918fb85bbaf774863d12f65d70c6977506187ef04420d74ec06c9e8f0dcb57ea042f85df87433dab17a1260ed8dde1bdf9d6d5d2de4b7bf8e993@206.189.243.163:443"

View File

@ -449,6 +449,7 @@ func createWakuService(ctx *node.ServiceContext, wakuCfg *params.WakuConfig, clu
cfg := &waku.Config{ cfg := &waku.Config{
MaxMessageSize: wakucommon.DefaultMaxMessageSize, MaxMessageSize: wakucommon.DefaultMaxMessageSize,
BloomFilterMode: wakuCfg.BloomFilterMode, BloomFilterMode: wakuCfg.BloomFilterMode,
FullNode: wakuCfg.FullNode,
MinimumAcceptedPoW: params.WakuMinimumPoW, MinimumAcceptedPoW: params.WakuMinimumPoW,
} }

View File

@ -1,6 +1,8 @@
package params package params
import ( import (
"crypto/ecdsa"
"encoding/hex"
"encoding/json" "encoding/json"
"errors" "errors"
"fmt" "fmt"
@ -145,6 +147,9 @@ type WakuConfig struct {
// LightClient should be true if the node should start with an empty bloom filter and not forward messages from other nodes // LightClient should be true if the node should start with an empty bloom filter and not forward messages from other nodes
LightClient bool LightClient bool
// FullNode should be true if waku should always acta as a full node
FullNode bool
// EnableMailServer is mode when node is capable of delivering expired messages on demand // EnableMailServer is mode when node is capable of delivering expired messages on demand
EnableMailServer bool EnableMailServer bool
@ -246,6 +251,9 @@ type ClusterConfig struct {
// TrustedMailServers is a list of verified and trusted Mail Server nodes. // TrustedMailServers is a list of verified and trusted Mail Server nodes.
TrustedMailServers []string TrustedMailServers []string
// PushNotificationsServers is a list of default push notification servers.
PushNotificationsServers []string
// RendezvousNodes is a list rendezvous discovery nodes. // RendezvousNodes is a list rendezvous discovery nodes.
RendezvousNodes []string RendezvousNodes []string
} }
@ -528,6 +536,9 @@ type ShhextConfig struct {
VerifyENSContractAddress string VerifyENSContractAddress string
VerifyTransactionChainID int64 VerifyTransactionChainID int64
// DefaultPushNotificationsServers is the default-status run push notification servers
DefaultPushNotificationsServers []*ecdsa.PublicKey
} }
// 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
@ -606,9 +617,41 @@ func NewNodeConfigWithDefaults(dataDir string, networkID uint64, opts ...Option)
return c, nil return c, nil
} }
// UpdateWithMobileDefaults updates config with missing default values func (c *NodeConfig) setDefaultPushNotificationsServers() error {
// tailored for the mobile nodes. // If empty load defaults from the fleet
func (c *NodeConfig) UpdateWithMobileDefaults() { if len(c.ClusterConfig.PushNotificationsServers) == 0 {
log.Debug("empty push notification servers, setting", "fleet", c.ClusterConfig.Fleet)
defaultConfig := &NodeConfig{}
err := loadConfigFromAsset(fmt.Sprintf("../config/cli/fleet-%s.json", c.ClusterConfig.Fleet), defaultConfig)
if err != nil {
return err
}
c.ClusterConfig.PushNotificationsServers = defaultConfig.ClusterConfig.PushNotificationsServers
}
// If empty set the default servers
if len(c.ShhextConfig.DefaultPushNotificationsServers) == 0 {
log.Debug("setting default push notification servers", "cluster servers", c.ClusterConfig.PushNotificationsServers)
for _, pk := range c.ClusterConfig.PushNotificationsServers {
keyBytes, err := hex.DecodeString(pk)
if err != nil {
return err
}
key, err := crypto.UnmarshalPubkey(keyBytes)
if err != nil {
return err
}
c.ShhextConfig.DefaultPushNotificationsServers = append(c.ShhextConfig.DefaultPushNotificationsServers, key)
}
}
return nil
}
// UpdateWithDefaults updates config with missing default values, as
// the config is only generated once and is thereafter pulled from the database.
// The way it is stored in the database makes this step necessary as it's stored as a blob and can't be easily migrated.
func (c *NodeConfig) UpdateWithDefaults() error {
// Empty APIModules will fallback to services' APIs definition. // Empty APIModules will fallback to services' APIs definition.
// If any API is defined as public, it will be exposed. // If any API is defined as public, it will be exposed.
// We disallow empty APIModules to avoid confusion // We disallow empty APIModules to avoid confusion
@ -627,6 +670,7 @@ func (c *NodeConfig) UpdateWithMobileDefaults() {
c.WhisperConfig.MinimumPoW = WhisperMinimumPoW c.WhisperConfig.MinimumPoW = WhisperMinimumPoW
} }
return c.setDefaultPushNotificationsServers()
} }
// NewNodeConfigWithDefaultsAndFiles creates new node configuration object // NewNodeConfigWithDefaultsAndFiles creates new node configuration object

View File

@ -42,6 +42,7 @@ func TestNewNodeConfigWithDefaults(t *testing.T) {
assert.NotEmpty(t, c.ClusterConfig.BootNodes) assert.NotEmpty(t, c.ClusterConfig.BootNodes)
assert.NotEmpty(t, c.ClusterConfig.StaticNodes) assert.NotEmpty(t, c.ClusterConfig.StaticNodes)
assert.NotEmpty(t, c.ClusterConfig.RendezvousNodes) assert.NotEmpty(t, c.ClusterConfig.RendezvousNodes)
assert.NotEmpty(t, c.ClusterConfig.PushNotificationsServers)
// assert LES // assert LES
assert.Equal(t, true, c.LightEthConfig.Enabled) assert.Equal(t, true, c.LightEthConfig.Enabled)
// assert peers limits // assert peers limits
@ -50,6 +51,9 @@ func TestNewNodeConfigWithDefaults(t *testing.T) {
// assert other // assert other
assert.Equal(t, false, c.HTTPEnabled) assert.Equal(t, false, c.HTTPEnabled)
assert.Equal(t, false, c.IPCEnabled) assert.Equal(t, false, c.IPCEnabled)
assert.NoError(t, c.UpdateWithDefaults())
assert.NotEmpty(t, c.ShhextConfig.DefaultPushNotificationsServers)
} }
func TestNewConfigFromJSON(t *testing.T) { func TestNewConfigFromJSON(t *testing.T) {

View File

@ -3181,11 +3181,11 @@ func (m *Messenger) Timesource() TimeSource {
} }
// AddPushNotificationsServer adds a push notification server // AddPushNotificationsServer adds a push notification server
func (m *Messenger) AddPushNotificationsServer(ctx context.Context, publicKey *ecdsa.PublicKey) error { func (m *Messenger) AddPushNotificationsServer(ctx context.Context, publicKey *ecdsa.PublicKey, serverType pushnotificationclient.ServerType) error {
if m.pushNotificationClient == nil { if m.pushNotificationClient == nil {
return errors.New("push notification client not enabled") return errors.New("push notification client not enabled")
} }
return m.pushNotificationClient.AddPushNotificationsServer(publicKey) return m.pushNotificationClient.AddPushNotificationsServer(publicKey, serverType)
} }
// RemovePushNotificationServer removes a push notification server // RemovePushNotificationServer removes a push notification server
@ -3293,8 +3293,8 @@ func (m *Messenger) DisablePushNotificationsFromContactsOnly() error {
return m.pushNotificationClient.DisablePushNotificationsFromContactsOnly(contactIDs, mutedChatIDs) return m.pushNotificationClient.DisablePushNotificationsFromContactsOnly(contactIDs, mutedChatIDs)
} }
// GetPushNotificationServers returns the servers used for push notifications // GetPushNotificationsServers returns the servers used for push notifications
func (m *Messenger) GetPushNotificationServers() ([]*pushnotificationclient.PushNotificationServer, error) { func (m *Messenger) GetPushNotificationsServers() ([]*pushnotificationclient.PushNotificationServer, error) {
if m.pushNotificationClient == nil { if m.pushNotificationClient == nil {
return nil, errors.New("no push notification client") return nil, errors.New("no push notification client")
} }

View File

@ -141,7 +141,7 @@ func (s *MessengerPushNotificationSuite) TestReceivePushNotification() {
bobInstallationIDs := []string{bob1.installationID, bob2.installationID} bobInstallationIDs := []string{bob1.installationID, bob2.installationID}
// Register bob1 // Register bob1
err = bob1.AddPushNotificationsServer(context.Background(), &server.identity.PublicKey) err = bob1.AddPushNotificationsServer(context.Background(), &server.identity.PublicKey, pushnotificationclient.ServerTypeCustom)
s.Require().NoError(err) s.Require().NoError(err)
err = bob1.RegisterForPushNotifications(context.Background(), bob1DeviceToken, testAPNTopic, protobuf.PushNotificationRegistration_APN_TOKEN) err = bob1.RegisterForPushNotifications(context.Background(), bob1DeviceToken, testAPNTopic, protobuf.PushNotificationRegistration_APN_TOKEN)
@ -167,11 +167,11 @@ func (s *MessengerPushNotificationSuite) TestReceivePushNotification() {
}) })
// Make sure we receive it // Make sure we receive it
s.Require().NoError(err) s.Require().NoError(err)
bob1Servers, err := bob1.GetPushNotificationServers() bob1Servers, err := bob1.GetPushNotificationsServers()
s.Require().NoError(err) s.Require().NoError(err)
// Register bob2 // Register bob2
err = bob2.AddPushNotificationsServer(context.Background(), &server.identity.PublicKey) err = bob2.AddPushNotificationsServer(context.Background(), &server.identity.PublicKey, pushnotificationclient.ServerTypeCustom)
s.Require().NoError(err) s.Require().NoError(err)
err = bob2.RegisterForPushNotifications(context.Background(), bob2DeviceToken, testAPNTopic, protobuf.PushNotificationRegistration_APN_TOKEN) err = bob2.RegisterForPushNotifications(context.Background(), bob2DeviceToken, testAPNTopic, protobuf.PushNotificationRegistration_APN_TOKEN)
@ -198,7 +198,7 @@ func (s *MessengerPushNotificationSuite) TestReceivePushNotification() {
}) })
// Make sure we receive it // Make sure we receive it
s.Require().NoError(err) s.Require().NoError(err)
bob2Servers, err := bob2.GetPushNotificationServers() bob2Servers, err := bob2.GetPushNotificationsServers()
s.Require().NoError(err) s.Require().NoError(err)
// Create one to one chat & send message // Create one to one chat & send message
@ -307,7 +307,7 @@ func (s *MessengerPushNotificationSuite) TestReceivePushNotificationFromContactO
bobInstallationIDs := []string{bob.installationID} bobInstallationIDs := []string{bob.installationID}
// Register bob // Register bob
err = bob.AddPushNotificationsServer(context.Background(), &server.identity.PublicKey) err = bob.AddPushNotificationsServer(context.Background(), &server.identity.PublicKey, pushnotificationclient.ServerTypeCustom)
s.Require().NoError(err) s.Require().NoError(err)
// Add alice has a contact // Add alice has a contact
@ -348,7 +348,7 @@ func (s *MessengerPushNotificationSuite) TestReceivePushNotificationFromContactO
}) })
// Make sure we receive it // Make sure we receive it
s.Require().NoError(err) s.Require().NoError(err)
bobServers, err := bob.GetPushNotificationServers() bobServers, err := bob.GetPushNotificationsServers()
s.Require().NoError(err) s.Require().NoError(err)
// Create one to one chat & send message // Create one to one chat & send message
@ -442,7 +442,7 @@ func (s *MessengerPushNotificationSuite) TestReceivePushNotificationRetries() {
bobInstallationIDs := []string{bob.installationID} bobInstallationIDs := []string{bob.installationID}
// Register bob // Register bob
err = bob.AddPushNotificationsServer(context.Background(), &server.identity.PublicKey) err = bob.AddPushNotificationsServer(context.Background(), &server.identity.PublicKey, pushnotificationclient.ServerTypeCustom)
s.Require().NoError(err) s.Require().NoError(err)
// Add alice has a contact // Add alice has a contact
@ -493,7 +493,7 @@ func (s *MessengerPushNotificationSuite) TestReceivePushNotificationRetries() {
}) })
// Make sure we receive it // Make sure we receive it
s.Require().NoError(err) s.Require().NoError(err)
bobServers, err := bob.GetPushNotificationServers() bobServers, err := bob.GetPushNotificationsServers()
s.Require().NoError(err) s.Require().NoError(err)
// Create one to one chat & send message // Create one to one chat & send message
@ -564,7 +564,7 @@ func (s *MessengerPushNotificationSuite) TestReceivePushNotificationRetries() {
return nil return nil
}) })
newBobServers, err := bob.GetPushNotificationServers() newBobServers, err := bob.GetPushNotificationsServers()
s.Require().NoError(err) s.Require().NoError(err)
// Make sure access token is not the same // Make sure access token is not the same
s.Require().NotEqual(newBobServers[0].AccessToken, bobServers[0].AccessToken) s.Require().NotEqual(newBobServers[0].AccessToken, bobServers[0].AccessToken)
@ -653,7 +653,7 @@ func (s *MessengerPushNotificationSuite) TestActAsYourOwnPushNotificationServer(
bobInstallationIDs := []string{bob1.installationID, bob2.installationID} bobInstallationIDs := []string{bob1.installationID, bob2.installationID}
// Register bob1 // Register bob1
err := bob1.AddPushNotificationsServer(context.Background(), &server.identity.PublicKey) err := bob1.AddPushNotificationsServer(context.Background(), &server.identity.PublicKey, pushnotificationclient.ServerTypeCustom)
s.Require().NoError(err) s.Require().NoError(err)
err = bob1.RegisterForPushNotifications(context.Background(), bob1DeviceToken, testAPNTopic, protobuf.PushNotificationRegistration_APN_TOKEN) err = bob1.RegisterForPushNotifications(context.Background(), bob1DeviceToken, testAPNTopic, protobuf.PushNotificationRegistration_APN_TOKEN)
@ -679,11 +679,11 @@ func (s *MessengerPushNotificationSuite) TestActAsYourOwnPushNotificationServer(
}) })
// Make sure we receive it // Make sure we receive it
s.Require().NoError(err) s.Require().NoError(err)
bob1Servers, err := bob1.GetPushNotificationServers() bob1Servers, err := bob1.GetPushNotificationsServers()
s.Require().NoError(err) s.Require().NoError(err)
// Register bob2 // Register bob2
err = bob2.AddPushNotificationsServer(context.Background(), &server.identity.PublicKey) err = bob2.AddPushNotificationsServer(context.Background(), &server.identity.PublicKey, pushnotificationclient.ServerTypeCustom)
s.Require().NoError(err) s.Require().NoError(err)
err = bob2.RegisterForPushNotifications(context.Background(), bob2DeviceToken, testAPNTopic, protobuf.PushNotificationRegistration_APN_TOKEN) err = bob2.RegisterForPushNotifications(context.Background(), bob2DeviceToken, testAPNTopic, protobuf.PushNotificationRegistration_APN_TOKEN)
@ -710,7 +710,7 @@ func (s *MessengerPushNotificationSuite) TestActAsYourOwnPushNotificationServer(
}) })
// Make sure we receive it // Make sure we receive it
s.Require().NoError(err) s.Require().NoError(err)
bob2Servers, err := bob2.GetPushNotificationServers() bob2Servers, err := bob2.GetPushNotificationsServers()
s.Require().NoError(err) s.Require().NoError(err)
// Create one to one chat & send message // Create one to one chat & send message
@ -817,7 +817,7 @@ func (s *MessengerPushNotificationSuite) TestContactCode() {
s.Require().NoError(alice.EnableSendingPushNotifications()) s.Require().NoError(alice.EnableSendingPushNotifications())
// Register bob1 // Register bob1
err = bob1.AddPushNotificationsServer(context.Background(), &server.identity.PublicKey) err = bob1.AddPushNotificationsServer(context.Background(), &server.identity.PublicKey, pushnotificationclient.ServerTypeCustom)
s.Require().NoError(err) s.Require().NoError(err)
err = bob1.RegisterForPushNotifications(context.Background(), bob1DeviceToken, testAPNTopic, protobuf.PushNotificationRegistration_APN_TOKEN) err = bob1.RegisterForPushNotifications(context.Background(), bob1DeviceToken, testAPNTopic, protobuf.PushNotificationRegistration_APN_TOKEN)

View File

@ -60,6 +60,13 @@ const pushNotificationBackoffTime int64 = 2
// RegistrationBackoffTime is the step of the exponential backoff // RegistrationBackoffTime is the step of the exponential backoff
const RegistrationBackoffTime int64 = 15 const RegistrationBackoffTime int64 = 15
type ServerType int
const (
ServerTypeDefault = iota + 1
ServerTypeCustom
)
type PushNotificationServer struct { type PushNotificationServer struct {
PublicKey *ecdsa.PublicKey `json:"-"` PublicKey *ecdsa.PublicKey `json:"-"`
Registered bool `json:"registered,omitempty"` Registered bool `json:"registered,omitempty"`
@ -67,6 +74,7 @@ type PushNotificationServer struct {
LastRetriedAt int64 `json:"lastRetriedAt,omitempty"` LastRetriedAt int64 `json:"lastRetriedAt,omitempty"`
RetryCount int64 `json:"retryCount,omitempty"` RetryCount int64 `json:"retryCount,omitempty"`
AccessToken string `json:"accessToken,omitempty"` AccessToken string `json:"accessToken,omitempty"`
Type ServerType `json:"type,omitempty"`
} }
func (s *PushNotificationServer) MarshalJSON() ([]byte, error) { func (s *PushNotificationServer) MarshalJSON() ([]byte, error) {
@ -121,6 +129,10 @@ type Config struct {
InstallationID string InstallationID string
Logger *zap.Logger Logger *zap.Logger
// DefaultServers holds the push notification servers used by
// default if none is selected
DefaultServers []*ecdsa.PublicKey
} }
type Client struct { type Client struct {
@ -176,6 +188,8 @@ func (c *Client) Start() error {
return errors.New("can't start, missing message processor") return errors.New("can't start, missing message processor")
} }
c.config.Logger.Debug("starting push notification client", zap.Any("config", c.config))
err := c.loadLastPushNotificationRegistration() err := c.loadLastPushNotificationRegistration()
if err != nil { if err != nil {
return err return err
@ -294,8 +308,23 @@ func (c *Client) Register(deviceToken, apnTopic string, tokenType protobuf.PushN
c.config.RemoteNotificationsEnabled = true c.config.RemoteNotificationsEnabled = true
// check if we need to fallback on default servers
currentServers, err := c.persistence.GetServers()
if err != nil {
return err
}
if len(currentServers) == 0 {
c.config.Logger.Debug("servers empty, checking default servers")
for _, s := range c.config.DefaultServers {
err = c.AddPushNotificationsServer(s, ServerTypeDefault)
if err != nil {
return err
}
}
}
// reset servers // reset servers
err := c.resetServers() err = c.resetServers()
if err != nil { if err != nil {
return err return err
} }
@ -482,7 +511,7 @@ func (c *Client) RemovePushNotificationServer(publicKey *ecdsa.PublicKey) error
return errors.New("not implemented") return errors.New("not implemented")
} }
func (c *Client) AddPushNotificationsServer(publicKey *ecdsa.PublicKey) error { func (c *Client) AddPushNotificationsServer(publicKey *ecdsa.PublicKey, serverType ServerType) error {
c.config.Logger.Debug("adding push notifications server", zap.Any("public-key", publicKey)) c.config.Logger.Debug("adding push notifications server", zap.Any("public-key", publicKey))
currentServers, err := c.persistence.GetServers() currentServers, err := c.persistence.GetServers()
if err != nil { if err != nil {
@ -497,6 +526,7 @@ func (c *Client) AddPushNotificationsServer(publicKey *ecdsa.PublicKey) error {
err = c.persistence.UpsertServer(&PushNotificationServer{ err = c.persistence.UpsertServer(&PushNotificationServer{
PublicKey: publicKey, PublicKey: publicKey,
Type: serverType,
}) })
if err != nil { if err != nil {
return err return err

View File

@ -2,6 +2,8 @@
// sources: // sources:
// 1593601729_initial_schema.down.sql (144B) // 1593601729_initial_schema.down.sql (144B)
// 1593601729_initial_schema.up.sql (1.773kB) // 1593601729_initial_schema.up.sql (1.773kB)
// 1597909626_add_server_type.down.sql (0)
// 1597909626_add_server_type.up.sql (145B)
// doc.go (382B) // doc.go (382B)
package migrations package migrations
@ -86,7 +88,7 @@ func _1593601729_initial_schemaDownSql() (*asset, error) {
return nil, err return nil, err
} }
info := bindataFileInfo{name: "1593601729_initial_schema.down.sql", size: 144, mode: os.FileMode(0644), modTime: time.Unix(1595840384, 0)} info := bindataFileInfo{name: "1593601729_initial_schema.down.sql", size: 144, mode: os.FileMode(0644), modTime: time.Unix(1596198373, 0)}
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xa, 0x95, 0x55, 0x64, 0x38, 0x40, 0x16, 0xbf, 0x8b, 0x1c, 0x18, 0xb4, 0xc5, 0x7f, 0xd0, 0xb8, 0xf0, 0x3c, 0xa2, 0x82, 0xf8, 0x8d, 0x5a, 0xd3, 0xb6, 0x6e, 0xa3, 0xb4, 0xc, 0x9, 0x33, 0x0}} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xa, 0x95, 0x55, 0x64, 0x38, 0x40, 0x16, 0xbf, 0x8b, 0x1c, 0x18, 0xb4, 0xc5, 0x7f, 0xd0, 0xb8, 0xf0, 0x3c, 0xa2, 0x82, 0xf8, 0x8d, 0x5a, 0xd3, 0xb6, 0x6e, 0xa3, 0xb4, 0xc, 0x9, 0x33, 0x0}}
return a, nil return a, nil
} }
@ -106,11 +108,51 @@ func _1593601729_initial_schemaUpSql() (*asset, error) {
return nil, err return nil, err
} }
info := bindataFileInfo{name: "1593601729_initial_schema.up.sql", size: 1773, mode: os.FileMode(0644), modTime: time.Unix(1595840384, 0)} info := bindataFileInfo{name: "1593601729_initial_schema.up.sql", size: 1773, mode: os.FileMode(0644), modTime: time.Unix(1596198373, 0)}
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x4e, 0x1e, 0x5, 0x35, 0x9, 0xb2, 0x2d, 0x6f, 0x33, 0x63, 0xa2, 0x7a, 0x5b, 0xd2, 0x2d, 0xcb, 0x79, 0x7e, 0x6, 0xb4, 0x9d, 0x35, 0xd8, 0x9b, 0x55, 0xe5, 0xf8, 0x44, 0xca, 0xa6, 0xf3, 0xd3}} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x4e, 0x1e, 0x5, 0x35, 0x9, 0xb2, 0x2d, 0x6f, 0x33, 0x63, 0xa2, 0x7a, 0x5b, 0xd2, 0x2d, 0xcb, 0x79, 0x7e, 0x6, 0xb4, 0x9d, 0x35, 0xd8, 0x9b, 0x55, 0xe5, 0xf8, 0x44, 0xca, 0xa6, 0xf3, 0xd3}}
return a, nil return a, nil
} }
var __1597909626_add_server_typeDownSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x01\x00\x00\xff\xff\x00\x00\x00\x00\x00\x00\x00\x00")
func _1597909626_add_server_typeDownSqlBytes() ([]byte, error) {
return bindataRead(
__1597909626_add_server_typeDownSql,
"1597909626_add_server_type.down.sql",
)
}
func _1597909626_add_server_typeDownSql() (*asset, error) {
bytes, err := _1597909626_add_server_typeDownSqlBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "1597909626_add_server_type.down.sql", size: 0, mode: os.FileMode(0644), modTime: time.Unix(1597909727, 0)}
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24, 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c, 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55}}
return a, nil
}
var __1597909626_add_server_typeUpSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x72\xf4\x09\x71\x0d\x52\x08\x71\x74\xf2\x71\x55\x28\x28\x2d\xce\x88\xcf\xcb\x2f\xc9\x4c\xcb\x4c\x4e\x2c\xc9\xcc\xcf\x8b\x4f\xce\xc9\x4c\xcd\x2b\x89\x2f\x4e\x2d\x2a\x4b\x2d\x2a\x56\x70\x74\x71\x51\x70\xf6\xf7\x09\xf5\xf5\x53\x80\x08\xc5\x97\x54\x16\xa4\x2a\x78\xfa\x85\x28\xb8\xb8\xba\x39\x86\xfa\x84\x28\x18\x59\x73\x85\x06\xb8\x38\x86\x10\x61\x5a\xb0\x6b\x08\x8a\x31\xb6\x20\xcd\x5c\x80\x00\x00\x00\xff\xff\x98\x88\x1e\xcd\x91\x00\x00\x00")
func _1597909626_add_server_typeUpSqlBytes() ([]byte, error) {
return bindataRead(
__1597909626_add_server_typeUpSql,
"1597909626_add_server_type.up.sql",
)
}
func _1597909626_add_server_typeUpSql() (*asset, error) {
bytes, err := _1597909626_add_server_typeUpSqlBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "1597909626_add_server_type.up.sql", size: 145, mode: os.FileMode(0644), modTime: time.Unix(1597909704, 0)}
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xc8, 0x3f, 0xe0, 0xe7, 0x57, 0x0, 0x5d, 0x60, 0xf3, 0x55, 0x64, 0x71, 0x80, 0x3c, 0xca, 0x8, 0x61, 0xb5, 0x3c, 0xe, 0xa1, 0xe4, 0x61, 0xd1, 0x4e, 0xd8, 0xb2, 0x55, 0xdd, 0x87, 0x62, 0x9b}}
return a, nil
}
var _docGo = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x84\x8f\x3d\x6e\xec\x30\x0c\x84\x7b\x9d\x62\xb0\xcd\x36\xcf\x52\xf3\xaa\x74\x29\xd3\xe7\x02\x5c\x89\x96\x88\xb5\x24\x43\xa4\xf7\xe7\xf6\x81\x37\x01\xe2\x2e\xed\x87\xf9\x86\xc3\x10\xf0\x59\x44\x31\xcb\xc2\x10\x45\xe3\xc8\xaa\x34\x9e\xb8\x70\xa4\x4d\x19\xa7\x2c\x56\xb6\x8b\x8f\xbd\x06\x35\xb2\x4d\x27\xa9\xa1\x4a\x1e\x64\x1c\x6e\xff\x4f\x2e\x04\x44\x6a\x67\x43\xa1\x96\x16\x7e\x75\x29\xd4\x68\x98\xb4\x8c\xbb\x58\x01\x61\x1d\x3c\xcb\xc3\xe3\xdd\xb0\x30\xa9\xc1\x0a\xd9\x59\x61\x85\x11\x49\x79\xaf\x99\xfb\x40\xee\xd3\x45\x5a\x22\x23\xbf\xa3\x8f\xf9\x40\xf6\x85\x91\x96\x85\x13\xe6\xd1\xeb\xcb\x55\xaa\x8c\x24\x83\xa3\xf5\xf1\xfc\x07\x52\x65\x43\xa3\xca\xba\xfb\x85\x6e\x8c\xd6\x7f\xce\x83\x5a\xfa\xfb\x23\xdc\xfb\xb8\x2a\x48\xc1\x8f\x95\xa3\x71\xf2\xce\xad\x14\xaf\x94\x19\xdf\x39\xe9\x4d\x9d\x0b\x21\xf7\xb7\xcc\x8d\x77\xf3\xb8\x73\x5a\xaf\xf9\x90\xc4\xd4\xe1\x7d\xf8\x05\x3e\x77\xf8\xe0\xbe\x02\x00\x00\xff\xff\x4d\x1d\x5d\x50\x7e\x01\x00\x00") var _docGo = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x84\x8f\x3d\x6e\xec\x30\x0c\x84\x7b\x9d\x62\xb0\xcd\x36\xcf\x52\xf3\xaa\x74\x29\xd3\xe7\x02\x5c\x89\x96\x88\xb5\x24\x43\xa4\xf7\xe7\xf6\x81\x37\x01\xe2\x2e\xed\x87\xf9\x86\xc3\x10\xf0\x59\x44\x31\xcb\xc2\x10\x45\xe3\xc8\xaa\x34\x9e\xb8\x70\xa4\x4d\x19\xa7\x2c\x56\xb6\x8b\x8f\xbd\x06\x35\xb2\x4d\x27\xa9\xa1\x4a\x1e\x64\x1c\x6e\xff\x4f\x2e\x04\x44\x6a\x67\x43\xa1\x96\x16\x7e\x75\x29\xd4\x68\x98\xb4\x8c\xbb\x58\x01\x61\x1d\x3c\xcb\xc3\xe3\xdd\xb0\x30\xa9\xc1\x0a\xd9\x59\x61\x85\x11\x49\x79\xaf\x99\xfb\x40\xee\xd3\x45\x5a\x22\x23\xbf\xa3\x8f\xf9\x40\xf6\x85\x91\x96\x85\x13\xe6\xd1\xeb\xcb\x55\xaa\x8c\x24\x83\xa3\xf5\xf1\xfc\x07\x52\x65\x43\xa3\xca\xba\xfb\x85\x6e\x8c\xd6\x7f\xce\x83\x5a\xfa\xfb\x23\xdc\xfb\xb8\x2a\x48\xc1\x8f\x95\xa3\x71\xf2\xce\xad\x14\xaf\x94\x19\xdf\x39\xe9\x4d\x9d\x0b\x21\xf7\xb7\xcc\x8d\x77\xf3\xb8\x73\x5a\xaf\xf9\x90\xc4\xd4\xe1\x7d\xf8\x05\x3e\x77\xf8\xe0\xbe\x02\x00\x00\xff\xff\x4d\x1d\x5d\x50\x7e\x01\x00\x00")
func docGoBytes() ([]byte, error) { func docGoBytes() ([]byte, error) {
@ -126,7 +168,7 @@ func docGo() (*asset, error) {
return nil, err return nil, err
} }
info := bindataFileInfo{name: "doc.go", size: 382, mode: os.FileMode(0644), modTime: time.Unix(1595840384, 0)} info := bindataFileInfo{name: "doc.go", size: 382, mode: os.FileMode(0644), modTime: time.Unix(1596198373, 0)}
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xc0, 0x2f, 0x1e, 0x64, 0x9, 0x93, 0xe4, 0x8b, 0xf2, 0x98, 0x5a, 0x45, 0xe2, 0x80, 0x88, 0x67, 0x7a, 0x2d, 0xd7, 0x4b, 0xd1, 0x73, 0xb6, 0x6d, 0x15, 0xc2, 0x0, 0x34, 0xcd, 0xa0, 0xdb, 0x20}} a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xc0, 0x2f, 0x1e, 0x64, 0x9, 0x93, 0xe4, 0x8b, 0xf2, 0x98, 0x5a, 0x45, 0xe2, 0x80, 0x88, 0x67, 0x7a, 0x2d, 0xd7, 0x4b, 0xd1, 0x73, 0xb6, 0x6d, 0x15, 0xc2, 0x0, 0x34, 0xcd, 0xa0, 0xdb, 0x20}}
return a, nil return a, nil
} }
@ -226,6 +268,10 @@ var _bindata = map[string]func() (*asset, error){
"1593601729_initial_schema.up.sql": _1593601729_initial_schemaUpSql, "1593601729_initial_schema.up.sql": _1593601729_initial_schemaUpSql,
"1597909626_add_server_type.down.sql": _1597909626_add_server_typeDownSql,
"1597909626_add_server_type.up.sql": _1597909626_add_server_typeUpSql,
"doc.go": docGo, "doc.go": docGo,
} }
@ -270,9 +316,11 @@ type bintree struct {
} }
var _bintree = &bintree{nil, map[string]*bintree{ var _bintree = &bintree{nil, map[string]*bintree{
"1593601729_initial_schema.down.sql": &bintree{_1593601729_initial_schemaDownSql, map[string]*bintree{}}, "1593601729_initial_schema.down.sql": &bintree{_1593601729_initial_schemaDownSql, map[string]*bintree{}},
"1593601729_initial_schema.up.sql": &bintree{_1593601729_initial_schemaUpSql, map[string]*bintree{}}, "1593601729_initial_schema.up.sql": &bintree{_1593601729_initial_schemaUpSql, map[string]*bintree{}},
"doc.go": &bintree{docGo, map[string]*bintree{}}, "1597909626_add_server_type.down.sql": &bintree{_1597909626_add_server_typeDownSql, map[string]*bintree{}},
"1597909626_add_server_type.up.sql": &bintree{_1597909626_add_server_typeUpSql, map[string]*bintree{}},
"doc.go": &bintree{docGo, map[string]*bintree{}},
}} }}
// RestoreAsset restores an asset under the given directory. // RestoreAsset restores an asset under the given directory.

View File

@ -0,0 +1,3 @@
ALTER TABLE push_notification_client_servers ADD COLUMN server_type INT DEFAULT 2;
UPDATE push_notification_client_servers SET server_type = 2;

View File

@ -333,13 +333,13 @@ func (p *Persistence) GetRetriablePushNotifications() ([]*SentNotification, erro
} }
func (p *Persistence) UpsertServer(server *PushNotificationServer) error { func (p *Persistence) UpsertServer(server *PushNotificationServer) error {
_, err := p.db.Exec(`INSERT INTO push_notification_client_servers (public_key, registered, registered_at, access_token, last_retried_at, retry_count) VALUES (?,?,?,?,?,?)`, crypto.CompressPubkey(server.PublicKey), server.Registered, server.RegisteredAt, server.AccessToken, server.LastRetriedAt, server.RetryCount) _, err := p.db.Exec(`INSERT INTO push_notification_client_servers (public_key, registered, registered_at, access_token, last_retried_at, retry_count, server_type) VALUES (?,?,?,?,?,?,?)`, crypto.CompressPubkey(server.PublicKey), server.Registered, server.RegisteredAt, server.AccessToken, server.LastRetriedAt, server.RetryCount, server.Type)
return err return err
} }
func (p *Persistence) GetServers() ([]*PushNotificationServer, error) { func (p *Persistence) GetServers() ([]*PushNotificationServer, error) {
rows, err := p.db.Query(`SELECT public_key, registered, registered_at,access_token,last_retried_at, retry_count FROM push_notification_client_servers`) rows, err := p.db.Query(`SELECT public_key, registered, registered_at,access_token,last_retried_at, retry_count, server_type FROM push_notification_client_servers`)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -349,7 +349,7 @@ func (p *Persistence) GetServers() ([]*PushNotificationServer, error) {
for rows.Next() { for rows.Next() {
server := &PushNotificationServer{} server := &PushNotificationServer{}
var key []byte var key []byte
err := rows.Scan(&key, &server.Registered, &server.RegisteredAt, &server.AccessToken, &server.LastRetriedAt, &server.RetryCount) err := rows.Scan(&key, &server.Registered, &server.RegisteredAt, &server.AccessToken, &server.LastRetriedAt, &server.RetryCount, &server.Type)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -495,7 +495,8 @@ func (api *PublicAPI) AddPushNotificationsServer(ctx context.Context, publicKeyB
return err return err
} }
return api.service.messenger.AddPushNotificationsServer(ctx, publicKey) // this is coming from a user, so it has to be a custom server
return api.service.messenger.AddPushNotificationsServer(ctx, publicKey, pushnotificationclient.ServerTypeCustom)
} }
func (api *PublicAPI) RemovePushNotificationServer(ctx context.Context, publicKeyBytes types.HexBytes) error { func (api *PublicAPI) RemovePushNotificationServer(ctx context.Context, publicKeyBytes types.HexBytes) error {
@ -507,8 +508,8 @@ func (api *PublicAPI) RemovePushNotificationServer(ctx context.Context, publicKe
return api.service.messenger.RemovePushNotificationServer(ctx, publicKey) return api.service.messenger.RemovePushNotificationServer(ctx, publicKey)
} }
func (api *PublicAPI) GetPushNotificationServers() ([]*pushnotificationclient.PushNotificationServer, error) { func (api *PublicAPI) GetPushNotificationsServers() ([]*pushnotificationclient.PushNotificationServer, error) {
return api.service.messenger.GetPushNotificationServers() return api.service.messenger.GetPushNotificationsServers()
} }
func (api *PublicAPI) RegisteredForPushNotifications() (bool, error) { func (api *PublicAPI) RegisteredForPushNotifications() (bool, error) {

View File

@ -483,6 +483,7 @@ func buildMessengerOptions(
} }
options = append(options, protocol.WithPushNotificationClientConfig(&pushnotificationclient.Config{ options = append(options, protocol.WithPushNotificationClientConfig(&pushnotificationclient.Config{
DefaultServers: config.DefaultPushNotificationsServers,
SendEnabled: settings.SendPushNotifications, SendEnabled: settings.SendPushNotifications,
AllowFromContactsOnly: settings.PushNotificationsFromContactsOnly, AllowFromContactsOnly: settings.PushNotificationsFromContactsOnly,
RemoteNotificationsEnabled: settings.RemotePushNotificationsEnabled, RemoteNotificationsEnabled: settings.RemotePushNotificationsEnabled,

File diff suppressed because one or more lines are too long