[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [depictor/master] Add bandwidth file info. Closes #29946 and #29947



commit d7aca8850f4bbff25d8c6155ac094c937d680bc5
Author: Tom Ritter <tom@xxxxxxxxx>
Date:   Thu Jun 20 07:02:34 2019 -0700

    Add bandwidth file info. Closes #29946 and #29947
---
 utility.py |  8 ++++++++
 website.py | 41 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+)

diff --git a/utility.py b/utility.py
index c931c59..38fb47a 100755
--- a/utility.py
+++ b/utility.py
@@ -26,6 +26,14 @@ def get_bwauths():
 	global config
 	return dict((k.lower(), v) for (k, v) in stem.descriptor.remote.get_authorities().items() if v.nickname.lower() in config['bwauths'])
 
+# How to grab a vote or consensus with stem:
+"""
+import stem.descriptor.remote
+authority = stem.descriptor.remote.get_authorities()['moria1']
+downloader = stem.descriptor.remote.DescriptorDownloader(fall_back_to_authority = False, document_handler = stem.descriptor.DocumentHandler.DOCUMENT)
+vote = downloader.query('/tor/status-vote/current/authority.z', default_params = False, endpoints=[(authority.address, authority.dir_port)]).run()[0]
+"""
+
 downloader = stem.descriptor.remote.DescriptorDownloader(
 	timeout = 30,
 	fall_back_to_authority = False,
diff --git a/website.py b/website.py
index 6d43e6f..f035da2 100755
--- a/website.py
+++ b/website.py
@@ -57,6 +57,7 @@ class WebsiteWriter:
 		self._write_protocols()
 		self._write_bandwidth_weights()
 		self._write_bandwidth_scanner_status(True)
+		self._write_bandwidth_scanner_info()
 		self._write_fallback_directory_status(True)
 		self._write_authority_versions()
 		self._write_download_statistics()
@@ -1071,6 +1072,46 @@ class WebsiteWriter:
 		self.site.write("</table>\n")
 
 	#-----------------------------------------------------------------------------------------
+	def _write_bandwidth_scanner_info(self):
+		"""
+		Write the headers and digest from the bandwidth file
+		"""
+		self.site.write("<br>\n\n\n"
+		+ " <!-- ================================================================= -->"
+		+ "<a name=\"bwauthinfo\">\n"
+		+ "<h3><a href=\"#bwauthinfo\" class=\"anchor\">"
+		+ "Bandwidth scanner information</a></h3>\n")
+		self.site.write("<table border=\"0\" cellpadding=\"4\" cellspacing=\"0\" summary=\"\">\n"
+		+ "  <colgroup>\n"
+		+ "    <col width=\"160\">\n"
+		+ "    <col width=\"640\">\n"
+		+ "  </colgroup>\n")
+		if not self.votes:
+			self.site.write("  <tr><td>(No votes.)</td><td></td></tr>\n")
+		else:
+			for dirauth_nickname in self.bandwidth_authorities:
+				if dirauth_nickname not in self.votes:
+					self.site.write("  <tr>\n"
+					+ "    <td>" + dirauth_nickname + "</td>\n"
+					+ "    <td class=\"oiv\">Missing vote</td>\n"
+					+ "  </tr>\n")
+				else:
+					vote = self.votes[dirauth_nickname]
+					self.site.write("  <tr>\n"
+					+ "    <td>" + dirauth_nickname + "</td>\n"
+					+ "    <td>")
+					for h in vote.bandwidth_file_headers:
+						self.site.write(h + "=" + vote.bandwidth_file_headers[h] + " ")
+						if h == "timestamp":
+							friendly = datetime.datetime.utcfromtimestamp(int(vote.bandwidth_file_headers[h])).isoformat().replace("T", " ")
+							self.site.write("(" + friendly + ") ")
+					for h in vote.bandwidth_file_digest:
+						self.site.write(h + "=" + vote.bandwidth_file_digest[h] + " ")
+					self.site.write("</td>\n"
+					+ "  </tr>\n")
+		self.site.write("</table>\n")
+
+	#-----------------------------------------------------------------------------------------
 	def _write_fallback_directory_status(self, linkToGraph):
 		"""
 		Write the status of the fallback directory mirrors

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits