def announce(self, port): #get the local ip and set it for later use ip = util.get_ip(self.conf) if len(ip) == 0: self.logger.error('No local ip-address could be found and none was specified, using default!') ip = constants.IP if ip != self.ip: self.logger.info('Found local ip %s!' % (ip)) self.ip = ip self.logger.debug('Announcing %s:%d!' % (self.ip, port)) msg = util.encrypt(self.conf['keyfile'],"CSHELO:%s:%d:OLEHSC" % (self.ip, port)) util.broadcast(msg, constants.PORT) #use fixed port for sending
def run(self): ''' This method starts the Clipshare server and starts listening on the given port. ''' while True: message, address = self.s.recvfrom(self.buf_size) self.logger.debug('Got message, decrypting') decrypted = None try: decrypted = util.decrypt(self.conf['keyfile'], message) except CipherError: #something went wrong during decrypting, probably garbage self.logger.debug('Got some garbage after decrypting, ignoring') t = util.get_message_type(decrypted) if t == 'CSHELO': #new client found, add it to the list (remote_ip, port) = util.parse_cs_helo_msg(decrypted) local_ip = util.get_ip(self.conf) #check that the remote_ip isn't our own ip: if str(remote_ip) != local_ip: self.clientlistlock.acquire() if str(remote_ip) not in self.clientlist: self.logger.info('Added client with ip %s on port %d!' % (remote_ip, port)) self.clientlist[remote_ip] = (port, datetime.now()) self.clientlistlock.release() elif t == 'CSCONTENT': #new content, put it in clipboard content = util.parse_cs_content_msg(decrypted) self.just_in = content if 'debug' in self.conf: self.logger.debug('Got new content: "' + content + '" from %s' % address[0]) else: self.logger.info('Got new content from %s!' % address[0]) util.store_in_clipboard(content) else: #garbage pass