Пример #1
0
    def mainloop(self, callback=lambda: None):
        try:
            while True:
                packet = self.sfk.get_packet()
                msg_type = packet.get_msg_type()

                if msg_type == 'msg':
                    guid = packet.get_guid()
                    client_sockwrap = self.client_sockwraps.get(guid, None)
                    if client_sockwrap is None:
                        # client already disconnected
                        LOGGER.info('Client with guid %s not connected' %
                                    str_uuid(guid))
                        continue
                    else:
                        spif2packet = self._unpack_scp_to_spif2(packet)
                        client_sockwrap.put_packet(spif2packet)

                elif msg_type == 'ping':
                    pong = packet.make_pong()
                    self.sfk.put_packet(pong)
                    LOGGER.debug("appid %s; sfk_id %s - recieved ping" % \
                                 (self.appid, self.sfk_id))

                else:
                    raise DockerError("unknown msg_type")

        except Exception:
            LOGGER.exception("Sfk Docker fails")
            callback()
Пример #2
0
 def pinger(self):
     try:
         while True:
             eventlet.sleep(PING_PERIOD)
             ping = self._make_ping_packet()
             self.queue_send.put(ping)
             LOGGER.info("PING! In sending queue %d" % self.queue_send.qsize())
     except Exception as e:
         LOGGER.exception("Pinger fails: %s" % str(e))
Пример #3
0
 def pinger(self):
     try:
         while True:
             eventlet.sleep(PING_PERIOD)
             ping = self._make_ping_packet()
             self.queue_send.put(ping)
             LOGGER.info("PING! In sending queue %d" %
                         self.queue_send.qsize())
     except Exception as e:
         LOGGER.exception("Pinger fails: %s" % str(e))
Пример #4
0
 def recved_packets_processor(self):
     try:
         while True:
             packet = self.queue_recv.get()
             self.guids.add(packet.guid)
             mtype = packet.get_msg_type()    
             payload = None
             if mtype == 'msg':
                 buf = StringIO.StringIO(packet.data)
                 pack_class = prot.determine_packet_type(buf)
                 client_pack = pack_class()
                 client_pack.read_fields(buf)
                 payload = client_pack.bindata
             elif mtype == 'sfkcontent':
                 SfkModel.sfkcontent_handler(packet)
                 continue
             elif mtype == 'session_dropped':
                 self.guids.remove(packet.guid)
                 LOGGER.info('session dropped guid {0}'.format(
                     str_uuid(packet.guid)))
                 continue
             elif mtype == 'pong':
                 LOGGER.info('Pong recieved')
             else:
                 LOGGER.error("Unknown message type: {0}".format(mtype))
                         
             LOGGER.info('recved packet guid {0}; mtype {1}'.format(
                                               str_uuid(packet.guid),
                                               mtype))
             if payload:
                 LOGGER.info('message: %s' % payload)
                 reply = self._make_reply_packet(payload=payload, 
                                                 guid=packet.guid)
                 self.queue_send.put(reply)
                 LOGGER.info('reply is sent')
     except Exception as e:
         LOGGER.exception("recved_packets_processor: " + str(e))
Пример #5
0
    def recved_packets_processor(self):
        try:
            while True:
                packet = self.queue_recv.get()
                self.guids.add(packet.guid)
                mtype = packet.get_msg_type()
                payload = None
                if mtype == 'msg':
                    buf = StringIO.StringIO(packet.data)
                    pack_class = prot.determine_packet_type(buf)
                    client_pack = pack_class()
                    client_pack.read_fields(buf)
                    payload = client_pack.bindata
                elif mtype == 'sfkcontent':
                    SfkModel.sfkcontent_handler(packet)
                    continue
                elif mtype == 'session_dropped':
                    self.guids.remove(packet.guid)
                    LOGGER.info('session dropped guid {0}'.format(
                        str_uuid(packet.guid)))
                    continue
                elif mtype == 'pong':
                    LOGGER.info('Pong recieved')
                else:
                    LOGGER.error("Unknown message type: {0}".format(mtype))

                LOGGER.info('recved packet guid {0}; mtype {1}'.format(
                    str_uuid(packet.guid), mtype))
                if payload:
                    LOGGER.info('message: %s' % payload)
                    reply = self._make_reply_packet(payload=payload,
                                                    guid=packet.guid)
                    self.queue_send.put(reply)
                    LOGGER.info('reply is sent')
        except Exception as e:
            LOGGER.exception("recved_packets_processor: " + str(e))