Пример #1
0
 def call(self, func_name, *args, **k_args):
     if not self.connected:
         raise RPC_Exception("not connected")
     try:
         start_ts = time.time()
         iv = random_string(self.block_size)
         crypter_r = AESCryptor(self.key, iv, self.block_size)
         crypter_w = AESCryptor(self.key, iv, self.block_size)
         req = RPC_Req(func_name, args, k_args)
         data = req.serialize()
         head = NetHead()
         buf = iv + crypter_w.encrypt(data)
         head.write_msg(self.sock, buf)
         resp = None
         resp_head = NetHead.read_head(self.sock)
         if not resp_head.body_len:
             raise RPC_Exception("rpc call %s, server-side return empty head" % (str(req)))
         buf = resp_head.read_data(self.sock)
         buf = crypter_r.decrypt(buf)
         resp = RPC_Resp.deserialize(buf)
         end_ts = time.time()
         timespan = end_ts - start_ts
         if resp.error is not None:
             raise RPC_Exception("rpc call %s return error: %s [%s sec]" % (str(req), str(resp.error), timespan))
         if self.logger:
             self.logger.info("rpc call %s returned  [%s sec]" % (str(req), timespan))
         return resp.retval
     except socket.error, e:
         self.close()
         raise e
Пример #2
0
 def call(self, func_name, *args, **k_args):
     if not self.connected:
         raise RPC_Exception("not connected")
     try:
         start_ts = time.time()
         iv = random_string(self.block_size)
         crypter_r = AESCryptor(self.key, iv, self.block_size)
         crypter_w = AESCryptor(self.key, iv, self.block_size)
         req = RPC_Req(func_name, args, k_args)
         data = req.serialize()
         head = NetHead()
         buf = iv + crypter_w.encrypt(data)
         head.write_msg(self.sock, buf)
         resp = None
         resp_head = NetHead.read_head(self.sock)
         if not resp_head.body_len:
             raise RPC_Exception(
                 "rpc call %s, server-side return empty head" %
                 (str(req)))
         buf = resp_head.read_data(self.sock)
         buf = crypter_r.decrypt(buf)
         resp = RPC_Resp.deserialize(buf)
         end_ts = time.time()
         timespan = end_ts - start_ts
         if resp.error is not None:
             raise RPC_Exception(
                 "rpc call %s return error: %s [%s sec]" %
                 (str(req), str(resp.error), timespan))
         if self.logger:
             self.logger.info("rpc call %s returned  [%s sec]" %
                              (str(req), timespan))
         return resp.retval
     except socket.error, e:
         self.close()
         raise e
Пример #3
0
 def _send(self, resp):
     conn = self.conn
     try:
         NetHead().write_msg(conn.sock, resp.serialize())
         self.server.engine.watch_conn(conn)
     except Exception, e:
         self.server.logger_err.exception(
             "peer %s, send response error: %s" % (conn.peer, str(e)))
         self.server.engine.close_conn(conn)
Пример #4
0
 def call(self, func_name, *args, **k_args):
     if not self.connected:
         raise RPC_Exception("not connected")
     if k_args.has_key('_retry'):
         retry = k_args['_retry']
         del k_args['_retry']
     else:
         retry = 0
     i = 0
     while True:
         try:
             start_ts = time.time()
             req = RPC_Req(func_name, args, k_args)
             data = req.serialize()
             head = NetHead()
             head.write_msg(self.sock, data)
             resp = None
             resp_head = NetHead.read_head(self.sock)
             if not resp_head.body_len:
                 raise RPC_Exception(
                     "rpc call %s, server-side return empty head" %
                     (str(req)))
             buf = resp_head.read_data(self.sock)
             resp = RPC_Resp.deserialize(buf)
             end_ts = time.time()
             timespan = end_ts - start_ts
             if resp.error is not None:
                 raise RPC_Exception(
                     "rpc call %s return error: %s [%s sec]" %
                     (str(req), str(resp.error), timespan))
             if self.logger:
                 self.logger.info("rpc call %s returned  [%s sec]" %
                                  (str(req), timespan))
             return resp.retval
         except socket.error, e:
             self.close()
             if e.args[0] == 0 and retry > 0 and i < retry:  # peer close
                 self.connect(self.addr)
                 i += 1
                 continue
             raise
 def _server_handle(self, conn):
     sock = conn.sock
     head = None
     try:
         head = NetHead.read_head(sock)
     except socket.error:
         self.engine.close_conn(conn)
         return
     except Exception, e:
         self.logger_err.exception(e)
         self.engine.close_conn(conn)
         return
Пример #6
0
 def _server_handle(self, conn):
     sock = conn.sock
     head = None
     try:
         head = NetHead.read_head(sock)
     except socket.error:
         self.engine.close_conn(conn)
         return
     except Exception, e:
         self.logger_err.exception(e)
         self.engine.close_conn(conn)
         return
Пример #7
0
Файл: rpc.py Проект: 42qu/vps
 def call(self, func_name, *args, **k_args):
     if not self.connected:
         raise RPC_Exception("not connected")
     if k_args.has_key('_retry'):
         retry = k_args['_retry']
         del k_args['_retry']
     else:
         retry = 0
     i = 0
     while True:
         try:
             start_ts = time.time()
             req = RPC_Req(func_name, args, k_args)
             data = req.serialize()
             head = NetHead()
             head.write_msg(self.sock, data)
             resp = None
             resp_head = NetHead.read_head(self.sock)
             if not resp_head.body_len:
                 raise RPC_Exception(
                     "rpc call %s, server-side return empty head" % (str(req)))
             buf = resp_head.read_data(self.sock)
             resp = RPC_Resp.deserialize(buf)
             end_ts = time.time()
             timespan = end_ts - start_ts
             if resp.error is not None:
                 raise RPC_Exception(
                     "rpc call %s return error: %s [%s sec]" % (str(req), str(resp.error), timespan))
             if self.logger:
                 self.logger.info(
                     "rpc call %s returned  [%s sec]" % (str(req), timespan))
             return resp.retval
         except socket.error, e:
             self.close()
             if e.args[0] == 0 and retry > 0 and i < retry: # peer close
                 self.connect(self.addr)
                 i += 1
                 continue
             raise