예제 #1
0
def outbox(outpacket, wide=False, callbacks={}, target=None, route=None):
    """
    Sends `packet` to the network.

        :param outpacket: an instance of ``signed.Packet``
        :param wide:  set to True if you need to send the packet
                      to all contacts of Remote Identity
        :param callbacks: provide a callback methods to get response
                          here need to provide a callback for given command
                          callback arguments are: (response_packet, info)
        :param target:  if your recipient is not equal to outpacket.RemoteID
        :param route:   dict with parameters, you can manage how to process this packet:
                'packet': <another packet to be send>,
                'proto': <receiver proto>,
                'host': <receiver host>,
                'remoteid': <receiver idurl>,
                'description': <description on the packet>,

    Returns:
        `None` if data was not sent, no filter was applied
        `Deferred` object if filter was applied but sending was delayed
        `packet_out.PacketOut` object if packet was sent
    """
    if _Debug:
        lg.out(
            _DebugLevel - 8,
            "gateway.outbox [%s] signed by %s|%s to %s, wide=%s" % (
                outpacket.Command,
                nameurl.GetName(outpacket.OwnerID),
                nameurl.GetName(outpacket.CreatorID),
                nameurl.GetName(outpacket.RemoteID),
                wide,
            ))
    return callback.run_outbox_filter_callbacks(outpacket, wide, callbacks)
예제 #2
0
def outbox(outpacket, wide=False, callbacks={}, target=None, route=None):
    """
    Sends `packet` to the network.

        :param outpacket: an instance of ``signed.Packet``
        :param wide:  set to True if you need to send the packet
                      to all contacts of Remote Identity
        :param callbacks: provide a callback methods to get response
                          here need to provide a callback for given command
                          callback arguments are: (response_packet, info)
        :param target:  if your recipient is not equal to outpacket.RemoteID
        :param route:   dict with parameters, you can manage how to process this packet:
                'packet': <another packet to be send>,
                'proto': <receiver proto>,
                'host': <receiver host>,
                'remoteid': <receiver idurl>,
                'description': <description on the packet>,

    Returns:
        `None` if data was not sent, no filter was applied
        `Deferred` object if filter was applied but sending was delayed
        `packet_out.PacketOut` object if packet was sent
    """
    if _Debug:
        lg.out(
            _DebugLevel - 8,
            "gateway.outbox [%s] signed by %s|%s to %s, wide=%s"
            % (
                outpacket.Command,
                nameurl.GetName(outpacket.OwnerID),
                nameurl.GetName(outpacket.CreatorID),
                nameurl.GetName(outpacket.RemoteID),
                wide,
            ),
        )
    return callback.run_outbox_filter_callbacks(outpacket, wide, callbacks)
예제 #3
0
def outbox(
    outpacket,
    wide=False,
    callbacks={},
    target=None,
    route=None,
    response_timeout=None,
    keep_alive=True,
):
    """
    Sends `packet` to the network.

        :param outpacket: an instance of ``signed.Packet``
        :param wide:  set to True if you need to send the packet
                      to all contacts of Remote Identity
        :param callbacks: provide a callback methods to get response
                          here need to provide a callback for given command
                          callback arguments are: (response_packet, info)
        :param target:  if your recipient is not equal to outpacket.RemoteID
        :param route:   dict with parameters, you can manage how to process this packet:
                'packet': <another packet to be send>,
                'proto': <receiver proto>,
                'host': <receiver host>,
                'remoteid': <receiver idurl>,
                'description': <description on the packet>,
        :param response_timeout   None, or integer to indicate how long to wait for an ack

    Returns:
        `None` if data was not sent, no filter was applied
        `Deferred` object if filter was applied but sending was delayed
        `packet_out.PacketOut` object if packet was sent
    """
    if _Debug:
        lg.out(
            _DebugLevel,
            "gateway.outbox [%s] signed by %s|%s to %s (%s), wide=%s" % (
                outpacket.Command,
                nameurl.GetName(outpacket.OwnerID),
                nameurl.GetName(outpacket.CreatorID),
                nameurl.GetName(outpacket.RemoteID),
                nameurl.GetName(target),
                wide,
            ))
    if _PacketLogFileEnabled:
        lg.out(0,
               '\033[1;49;96mOUTBOX %s(%s) %s %s to %s\033[0m' % (
                   outpacket.Command,
                   outpacket.PacketID,
                   global_id.UrlToGlobalID(outpacket.OwnerID),
                   global_id.UrlToGlobalID(outpacket.CreatorID),
                   global_id.UrlToGlobalID(outpacket.RemoteID),
               ),
               log_name='packet',
               showtime=True)
    return callback.run_outbox_filter_callbacks(
        outpacket,
        wide=wide,
        callbacks=callbacks,
        target=target,
        route=route,
        response_timeout=response_timeout,
        keep_alive=keep_alive,
    )