def gotChannelCastMessage(self, recv_msg, sender_permid, selversion): """ Receive and handle a ChannelCast message """ # ChannelCast feature starts from eleventh version; hence, do not receive from lower version peers if selversion < OLPROTO_VER_ELEVENTH: if DEBUG: print >> sys.stderr, "Do not receive from lower version peer:", selversion return if DEBUG: print >> sys.stderr, 'channelcast: Received a msg from ', permid_for_user( sender_permid) print >> sys.stderr, " my_permid=", permid_for_user(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", \ permid_for_user(sender_permid), recv_msg return False #if len(recv_msg) > self.max_length: # if DEBUG: # print >> sys.stderr, "channelcast: warning - got large channelCastHaveMsg", len(recv_msg) # return False channelcast_data = {} try: channelcast_data = bdecode(recv_msg) except: print >> sys.stderr, "channelcast: warning, invalid bencoded data" return False # check message-structure if not validChannelCastMsg(channelcast_data): print >> sys.stderr, "channelcast: invalid channelcast_message" return False self.handleChannelCastMsg(sender_permid, channelcast_data) #Log RECV_MSG of uncompressed message 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) return True
def handleVoteCastMsg(self, sender_permid, data): """ Handles VoteCast message """ if DEBUG: print >> sys.stderr, "Processing VOTECAST msg from: ", permid_for_user(sender_permid), "; data: ", repr(data) for value in data: vote = {} vote['mod_id'] = value[0] vote['voter_id'] = permid_for_user(sender_permid) vote['vote'] = value[1] self.votecastdb.addVote(vote) if DEBUG: print >> sys.stderr,"Processing VOTECAST msg from: ", permid_for_user(sender_permid), "DONE; data:"
def gotChannelCastMessage(self, recv_msg, sender_permid, selversion): """ Receive and handle a ChannelCast message """ # ChannelCast feature starts from eleventh version; hence, do not receive from lower version peers if selversion < OLPROTO_VER_ELEVENTH: if DEBUG: print >> sys.stderr, "Do not receive from lower version peer:", selversion return if DEBUG: print >> sys.stderr,'channelcast: Received a msg from ', permid_for_user(sender_permid) print >> sys.stderr," my_permid=", permid_for_user(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", \ permid_for_user(sender_permid), recv_msg return False #if len(recv_msg) > self.max_length: # if DEBUG: # print >> sys.stderr, "channelcast: warning - got large channelCastHaveMsg", len(recv_msg) # return False channelcast_data = {} try: channelcast_data = bdecode(recv_msg) except: print >> sys.stderr, "channelcast: warning, invalid bencoded data" return False # check message-structure if not validChannelCastMsg(channelcast_data): print >> sys.stderr, "channelcast: invalid channelcast_message" return False self.handleChannelCastMsg(sender_permid, channelcast_data) #Log RECV_MSG of uncompressed message 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) return True
def gotVoteCastMessage(self, recv_msg, sender_permid, selversion): """ Receives VoteCast message and handles it. """ # VoteCast feature is renewed in eleventh version; hence, do not receive from lower version peers if selversion < OLPROTO_VER_ELEVENTH: if DEBUG: print >> sys.stderr, "Do not receive from lower version peer:", selversion return if DEBUG: print >> sys.stderr,'votecast: Received a msg from ', permid_for_user(sender_permid) if not sender_permid or sender_permid == self.my_permid: if DEBUG: print >> sys.stderr, "votecast: error - got votecastMsg from a None peer", \ permid_for_user(sender_permid), recv_msg return False if self.max_length > 0 and len(recv_msg) > self.max_length: if DEBUG: print >> sys.stderr, "votecast: warning - got large voteCastHaveMsg; msg_size:", len(recv_msg) return False votecast_data = {} try: votecast_data = bdecode(recv_msg) except: print >> sys.stderr, "votecast: warning, invalid bencoded data" return False # check message-structure if not validVoteCastMsg(votecast_data): print >> sys.stderr, "votecast: warning, invalid votecast_message" return False self.handleVoteCastMsg(sender_permid, votecast_data) #Log RECV_MSG of uncompressed message if self.log: dns = self.dnsindb(sender_permid) if dns: ip,port = dns MSG_ID = "VOTECAST" msg = voteCastMsgToString(votecast_data) self.overlay_log('RECV_MSG', ip, port, show_permid(sender_permid), selversion, MSG_ID, msg) return True
def handleVoteCastMsg(self, sender_permid, data): """ Handles VoteCast message """ if DEBUG: print >> sys.stderr, "votecast: Processing VOTECAST msg from: ", show_permid_short(sender_permid), "; data: ", repr(data) mod_ids = Set() for key, value in data.items(): vote = {} vote['mod_id'] = bin2str(key) vote['voter_id'] = permid_for_user(sender_permid) vote['vote'] = value['vote'] vote['time_stamp'] = value['time_stamp'] self.votecastdb.addVote(vote) mod_ids.add(vote['mod_id']) # Arno, 2010-02-24: Generate event for mod_id in mod_ids: try: self.notifier.notify(NTFY_VOTECAST, NTFY_UPDATE, mod_id) except: print_exc() if DEBUG: print >> sys.stderr,"votecast: Processing VOTECAST msg from: ", show_permid_short(sender_permid), "DONE; data:"
def logMsg(self, msg_data, msg_permid, in_or_out, logfile): if in_or_out == 'in': permid_from = permid_for_user(msg_permid) elif in_or_out == 'out': permid_from = 'LOCAL' else: return timestamp = now() log = open(logfile, 'a') string = '%.1f %s %s' % (timestamp, in_or_out, permid_for_user(msg_permid)) log.write(string + '\n') print >> sys.stderr, string data = msg_data.get('data', []) for permid in data: u = data[permid]['u'] d = data[permid]['d'] string = '%.1f %s %s %d %d' % (timestamp, permid_from, permid_for_user(permid), u, d) log.write(string + '\n') print >> sys.stderr, string totals = msg_data.get('totals', None) if totals != None: (u, d) = totals string = '%.1f TOT %s %d %d' % (timestamp, permid_from, u, d) log.write(string + '\n') print >> sys.stderr, string log.close()
def channelCastSendCallback(self, exc, target_permid, other=0): if DEBUG: if exc is None: print >> sys.stderr,"channelcast: *** msg was sent successfully to peer", permid_for_user(target_permid) else: print >> sys.stderr, "channelcast: *** warning - error in sending msg to", permid_for_user(target_permid), exc
def channelCastSendCallback(self, exc, target_permid, other=0): if DEBUG: if exc is None: print >> sys.stderr, "channelcast: *** msg was sent successfully to peer", permid_for_user( target_permid) else: print >> sys.stderr, "channelcast: *** warning - error in sending msg to", permid_for_user( target_permid), exc