示例#1
0
def test_signaling_answer_message_serde() -> None:
    bob_vm = sy.VirtualMachine(name="Bob")
    target = Address(name="Alice")
    target_id = secrets.token_hex(nbytes=16)
    host_id = secrets.token_hex(nbytes=16)

    msg = SignalingAnswerMessage(
        address=target,
        payload="SDP",
        host_metadata=bob_vm.get_metadata_for_client(),
        target_peer=target_id,
        host_peer=host_id,
    )
    msg_metadata = bob_vm.get_metadata_for_client()

    blob = msg.serialize()
    msg2 = sy.deserialize(blob=blob)
    msg2_metadata = msg2.host_metadata

    assert msg.id == msg2.id
    assert msg.address == target
    assert msg.payload == msg2.payload
    assert msg2.payload == "SDP"
    assert msg2.host_peer == host_id
    assert msg2.target_peer == target_id
    assert msg == msg2

    assert msg_metadata.name == msg2_metadata.name
    assert msg_metadata.node == msg2_metadata.node
    assert msg_metadata.id == msg2_metadata.id
示例#2
0
def test_loopback_answer_signaling_service() -> None:
    om_network, bob_vm, alice_vm = get_preset_nodes()
    om_network_client = om_network.get_root_client()

    msg = RegisterNewPeerMessage(
        address=om_network.address, reply_to=om_network_client.address
    )

    host_id = om_network_client.send_immediate_msg_with_reply(msg=msg).peer_id

    metadata = alice_vm.get_metadata_for_client()
    answer_msg = SignalingAnswerMessage(
        address=om_network.address,
        payload="SDP",
        host_metadata=metadata,
        target_peer=host_id,
        host_peer=host_id,
    )
    om_network_client.send_immediate_msg_without_reply(msg=answer_msg)

    # Do not enqueue loopback requests
    assert len(om_network.signaling_msgs[host_id][SyftMessage]) == 0

    ans_pull_req = AnswerPullRequestMessage(
        address=om_network.address,
        target_peer=host_id,
        host_peer=host_id,
        reply_to=om_network_client.address,
    )

    response = om_network_client.send_immediate_msg_with_reply(msg=ans_pull_req)

    # Return InvalidLoopBackMessage
    assert isinstance(response, InvalidLoopBackRequest)
示例#3
0
def test_pull_answer_signaling_service() -> None:
    om_network, bob_vm, alice_vm = get_preset_nodes()
    om_network_client = om_network.get_root_client()

    msg = RegisterNewPeerMessage(
        address=om_network.address, reply_to=om_network_client.address
    )

    target_id = om_network_client.send_immediate_msg_with_reply(msg=msg).peer_id
    host_id = om_network_client.send_immediate_msg_with_reply(msg=msg).peer_id

    answer_msg = SignalingAnswerMessage(
        address=om_network.address,
        payload="SDP",
        host_metadata=alice_vm.get_metadata_for_client(),
        target_peer=target_id,
        host_peer=host_id,
    )
    om_network_client.send_immediate_msg_without_reply(msg=answer_msg)

    assert (
        om_network.signaling_msgs[target_id][SyftMessage].get(answer_msg.id)
        == answer_msg
    )

    ans_pull_req = AnswerPullRequestMessage(
        address=om_network.address,
        target_peer=host_id,
        host_peer=target_id,
        reply_to=om_network_client.address,
    )

    response = om_network_client.send_immediate_msg_with_reply(msg=ans_pull_req)

    assert response == answer_msg