Example #1
0
    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)
Example #2
0
    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)
Example #3
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)
Example #4
0
File: msgpack.py Project: plq/spyne
    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)
Example #5
0
    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
Example #7
0
    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()
Example #8
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)
Example #9
0
File: msgpack.py Project: plq/spyne
    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()
Example #10
0
    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)
Example #11
0
    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()
Example #12
0
    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)
Example #13
0
    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()
Example #14
0
File: http.py Project: knoxsp/spyne
    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)
Example #15
0
File: msgpack.py Project: plq/spyne
    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)
Example #16
0
    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)
Example #17
0
 def get_peer(self):
     if self.client_handle is not None:
         peer = self.client_handle.transport.getPeer()
         return Address.from_twisted_address(peer)
Example #18
0
 def get_peer(self):
     if self.client_handle is not None:
         peer = self.client_handle.transport.getPeer()
         return Address.from_twisted_address(peer)
Example #19
0
 def get_peer(self):
     if self.protocol is not None:
         peer = self.protocol.transport.getPeer()
         return Address.from_twisted_address(peer)
Example #20
0
def _address_from_twisted_address(peer):
    return Address(type=_TYPE_MAP.get(peer.type, None),
                   host=peer.host,
                   port=peer.port)
Example #21
0
 def get_peer(self):
     if self.protocol is not None:
         peer = self.protocol.transport.getPeer()
         return Address.from_twisted_address(peer)