Skip to content

Push Notification Service Erlang Support Library

License

Notifications You must be signed in to change notification settings

SilentCircle/sc_push_lib

Repository files navigation

Push Notification Service Erlang Support Library

Copyright (c) 2015,2016 Silent Circle, LLC.

Version: 2.0.1

Authors: Edwin Fine ([email protected]).

This application contains Erlang support modules for the Push Service. It includes all database support.

sc_push_lib requires at least Mnesia for local, non-replicated data, and supports Mnesia and Postgres >= 9.4 for storage of registered push tokens.

Although sc_push_lib will automatically create local Mnesia database tables, if using Postgres as a backend for push token storage, the Postgres database and tables must be pre-created.

This is also true for running CommonTest (make ct).

As already mentioned, Mnesia is always used for local data, but you can choose between Mnesia and Postgres for push token storage.

To select the database you want to use for push token storage, change the db_mod tuple in the sc_push_lib part of sys.config to the name of one of the available database backend modules. See the sample config/shell.config for exact syntax.

sc_push_reg_db_mnesia
Mnesia push token backend
sc_push_reg_db_postgres
Postgres push token backend

You will need to restart scpf to make this change active.

%% ...
{sc_push_lib,
 [
  {db_pools,
   [
    {sc_push_reg_pool,
    [ % sizeargs
      % ...
    ],
    [ % workerargs
      {db_mod, sc_push_reg_db_postgres},
      % ...
    ]}]}]
}
%% ...

sc_push_lib uses the default public Postgres schema for maximum compatibility. However, this can be overridden in the sys.config, as can the push token table name, for flexibility. Using a different schema name helps to avoid namespacing issues, and obviates the need for a separate production database for its tables (although nothing stops you from putting the tables in a separate database anyway).

For running CommonTest cases, it is probably wise to create a totally separate database on localhost, and an sql script is provided to assist with that.

Hint: When testing, after logging on as the database user, you may want to set the search path as follows: SET search_path = 'scpf','pg_common';

If you fail to do this, the psql \d command may display No relations found.

Modify the test script to suit your environment and create the scpf table(s) accordingly.

Modify the sys.config to match your environment, by adding a section similar to that shown in the example below.

The settings for table_config key as shown are the defaults, so the entire key could be omitted. Leaving it in does make it more obvious where things are found, though.

 %% ...
 {sc_push_lib,
  [
   {db_pools,
    [
     {sc_push_reg_pool, % name
      [ % sizeargs
       {size, 50},
       {max_overflow, 0}
      ],
      [ % workerargs
       {db_mod, sc_push_reg_db_postgres},
       {db_config, #{connection => [
                                    {host, "localhost"},
                                    {database, "sc_push_lib_test"},
                                    {username, "sc_push_lib_test"},
                                    {password, "test"}
                                   ],
                     table_config => [
                                      {table_schema, "public"},
                                      {table_name, "push_tokens"}
                                     ]
                    }}
      ]}
    ]}
  ]}
  %% ...

The script to create a test Postgres database may be found in test/sql/sc_push_lib.sql. It is strongly recommended that a local Postgres installation be used for this, and the default username and password be used as configured in test/test.config:

{connect_info,
 #{postgres => #{connection => [
                                {host, "localhost"},
                                {database, "sc_push_lib_test"},
                                {username, "sc_push_lib_test"},
                                {password, "test"}
                               ],
                 table_config => [
                                  {table_schema, "scpf"},
                                  {table_name, "push_tokens"}
                                 ]
                }
  }
}.
  • Edit /etc/postgresql/<version>/<cluster>/pg_ident.conf and add a mapping to your local user's login on localhost:
# MAPNAME           SYSTEM-USERNAME     PG-USERNAME
sc_push_lib_test    <your local user>   sc_push_lib_test
  • Reload postgres, for example, sudo systemctl reload postgresql.
  • Try to log in as follows:
$ psql -U sc_push_lib_test -d sc_push_lib_test -h localhost
Password for user sc_push_lib_test: test
...
sc_push_lib_test=#
  • Once able to log in, you should be able to do the following:
sc_push_lib_test=# SET search_path = 'scpf', 'pg_common';
SET
sc_push_lib_test=# select current_database(), current_user, current_setting('search_path');
 current_database |   current_user   | current_setting
------------------+------------------+-----------------
 sc_push_lib_test | sc_push_lib_test | scpf, pg_common
(1 row)

Modules

sc_config
sc_push_lib
sc_push_lib_app
sc_push_lib_sup
sc_push_reg_api
sc_push_reg_db
sc_push_reg_db_mnesia
sc_push_reg_db_postgres
sc_push_req_mgr

About

Push Notification Service Erlang Support Library

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages