def __init__(self, grid_descriptor, worker, destination, connections, conn_type): """ Create a new webrtc peer connection. Args: grid_descriptor: Grid network's websocket descriptor to forward webrtc connection request. worker: Virtual Worker that represents this peer. destination: Destination Peer ID. connections: Peer connection descriptors. conn_type: Connection responsabilities this peer should provide. (offer, answer) """ threading.Thread.__init__(self) BaseWorker.__init__(self, hook=sy.hook, id=destination) self._conn_type = conn_type self._origin = worker.id self._worker = worker self._worker.tensor_requests = [] self._destination = destination self._grid = grid_descriptor self._msg = "" self._request_pool = queue.Queue() self._response_pool = queue.Queue() self.channel = None self.available = True self.connections = connections
def __init__(self, grid_descriptor, worker, destination, conn_type): threading.Thread.__init__(self) BaseWorker.__init__(self, hook=hook, id=destination) self._conn_type = conn_type self._origin = worker.id self._worker = worker self._destination = destination self._grid = grid_descriptor self._msg = "" self._request_pool = queue.Queue() self._response_pool = queue.Queue() self.channel = None
def _send_msg(self, message: bin, location: BaseWorker) -> bin: """send message to worker location""" if self.message_pending_time > 0: if self.verbose: print(f"pending time of {self.message_pending_time} seconds to send message...") sleep(self.message_pending_time) return location._recv_msg(message)
def detail(worker: BaseWorker, protocol_tuple: tuple) -> "Protocol": """This function reconstructs a Protocol object given its attributes in the form of a tuple. Args: worker: the worker doing the deserialization protocol_tuple: a tuple holding the attributes of the Protocol Returns: protocol: a Protocol object """ id, tags, description, plans_reference, workers_resolved = map( lambda o: sy.serde._detail(worker, o), protocol_tuple ) plans = [] for owner_id, plan_id in plans_reference: if workers_resolved: plan_owner = worker.get_worker(owner_id, fail_hard=True) plan_pointer = worker.request_search(plan_id, location=plan_owner)[0] worker.register_obj(plan_pointer) plans.append((plan_owner, plan_pointer)) else: try: plan_owner = worker.get_worker(owner_id, fail_hard=True) plan_pointer = worker.request_search(plan_id, location=plan_owner)[0] plan = plan_pointer.get() except WorkerNotFoundException: plan = worker.get_obj(plan_id) plans.append((worker.id, plan)) protocol = sy.Protocol(plans=plans, id=id, owner=worker, tags=tags, description=description) return protocol
def detail(worker: AbstractWorker, worker_tuple: tuple) -> Union["VirtualWorker", int, str]: detailed = BaseWorker.detail(worker, worker_tuple) if isinstance(detailed, int): result = VirtualWorker(id=detailed, hook=worker.hook) else: result = detailed return result
def detail(worker: BaseWorker, simple_obj): """Create an object of type DocPointer from the reduced representation in `simple_obj`. Args: worker (BaseWorker): The worker on which the new DocPointer object is to be created. simple_obj (tuple): A tuple resulting from the serialized then deserialized returned tuple from the `_simplify` static method above. Returns: DocPointer: a DocPointer object, pointing to a Doc object """ # Get the typle elements ( location_id, id_at_location, id, garbage_collect_data, tags, description, ) = simple_obj # Unpickle location_id = pickle.loads(location_id) tags = [pickle.loads(tag) for tag in tags] if tags else None description = pickle.loads(description) # Get the worker `location` on which lives the pointed-to Doc object location = worker.get_worker(id_or_worker=location_id) # Create a DocPointer object doc_pointer = DocPointer( location=location, id_at_location=id_at_location, owner=worker, id=id, garbage_collect_data=garbage_collect_data, tags=tags, description=description, ) return doc_pointer
def simplify(_worker: AbstractWorker, worker: "VirtualWorker") -> tuple: return BaseWorker.simplify(_worker, worker)
def _send_msg(self, message: bin, location: BaseWorker) -> bin: return location._recv_msg(message)
def _send_msg(self, message: bin, location: BaseWorker) -> bin: """send message to worker location""" return location._recv_msg(message)
def force_detail(worker: AbstractWorker, worker_tuple: tuple) -> "VirtualWorker": return BaseWorker.force_detail(worker, worker_tuple)
def force_simplify(_worker: AbstractWorker, worker: AbstractWorker) -> tuple: return BaseWorker.force_simplify(_worker, worker)
def _send_msg(self, message: bin, location: BaseWorker) -> bin: print("THIS IS WHERE I AM SENDING THE THING: ") print(location) print("WHEREAS I AM:") print(self) return location._recv_msg(message)