Repository: OpenMined/PySyft
Pull request: Connection get overload
## Description

This PR aims to create a function that will return a node from connections without have to use a private key.

Resolves #3577


## Checklist:
* [ ] My changes are covered by tests.
* [x] I have run [the pre-commit hooks](https://github.com/OpenMined/PySyft/blob/master/CONTRIBUTING.md#setting-up-pre-commit-hook) to format and check my code for style issues.
* [x] I have commented my code following [Google style](https://sphinxcontrib-napoleon.readthedocs.io/en/latest/example_google.html).

(See the [the contribution guidelines](https://github.com/OpenMined/PySyft/blob/master/CONTRIBUTING.md) for additional tips.)


Problem statement:
Overload __getitem__ to be able to index into connected nodes
**Is your feature request related to a problem? Please describe.**

When I call 

```
me = sy.grid.register()
```
I want to be able to select connected nodes by just calling 

```
me['another_node']
```

instead of having to use a private variable

me._connection_handler.get("another_node")

Hints from issue discussion:
Can i take this one?
May I suggest something like `me.peers[“another_node”]` to make explicit what’s happening? 
@karlhigley  in this case, overload `__getitem__` is not necessary anymore?
Yeah, I guess not. 👍

Commit message: running pre-commit

Patch to review:
diff --git a/syft/grid/network.py b/syft/grid/network.py
index cebb1d73c76..a28dbfa60bc 100644
--- a/syft/grid/network.py
+++ b/syft/grid/network.py
@@ -18,7 +18,7 @@
 class Network(threading.Thread):
     """ Grid Network class to operate in background processing grid requests
         and handling multiple peer connections with different nodes.
-    
+
     """
 
     # Events called by the grid monitor to health checking and signaling webrtc connections.
@@ -31,7 +31,7 @@ class Network(threading.Thread):
 
     def __init__(self, node_id: str, **kwargs):
         """ Create a new thread to send/receive messages from the grid service.
-        
+
             Args:
                 node_id: ID used to identify this peer.
         """
@@ -59,8 +59,8 @@ def stop(self):
         self._ws.shutdown()
 
     def _update_node_infos(self, node_id: str):
-        """ Create a new virtual worker to store/compute datasets owned by this peer. 
-            
+        """ Create a new virtual worker to store/compute datasets owned by this peer.
+
             Args:
                 node_id: ID used to identify this peer.
         """
@@ -79,8 +79,8 @@ def _listen(self):
                 self._ws.send(json.dumps(response))
 
     def _handle_messages(self, message):
-        """ Route and process the messages received from the websocket connection. 
-            
+        """ Route and process the messages received from the websocket connection.
+
             Args:
                 message : message to be processed.
         """
@@ -99,14 +99,11 @@ def id(self):
     def connect(self, destination_id: str):
         """ Create a webrtc connection between this peer and the destination peer by using the grid network
             to forward the webrtc connection request protocol.
-            
+
             Args:
                 destination_id : Id used to identify the peer to be connected.
         """
-        webrtc_request = {
-            MSG_FIELD.TYPE: NODE_EVENTS.WEBRTC_SCOPE,
-            MSG_FIELD.FROM: self.id,
-        }
+        webrtc_request = {MSG_FIELD.TYPE: NODE_EVENTS.WEBRTC_SCOPE, MSG_FIELD.FROM: self.id}
 
         forward_payload = {
             MSG_FIELD.TYPE: GRID_EVENTS.FORWARD,
@@ -121,8 +118,8 @@ def connect(self, destination_id: str):
         return self._connection_handler.get(destination_id)
 
     def disconnect(self, destination_id: str):
-        """ Disconnect with some peer connected previously. 
-            
+        """ Disconnect with some peer connected previously.
+
             Args:
                 destination_id: Id used to identify the peer to be disconnected.
         """
@@ -132,7 +129,7 @@ def disconnect(self, destination_id: str):
 
     def host_dataset(self, dataset):
         """ Host dataset using the virtual worker defined previously.
-            
+
             Args:
                 dataset: Dataset to be hosted.
         """
@@ -147,10 +144,7 @@ def host_model(self, model):
     def _join(self):
         """ Send a join requet to register this peer on the grid network. """
         # Join into the network
-        join_payload = {
-            MSG_FIELD.TYPE: GRID_EVENTS.JOIN,
-            MSG_FIELD.NODE_ID: self._worker.id,
-        }
+        join_payload = {MSG_FIELD.TYPE: GRID_EVENTS.JOIN, MSG_FIELD.NODE_ID: self._worker.id}
         self._ws.send(json.dumps(join_payload))
         response = json.loads(self._ws.recv())
         self.available = True
@@ -164,3 +158,12 @@ def __repr__(self):
             list(self._worker.models.keys()),
             list(self._connection_handler.nodes),
         )
+
+    def peers(self, key):
+        """
+        Get selected node from WebRTCManager connections
+
+        Args:
+            key: Node ID
+        """
+        return self._connection_handler.get(key)


Code review comments:
diff_hunk: @@ -164,3 +158,12 @@ def __repr__(self):
             list(self._worker.models.keys()),
             list(self._connection_handler.nodes),
         )
+
+    def peers(self, key):
path: syft/grid/network.py
text: @user2:
Just an ideia! Take peers as a @user1 here and overload the WebRTCManager \__getitem__ function. With this it would be possible to do things like me.peers['peer_name'] too.

@author:
Done!