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))
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))
def load_func(s): def func(): pass code = type(load_func.func_code)(*mummy.loads(s)) func.func_code = code return func
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
def _recv(pipefd, os): length = struct.unpack('>I', os.read(pipefd, 4))[0] return mummy.loads(os.read(pipefd, length))
def deepcopy(item): return mummy.loads(mummy.dumps(item))
def recv_one(self): size = struct.unpack("!I", self.read_bytes(4))[0] return mummy.loads(self.read_bytes(size))