Skip to content

Commit

Permalink
An insane number of changes;
Browse files Browse the repository at this point in the history
  • Loading branch information
iamtrask committed Jul 25, 2020
1 parent 31a4ab8 commit 835cd36
Show file tree
Hide file tree
Showing 57 changed files with 1,152 additions and 632 deletions.
393 changes: 286 additions & 107 deletions examples/Dev.ipynb

Large diffs are not rendered by default.

13 changes: 11 additions & 2 deletions src/syft/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,14 @@
finally:
del get_distribution, DistributionNotFound

def helloworld():
print("hello")
from syft.core.nodes.vm.vm import VirtualMachine
from syft.core.nodes.device.device import Device
from syft.core.nodes.domain.domain import Domain
from syft.core.nodes.network.network import Network

from syft.core.nodes.abstract.service.repr_service import ReprMessage

# def get_client(host="127.0.0.1", port="5000"):
# res = requests.get(f"http://{host}:{port}/")
# client = pickle.loads(bytes.fromhex(res.text))
# return client
1 change: 0 additions & 1 deletion src/syft/common/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
from .node import AbstractNode # noqa: F401
12 changes: 12 additions & 0 deletions src/syft/common/id.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,15 @@ class UID(object):
def __init__(self):
# TODO find out what type is smaller for protobuf msgs.
self.value = uuid.uuid4()

def __hash__(self):
return hash(self.value)

def __eq__(self, other):
if isinstance(other, UID):
return self.value == other.value
return False

def __repr__(self):
return f"<UID:{self.value}>"

5 changes: 0 additions & 5 deletions src/syft/common/node.py

This file was deleted.

14 changes: 11 additions & 3 deletions src/syft/core/io/abstract.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
from ..message.syft_message import SyftMessage
from ..message.syft_message import SyftMessageWithReply
from ..message.syft_message import SyftMessageWithoutReply
from ...decorators import syft_decorator
from typing import final


@final
class ServerConnection(object):
@syft_decorator(typechecking=True)
def recv_msg(self, msg: SyftMessage) -> SyftMessage:
def recv_msg_with_reply(self, msg: SyftMessageWithReply) -> SyftMessageWithoutReply:
raise NotImplementedError

def recv_msg_without_reply(self, msg: SyftMessageWithoutReply) -> None:
raise NotImplementedError


@final
class ClientConnection(object):
@syft_decorator(typechecking=True)
def send_msg(self, msg: SyftMessage) -> SyftMessage:
def send_msg_with_reply(self, msg: SyftMessageWithReply) -> SyftMessageWithoutReply:
raise NotImplementedError

@syft_decorator(typechecking=True)
def send_msg_without_reply(self, msg: SyftMessageWithoutReply) -> None:
raise NotImplementedError
7 changes: 7 additions & 0 deletions src/syft/core/io/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ def __init__(self, pub_address: PublicAddress, pri_address: PrivateAddress):
self.pub_address = pub_address
self.pri_address = pri_address

def __repr__(self):
out = ""
out += f"Public(Network:{self.pub_address.network},"
out += f" Domain:{self.pub_address.domain}) "
out += f" Private(Device:{self.pri_address.device},"
out += f" VM:{self.pri_address.vm})"
return out

@syft_decorator(typechecking=True)
def address(network: (str, UID), domain: (str, UID), device: (str, UID), vm: (str, UID)) -> Address:
Expand Down
70 changes: 39 additions & 31 deletions src/syft/core/io/route.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,54 @@
from ...decorators import syft_decorator
from ...common.id import UID
from typing import final

from ...common.message import AbstractMessage
from typing import List

class Route(object):
"""
A route is how a node can be reached by other nodes.
Route provides a name, imagine it like a name server
so that if user had multiple routes to the same name server
it can identify it that these routes lead to the same
destination.
and Route provides connection details which could be any protocol.
potentially this could also serve authentication details.
A route is the highest level interface for how a node can
reach other nodes. Route provides a name, imagine it like a name server
so that if user had multiple routes to the same name server
it can identify it that these routes lead to the same
destination.
Route also maintains connection objects which allow for actual
communication over this route.
"""
def __init__(self, node_unique_name: UID):
self.name = node_unique_name
self.connection_details = {}

def configure_connection(self, protocol: str, host: str, port: int):
"""
the route should have connection details embedded in it.
so that nodes operators can utilize it to route messages.
"""
self.connection_details.update({
'host': host,
'protocol': protocol,
'port': port
})

def register_broadcast_channel(self, channel_name: str):
"""
In the case configured protocol is pub/sub or event driven.
Args:
channel_name: the name of the channel to broadcast on.
"""
self.connection_details.update({'broadcast_channel': channel_name})

def __init__(self, connection_client_type):
self.connection_client_type = connection_client_type
self.connection_client = None

def connect(self, *args, **kwargs):
"""This method should initialize the connection_client with the correct
metadata. Args and Kwargs are the connection parameters."""
return self.connection_client_type(**kwargs)

def send_msg(self, msg: AbstractMessage):
raise self.connection_client.send_msg(msg)


class PointToPointRoute(Route):

def __init__(self, target_node_id: UID, connection_client_type: type):
super().__init__(connection_client_type=connection_client_type)
self.target_node_id = target_node_id

class BroadcastRoute(Route):

#TODO: instead of passing in a list, come up with an abstractoin for
# "worker group" of arbitrary size and membership which can include
# "known members" but isn't intended to be exhaustive.
def __init__(self, target_node_ids: List[UID], connection_client_type: type):
super().__init__(connection_client_type=connection_client_type)
self.target_node_ids = target_node_ids

class MQTTRoute(Route):
def connect(self):
pass


class HTTPRoute(Route):
def connect(self):
pass

18 changes: 13 additions & 5 deletions src/syft/core/io/virtual.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
(such as one powered by P2P tech, web sockets, or HTTP) should
execute the exact same functionality but do so over a network"""

from ..message.syft_message import SyftMessage
from ..message.syft_message import SyftMessageWithReply
from ..message.syft_message import SyftMessageWithoutReply
from ..nodes.abstract.node import Node
from ...decorators import syft_decorator
from typing import final
Expand All @@ -22,8 +23,12 @@ def __init__(self, node: Node):
self.node = node

@syft_decorator(typechecking=True)
def recv_msg(self, msg: SyftMessage) -> SyftMessage:
return self.node.recv_msg(msg=msg)
def recv_msg_with_reply(self, msg: SyftMessageWithReply) -> SyftMessageWithoutReply:
return self.node.recv_msg_with_reply(msg=msg)

@syft_decorator(typechecking=True)
def recv_msg_without_reply(self, msg: SyftMessageWithoutReply) -> None:
self.node.recv_msg_without_reply(msg=msg)


@final
Expand All @@ -32,9 +37,12 @@ class VirtualClientConnection(ClientConnection):
def __init__(self, server: VirtualServerConnection):
self.server = server

def send_msg_without_reply(self, msg: SyftMessageWithoutReply) -> None:
self.server.recv_msg_without_reply(msg=msg)

@syft_decorator(typechecking=True)
def send_msg(self, msg: SyftMessage) -> SyftMessage:
return self.server.recv_msg(msg=msg)
def send_msg_with_reply(self, msg: SyftMessageWithReply) -> SyftMessageWithoutReply:
return self.server.recv_msg_with_reply(msg=msg)


@syft_decorator(typechecking=True)
Expand Down
1 change: 0 additions & 1 deletion src/syft/core/message/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from .syft_message import SyftMessage # noqa: F401
from .delete_object_message import DeleteObjectMessage # noqa: F401
from .get_object_message import GetObjectMessage # noqa: F401
from .run_class_method_message import RunClassMethodMessage # noqa: F401
Expand Down
4 changes: 2 additions & 2 deletions src/syft/core/message/delete_object_message.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .syft_message import SyftMessage
from .syft_message import SyftMessageWithoutReply

class DeleteObjectMessage(SyftMessage):
class DeleteObjectMessage(SyftMessageWithoutReply):
def __init__(self, obj_id, address, msg_id=None):
super().__init__(address=address, msg_id=msg_id)
self.obj_id = obj_id
4 changes: 2 additions & 2 deletions src/syft/core/message/get_object_message.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .syft_message import SyftMessage
from .syft_message import SyftMessageWithReply

class GetObjectMessage(SyftMessage):
class GetObjectMessage(SyftMessageWithReply):
def __init__(self, obj_id, address, msg_id=None):
super().__init__(address=address, msg_id=msg_id)
self.obj_id = obj_id
4 changes: 2 additions & 2 deletions src/syft/core/message/run_function_or_constructor_message.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .syft_message import SyftMessage
from .syft_message import SyftMessageWithoutReply


class RunFunctionOrConstructorMessage(SyftMessage):
class RunFunctionOrConstructorMessage(SyftMessageWithoutReply):
def __init__(self, path, args, kwargs, address, msg_id=None):
super().__init__(address=address, msg_id=msg_id)
self.path = path
Expand Down
4 changes: 2 additions & 2 deletions src/syft/core/message/save_object_message.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .syft_message import SyftMessage

class SaveObjectMessage(SyftMessage):
def __init__(self, id, obj, address, msg_id=None):
def __init__(self, obj_id, obj, address, msg_id=None):
super().__init__(address=address, msg_id=msg_id)
self.id = id
self.obj_id = obj_id
self.obj = obj
8 changes: 5 additions & 3 deletions src/syft/core/message/search_message.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from .syft_message import SyftMessage, SyftMessageWithReply
from ..io.route import Route
from .syft_message import SyftMessageWithoutReply
from .syft_message import SyftMessageWithReply
from ..io.address import Address
from ...common.id import UID


class SearchMessage(SyftMessageWithReply):
Expand All @@ -11,7 +12,8 @@ class SearchMessage(SyftMessageWithReply):
def __init__(self, reply_to: Address, address: Address, msg_id: UID = None) -> None:
super().__init__(reply_to=reply_to, address=address, msg_id=msg_id)

class SearchMessageReply(SyftMessage):

class SearchMessageReply(SyftMessageWithReply):
"""
When a domain wants to inform a network of the route to a certain dataset
this message is sent.
Expand Down
19 changes: 13 additions & 6 deletions src/syft/core/message/syft_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,19 @@
class SyftMessage(AbstractMessage):
def __init__(self, address: Address, msg_id: UID = None) -> None:
self.msg_id = msg_id
self.address = address

class SignedMessage(SyftMessage):
def sign(self, my_route):
self.my_route = my_route
# TODO: I think this is really cool but we don't have the notion of a signature yet.
# TODO: (cont) so commenting out for now but will likely bring back in the future
# class SignedMessage(SyftMessage):
# def sign(self, signature):
# self.my_route = my_route

class SyftMessageWithReply(SignedMessage):
class SyftMessageWithoutReply(SyftMessage):
def __init__(self, address: Address, msg_id: UID = None) -> None:
super().__init__(address=address, msg_id=msg_id)

class SyftMessageWithReply(SyftMessage):
def __init__(self, reply_to: Address, address: Address, msg_id: UID = None) -> None:
super(self).__init__(route, msg_id)
msg.reply_to = reply_to
super().__init__(address=address, msg_id=msg_id)
self.reply_to = reply_to

0 comments on commit 835cd36

Please sign in to comment.