Created
January 2, 2017 15:54
-
-
Save azmeuk/ea229445019d2fa7c16d809369b1b38a to your computer and use it in GitHub Desktop.
Firebase Cloud Messaging and aioxmpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2017-01-02 16:44:24,038 selector_events:53 DEBUG Using selector: EpollSelector | |
2017-01-02 16:44:24,040 callbacks:478 DEBUG connecting <bound method PresenceManagedClient._handle_stream_established of <aioxmpp.node.PresenceManagedClient object at 0x7f70e4ea7128>> with mode <bound method AdHocSignal.STRONG of <class 'aioxmpp.callbacks.AdHocSignal'>> | |
2017-01-02 16:44:24,040 callbacks:478 DEBUG connecting <Future pending> with mode <bound method AdHocSignal.AUTO_FUTURE of <class 'aioxmpp.callbacks.AdHocSignal'>> | |
2017-01-02 16:44:24,040 callbacks:478 DEBUG connecting <Future pending> with mode <bound method AdHocSignal.AUTO_FUTURE of <class 'aioxmpp.callbacks.AdHocSignal'>> | |
2017-01-02 16:44:24,041 callbacks:478 DEBUG connecting <bound method AbstractClient._stream_failure of <aioxmpp.node.PresenceManagedClient object at 0x7f70e4ea7128>> with mode <bound method AdHocSignal.STRONG of <class 'aioxmpp.callbacks.AdHocSignal'>> | |
2017-01-02 16:44:24,041 callbacks:478 DEBUG connecting <bound method AbstractClient._stream_destroyed of <aioxmpp.node.PresenceManagedClient object at 0x7f70e4ea7128>> with mode <bound method AdHocSignal.STRONG of <class 'aioxmpp.callbacks.AdHocSignal'>> | |
2017-01-02 16:44:24,041 node:199 DEBUG domain gcm.googleapis.com: trying to connect to 'fcm-xmpp.googleapis.com':5235 using <aioxmpp.connector.XMPPOverTLSConnector object at 0x7f70e7d766a0> | |
2017-01-02 16:44:24,127 __init__:289 DEBUG _initiate_tls called | |
2017-01-02 16:44:24,128 __init__:314 DEBUG _tls_do_handshake called | |
2017-01-02 16:44:24,128 __init__:322 DEBUG registering reader for _tls_do_handshake | |
2017-01-02 16:44:24,147 __init__:314 DEBUG _tls_do_handshake called | |
2017-01-02 16:44:24,148 security_layer:292 INFO verifying certificate (preverify=1) | |
2017-01-02 16:44:24,149 security_layer:292 INFO verifying certificate (preverify=1) | |
2017-01-02 16:44:24,150 security_layer:292 INFO verifying certificate (preverify=1) | |
2017-01-02 16:44:24,157 __init__:322 DEBUG registering reader for _tls_do_handshake | |
2017-01-02 16:44:24,175 __init__:314 DEBUG _tls_do_handshake called | |
2017-01-02 16:44:24,175 __init__:256 DEBUG clearing readers/writers | |
2017-01-02 16:44:24,176 __init__:346 DEBUG handshake complete | |
2017-01-02 16:44:24,176 __init__:352 DEBUG post handshake scheduled via callback | |
2017-01-02 16:44:24,177 __init__:370 DEBUG _tls_post_handshake called | |
2017-01-02 16:44:24,180 protocol:158 DEBUG SENT b'<?xml version="1.0"?><stream:stream xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" version="1.0" to="gcm.googleapis.com">' | |
2017-01-02 16:44:24,181 __init__:497 DEBUG _write_ready: nothing more to write, removing writer | |
2017-01-02 16:44:24,340 protocol:476 DEBUG RECV b'<stream:stream from="gcm.googleapis.com" id="F93802D1C1899812" version="1.0" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client">' | |
2017-01-02 16:44:24,342 protocol:476 DEBUG RECV b'<stream:features><mechanisms xmlns="urn:ietf:params:xml:ns:xmpp-sasl"><mechanism>X-OAUTH2</mechanism><mechanism>X-GOOGLE-TOKEN</mechanism><mechanism>PLAIN</mechanism></mechanisms></stream:features>' | |
2017-01-02 16:44:24,344 node:220 DEBUG domain gcm.googleapis.com: connection succeeded using <aioxmpp.connector.XMPPOverTLSConnector object at 0x7f70e7d766a0> | |
2017-01-02 16:44:24,344 __init__:482 INFO attempting PLAIN mechanism | |
2017-01-02 16:44:24,349 protocol:158 DEBUG SENT b'<auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" mechanism="PLAIN">xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx=</auth>' | |
2017-01-02 16:44:24,350 __init__:497 DEBUG _write_ready: nothing more to write, removing writer | |
2017-01-02 16:44:24,435 protocol:476 DEBUG RECV b'<success xmlns="urn:ietf:params:xml:ns:xmpp-sasl"/>' | |
2017-01-02 16:44:24,436 protocol:158 DEBUG SENT b'' | |
2017-01-02 16:44:24,437 protocol:158 DEBUG SENT b'<?xml version="1.0"?><stream:stream xmlns="jabber:client" xmlns:stream="http://etherx.jabber.org/streams" version="1.0" to="gcm.googleapis.com">' | |
2017-01-02 16:44:24,438 __init__:497 DEBUG _write_ready: nothing more to write, removing writer | |
2017-01-02 16:44:24,488 protocol:476 DEBUG RECV b'<stream:stream from="gcm.googleapis.com" id="AEC198CD323A53DE" version="1.0" xmlns:stream="http://etherx.jabber.org/streams" xmlns="jabber:client">' | |
2017-01-02 16:44:24,490 protocol:476 DEBUG RECV b'<stream:features><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"/><session xmlns="urn:ietf:params:xml:ns:xmpp-session"/></stream:features>' | |
2017-01-02 16:44:24,491 node:634 DEBUG negotiating stream (server_can_do_sm=False) | |
2017-01-02 16:44:24,492 callbacks:478 DEBUG connecting <bound method StanzaStream._xmlstream_failed of <aioxmpp.stream.StanzaStream object at 0x7f70e4ea7550>> with mode <bound method AdHocSignal.STRONG of <class 'aioxmpp.callbacks.AdHocSignal'>> | |
2017-01-02 16:44:24,492 stream:1543 DEBUG broker task started as <Task pending coro=<StanzaStream._run() running at env/lib/python3.5/site-packages/aioxmpp/stream.py:1630> cb=[StanzaStream._done_handler()]> | |
2017-01-02 16:44:24,493 node:648 DEBUG binding to resource | |
2017-01-02 16:44:24,494 stream:1187 DEBUG iq response future registered: from=None, id='xpwtOY3f+B0NJKAtRS6WS' | |
2017-01-02 16:44:24,494 stream:2141 DEBUG sending <iq from=None to=None id='xpwtOY3f+B0NJKAtRS6WS' type=<IQType.SET: 'set'> data=<aioxmpp.rfc6120.Bind object at 0x7f70e40318d0>> and waiting for it to be sent | |
2017-01-02 16:44:24,495 stream:1724 DEBUG enqueued stanza <iq from=None to=None id='xpwtOY3f+B0NJKAtRS6WS' type=<IQType.SET: 'set'> data=<aioxmpp.rfc6120.Bind object at 0x7f70e40318d0>> with token <StanzaToken id=0x00007f70e4031c88> | |
2017-01-02 16:44:24,495 stream:2161 DEBUG using token <StanzaToken id=0x00007f70e4031c88> | |
2017-01-02 16:44:24,497 stream:1016 DEBUG forwarding stanza to xmlstream: <iq from=None to=None id='xpwtOY3f+B0NJKAtRS6WS' type=<IQType.SET: 'set'> data=<aioxmpp.rfc6120.Bind object at 0x7f70e40318d0>> | |
2017-01-02 16:44:24,498 protocol:158 DEBUG SENT b'<iq type="set" id="xpwtOY3f+B0NJKAtRS6WS"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"/></iq>' | |
2017-01-02 16:44:24,498 stream:2144 DEBUG token <StanzaToken id=0x00007f70e4031c88> enters state <StanzaState.SENT_WITHOUT_SM: 3> | |
2017-01-02 16:44:24,499 __init__:497 DEBUG _write_ready: nothing more to write, removing writer | |
2017-01-02 16:44:24,550 protocol:476 DEBUG RECV b'<iq id="xpwtOY3f+B0NJKAtRS6WS" type="result"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><jid>175344936614@gcm.googleapis.com/CD6B6BCF</jid></bind></iq>' | |
2017-01-02 16:44:24,553 protocol:476 DEBUG RECV b' ' | |
2017-01-02 16:44:24,554 stream:748 DEBUG incoming iq: <iq from=None to=None id='xpwtOY3f+B0NJKAtRS6WS' type=<IQType.RESULT: 'result'> data=<aioxmpp.rfc6120.Bind object at 0x7f70e4031fd0>> | |
2017-01-02 16:44:24,554 stream:751 DEBUG iq is response | |
2017-01-02 16:44:24,555 stream:757 DEBUG iq response delivered to key (None, 'xpwtOY3f+B0NJKAtRS6WS') | |
2017-01-02 16:44:24,556 node:686 INFO bound to jid: xxxxx@gcm.googleapis.com/CD6B6BCF | |
2017-01-02 16:44:24,556 node:612 DEBUG remote server announces support for legacy sessions | |
2017-01-02 16:44:24,557 stream:1187 DEBUG iq response future registered: from=None, id='xMJ5qQfLflaZbkP8bwonE' | |
2017-01-02 16:44:24,557 stream:2141 DEBUG sending <iq from=None to=None id='xMJ5qQfLflaZbkP8bwonE' type=<IQType.SET: 'set'> data=<aioxmpp.rfc3921.Session object at 0x7f70e4031dd8>> and waiting for it to be sent | |
2017-01-02 16:44:24,558 stream:1724 DEBUG enqueued stanza <iq from=None to=None id='xMJ5qQfLflaZbkP8bwonE' type=<IQType.SET: 'set'> data=<aioxmpp.rfc3921.Session object at 0x7f70e4031dd8>> with token <StanzaToken id=0x00007f70e4031e48> | |
2017-01-02 16:44:24,558 stream:2161 DEBUG using token <StanzaToken id=0x00007f70e4031e48> | |
2017-01-02 16:44:24,559 stream:1016 DEBUG forwarding stanza to xmlstream: <iq from=None to=None id='xMJ5qQfLflaZbkP8bwonE' type=<IQType.SET: 'set'> data=<aioxmpp.rfc3921.Session object at 0x7f70e4031dd8>> | |
2017-01-02 16:44:24,560 protocol:158 DEBUG SENT b'<iq type="set" id="xMJ5qQfLflaZbkP8bwonE"><session xmlns="urn:ietf:params:xml:ns:xmpp-session"/></iq>' | |
2017-01-02 16:44:24,560 stream:2144 DEBUG token <StanzaToken id=0x00007f70e4031e48> enters state <StanzaState.SENT_WITHOUT_SM: 3> | |
2017-01-02 16:44:24,561 __init__:497 DEBUG _write_ready: nothing more to write, removing writer | |
2017-01-02 16:44:24,611 protocol:476 DEBUG RECV b'<iq type="result" id="xMJ5qQfLflaZbkP8bwonE"/>' | |
2017-01-02 16:44:24,612 stream:748 DEBUG incoming iq: <iq from=None to=None id='xMJ5qQfLflaZbkP8bwonE' type=<IQType.RESULT: 'result'>> | |
2017-01-02 16:44:24,613 stream:751 DEBUG iq is response | |
2017-01-02 16:44:24,613 stream:757 DEBUG iq response delivered to key (None, 'xMJ5qQfLflaZbkP8bwonE') | |
2017-01-02 16:44:24,614 node:619 DEBUG legacy session negotiated (upgrade your server!) | |
2017-01-02 16:44:24,615 stream:1724 DEBUG enqueued stanza <presence from=None to=None id='x2L8+x5i9ugGqPtHGgzfm' type=<PresenceType.AVAILABLE: None>> with token <StanzaToken id=0x00007f70e4031e80> | |
2017-01-02 16:44:24,616 stream:2141 DEBUG sending <message from=None to=None id=None type=<MessageType.NORMAL: 'normal'>> and waiting for it to be sent | |
2017-01-02 16:44:24,617 stream:1724 DEBUG enqueued stanza <message from=None to=None id='x7Mt5loyZCjJ0vKSStiHs' type=<MessageType.NORMAL: 'normal'>> with token <StanzaToken id=0x00007f70e4ea7cc0> | |
2017-01-02 16:44:24,617 stream:2161 DEBUG using token <StanzaToken id=0x00007f70e4ea7cc0> | |
2017-01-02 16:44:24,618 stream:1016 DEBUG forwarding stanza to xmlstream: <presence from=None to=None id='x2L8+x5i9ugGqPtHGgzfm' type=<PresenceType.AVAILABLE: None>> | |
2017-01-02 16:44:24,619 protocol:158 DEBUG SENT b'<presence id="x2L8+x5i9ugGqPtHGgzfm"/>' | |
2017-01-02 16:44:24,619 stream:1016 DEBUG forwarding stanza to xmlstream: <message from=None to=None id='x7Mt5loyZCjJ0vKSStiHs' type=<MessageType.NORMAL: 'normal'>> | |
2017-01-02 16:44:24,621 protocol:158 DEBUG SENT b'<message id="x7Mt5loyZCjJ0vKSStiHs"><gcm xmlns="google:mobile:data">{"notification": {"title": "Hello", "text": "World"}, "to": "fEIQNAAOnlo:APA91bF_MwnN7SnI0p1b8seLsVYeAYY0QGsPinp1BWSKOyqUZ2ZYsYRzrsxgAYmxFt3jODe_Pmf6hXabeQDamnXLzTxr0OFlLG2ut23Jmmu8P-K4-6ao4jw0KOJdV6cn7XQVphZixNVs", "message_id": "490dd9f2-29cb-4945-831b-676f4c9bb6a1"}</gcm></message>' | |
2017-01-02 16:44:24,621 stream:2144 DEBUG token <StanzaToken id=0x00007f70e4ea7cc0> enters state <StanzaState.SENT_WITHOUT_SM: 3> | |
2017-01-02 16:44:24,622 __init__:497 DEBUG _write_ready: nothing more to write, removing writer | |
2017-01-02 16:44:24,689 protocol:476 DEBUG RECV b'<message><data:gcm xmlns:data="google:mobile:data">{"message_type":"nack","from":"fEIQNAAOnlo:APA91bF_MwnN7SnI0p1b8seLsVYeAYY0QGsPinp1BWSKOyqUZ2ZYsYRzrsxgAYmxFt3jODe_Pmf6hXabeQDamnXLzTxr0OFlLG2ut23Jmmu8P-K4-6ao4jw0KOJdV6cn7XQVphZixNVs","message_id":"490dd9f2-29cb-4945-831b-676f4c9bb6a1","error":"DEVICE_UNREGISTERED","error_description":""}</data:gcm></message>' | |
2017-01-02 16:44:24,691 stream:796 DEBUG incoming messgage: <message from=None to=None id=None type=<MessageType.NORMAL: 'normal'>> | |
2017-01-02 16:44:24,691 stream:1673 DEBUG task terminating, rescuing stanzas and clearing handlers | |
2017-01-02 16:44:24,692 stream:704 DEBUG destroying stream state | |
2017-01-02 16:44:24,693 protocol:158 DEBUG SENT b'</stream:stream>' | |
2017-01-02 16:44:24,693 stream:693 ERROR broker task failed | |
Traceback (most recent call last): | |
File "env/lib/python3.5/site-packages/aioxmpp/stream.py", line 680, in _done_handler | |
task.result() | |
File "/usr/lib64/python3.5/asyncio/futures.py", line 274, in result | |
raise self._exception | |
File "/usr/lib64/python3.5/asyncio/tasks.py", line 239, in _step | |
result = coro.send(None) | |
File "env/lib/python3.5/site-packages/aioxmpp/stream.py", line 1661, in _run | |
incoming_fut.result()) | |
File "env/lib/python3.5/site-packages/aioxmpp/stream.py", line 957, in _process_incoming | |
self._process_incoming_message(stanza_obj) | |
File "env/lib/python3.5/site-packages/aioxmpp/stream.py", line 811, in _process_incoming_message | |
(stanza_obj.type_, stanza_obj.from_.bare()), | |
AttributeError: 'NoneType' object has no attribute 'bare' | |
2017-01-02 16:44:24,696 node:720 ERROR stream failed: 'NoneType' object has no attribute 'bare' | |
2017-01-02 16:44:24,697 node:728 INFO stopping stream | |
2017-01-02 16:44:24,698 __init__:497 DEBUG _write_ready: nothing more to write, removing writer | |
2017-01-02 16:44:24,698 node:596 ERROR main failed | |
Traceback (most recent call last): | |
File "env/lib/python3.5/site-packages/aioxmpp/node.py", line 591, in _on_main_done | |
task.result() | |
File "/usr/lib64/python3.5/asyncio/futures.py", line 274, in result | |
raise self._exception | |
File "/usr/lib64/python3.5/asyncio/tasks.py", line 239, in _step | |
result = coro.send(None) | |
File "env/lib/python3.5/site-packages/aioxmpp/node.py", line 744, in _main | |
yield from self._main_impl() | |
File "env/lib/python3.5/site-packages/aioxmpp/node.py", line 721, in _main_impl | |
raise exc | |
File "env/lib/python3.5/site-packages/aioxmpp/stream.py", line 680, in _done_handler | |
task.result() | |
File "/usr/lib64/python3.5/asyncio/futures.py", line 274, in result | |
raise self._exception | |
File "/usr/lib64/python3.5/asyncio/tasks.py", line 239, in _step | |
result = coro.send(None) | |
File "env/lib/python3.5/site-packages/aioxmpp/stream.py", line 1661, in _run | |
incoming_fut.result()) | |
File "env/lib/python3.5/site-packages/aioxmpp/stream.py", line 957, in _process_incoming | |
self._process_incoming_message(stanza_obj) | |
File "env/lib/python3.5/site-packages/aioxmpp/stream.py", line 811, in _process_incoming_message | |
(stanza_obj.type_, stanza_obj.from_.bare()), | |
AttributeError: 'NoneType' object has no attribute 'bare' | |
2017-01-02 16:44:24,700 protocol:353 DEBUG waiting for at most 15 seconds for peer stream footer | |
2017-01-02 16:44:24,750 base_events:1148 ERROR Fatal read error on STARTTLS transport | |
protocol: <aioxmpp.protocol.XMLStream object at 0x7f70e4ea7cf8> | |
transport: <aioopenssl.STARTTLSTransport object at 0x7f70e4eb8048> | |
Traceback (most recent call last): | |
File "env/lib/python3.5/site-packages/aioopenssl/__init__.py", line 440, in _read_ready | |
data = self._sock.recv(self.MAX_SIZE) | |
File "env/lib/python3.5/site-packages/OpenSSL/SSL.py", line 1304, in recv | |
self._raise_ssl_error(self._ssl, result) | |
File "env/lib/python3.5/site-packages/OpenSSL/SSL.py", line 1167, in _raise_ssl_error | |
raise SysCallError(-1, "Unexpected EOF") | |
OpenSSL.SSL.SysCallError: (-1, 'Unexpected EOF') | |
2017-01-02 16:44:24,753 __init__:239 DEBUG _force_close called | |
2017-01-02 16:44:24,753 __init__:256 DEBUG clearing readers/writers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio, logging, aioxmpp.xso, aioxmpp.utils, aioxmpp.node, aioxmpp.security_layer, aioxmpp.structs, aioxmpp.stanza, colorlog, signal, sys, uuid, json | |
FCM_SERVER_URL = "fcm-xmpp.googleapis.com" | |
FCM_SERVER_PORT = 5235 | |
RECIPIENT = "xxxx" | |
FCM_API_KEY = 'x' | |
FCM_APP_ID = 'xxxxx' | |
FCM_JID = "%s@gcm.googleapis.com" % FCM_APP_ID | |
class FCMPayload(aioxmpp.xso.XSO): | |
TAG = ("google:mobile:data", "gcm") | |
text = aioxmpp.xso.Text(default=None) | |
aioxmpp.stanza.Message.fcm_payload = aioxmpp.xso.Child([FCMPayload]) | |
class ProtoClass: | |
client = None | |
def make_sigint_event(self): | |
event = asyncio.Event() | |
loop = asyncio.get_event_loop() | |
loop.add_signal_handler(signal.SIGINT, event.set) | |
return event | |
@asyncio.coroutine | |
def do_things(self): | |
stop_event = self.make_sigint_event() | |
payload = FCMPayload() | |
payload.text = json.dumps({ | |
"message_id": str(uuid.uuid4()), | |
"to": RECIPIENT, | |
"notification": { | |
"title": "Hello", | |
"text": "World", | |
} | |
}) | |
msg = aioxmpp.stanza.Message(type_="normal") | |
msg.fcm_payload = payload | |
yield from self.client.stream.send_and_wait_for_sent(msg) | |
yield from stop_event.wait() | |
@asyncio.coroutine | |
def main(self): | |
self.client = aioxmpp.node.PresenceManagedClient( | |
aioxmpp.JID.fromstr(FCM_JID), | |
aioxmpp.make_security_layer(FCM_API_KEY), | |
override_peer = [(FCM_SERVER_URL, FCM_SERVER_PORT, aioxmpp.connector.XMPPOverTLSConnector())], | |
) | |
cm = self.client.connected() | |
yield from cm.__aenter__() | |
try: | |
yield from self.do_things() | |
except: | |
if not (yield from cm.__aexit__(*sys.exc_info())): | |
raise | |
else: | |
yield from cm.__aexit__(None, None, None) | |
if __name__ == "__main__": | |
proto = ProtoClass() | |
aioloop = asyncio.get_event_loop() | |
try: | |
aioloop.run_until_complete(proto.main()) | |
finally: | |
aioloop.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment