Пример #1
0
    def gotChannelCastMessage(self, recv_msg, sender_permid, selversion):
        if selversion < OLPROTO_VER_THIRTEENTH:
            if DEBUG:
                print >> sys.stderr, 'channelcast: Do not receive from lower version peer:', selversion
            return True
        if DEBUG:
            print >> sys.stderr, 'channelcast: Received a msg from ', show_permid_short(
                sender_permid)
            print >> sys.stderr, 'channelcast: my_permid=', show_permid_short(
                self.my_permid)
        if not sender_permid or sender_permid == self.my_permid:
            if DEBUG:
                print >> sys.stderr, 'channelcast: warning - got channelcastMsg from a None/Self peer', show_permid_short(
                    sender_permid), recv_msg
            return False
        channelcast_data = {}
        try:
            channelcast_data = bdecode(recv_msg)
        except:
            print >> sys.stderr, 'channelcast: warning, invalid bencoded data'
            return False

        if not validChannelCastMsg(channelcast_data):
            print >> sys.stderr, 'channelcast: invalid channelcast_message'
            return False
        for ch in channelcast_data.values():
            if isinstance(ch['publisher_name'], str):
                ch['publisher_name'] = str2unicode(ch['publisher_name'])
            if isinstance(ch['torrentname'], str):
                ch['torrentname'] = str2unicode(ch['torrentname'])

        self.handleChannelCastMsg(sender_permid, channelcast_data)
        if self.log:
            dns = self.dnsindb(sender_permid)
            if dns:
                ip, port = dns
                MSG_ID = 'CHANNELCAST'
                msg = repr(channelcast_data)
                self.overlay_log('RECV_MSG', ip, port,
                                 show_permid(sender_permid), selversion,
                                 MSG_ID, msg)
        if self.TESTASSERVER:
            self.createAndSendChannelCastMessage(sender_permid, selversion)
        return True
Пример #2
0
    def gotChannelCastMessage(self, recv_msg, sender_permid, selversion):
        if selversion < OLPROTO_VER_THIRTEENTH:
            if DEBUG:
                print >> sys.stderr, 'channelcast: Do not receive from lower version peer:', selversion
            return True
        if DEBUG:
            print >> sys.stderr, 'channelcast: Received a msg from ', show_permid_short(sender_permid)
            print >> sys.stderr, 'channelcast: my_permid=', show_permid_short(self.my_permid)
        if not sender_permid or sender_permid == self.my_permid:
            if DEBUG:
                print >> sys.stderr, 'channelcast: warning - got channelcastMsg from a None/Self peer', show_permid_short(sender_permid), recv_msg
            return False
        channelcast_data = {}
        try:
            channelcast_data = bdecode(recv_msg)
        except:
            print >> sys.stderr, 'channelcast: warning, invalid bencoded data'
            return False

        if not validChannelCastMsg(channelcast_data):
            print >> sys.stderr, 'channelcast: invalid channelcast_message'
            return False
        for ch in channelcast_data.values():
            if isinstance(ch['publisher_name'], str):
                ch['publisher_name'] = str2unicode(ch['publisher_name'])
            if isinstance(ch['torrentname'], str):
                ch['torrentname'] = str2unicode(ch['torrentname'])

        self.handleChannelCastMsg(sender_permid, channelcast_data)
        if self.log:
            dns = self.dnsindb(sender_permid)
            if dns:
                ip, port = dns
                MSG_ID = 'CHANNELCAST'
                msg = repr(channelcast_data)
                self.overlay_log('RECV_MSG', ip, port, show_permid(sender_permid), selversion, MSG_ID, msg)
        if self.TESTASSERVER:
            self.createAndSendChannelCastMessage(sender_permid, selversion)
        return True
Пример #3
0
def save_ssocnet_peer(self, permid, record, persinfo_ignore, hrwidinfo_ignore, ipinfo_ignore):
    if permid == self.mypermid:
        return
    if not persinfo_ignore:
        persinfo = record['persinfo']
        if DEBUG:
            print >> sys.stderr, 'socnet: Got persinfo', persinfo.keys()
            if len(persinfo.keys()) > 1:
                print >> sys.stderr, 'socnet: Got persinfo THUMB THUMB THUMB THUMB'
        name = str2unicode(persinfo['name'])
        if DEBUG:
            print >> sys.stderr, 'socnet: SOCIAL_OVERLAP', show_permid_short(permid), `name`
        if self.peer_db.hasPeer(permid):
            self.peer_db.updatePeer(permid, name=name)
        else:
            self.peer_db.addPeer(permid, {'name': name})
        if 'icontype' in persinfo and 'icondata' in persinfo:
            if DEBUG:
                print >> sys.stderr, 'socnet: saving icon for', show_permid_short(permid), `name`
            self.peer_db.updatePeerIcon(permid, persinfo['icontype'], persinfo['icondata'])
Пример #4
0
def save_ssocnet_peer(self, permid, record, persinfo_ignore, hrwidinfo_ignore,
                      ipinfo_ignore):
    if permid == self.mypermid:
        return
    if not persinfo_ignore:
        persinfo = record['persinfo']
        if DEBUG:
            print >> sys.stderr, 'socnet: Got persinfo', persinfo.keys()
            if len(persinfo.keys()) > 1:
                print >> sys.stderr, 'socnet: Got persinfo THUMB THUMB THUMB THUMB'
        name = str2unicode(persinfo['name'])
        if DEBUG:
            print >> sys.stderr, 'socnet: SOCIAL_OVERLAP', show_permid_short(
                permid), ` name `
        if self.peer_db.hasPeer(permid):
            self.peer_db.updatePeer(permid, name=name)
        else:
            self.peer_db.addPeer(permid, {'name': name})
        if 'icontype' in persinfo and 'icondata' in persinfo:
            if DEBUG:
                print >> sys.stderr, 'socnet: saving icon for', show_permid_short(
                    permid), ` name `
            self.peer_db.updatePeerIcon(permid, persinfo['icontype'],
                                        persinfo['icondata'])