def wrap_grpc_packet(_json_body, _method, _url, _src_party_id, _dst_party_id, job_id=None, overall_timeout=DEFAULT_GRPC_OVERALL_TIMEOUT): _src_end_point = basic_meta_pb2.Endpoint(ip=IP, port=GRPC_PORT) _src = proxy_pb2.Topic(name=job_id, partyId="{}".format(_src_party_id), role=ROLE, callback=_src_end_point) _dst = proxy_pb2.Topic(name=job_id, partyId="{}".format(_dst_party_id), role=ROLE, callback=None) _task = proxy_pb2.Task(taskId=job_id) _command = proxy_pb2.Command(name=ROLE) _conf = proxy_pb2.Conf(overallTimeout=overall_timeout) _meta = proxy_pb2.Metadata(src=_src, dst=_dst, task=_task, command=_command, operator=_method, conf=_conf) _data = proxy_pb2.Data(key=_url, value=bytes(json.dumps(_json_body), 'utf-8')) return proxy_pb2.Packet(header=_meta, body=_data)
def test_get_route_table(self, point='localhost:9470', party='10001', key="shiqili"): channel = grpc.insecure_channel(point) stub = proxy_pb2_grpc.DataTransferServiceStub(channel) salt = self._get_salt() md5hash = hashlib.md5((salt + key).encode("utf-8")).hexdigest() topic_dst = proxy_pb2.Topic(partyId=party) metadata = proxy_pb2.Metadata(dst=topic_dst, operator="get_route_table") data = proxy_pb2.Data(key=md5hash, value=salt.encode('utf-8')) packet = proxy_pb2.Packet(header=metadata, body=data) ret_packet = stub.unaryCall(packet) print(ret_packet.body.value.decode('utf8')) return ret_packet.body.value.decode('utf8')
def encode_packet(rs_header_inner, batch_inner): header = proxy_pb2.Metadata( src=proxy_pb2.Topic(partyId=rs_header_inner._src_party_id, role=rs_header_inner._src_role), dst=proxy_pb2.Topic(partyId=rs_header_inner._dst_party_id, role=rs_header_inner._dst_role), seq=rs_header_inner._batch_seq, ext=rs_header_inner.to_proto_string(), version=eggroll_version) if batch_inner: result = proxy_pb2.Packet( header=header, body=proxy_pb2.Data(value=batch_inner)) else: result = proxy_pb2.Packet(header=header) return result
def generate_message(self, obj, metadata): data = proxy_pb2.Data(value=obj) metadata.seq += 1 packet = proxy_pb2.Packet(header=metadata, body=data) yield packet