Websocket Protocol handler and HTTP Endpoints for Connection Node
Private HTTP Endpoints¶
These HTTP endpoints are only for communication from endpoint nodes and must not be publicly exposed.
Send a notification to a connected client with the given uaid.
Trigger a stored notification check for a connected client.
Immediately drop a client of this uaid if its connection time matches the connected_at provided.
Main Websocket Connection Protocol
randrange(start, stop=None, step=1, _int=<type 'int'>, _maxwidth=9007199254740992L)¶
Choose a random item from range(start, stop[, step]).
This fixes the problem with randint() which includes the endpoint; in Python this is usually not what you want.
deferToThread(func, *args, **kwargs)¶
deferToThread helper that tracks defers outstanding
deferToLater(when, func, *args, **kwargs)¶
deferToLater helper that tracks defers outstanding
force_retry(func, *args, **kwargs)¶
Forcefully retry a function in a thread until it doesn’t error
Note that this does not use
self.deferToThread, so this will continue to retry even if the client drops.
Property that uses None if there’s no tags due to a DataDog library bug
Log a twisted failure out through twisted’s log.failure
Indicates if we are paused for output production or not
Override for sanity checking during auto-ping interval
Override to add tracker that ensures the connection is truly torn down
Aggressive connection shutdown using abortConnection if onClose still hadn’t run by this point
autobahn onConnect handler for when a connection has started
Disable host port checking on nonstandard ports since some clients are buggy and don’t provide it
autobahn onMessage processor for incoming messages
Idle timer fired.
Override to track that this shut-down is from a ping timeout
autobahn onClose handler for shutting down the connection and any outstanding deferreds related to this connection
cleanUp(wasClean, code, reason)¶
Thorough clean-up method to cancel all remaining deferreds, and send connection metrics in
Save a direct_update webpush style notification
Save a simplepush notification
Looks up the node to send a notify for it to check storage if connected
Traps UAID not found error
Checks the result of lookup node to send the notify if the client is connected elsewhere now
returnError(messageType, reason, statusCode, close=True, message='', url='http://autopush.readthedocs.io/en/latest/api/websocket.html#private-http-endpoint')¶
Return an error to a client, and optionally shut down the connection safely
err_overload(failure, message_type, disconnect=True)¶
Handle database overloads and errors
disconnectis False, the an overload error is returned and the client is not disconnected.
Otherwise, pause producing to cease incoming notifications while we wait a random interval up to 8 seconds before closing down the connection. Most clients wait up to 10 seconds for a command, but this is not a guarantee, so rather than never reply, we still shut the connection down.
Parameters: disconnect – Whether the client should be disconnected or not.
Close the connection down and resume consuming input after the random interval from a db overload
Send a Python dict as a JSON string in a websocket message
Process a hello message
Register a returning or new user
Verify a user record is valid
Returns a record that is ready for registering in the database if the user record was found.
errBack for hello failures
callback to check other nodes for clients and send them a delete as needed
callback for successful hello message, that sends hello reply
Run a notification check against storage
Helper to return an appropriate function to fetch messages
errBack for notification check failing
errBack for provisioned errors during notification check
errBack for handling excessive messages per UAID
callback for processing notifications from storage
WebPush notification processor
Function to fire off a message table copy of channels + update the router current_month entry
Transition the client to use a new message month
Utilized to migrate a users channels to a new message month and update the router record reflecting the proper month.
This is a blocking function that does not run on the event loop.
Mark the client as successfully transitioned and resume
Capture overload on monthly table rotation attempt
If a provision exdeeded error hits while attempting monthly table rotation, schedule it all over and re-scan the messages. Normal websocket client flow is returned in the meantime.
Helper for ping sending that tracks when the ping was sent
Clients in the wild have a bug that lowers their ping interval to 0. It will never increase for them, as there is no way to remedy this without causing the client to use drastically more battery/data-usage we send them a code 4774 close to signify that they should stop until network change.
No other client should ping more than once per minute, or we tell them to go away.
Process a register message
errBack handler for registering to fail
callback for successful endpoint creation, sends register reply
Process an unregister message
Helper function for tracking ack’d updates
Returns either None, if no delete_notification call is needed, or a deferred for the delete_notification call if it was needed.
_handle_webpush_ack(chid, version, code)¶
Handle clearing out a webpush ack
_handle_webpush_update_remove(result, chid, notif)¶
Handle clearing out the updates_sent
It’s possible the client may leave before this runs, so this is wrapped in a try/except in case the tear-down of self has started.
_handle_simple_ack(chid, version, code)¶
Handle clearing out a simple ack
Process an ack message, delete notifications from storage if needed
Process a nack message and log its contents
Check to see if notifications were missed
bad_message(typ, message=None, url='http://autopush.readthedocs.io/en/latest/api/websocket.html#private-http-endpoint')¶
Error helper for sending a 401 status back
Returns whether a newer channel_id/version has already been sent
Utility function for external use
This function is called by the HTTP handler to deliver an incoming update notification from an endpoint.
RouterHandler(application, request, **kwargs)¶
Handles routing a notification to a connected client from an endpoint.
Attempt delivery of a notification to a connected client.