示例#1
0
    def on_msnp2p_file_ready(self, obj, flags, data, footer, callback,
                             baseheader=None):
        '''this method starts sending a file via p2p, abstracting most stuff
        like offsets, select() on sockets, etc'''
        
        # go to the end, get the size, go back to the start
        # i tested it in a 134mb file after flushing disk cache, it's fast
        data.seek(0, 2)
        data_size = data.tell()
        data.seek(0, 0)

        identifier = self.next_id()
        if baseheader is None:
            header = BinHeader()
            header.session_id = int(obj.session_id)
            header.identifier = identifier
            header.flag = flags
            header.acknowledged_identifier = msn_p2p.random_number(50000)
        else:
            header = baseheader
        
        header.identifier = identifier
        header.total_data_size = data_size
        
        if obj:
            obj.current_transfer = int(identifier)
        
        self.outgoing_pending_messages[identifier] = \
            (header, data, footer, callback)
        self.outgoing_identifier_list.append(identifier)
        
        # this allows the mainloop work while sending data
        self.output_connected = True
示例#2
0
    def __init__(self, manager, mail):

        gobject.GObject.__init__( self )

        self.manager = manager
        self.mail = str(mail)
        self.object_manager = manager.msn.msnObjectsManager
        self.last_requested_msnobj = None  # to avoid duplicates

        self.transports = []
        self._output_connected = False
        
        self.dchandler = None

        self.connect('display-picture-received', \
            self.manager.msn.on_display_picture_received)
        self.connect('custom-emoticon-data-received', \
            self.manager.msn.on_custom_emoticon_received)
        self.connect('wink-data-received', \
            self.manager.msn.on_wink_received)
        
        # multipart messages that haven't been received/sent completely yet
        # file object could be a file or a StringIO
        self.incoming_pending_messages = {} # {identifier: file object}
        self.outgoing_pending_messages = {} # [identifier: {dict}]
        self.outgoing_identifier_list = [] # this will evolve to priorities
        
        # per-user identifiers, let's see if this works
        self.my_identifier = msn_p2p.random_number(50000)
示例#3
0
 def on_msnp2p_message_ready(self, obj, slp_message, session_id):#XXX footer
     '''called when a p2p/slp message is ready to be sent'''
     body = str(slp_message)
     header = BinHeader()
     header.session_id = int(session_id)
     header.identifier = self.next_id()
     header.acknowledged_identifier = msn_p2p.random_number(50000)
     header.total_data_size = len(body)
     header.message_length = len(body)
     self.send_message(obj, \
         str(header) + body + msn_p2p.Base.FOOTER)
示例#4
0
 def on_msnp2p_message_ready(self, obj, slp_message, session_id):#XXX footer
     '''called when a p2p/slp message is ready to be sent'''
     
     body = str(slp_message)
     
     header = BinHeader()
     header.session_id = int(session_id)
     header.identifier = self.next_id()
     header.acknowledged_identifier = msn_p2p.random_number(50000)
     header.total_data_size = len(body)
     header.message_length = len(body)
     self.send_message(obj, \
         str(header) + body + msn_p2p.Base.FOOTER)
示例#5
0
 def on_msnp2p_file_ready(self, obj, flags, data, footer, callback,
                          baseheader=None):
     '''this method starts sending a file via p2p, abstracting most stuff
     like offsets, select() on sockets, etc'''
     data.seek(0, 2)
     data_size = data.tell()
     data.seek(0, 0)
     identifier = self.next_id()
     if baseheader is None:
         header = BinHeader()
         header.session_id = int(obj.session_id)
         header.identifier = identifier
         header.flag = flags
         header.acknowledged_identifier = msn_p2p.random_number(50000)
     else:
         header = baseheader
     header.identifier = identifier
     header.total_data_size = data_size
     if obj:
         obj.current_transfer = int(identifier)
     self.outgoing_pending_messages[identifier] = \
         (header, data, footer, callback)
     self.outgoing_identifier_list.append(identifier)
     self.output_connected = True