Esempio n. 1
0
 def OnDataRecv(self, data):
     if data == 'ping':
         return 'ping', statuscode.STATUS_OK
     elif data == 'reboot':
         log.info('Rebooting...')
         os.execl(sys.executable, *([sys.executable]+sys.argv))
         return 'failed', statuscode.STATUS_CUSTOM_ERROR
Esempio n. 2
0
 def retry(self, interest):
     if not self.retries:
         self.recv_queue.put_nowait(QueueItem(interest, QueueItem.STATUS_TIME_OUT))
         return pyndn.RESULT_OK
     else:
         self.retries -= 1
         log.info('interest timed out, retrying...')
         return pyndn.RESULT_REEXPRESS
Esempio n. 3
0
	def start(self):
		log.info("listening on %s"% self.name)
		# register our name, so upcall is called when interest arrives
		self.handle.setInterestFilter(self.name, self)

		# enter ndn loop (upcalls won't be called without it, get
		# doesn't require it as well)
		# -1 means wait forever
		self.handle.run(-1)
Esempio n. 4
0
 def Start(self):
     # self.thread = _thread()
     # self.thread.start()
     
     log.info('Starting...')
     log.debug('Trying to connect servers')
     for x in self.clients:
         self.doConnect(x)
     CmdLineBackend._monitor(self.clients).start()
Esempio n. 5
0
    def _recv_thread(self):
        while True:
            try:
                item = self.recv_queue.get()
            except Exception, e:
                log.error(e)
                continue

            if self.state == STATE_NOT_AUTH:
                #handle auth response
                if item.status == QueueItem.STATUS_TIME_OUT:
                    self._auth_timed_out()
                else:
                    self._auth_response(item.content)
                continue

            if item.status == QueueItem.STATUS_TIME_OUT:
                log.info("send timed out %s" % item.name)
                self.state = STATE_IDLE
                continue

            if self.state != STATE_WAIT_RECV:
                log.warn('content received in a wrong state %d'%self.state)
                continue

            if item.status in [QueueItem.STATUS_BAD, QueueItem.STATUS_UNVERIFIED]:
                log.warn('got bad content')
                self.state = STATE_IDLE
            elif item.status == QueueItem.STATUS_OK:
                log.debug('got content')
                try:
                    (seq, status, content) = self._decode_response(item.content)
                    if int(status) == common.statuscode.STATUS_AUTH_ERROR:
                        log.warn("session expired")
                        self.ReConnect(self.connect_timeout or 10.0)
                        raise RMSAuthException #quit normal receiving procedure
                    seq = int(seq)
                    content = self._decrypt(content)
                    log.debug("content: %s" %(content))
                except RMSAuthException:
                    pass
                except Exception, e:
                    log.error("unable to decode content, %s" % e)
                except:
Esempio n. 6
0
    def doAuth(self, param, interest):
        try:
            if param[1] in self.auth_cache:
                log.info("Received duplicated authorization request, ignored.")
                return None
            self.auth_cache[param[1]] = True

            auth = security.Auth()
            auth.setOtherDHKey(long(param[1], 0))
            randS, preMaster = auth.getDHKey(), auth.genPreMasterKey(self.pubFile)
            s = self.newSession(security.AESCipher(auth.genMasterKey()))
            ret = json.dumps(dict(
                randS = hex(randS),
                preMaster = hexlify(preMaster),
                session = s
                ))
            log.info("New client connected")
        except Exception, e:
            ret = ''