Browse Source

Improve some comments and whitespacing

Ian Goldberg 4 years ago
parent
commit
815099707e
3 changed files with 14 additions and 1 deletions
  1. 5 0
      dirauth.py
  2. 8 1
      network.py
  3. 1 0
      relay.py

+ 5 - 0
dirauth.py

@@ -41,6 +41,7 @@ class RelayDescriptor:
         serialized = self.__str__(False)
         self.descdict["idkey"].verify(serialized.encode("ascii"), self.descdict["sig"])
 
+
 # A consensus is a dict containing:
 #  epoch: epoch id
 #  numrelays: total number of relays
@@ -87,6 +88,7 @@ class Consensus:
         for i, vk in enumerate(verifkeylist):
             vk.verify(serialized.encode("ascii"), self.consdict['sigs'][i])
 
+
 class DirAuthNetMsg(network.NetMsg):
     """The subclass of NetMsg for messages to and from directory
     authorities."""
@@ -116,6 +118,7 @@ class DirAuthENDIVEMsg(DirAuthNetMsg):
     def __init__(self, endive):
         self.endive = endive
 
+
 class DirAuthConnection(network.ClientConnection):
     """The subclass of Connection for connections to directory
     authorities."""
@@ -145,6 +148,7 @@ class DirAuthConnection(network.ClientConnection):
         else:
             raise TypeError('Not a server-originating DirAuthNetMsg', msg)
     
+
 class DirAuth(network.Server):
     """The class representing directory authorities."""
 
@@ -231,6 +235,7 @@ class DirAuth(network.Server):
     def closed(self):
         pass
 
+
 if __name__ == '__main__':
     # Start some dirauths
     numdirauths = 9

+ 8 - 1
network.py

@@ -106,6 +106,7 @@ class NetMsg:
     """The parent class of network messages.  Subclass this class to
     implement specific kinds of network messages."""
 
+
 class StringNetMsg(NetMsg):
     """Send an arbitratry string as a NetMsg."""
     def __init__(self, str):
@@ -114,6 +115,7 @@ class StringNetMsg(NetMsg):
     def __str__(self):
         return self.data.__str__()
 
+
 class Connection:
     def __init__(self, peer = None):
         """Create a Connection object with the given peer."""
@@ -128,10 +130,13 @@ class Connection:
         self.peer.closed()
         self.peer = None
 
+
 class ClientConnection(Connection):
     """The parent class of client-side network connections.  Subclass
     this class to do anything more elaborate than just passing arbitrary
-    NetMsgs, which then get ignored."""
+    NetMsgs, which then get ignored.  Use subclasses of this class when
+    the server required no per-connection state, such as just fetching
+    consensus documents."""
     
     def __init__(self, peer):
         """Create a ClientConnection object with the given peer.  The
@@ -163,6 +168,7 @@ class ServerConnection(Connection):
     def received(self, client, netmsg):
         print("received", netmsg, "from client", client)
 
+
 class Server:
     """The parent class of network servers.  Subclass this class to
     implement servers of different kinds.  You will probably only need
@@ -196,6 +202,7 @@ class Server:
         serverconnection.peer = clientconnection
         return clientconnection
 
+
 if __name__ == '__main__':
     n1 = NetAddr()
     n2 = NetAddr()

+ 1 - 0
relay.py

@@ -68,6 +68,7 @@ class Relay(network.Server):
             c.sendmsg(descmsg)
             c.close()
 
+
 if __name__ == '__main__':
     # Start some dirauths
     numdirauths = 9