GithubHelp home page GithubHelp logo

inaka / apns4erl Goto Github PK

View Code? Open in Web Editor NEW
370.0 77.0 216.0 449 KB

Apple Push Notification Server for Erlang

Home Page: http://inaka.github.com/apns4erl

Erlang 98.81% Shell 1.19%
erlang apns notifications apple hacktoberfest

apns4erl's People

Contributors

andreabenini avatar cabol avatar danielfinke avatar dcy avatar dgtony avatar dsrosario avatar elbrujohalcon avatar essen avatar euen avatar ferigis avatar getong avatar harenson avatar igaray avatar lazedo avatar paulo-ferraz-oliveira avatar sztheory avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

apns4erl's Issues

Queue Resource Release

When close a apns connection, the queue resource doesn't release,which leads to a lot of useless apns queue left in system that cannot be GC.
Add apns_queue:stop in apns_connection:terminate can fix it.

SSL: Socket error: etimedout

I got following in my logs. It is coming from apns4erl.

2015-04-29 00:01:59.992 [info] <0.3157.0> SSL: Socket error: etimedout
2015-04-29 00:01:59.992 [info] <0.395.0> APNS disconnected

Till this point I lost all my messages needed to be sent via apns.

After this, when I send another message:

I got following:
2015-04-29 00:03:03.134 [info] <0.395.0> Reconnecting to APNS...

Then I was able to send apns messages.

Would you know what could cause the disconnect?

Can I set any configuration to timeout faster to minimize loss of messages?

Should I disconnect and reconnect everytime I send a message?

Handling 'DOWN' connection when sending message using send_message

I observe following code in test_suite:

apns:send_message(
  ?TEST_CONNECTION, ?DEVICE_TOKEN,
  Now ++ " - Test Alert", random:uniform(10), "chime"),

receive
{'DOWN', Ref, _, _, _} = DownMsg ->
throw(DownMsg);
DownMsg ->
throw(DownMsg)
after 1000 ->
ok
end,

If I understand this correctly (new to Erlang) its looking for "DOWN" message which will come as part of connection monitoring if the connection goes down - Ref = erlang:monitor(process, Pid),

  • Does "after -> 1000" mean that apns worker will go down after 1 sec it detected a connection "DOWN"?
  • Would this mean that message will be lost?
  • Would apns_sup restart the worker process, reset the connection?
  • What needs to be done for the message which was being sent when connection was detected 'DOWN'

Please guide me to understand this better.

spawned process to handle the connection crashes sometimes

Hi,
I have successfully integrated apns4erl with our application and it's working fine, but some times below crash is happening and some APNs messages will not be sent because of the crash.

gen_server my_apns_connection terminated with reason: {error,closed}
09:37:53.977 [error] CRASH REPORT Process my_apns_connection with 1 neighbours exited with reason: {error,closed} in gen_server:terminate/7 line 826
09:37:53.978 [error] Supervisor apns_sup had child undefined started with apns_connection:start_link(my_apns_connection, {apns_connection,"gateway.push.apple.com",2195,undefined,"priv/certs/ios_privkey.pem",...}) at <0.6600.18> exit with reason {error,closed} in context child_terminated

I have investigate many in many ways, but couldn't find any clue, any Ideas?

Thanks,
udaya.

Full Library Revamp

We need to get this library into Erlang/OTP 18.x world.
The plan is to start using maps where we used records before, stop requiring headers, revisit the way we start/stop connections and how we properly display errors from APNS.
In the process, we should address as many open issues as possible and ensure 100% code coverage in tests.

Post 1.0.0 Tagged Release

The only tagged release, 1.0.0, doesn't support R16 and is missing a lot of new commits. Specifying HEAD as the dependency's version has caused me problems in the past, so I'd love to see a new release get tagged. Thanks!

APNS return invalid_token, but the token is ok!

I've a problem because I send messages in broadcast to several devices, apns return invalid_token for me every few seconds, I resend the msg for this invalid_token is ok, this means the returned invalid_token is ok. Why apns return invalid_token every few seconds?

How can I get apns4erl integrated with ejabberd

I am new to erlang and ejabberd. I have gone through docs and tutorials on erlang and ejabberd.

I am still not sure how to integrate apns4erl with ejabberd. I need to be able to do the following:

  • Add apns4erl module to with ejabberd_hooks for event offline_message_hook
  • That should start the apns4erl module.
  • From there, every a offline message is received, I need to be able to call send_message from apns4erl.
  • Also, I need have an persistent connection from apns4erl to Apple APN server.

Would you be able to give me starting pointers on to get apns4erl started with ejabberd??

Do I need to start apns4erl application from my custom module that I will hook with ejabberd. is that how it will work??

Thanks in advance!
Gaurav Jain

ssl:connect with the content of the certificate not pem file

Hello,
"case ssl:connect(
Connection#apns_connection.apple_host,
Connection#apns_connection.apple_port,
RealSslOpts,
Connection#apns_connection.timeout
) "
RealSslOpts is [{certfile,"/etc/certs/*.pem"},{mode,binary}],but I want to use "{cert, der_encoded()}" not "{certfile, path()}",how can I do? Thank you!

Badmatch on keyfile when calling apns:connect/2

I get the following error when calling apns:connect(apns_push, ApnsConnection):

{error,{keyfile,{badmatch,[]}}}

where ApnsConnection is a apns_connection-record. The key-file is set to undefined in ApnsConnection.

What could be the reason?

How can I get apns4erl integrated with ejabberd

Indeed I've seen that there's another closed issue with the same name, but there's no any guide/tutorial that explains how to make this integration.

I don't know some things:

  1. Where I have to put the dependency (maybe on rebar.config.script)?
  2. Where I have to put the configuration?
  3. Where I have to make the connection?

And some other things..

Someone can helps me?

Thanks!

Multiple connections to feedback service

Correct me if I am wrong, but if I wanted to create multiple connections to the APN services, I would simply call connect function with a different connection name atom. Would I not end up connecting to the feedback server in each gen_server worker which is probably redundant?

Thanks, O.

ssl:connect return {error,closed}

Hi,I've encountered a problem as the title describes

The Erlang version is R17.5,but the ssl version is 7.0(because ssl6.0 caused error})

Handle disconnections from apple internally

After a couple of mails with @jamesgolick I understood that letting apns_connection processes die normally when they're disconnected from Apple is not the best idea. This is the final mail

Since my applications usually send packs of notifications (i.e. the same notification to a bunch of users instead of just one notification to some user)… I run this code right before trying to send each pack:

ensure_started() ->
  try apns:connect(?APPLE_CONNECTION,
                   fun handle_apns_error/2,
                   fun handle_delete_subscription/1) of
    {ok, _} ->
      ok;
    {error, {already_started, _}} ->
      ok;
    {error, Reason} ->
      ?THROW("Couldn't start APNS4ERL: ~p. Apple Push Notifications will not work until the admin fixes this~n", [Reason])
  catch
    _:Reason ->
      ?THROW("Couldn't start APNS4ERL: ~p. Apple Push Notifications will not work until the admin fixes this~n", [Reason])
  end.

After thinking about it for a while, I feel the right thing to do would be to keep apns_connection process running even when it was disconnected from Apple and then connect it again when it has a new notification to send… Most likely it would be a good idea to turn it into a gen_fsm… I'll probably implement that in the near future.

Build error on R16B03-01 and R15B03

Thanks for the great library! We've been running it in production for three or four years with great success.

It looks like the change (bd9048e) to use queue:queue() as a type rather than plain queue() might have broken the build on releases older than R17:

ERLC   apns.erl apns_queue.erl apns_sup.erl apns_connection.erl
src/apns_queue.erl:32: referring to built-in type queue as a remote type; please take out the module name
src/apns_queue.erl:111: referring to built-in type queue as a remote type; please take out the module name
make: *** [ebin/apns.app] Error 1

It looks like the OTP team knew this would be a backwards-incompatible change and introduced a compiler option to suppress the warning, which might be more appropriate than switching to the new type (at least until R18 is released): http://erlang.org/pipermail/erlang-questions/2014-March/078081.html

If support for older releases (R14, 15, and 16, as defined in the rebar.config) is still desired, is it possible to use a preprocessor guard around the new types? We don't use types in our Erlang app, so I'm unsure here.

Here are the build results from three OTP versions: https://travis-ci.org/eleostech/apns4erl/builds/67406167

loss of network connectivity crashes the app

if the network is lost after apns is started, .eg. {error, nxdomain}, the app crashes. What happens is when the feedback timeout occurs, a reconnect message is sent, which fails, crashing the gen_server. The simple_one_for_one strategy with transient workers is quickly exhausted, crashing the supervisor and eventually the app.

ssl_closed after some messages

hi,
After sending messages we get usual

Sending msg <<"½U÷N">> (expires on 1474400981)

but the message is not delivered to a device.

After some of those, connection to apple push server is closed.
We dont have feedback from apple, because connection to feedback server is also closed.
In both cases its sl_closed. What may be the reason of that?

It seems that it happens when we send some non-standard characters (emojis, ellipsis).
There are no crashes or side errors.
Any advice?

thanks

delete subscription callback not getting called

Hi,
I am experiencing an issue which I do not know how to resolve.

I am able to send notifications but when I delete the app, I do not receive feedback.

I started apns connection:

        apns:connect(?APNS_CONNECTION, fun ?MODULE:handle_apns_error/2, fun ?MODULE:handle_apns_delete_subscription/1).

My handler is as follows:

handle_apns_delete_subscription(Token) ->
  error_logger:warning_msg("Device with token ~p removed the app~n", [Token]),

I did not see the above output in my logs.

I logs I have

2015-04-03 05:38:58.863 [info] <0.388.0> Feedback server disconnected. Waiting 18000000 millis to connect again...
2015-04-03 10:38:59.191 [info] <0.388.0> Feedback server disconnected. Waiting 18000000 millis to connect again...
2015-04-03 15:38:59.301 [info] <0.388.0> Feedback server disconnected. Waiting 18000000 millis to connect again...

Would you be able to tell if I am missing something?

I am on Sandbox

How to get query and get data from FeebackService

In Apple APNS "The Feedback Service" doc section, this is mentioned:

Query the feedback service daily to get the list of device tokens. Use the timestamp to verify that the device tokens haven’t been reregistered since the feedback entry was generated. For each device that has not been reregistered, stop sending notifications.

  • Would you be able to tell how can I get the list of tokens using apns4erl from Apple Feedback Service?

There is a feedback connection. But how do I get data and process it? Is there an example?

Please provide pointers!

Support latest APNs notification format

Add synchronous calls for sending messages.

Sending too many devices with wrong device ids causes closing socket by APNS server, which in turn crashes apns_connection gen_server.

The carsh is not a big deal, because apns_connection is supervised, but send function is using gen_server:cast, so when the server crashes, all messages that were queued in process mailbox are gone and we don't know, what messages were there.

My solution to this problem would be to add gen_server:call doing exactly the same thing - sending messages, but because it is synchronous, we might be sure that:

  • we know, that it crashed and we can retry sending the message after it gets restarted
  • no other messages hidden in mailbox are lost (if we are not using cast)

If you think, this is a good idea, I can make a pull request, but it would be great to fix #71 before that.
Otherwise, it is a little bit hard to test, if everything is working correctly.

If you can think of a better solution, I am open.

{error, closed} in apns:connect and general cluelessness on my behalf

Hi,

When I do apns:connect I get an {error, closed} back in return. What is the recommended way of finding out why this happens? I do not see any logs anywhere and I see nothing on the console.

Also, I suspect this is due to some problems with my certificates - an area which I am in general a bit clueless about at the moment and I find it a bit complex. Is there some documentation on how the cert_file and key_file used in apns4erl relates to the Apple certificates (the developer certificate and the push notification certificates) or any good documentation on how to set it up? I have for instance both an aps.cer and aps_development.cer and I understand I should generate a .pem file to input to apns4erl. Which .p12 file should I combine with the .cer to generate the cert_file .pem and which files should I combine to generate the key_file .pem? In your example sys.config you leave the key_file as "undefined" but I really need to specify a keyfile don't I?

/Stefan

`apns_queue` module question

What is purposes of apns_queue module usage?

As far as I got we store push messages inside of queue just before send message itself, for sure, to handle case when connection to apple's server is unstable, or closed at the moment.
Also apns_queue serves e to resend failed push messages.
But we do not remove successfully sent push message from that queue, and new messages just displace prev one.

Should I remove messages from queue by myself? Looks like no, cause there is no any interface funs to do this.

Can't use multiple certificates

Hi! I have no problem using one certificates, just specifying it in sys.conf and everything works.
But I want to have different connections with different certificates, so I have to use this sample:

Connection = #apns_connection{cert_file=undefined,
                              cert=CertDER,
                              key={'RSAPrivateKey', KeyDER}},
apns:connect(Connection).

The problem is, that I got errors:

{badmatch,{error,{{badarg,[{ets,select_delete,[undefined,[{{{undefined,'_','_'},'_'},[],[true]}]],[]},{ets,match_delete,2,[{file,"ets.erl"},{line,700}]},{ssl_pkix_db,remove_certs,2,[{file,"ssl_pkix_db.erl"},{line,243}]},{ssl_connection,terminate,3,[{file,"ssl_connection.erl"},{line,935}]},{tls_connection,terminate,3,[{file,"tls_connection.erl"},{line,335}]},{gen_fsm,terminate,7,[{file,"gen_fsm.erl"},{line,610}]},{proc_lib,init_p_do_apply,3,[{file,"proc_lib.erl"},{line,239}]}]},{gen_fsm,sync_send_all_state_event,[<0.461.0>,{start,30000},infinity]}}}}

apns app is started.
I made a guess, that my sertificates are encrypted - but public_key:pem_decode(CertBin) returns [] on both key and cert files.
What should I do to make it working?

no function clause matching ssl_cipher:hash_algorithm(239)

I moved to 1.0.5 and compiled and used apns*beams but I get following error in ejabberd logs

Would you be able to provide pointers on how to fix this?

Best Regards,

 gen_fsm <0.412.0> in state certify terminated with reason: no function clause matching ssl_cipher:hash_algorithm(239) line 1174
2015-06-08 22:57:11.762 [error] <0.412.0> CRASH REPORT Process <0.412.0> with 0 neighbours exited with reason: no function clause matching ssl_cipher:hash_algorithm(239) line 1174 in gen_fsm:terminate/7 line 622
2015-06-08 22:57:11.763 [error] <0.99.0> Supervisor tls_connection_sup had child undefined started with {tls_connection,start_link,undefined} at <0.412.0> exit with reason no function clause matching ssl_cipher:hash_algorithm(239) line 1174 in context child_terminated
2015-06-08 22:57:11.763 [error] <0.409.0> CRASH REPORT Process <0.409.0> with 1 neighbours exited with reason: {{function_clause,[{ssl_cipher,hash_algorithm,"ï",[{file,"ssl_cipher.erl"},{line,1174}]},{ssl_handshake,'-decode_handshake/3-blc$^0/1-0-',1,[{file,"ssl_handshake.erl"},{line,898}]},{ssl_handshake,'-decode_handshake/3-blc$^0/1-0-',1,[{file,"ssl_handshake.erl"},{line,899}]},{ssl_handshake,decode_handshake,3,[{file,"ssl_handshake.erl"},{line,898}]},{tls_handshake,get_tls_handshake_aux,3,[{file,"tls_handshake.erl"},{line,153}]},{tls_connection,next_state,4,[{file,"tls_connection.erl"},{line,454}]},...]},...} in gen_server:init_it/6 line 328
2015-06-08 22:57:11.764 [error] <0.404.0> CRASH REPORT Process <0.404.0> with 0 neighbours exited with reason: no match of right hand value {error,{{function_clause,[{ssl_cipher,hash_algorithm,"ï",[{file,"ssl_cipher.erl"},{line,1174}]},{ssl_handshake,'-decode_handshake/3-blc$^0/1-0-',1,[{file,"ssl_handshake.erl"},{line,898}]},{ssl_handshake,'-decode_handshake/3-blc$^0/1-0-',1,[{file,"ssl_handshake.erl"},{line,899}]},{ssl_handshake,decode_handshake,3,[{file,"ssl_handshake.erl"},{line,898}]},{tls_handshake,get_tls_handshake_aux,3,[{file,"tls_handshake.erl"},{line,153}]},{tls_connection,next_state,4,[{file,"tls_connection.erl"},{line,...}]},...]},...}}

Fulfill the open-source checklist

General Items

  • It has a github repo
  • It has a proper LICENSE file
  • It's hooked to a hipchat room
  • It's has a clear and useful README.md
  • It's documented (with examples)
  • It's tested

Exhibition

  • There is a blog post about it
  • It's shared on social networks
  • It's shared on reddit
  • It's shared on hacker news with a title like Show HN: description
  • It has a landing page built in github pages

For Libraries

  • Examples of use are documented in the README or linked from there

For Erlang Projects

  • It's checked with Elvis

Hex Package

Make sure the repo is rebar3-compatible and its deps are also hex.pm packages, then publish it on hex.pm using inaka's hex.pm account.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.