-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce remote nodes and dynamic routing
- Loading branch information
Rima
committed
Jul 21, 2020
1 parent
d06f424
commit e7710b2
Showing
5 changed files
with
84 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,54 @@ | ||
import enum | ||
from .client import Client | ||
from ...io.route import Route | ||
from ...message.syft_message import SyftMessage | ||
|
||
class RemoteNodeTypes(enum.Enum): | ||
VM = 1 | ||
Device = 2 | ||
Domain = 3 | ||
Network = 4 | ||
|
||
class RemoteNode(object): | ||
def __init__(self, route: Route, type: RemoteNodeType) -> None: | ||
self.id = id | ||
self.route = route | ||
|
||
class RemoteNodes(object): | ||
class MyRemoteNodes(object): | ||
nodes = {} | ||
|
||
def __init__(self): | ||
for type in RemoteNodeTypes: | ||
def __init__(self, my_route: Route): | ||
for type in RouteTypes: | ||
self.nodes.update({type.name: []}) | ||
self.iam = iam.type | ||
self.my_route = my_route | ||
|
||
def register_worker(self, route: Route, type: RemoteNodeType) -> None: | ||
def register_node(self, route: Route, type: RouteTypes) -> None: | ||
if type not in self.nodes: | ||
# log unknown type | ||
return | ||
|
||
self.nodes[type].append(route) | ||
|
||
def forget_worker(self, route: Route, type: RemoteNodeType) -> None: | ||
def forget_node(self, route: Route, type: RouteTypes) -> None: | ||
self.nodes[type].pop(route) | ||
|
||
def route_message_to_relevant_nodes(self, route: Route, message: SyftMessage) -> None: | ||
""" | ||
check if the message should be forwarded. | ||
Network: routes to domains | ||
Domain: routes to devices | ||
Device: routes to VMs | ||
VM: doesn't route | ||
""" | ||
if self.iam == 'network': | ||
if route.domain != '*': | ||
route.domain.client().send(message) | ||
else: | ||
for domain in self.nodes['domain']: | ||
domain.client().send(message) | ||
elif self.iam == 'domain': | ||
if route.device != '*': | ||
route.device.client().send(message) | ||
else: | ||
for device in self.nodes['device']: | ||
device.client().send(message) | ||
elif self.iam == 'device': | ||
if route.vm != '*': | ||
route.vm.client().send(message) | ||
else: | ||
for vm in self.nodes['vm']: | ||
vm.client().send(message) | ||
|
||
def broadcast(self, route: Route): | ||
channel = route.broadcast_channel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters