diff --git a/federation/inbound.py b/federation/inbound.py index 1010619..245d99b 100644 --- a/federation/inbound.py +++ b/federation/inbound.py @@ -1,7 +1,10 @@ import importlib +import logging from federation.exceptions import NoSuitableProtocolFoundError +logger = logging.getLogger("social-federation") + PROTOCOLS = ( "diaspora", ) @@ -16,6 +19,7 @@ def handle_receive(payload, user=None, sender_key_fetcher=None, skip_author_veri sender_key_fetcher (optional, func) - Function that accepts sender handle and returns public key skip_author_verification (optional, bool) - Don't verify sender (test purposes, false default) """ + logger.debug("handle_receive: processing payload: %s", payload) found_protocol = None for protocol_name in PROTOCOLS: protocol = importlib.import_module("federation.protocols.%s.protocol" % protocol_name) @@ -24,13 +28,16 @@ def handle_receive(payload, user=None, sender_key_fetcher=None, skip_author_veri break if found_protocol: + logger.debug("handle_receive: using protocol %s", found_protocol.PROTOCOL_NAME) protocol = found_protocol.Protocol() sender, message = protocol.receive( payload, user, sender_key_fetcher, skip_author_verification=skip_author_verification) + logger.debug("handle_receive: sender %s, message %s", sender, message) else: raise NoSuitableProtocolFoundError() mappers = importlib.import_module("federation.entities.%s.mappers" % found_protocol.PROTOCOL_NAME) entities = mappers.message_to_objects(message) + logger.debug("handle_receive: entities %s", entities) return sender, found_protocol.PROTOCOL_NAME, entities diff --git a/federation/protocols/diaspora/protocol.py b/federation/protocols/diaspora/protocol.py index bf88f3f..9767eb3 100644 --- a/federation/protocols/diaspora/protocol.py +++ b/federation/protocols/diaspora/protocol.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +import logging from base64 import b64decode, urlsafe_b64decode, b64encode, urlsafe_b64encode from json import loads, dumps from urllib.parse import unquote_plus, quote_plus, urlencode @@ -13,10 +14,10 @@ from lxml import etree from federation.exceptions import EncryptedMessageError, NoHeaderInMessageError, NoSenderKeyFoundError from federation.protocols.base import BaseProtocol +logger = logging.getLogger("social-federation") PROTOCOL_NAME = "diaspora" PROTOCOL_NS = "https://joindiaspora.com/protocol" -USER_AGENT = 'social-federation/diaspora/0.1' def identify_payload(payload): @@ -41,6 +42,7 @@ class Protocol(BaseProtocol): # Prepare payload xml = unquote_plus(payload) xml = xml.lstrip().encode("utf-8") + logger.debug("diaspora.protocol.receive: xml content: %s", xml) self.doc = etree.fromstring(xml) self.find_header() # Open payload and get actual message