Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow custom callback for checking recv messages #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions bromelia/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
:license: MIT, see LICENSE for more details.
"""
import logging
import types

from .avps import AuthRequestTypeAVP
from .constants import *
Expand Down Expand Up @@ -99,7 +100,6 @@ def process_answer_from_existing_pending_request(association, message):
if hop_by_hop_key in association.pending_requests:
if message.header.end_to_end == association.pending_requests[hop_by_hop_key].header.end_to_end:
association.pending_requests.pop(hop_by_hop_key)


@staticmethod
def is_valid_origin_host_avp(avp, connection):
Expand Down Expand Up @@ -338,13 +338,11 @@ def process_request(self):
elif ProcessDiameterMessage.is_valid_origin_state_id_avp(avp, self.connection):
self.checklist_optional_avps += 1


if (self.checklist_mandatory_avps == 5) and (self.checklist_optional_avps >= 0 and self.checklist_optional_avps <= 7):
self.is_valid = True
else:
self.is_valid = False


def process_answer(self):
ProcessDiameterMessage.process_answer_from_existing_pending_request(self.association, self.message)
for avp in self.message.avps:
Expand Down Expand Up @@ -496,6 +494,12 @@ def process_answer(self):


class BaseMessageProcessor:

recv_callback = None

def set_recv_callback(callback: types.FunctionType):
BaseMessageProcessor.recv_callback = callback

def __init__(self, association):
self.association = association

Expand Down Expand Up @@ -532,6 +536,11 @@ def create_answer(self, msg):


def check_message(self, msg):

if BaseMessageProcessor.recv_callback:
BaseMessageProcessor.recv_callback(self.association, msg)
return

if is_answer_message(msg):
process_answer(self.association, msg)

Expand Down