Beispiel #1
0
def on_cancelled_file_sending(proto,
                              host,
                              filename,
                              size,
                              description='',
                              error_message=None):
    """
    """
    pkt_out, work_item = packet_out.search(proto, host, filename)
    if pkt_out is None:
        if _Debug:
            lg.out(
                _DebugLevel,
                'gateway.on_cancelled_file_sending packet_out %s %s %s not found - IT IS OK'
                % (proto, host, os.path.basename(filename)))
        return True
    pkt_out.automat('item-cancelled',
                    (proto, host, filename, size, description, error_message))
    if pkt_out.outpacket:
        control.request_update([('packet', pkt_out.outpacket.PacketID)])
    if _Debug:
        lg.out(
            _DebugLevel, '>>> OUT >>>  {%s} CANCELLED via [%s] to %s : %s' %
            (os.path.basename(filename), proto, host, error_message))
    return True
Beispiel #2
0
def on_register_file_sending(proto, host, receiver_idurl, filename, size=0, description=""):
    """
    Called from transport plug-in when sending a single file were started to
    some remote peer. Must return a unique transfer ID so plug-in will know
    that ID.

    After finishing that given transfer - that ID is passed to `unregister_file_sending()`.
    """
    if _Debug:
        lg.out(_DebugLevel, "gateway.on_register_file_sending %s %s" % (filename, description))
    pkt_out, work_item = packet_out.search(proto, host, filename, remote_idurl=receiver_idurl)
    if pkt_out is None:
        if _Debug:
            lg.out(_DebugLevel, "    skip, packet_out not found: %r %r %r" % (proto, host, os.path.basename(filename)))
        return None
    transfer_id = make_transfer_ID()
    if _Debug:
        lg.out(
            _DebugLevel,
            "... OUT ... %s (%d) send {%s} via [%s] to %s at %s"
            % (
                pkt_out.description,
                transfer_id,
                os.path.basename(filename),
                proto,
                nameurl.GetName(receiver_idurl),
                host,
            ),
        )
    #    if pkt_out.remote_idurl != receiver_idurl and receiver_idurl:
    #        if _Debug:
    #            lg.out(_DebugLevel, 'gateway.on_register_file_sending [%s] receiver idurl is different [%s]' % (pkt_out.remote_idurl, receiver_idurl))
    pkt_out.automat("register-item", (proto, host, filename, transfer_id))
    control.request_update([("stream", transfer_id)])
    return transfer_id
Beispiel #3
0
def cancel_outbox_file(proto, host, filename, why=None):
    pkt_out, _ = packet_out.search(proto, host, filename)
    if pkt_out is None:
        lg.err('gateway.cancel_outbox_file ERROR packet_out not found: %r' %
               ((proto, host, filename), ))
        return None
    if _Debug:
        lg.out(
            _DebugLevel - 4, 'gateway.cancel_outbox_file : %s:%s %s, why: %s' %
            (proto, host, filename, why))
    pkt_out.automat('cancel', why)
Beispiel #4
0
def on_register_file_sending(proto,
                             host,
                             receiver_idurl,
                             filename,
                             size=0,
                             description=''):
    """
    Called from transport plug-in when sending a single file were started to
    some remote peer. Must return a unique transfer ID so plug-in will know
    that ID.

    After finishing that given transfer - that ID is passed to `unregister_file_sending()`.
    """
    if _Debug:
        lg.out(
            _DebugLevel,
            'gateway.on_register_file_sending %s %s' % (filename, description))
    pkt_out, work_item = packet_out.search(proto,
                                           host,
                                           filename,
                                           remote_idurl=receiver_idurl)
    if pkt_out is None:
        if _Debug:
            lg.out(
                _DebugLevel, '    skip, packet_out not found: %r %r %r' %
                (proto, host, os.path.basename(filename)))
        return None
    transfer_id = make_transfer_ID()
    if _Debug:
        lg.out(
            _DebugLevel, '... OUT ... %s (%d) send {%s} via [%s] to %s at %s' %
            (pkt_out.description, transfer_id, os.path.basename(filename),
             proto, nameurl.GetName(receiver_idurl), host))


#    if pkt_out.remote_idurl != receiver_idurl and receiver_idurl:
#        if _Debug:
#            lg.out(_DebugLevel, 'gateway.on_register_file_sending [%s] receiver idurl is different [%s]' % (pkt_out.remote_idurl, receiver_idurl))
    pkt_out.automat('register-item', (proto, host, filename, transfer_id))
    control.request_update([('stream', transfer_id)])
    return transfer_id
Beispiel #5
0
def on_register_file_sending(proto,
                             host,
                             receiver_idurl,
                             filename,
                             size=0,
                             description=''):
    """
    Called from transport plug-in when sending of a single file started towards remote peer.
    Must return a unique transfer ID so plug-in will know that ID.
    After finishing that given transfer - that ID is passed to `unregister_file_sending()`.
    Need to first find existing outgoing packet and register that item.
    """
    if _Debug:
        lg.out(
            _DebugLevel, 'gateway.on_register_file_sending %s %s to %r' %
            (filename, description, receiver_idurl))


#     if id_url.field(receiver_idurl).to_bin() == my_id.getLocalID().to_bin():
#         pkt_out, work_item = packet_out.search(proto, host, filename)
#     else:
#         pkt_out, work_item = packet_out.search(proto, host, filename, remote_idurl=receiver_idurl)
    pkt_out, work_item = packet_out.search(proto, host, filename)
    if pkt_out is None:
        lg.warn(
            'skip register file sending, packet_out not found: %r %r %r %r' % (
                proto,
                host,
                os.path.basename(filename),
                receiver_idurl,
            ))
        return None
    transfer_id = make_transfer_ID()
    if _Debug:
        lg.out(
            _DebugLevel, '... OUT ... %s (%d) send {%s} via [%s] to %s at %s' %
            (pkt_out.description, transfer_id, os.path.basename(filename),
             proto, nameurl.GetName(receiver_idurl), host))
    pkt_out.automat('register-item', (proto, host, filename, transfer_id))
    control.request_update([('stream', transfer_id)])
    return transfer_id
Beispiel #6
0
def on_cancelled_file_sending(proto, host, filename, size, description="", error_message=None):
    """
    
    """
    pkt_out, work_item = packet_out.search(proto, host, filename)
    if pkt_out is None:
        if _Debug:
            lg.out(
                _DebugLevel,
                "gateway.on_cancelled_file_sending packet_out %s %s %s not found - IT IS OK"
                % (proto, host, os.path.basename(filename)),
            )
        return True
    pkt_out.automat("item-cancelled", (proto, host, filename, size, description, error_message))
    control.request_update([("packet", pkt_out.outpacket.PacketID)])
    if _Debug:
        lg.out(
            _DebugLevel,
            ">>> OUT >>>  {%s} CANCELLED via [%s] to %s : %s"
            % (os.path.basename(filename), proto, host, error_message),
        )
    return True
Beispiel #7
0
def cancel_outbox_file(proto, host, filename, why=None):
    pkt_out, work_item = packet_out.search(proto, host, filename)
    if pkt_out is None:
        lg.err("gateway.cancel_outbox_file ERROR packet_out not found: %r" % ((proto, host, filename),))
        return None
    pkt_out.automat("cancel", why)