def isMyOwnArchive(self, *args, **kwargs): """ Condition method. """ _, queue_owner_id, _ = global_id.SplitGlobalQueueID(kwargs['queue_id']) return my_id.getID() == queue_owner_id
def do_handle_event_packet(newpacket, e_json): event_id = strng.to_text(e_json['event_id']) payload = e_json['payload'] queue_id = strng.to_text(e_json.get('queue_id')) producer_id = e_json.get('producer_id') message_id = strng.to_text(e_json.get('message_id')) created = strng.to_text(e_json.get('created')) if _Debug: lg.args(_DebugLevel, event_id=event_id, queue_id=queue_id, producer_id=producer_id, message_id=message_id) if queue_id and producer_id and message_id: # this message have an ID and producer so it came from a queue and needs to be consumed # also needs to be attached more info coming from the queue to the event body if _Debug: lg.info('received new event %s from the queue at %s' % ( event_id, queue_id, )) payload.update( dict( queue_id=queue_id, producer_id=producer_id, message_id=message_id, created=created, )) events.send(event_id, data=payload) p2p_service.SendAck(newpacket) return True if producer_id == my_id.getID() and not queue_id: # this message addressed to me but not to any queue exclusively return True # this message does not have nor ID nor producer so it came from another user directly # lets' try to find a queue for that event and see if we need to publish it or not queue_id = global_id.MakeGlobalQueueID( queue_alias=event_id, owner_id=global_id.MakeGlobalID(idurl=newpacket.OwnerID), supplier_id=global_id.MakeGlobalID(idurl=my_id.getGlobalID()), ) if queue_id not in queue(): # such queue is not found locally, that means message is # probably addressed to that node and needs to be consumed directly if _Debug: lg.warn( 'received event %s was not delivered to any queue, consume now and send an Ack' % event_id) # also add more info comming from the queue payload.update( dict( queue_id=queue_id, producer_id=producer_id, message_id=message_id, created=created, )) events.send(event_id, data=payload) p2p_service.SendAck(newpacket) return True # found a queue for that message, pushing there # TODO: add verification of producer's identity and signature if _Debug: lg.info('pushing event %s to the queue %s on behalf of producer %s' % (event_id, queue_id, producer_id)) try: write_message( producer_id=producer_id, queue_id=queue_id, data=payload, creation_time=created, ) except Exception as exc: lg.exc() p2p_service.SendFail(newpacket, str(exc)) return True p2p_service.SendAck(newpacket) return True