Exemplo n.º 1
0
    def _udp_listener(self):
        sock = backend.Socket(socket.AF_INET, socket.SOCK_DGRAM)
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        sock.bind(self.addr)

        log.info("starting UDP listener socket on %r" % (self.addr,))

        while not self._closing:
            try:
                msg, addr = sock.recvfrom(MAX_UDP_PACKET_SIZE)
            except errors._BailOutOfListener:
                log.info("closing listener socket")
                server.close()
                break

            msg = mummy.loads(msg)
            if not isinstance(msg, tuple) or len(msg) != 3:
                log.warn("malformed UDP message sent from %r" % (addr,))

            msg_type, sender_hostport, msg = msg
            if msg_type not in const.UDP_ALLOWED:
                log.warn("disallowed UDP message type %r from %r" %
                        (msg_type, sender_hostport))
                continue

            if sender_hostport not in self._dispatcher.peers:
                log.warn("UDP message from unknown sender: %r" %
                        (sender_hostport,))
                continue

            log.debug("UDP message received from %r" % (sender_hostport,))

            peer = self._dispatcher.peers[sender_hostport]
            self._dispatcher.incoming(peer, (msg_type, msg))
Exemplo n.º 2
0
    def _udp_listener(self):
        sock = backend.Socket(socket.AF_INET, socket.SOCK_DGRAM)
        sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        sock.bind(self.addr)

        log.info("starting UDP listener socket on %r" % (self.addr, ))

        while not self._closing:
            try:
                msg, addr = sock.recvfrom(MAX_UDP_PACKET_SIZE)
            except errors._BailOutOfListener:
                log.info("closing listener socket")
                server.close()
                break

            msg = mummy.loads(msg)
            if not isinstance(msg, tuple) or len(msg) != 3:
                log.warn("malformed UDP message sent from %r" % (addr, ))

            msg_type, sender_hostport, msg = msg
            if msg_type not in const.UDP_ALLOWED:
                log.warn("disallowed UDP message type %r from %r" %
                         (msg_type, sender_hostport))
                continue

            if sender_hostport not in self._dispatcher.peers:
                log.warn("UDP message from unknown sender: %r" %
                         (sender_hostport, ))
                continue

            log.debug("UDP message received from %r" % (sender_hostport, ))

            peer = self._dispatcher.peers[sender_hostport]
            self._dispatcher.incoming(peer, (msg_type, msg))
Exemplo n.º 3
0
def load_func(s):
    def func():
        pass

    code = type(load_func.func_code)(*mummy.loads(s))
    func.func_code = code
    return func
Exemplo n.º 4
0
def storage_unwrap(ctx, value):
    st = ctx_storage(ctx)
    if st is None:
        raise error.BadContext(ctx)

    if isinstance(value, _Binary):
        value = value.adapted
    if isinstance(value, buffer):
        value = str(value)

    if st == storage.UTF:
        value = value.decode("utf8")

    if st == storage.SERIAL:
        schema = ctx_schema(ctx)
        if schema:
            value = schema.untransform(mummy.loads(value))
        else:
            value = mummy.loads(value)

    return value
Exemplo n.º 5
0
def load_func(s):
    def func():
        pass
    code = type(load_func.func_code)(*mummy.loads(s))
    func.func_code = code
    return func
Exemplo n.º 6
0
def _recv(pipefd, os):
    length = struct.unpack('>I', os.read(pipefd, 4))[0]
    return mummy.loads(os.read(pipefd, length))
Exemplo n.º 7
0
def deepcopy(item):
    return mummy.loads(mummy.dumps(item))
Exemplo n.º 8
0
 def recv_one(self):
     size = struct.unpack("!I", self.read_bytes(4))[0]
     return mummy.loads(self.read_bytes(size))
Exemplo n.º 9
0
 def recv_one(self):
     size = struct.unpack("!I", self.read_bytes(4))[0]
     return mummy.loads(self.read_bytes(size))
Exemplo n.º 10
0
def deepcopy(item):
    return mummy.loads(mummy.dumps(item))