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

+ 8 - 1
network.py

@@ -106,6 +106,7 @@ class NetMsg:
     """The parent class of network messages.  Subclass this class to
     """The parent class of network messages.  Subclass this class to
     implement specific kinds of network messages."""
     implement specific kinds of network messages."""
 
 
+
 class StringNetMsg(NetMsg):
 class StringNetMsg(NetMsg):
     """Send an arbitratry string as a NetMsg."""
     """Send an arbitratry string as a NetMsg."""
     def __init__(self, str):
     def __init__(self, str):
@@ -114,6 +115,7 @@ class StringNetMsg(NetMsg):
     def __str__(self):
     def __str__(self):
         return self.data.__str__()
         return self.data.__str__()
 
 
+
 class Connection:
 class Connection:
     def __init__(self, peer = None):
     def __init__(self, peer = None):
         """Create a Connection object with the given peer."""
         """Create a Connection object with the given peer."""
@@ -128,10 +130,13 @@ class Connection:
         self.peer.closed()
         self.peer.closed()
         self.peer = None
         self.peer = None
 
 
+
 class ClientConnection(Connection):
 class ClientConnection(Connection):
     """The parent class of client-side network connections.  Subclass
     """The parent class of client-side network connections.  Subclass
     this class to do anything more elaborate than just passing arbitrary
     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):
     def __init__(self, peer):
         """Create a ClientConnection object with the given peer.  The
         """Create a ClientConnection object with the given peer.  The
@@ -163,6 +168,7 @@ class ServerConnection(Connection):
     def received(self, client, netmsg):
     def received(self, client, netmsg):
         print("received", netmsg, "from client", client)
         print("received", netmsg, "from client", client)
 
 
+
 class Server:
 class Server:
     """The parent class of network servers.  Subclass this class to
     """The parent class of network servers.  Subclass this class to
     implement servers of different kinds.  You will probably only need
     implement servers of different kinds.  You will probably only need
@@ -196,6 +202,7 @@ class Server:
         serverconnection.peer = clientconnection
         serverconnection.peer = clientconnection
         return clientconnection
         return clientconnection
 
 
+
 if __name__ == '__main__':
 if __name__ == '__main__':
     n1 = NetAddr()
     n1 = NetAddr()
     n2 = NetAddr()
     n2 = NetAddr()

+ 1 - 0
relay.py

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