Exemplo n.º 1
0
    def got_data(self, user, d):
        validator = {
            'packet': int,
            'frag': lambda i: is_unsigned_int('frag', i),
            'fragcount': lambda i: is_unsigned_int('fragcount', i),
            'payload': str,
            'ack': bool,
        }
        if not validate(validator, d):
            warning('fetcher: Invalid data packet %s\n' % str(d))
            return

        if d['fragcount'] > TP_MAX_RECORD_SIZE // MTU + 1:
            warning('fetcher: Too large packet %d\n' % d['fragcount'])
            return
        if len(d['payload']) > MTU * 2:
            warning('fetcher: Received too large fragment %d\n' % len(d['payload']))
            return

        key = (user, d['packet'])
        o = pending_receives.get(key)
        if o == None:
            # We have not yet received any fragments from this packet
            o = UDP_Receiver(user, d['packet'])

        o.handle_data(d)
Exemplo n.º 2
0
    def got_ack(self, user, d):
        validator = {
            'packet': int,
            'ack': [ONE_OR_MORE, lambda i: is_unsigned_int('ack', i)],
        }
        if not validate(validator, d):
            warning('fetcher: Invalid ack packet %s\n' % str(d))
            return

        key = (user, d['packet'])
        o = pending_sends.get(key)
        if o != None:
            o.handle_ack(d)
Exemplo n.º 3
0
    def handle_icon_push(self, user, request):
        """ This is called when is received. Save the icon image. """

        validator = {'icon': str,
                     'iconid': str,
                     'version': lambda i: is_unsigned_int('version', i)
                    }
        if not validate(validator, request):
            return None

        icon = request['icon']
        iconid = request['iconid']

        if iconid == 'user':
            if user.get('faceversion') != request['version']:
                # This is an outdated version of the icon..
                return None
            if icon == '':
                # if we got an empty string, user removed the icon
                # giving None to save_face removes the picture
                delete_face(user)
            elif not save_face(user, icon):
                warning('Could not save face for %s: %d bytes\n' % (user.tag(), len(icon)))
                return None
            user.set('myfaceversion', request['version'])
            self.announce_user_change(user, what=(PROFILE_ICON_CHANGED, None))

        elif iconid.startswith('c:'):
            cname = iconid[2:]
            if cname == DEFAULT_COMMUNITY_NAME:
                return None
            com = self.get_ordinary_community(cname)
            if com == None:
                return None
            if com.get('iconversion') != request['version']:
                # This is an outdated version of the icon..
                return None
            if com.get('iconlocked'):
                return None
            if icon == '':
                delete_community_icon(com)
            elif not save_community_icon(com, icon):
                warning('Failed to update community icon: %s\n' % cname)
                return None
            com.set('myiconversion', request['version'])
            self.announce_community_change(com)
        return None
Exemplo n.º 4
0
    def handle_community_profiles_fetch(self, user, request):
        validator = {
            'cname': [ZERO_OR_MORE, str],
            'version': [ZERO_OR_MORE, lambda i: is_unsigned_int('version', i)]
           }
        if not validate(validator, request):
            warning('Invalid community profiles fetch\n' % str(request))
            return None

        cnames = []
        profiles = []
        for (cname, version) in zip(request['cname'], request['version']):
            com = self.get_ordinary_community(cname)
            if com == None:
                continue
            if version < com.get('v'):
                cnames.append(cname)
                profiles.append(com.serialize())
                debug('Sending %s community profile to %s\n' %
                    (com.get('name'), user.get('nick')))
        return {'cname': cnames, 'profile': profiles}