def get_peer(self): addr, port = address_parser.get_ip(self.req),\ address_parser.get_port(self.req) if address_parser.is_valid_ipv4(addr): return Address(type=Address.TCP4, host=addr, port=port) if address_parser.is_valid_ipv6(addr): return Address(type=Address.TCP6, host=addr, port=port)
def get_peer(self): peer = Address.from_twisted_address(self.req.transport.getPeer()) addr = address_parser.get_ip(_Transformer(self.req)) if addr is None: return peer if address_parser.is_valid_ipv4(addr): return Address(type=Address.TCP4, host=addr, port=0) if address_parser.is_valid_ipv6(addr): return Address(type=Address.TCP6, host=addr, port=0)
def process_incoming_message(self, msg): p_ctx, others = self._transport.produce_contexts(msg) p_ctx.transport.remote_addr = Address.from_twisted_address( self.transport.getPeer()) p_ctx.transport.protocol = self self.process_contexts(p_ctx, others)
def process_inactive(self): peer = self.transport.getPeer() addr_str = Address.from_twisted_address(peer) if self.max_in_queue_size == 0: while self.num_inactive_contexts > 0: p_ctx, others = self.inactive_queue.pop() self.active_queue[id(p_ctx)] = p_ctx self.inreq_queue[id(p_ctx)] = None self.process_contexts(p_ctx, others) else: while self.num_active_contexts < self.max_in_queue_size and \ self.num_inactive_contexts > 0: p_ctx, others = self.inactive_queue.pop() self.active_queue[id(p_ctx)] = p_ctx self.inreq_queue[id(p_ctx)] = None self.process_contexts(p_ctx, others) if self.num_active_contexts > self.MAX_INACTIVE_CONTEXTS: logger.error("%s Too many inactive contexts. " "Closing connection.", addr_str) self.loseConnection("Too many inactive contexts") logger.debug("%s active %d inactive %d", addr_str, self.num_active_contexts, self.num_inactive_contexts)
def process_inactive(self): peer = self.transport.getPeer() addr_str = Address.from_twisted_address(peer) if self.max_in_queue_size == 0: while self.num_inactive_contexts > 0: p_ctx, others = self.inactive_queue.pop() self.active_queue[id(p_ctx)] = p_ctx self.inreq_queue[id(p_ctx)] = None self.process_contexts(p_ctx, others) else: while self.num_active_contexts < self.max_in_queue_size and \ self.num_inactive_contexts > 0: p_ctx, others = self.inactive_queue.pop() self.active_queue[id(p_ctx)] = p_ctx self.inreq_queue[id(p_ctx)] = None self.process_contexts(p_ctx, others) if self.num_active_contexts > self.MAX_INACTIVE_CONTEXTS: logger.error( "%s Too many inactive contexts. " "Closing connection.", addr_str) self.loseConnection("Too many inactive contexts") logger.debug("%s active %d inactive %d", addr_str, self.num_active_contexts, self.num_inactive_contexts)
def get_peer(self) -> typing.Optional[Address]: if not self.req_env.transport: return None peer = self.req_env.transport.get_extra_info("peername") if not peer: return None host, port = peer if address_parser.is_valid_ipv4(host): return Address(type=Address.TCP4, host=host, port=port) if address_parser.is_valid_ipv6(host): return Address(type=Address.TCP6, host=host, port=port) return None
def gen_sessid(self, *args): """It's up to you to use this in a subclass.""" retval = _cha(Address.from_twisted_address(self.transport.getPeer()), time(), *args) return md5(repr(retval).encode('utf8')).hexdigest()
def process_incoming_message(self, msg): p_ctx, others = self.spyne_tpt.produce_contexts(msg) p_ctx.transport.remote_addr = Address.from_twisted_address(self.transport.getPeer()) p_ctx.transport.protocol = self p_ctx.transport.sessid = self.sessid self.inactive_queue.append((p_ctx, others)) self.process_inactive()
def process_incoming_message(self, msg): p_ctx, others = self.spyne_tpt.produce_contexts(msg) p_ctx.transport.remote_addr = Address.from_twisted_address(self.transport.getPeer()) p_ctx.transport.protocol = self p_ctx.transport.sessid = self.sessid self.inreq_queue[id(p_ctx)] = None self.process_contexts(p_ctx, others)
def process_incoming_message(self, msg): p_ctx, others = self.spyne_tpt.produce_contexts(msg) p_ctx.transport.remote_addr = Address.from_twisted_address( self.transport.getPeer()) p_ctx.transport.protocol = self p_ctx.transport.sessid = self.sessid self.inactive_queue.append((p_ctx, others)) self.process_inactive()
def process_incoming_message(self, msg): p_ctx, others = self.spyne_tpt.produce_contexts(msg) p_ctx.transport.remote_addr = Address.from_twisted_address( self.transport.getPeer()) p_ctx.transport.protocol = self p_ctx.transport.sessid = self.sessid self.inreq_queue[id(p_ctx)] = None self.process_contexts(p_ctx, others)
def gen_sessid(self, *args): """It's up to you to use this in a subclass.""" retval = _cha( Address.from_twisted_address(self.transport.getPeer()), time(), *args ) return md5(repr(retval)).hexdigest()
def process_inactive(self): if self.max_in_queue_size == 0: while self.num_inactive_contexts > 0: p_ctx, others = self.inactive_queue.pop() self.inreq_queue[id(p_ctx)] = None self.process_contexts(p_ctx, others) else: while self.num_active_contexts < self.max_in_queue_size and self.num_inactive_contexts > 0: p_ctx, others = self.inactive_queue.pop() self.inreq_queue[id(p_ctx)] = None self.process_contexts(p_ctx, others) peer = self.transport.getPeer() addr_str = Address.from_twisted_address(peer) logger.debug("%s active %d inactive %d", addr_str, self.num_active_contexts, self.num_inactive_contexts)
def process_inactive(self): if self.max_in_queue_size == 0: while self.num_inactive_contexts > 0: p_ctx, others = self.inactive_queue.pop() self.inreq_queue[id(p_ctx)] = None self.process_contexts(p_ctx, others) else: while self.num_active_contexts < self.max_in_queue_size and \ self.num_inactive_contexts > 0: p_ctx, others = self.inactive_queue.pop() self.inreq_queue[id(p_ctx)] = None self.process_contexts(p_ctx, others) peer = self.transport.getPeer() addr_str = Address.from_twisted_address(peer) logger.debug("%s active %d inactive %d", addr_str, self.num_active_contexts, self.num_inactive_contexts)
def get_peer(self): if self.client_handle is not None: peer = self.client_handle.transport.getPeer() return Address.from_twisted_address(peer)
def get_peer(self): if self.protocol is not None: peer = self.protocol.transport.getPeer() return Address.from_twisted_address(peer)
def _address_from_twisted_address(peer): return Address(type=_TYPE_MAP.get(peer.type, None), host=peer.host, port=peer.port)