def rengine_side(self, appid, token, uri): """ Handle rengine (client) GET requests """ if not self.rengine_authorization_ok(appid, token): LOGGER.info('Rengine content request authorization fails') abort(401, 'Authorization failed') evt = Event() request_id = str(uuid4()) self.request_id_events[request_id] = evt headers = [ "%s: %s" % (header, val) for (header, val) in request.headers.items() ] packet = ScpPacket.make_sfkcontent(uri, request_id, headers) try: self._send(packet, appid) except Exception as e: abort(500, str(e)) LOGGER.debug("uri %s expected" % uri) timeout = Timeout(TIMEOUT) try: resp = evt.wait() except Timeout: del self.request_id_events[request_id] abort(504, 'Gateway Timeout') finally: timeout.cancel() LOGGER.debug("uri %s got" % uri) return resp
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()
def rengine_side(self, appid, token, uri): """ Handle rengine (client) GET requests """ if not self.rengine_authorization_ok(appid, token): LOGGER.info('Rengine content request authorization fails') abort(401, 'Authorization failed') evt = Event() request_id = str(uuid4()) self.request_id_events[request_id] = evt headers = ["%s: %s" % (header, val) for (header, val) in request.headers.items()] packet = ScpPacket.make_sfkcontent(uri, request_id, headers) try: self._send(packet, appid) except Exception as e: abort(500, str(e)) LOGGER.debug("uri %s expected" % uri) timeout = Timeout(TIMEOUT) try: resp = evt.wait() except Timeout: del self.request_id_events[request_id] abort(504, 'Gateway Timeout') finally: timeout.cancel() LOGGER.debug("uri %s got" % uri) return resp
def determine_packet_type(fileobj): """ reads magic from fileobj, return one of children packets - scp or spif2 """ # TODO timeout ?? magic = Packet._read_int(fileobj) if magic is None: raise Disconnection("disconnected") for packet in _CHRILDREN_PACKETS: if magic == packet.MAGIC: return packet LOGGER.debug("magic: %s" % magic) raise UnexpectedProtocol("cannot determine packet type")
def determine_packet_type(fileobj): """ reads magic from fileobj, return one of children packets - scp or spif2 """ # TODO timeout ?? magic = Packet._read_int(fileobj) if magic is None: raise Disconnection("disconnected") for packet in _CHRILDREN_PACKETS: if magic == packet.MAGIC: return packet LOGGER.debug("magic: %s" % magic) raise UnexpectedProtocol("cannot determine packet type")
def sender(self, callback=lambda: None): """get packet from sending queue, send it via sock. By convention, packet type checking performed before putting in queue """ try: while True: packet = self.queue_send.get() data = packet.assemble() self.sock.sendall(data) # TODO if DEBUG try: if packet.get_msg_type() == 'pong': LOGGER.debug('pong sent %s' % self) except AttributeError: pass except Exception: LOGGER.error(str(self) + " sender error") eventlet.spawn_n(callback)
def sender(self, callback=lambda: None): """get packet from sending queue, send it via sock. By convention, packet type checking performed before putting in queue """ try: while True: packet = self.queue_send.get() data = packet.assemble() self.sock.sendall(data) # TODO if DEBUG try: if packet.get_msg_type() == 'pong': LOGGER.debug('pong sent %s' % self) except AttributeError: pass except Exception: LOGGER.error(str(self) + " sender error") eventlet.spawn_n(callback)