Esempio n. 1
0
 def process_network_msgs() -> flask.Response:
     data = flask.request.get_data()
     obj_msg = _deserialize(blob=data, from_bytes=True)
     if isinstance(obj_msg, SignedImmediateSyftMessageWithReply):
         info(
             f"Signaling server SignedImmediateSyftMessageWithReply: {obj_msg.message} watch"
         )
         reply = network.recv_immediate_msg_with_reply(msg=obj_msg)
         r = Response(response=serialize(reply, to_bytes=True), status=200)
         r.headers["Content-Type"] = "application/octet-stream"
         return r
     elif isinstance(obj_msg, SignedImmediateSyftMessageWithoutReply):
         info(
             f"Signaling server SignedImmediateSyftMessageWithoutReply: {obj_msg.message} watch"
         )
         network.recv_immediate_msg_without_reply(msg=obj_msg)
         r = Response(status=200)
         return r
     else:
         info(
             f"Signaling server SignedImmediateSyftMessageWithoutReply: {obj_msg.message} watch"
         )
         network.recv_eventual_msg_without_reply(msg=obj_msg)
         r = Response(status=200)
         return r
Esempio n. 2
0
    def _proto2object(proto: SaveObjectMessage_PB, ) -> "SaveObjectMessage":
        """Creates a SaveObjectMessage from a protobuf
        As a requirement of all objects which inherit from Serializable,
        this method transforms a protobuf object into an instance of this class.
        :return: returns an instance of SignalingOfferMessage
        :rtype: SaveObjectMessage
        .. note::
            This method is purely an internal method. Please use syft.deserialize()
            if you wish to deserialize an object.
        """

        return SaveObjectMessage(
            msg_id=_deserialize(blob=proto.msg_id),
            address=_deserialize(blob=proto.address),
            content=json.loads(proto.content),
        )
Esempio n. 3
0
def test_torch_valuesindices_serde():
    x = torch.Tensor([1, 2, 3])
    y = x.cummax(0)
    values = y.values
    indices = y.indices

    ser = y.serialize()
    # horrible hack, we shouldnt be constructing these right now anyway
    params = [None] * 17
    params[0] = values
    params[1] = indices
    vi = ValuesIndices(*params)
    de = _deserialize(blob=ser)

    assert (de.values == y.values).all()
    assert (de.indices == y.indices).all()
    assert (vi.values == de.values).all()
    assert (vi.indices == de.indices).all()
Esempio n. 4
0
    def process(
        node: AbstractNode,
        msg: Union[
            LoadObjectMessage,
        ],
        verify_key: VerifyKey,
    ) -> Union[LoadObjectResponse, SaveObjectResponse,]:
        _worker_address = msg.content.get("address", None)
        _obj_id = msg.content.get("uid", None)
        _current_user_id = msg.content.get("current_user", None)

        users = node.users

        if not _current_user_id:
            _current_user_id = users.first(
                verify_key=verify_key.encode(encoder=HexEncoder).decode("utf-8")
            ).id

        addr_pb = Address_PB()
        addr_pb.ParseFromString(_worker_address.encode("ISO-8859-1"))
        _syft_address = _deserialize(blob=addr_pb)

        _syft_id = UID.from_string(value=_obj_id)

        _worker_client = node.in_memory_client_registry[_syft_address.domain_id]

        try:
            _obj = node.store[_syft_id]
        except Exception:
            raise Exception("Object Not Found!")

        _obj.data.send(
            _worker_client,
            searchable=True,
            tags=_obj.tags,
            description=_obj.description,
        )

        return LoadObjectResponse(
            address=msg.reply_to,
            status_code=200,
            content={"msg": "Object loaded successfully!"},
        )
Esempio n. 5
0
def test_fail_deserialize_no_format() -> None:
    with raises(TypeError):
        _deserialize(blob="to deserialize", from_proto=False)
Esempio n. 6
0
def test_fail_deserialize_wrong_format() -> None:
    with raises(TypeError,
                match="You tried to deserialize an unsupported type."):
        _deserialize(blob="to deserialize")