[tor-commits] [onionoo/master] Index relays with no known country or AS

2018-07-11 Thread karsten
commit 641a939cde75fa3a5cddd32ee29a6508fd66b4c4
Author: Iain R. Learmonth 
Date:   Tue Jul 10 11:51:23 2018 +0100

Index relays with no known country or AS

Indexes are created for relays with no known country code or
autonomous system number using the special values "xz" and "AS0"
respectively.

No changes are made to the summary or details documents.

Fixes: #26665
---
 CHANGELOG.md   |  4 ++
 .../org/torproject/onionoo/server/NodeIndexer.java | 43 ++
 2 files changed, 32 insertions(+), 15 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index c9c9aba..ca0142b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,10 @@
- Provide more accurate DNS results in "verified_host_names" and
  "unverified_host_names".
 
+ * Minor changes
+   - Index relays with no known country code or autonomous system
+ number using the special values "xz" and "AS0" respectively.
+
 
 # Changes in version 6.0-1.14.0 - 2018-05-29
 
diff --git a/src/main/java/org/torproject/onionoo/server/NodeIndexer.java 
b/src/main/java/org/torproject/onionoo/server/NodeIndexer.java
index c95818d..f6b84b8 100644
--- a/src/main/java/org/torproject/onionoo/server/NodeIndexer.java
+++ b/src/main/java/org/torproject/onionoo/server/NodeIndexer.java
@@ -198,23 +198,36 @@ public class NodeIndexer implements 
ServletContextListener, Runnable {
   .toUpperCase();
   newRelayFingerprintSummaryLines.put(fingerprint, entry);
   newRelayFingerprintSummaryLines.put(hashedFingerprint, entry);
-  if (entry.getCountryCode() != null) {
-String countryCode = entry.getCountryCode();
-if (!newRelaysByCountryCode.containsKey(countryCode)) {
-  newRelaysByCountryCode.put(countryCode,
-  new HashSet());
-}
-newRelaysByCountryCode.get(countryCode).add(fingerprint);
-newRelaysByCountryCode.get(countryCode).add(hashedFingerprint);
+  String countryCode;
+  if (null != entry.getCountryCode()) {
+countryCode = entry.getCountryCode();
+  } else {
+/* The country code xz will never be assigned for use with ISO 3166-1
+ * and is "user-assigned". Fun fact: UN/LOCODE assigns XZ to represent
+ * installations in international waters. */
+countryCode = "xz";
   }
-  if (entry.getAsNumber() != null) {
-String asNumber = entry.getAsNumber();
-if (!newRelaysByAsNumber.containsKey(asNumber)) {
-  newRelaysByAsNumber.put(asNumber, new HashSet());
-}
-newRelaysByAsNumber.get(asNumber).add(fingerprint);
-newRelaysByAsNumber.get(asNumber).add(hashedFingerprint);
+  if (!newRelaysByCountryCode.containsKey(countryCode)) {
+newRelaysByCountryCode.put(countryCode,
+new HashSet());
+  }
+  newRelaysByCountryCode.get(countryCode).add(fingerprint);
+  newRelaysByCountryCode.get(countryCode).add(hashedFingerprint);
+  String asNumber;
+  if (null != entry.getAsNumber()) {
+asNumber = entry.getAsNumber();
+  } else {
+/* Autonomous system number 0 is reserved by RFC6707, to be used for
+ * networks that are not routed. The use of this number should be,
+ * and in the majority of cases probably is, filtered and so it
+ * shouldn't appear in any lookup databases. */
+asNumber = "AS0";
+  }
+  if (!newRelaysByAsNumber.containsKey(asNumber)) {
+newRelaysByAsNumber.put(asNumber, new HashSet());
   }
+  newRelaysByAsNumber.get(asNumber).add(fingerprint);
+  newRelaysByAsNumber.get(asNumber).add(hashedFingerprint);
   for (String flag : entry.getRelayFlags()) {
 String flagLowerCase = flag.toLowerCase();
 if (!newRelaysByFlag.containsKey(flagLowerCase)) {

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


[tor-commits] [translation/support-topics_completed] Update translations for support-topics_completed

2018-07-11 Thread translation
commit abd8b1ed5609f7bc52072c71cfc03ef4bdd8f26c
Author: Translation commit bot 
Date:   Wed Jul 11 10:49:49 2018 +

Update translations for support-topics_completed
---
 es.json | 110 
 1 file changed, 55 insertions(+), 55 deletions(-)

diff --git a/es.json b/es.json
index 86813a614..951832313 100644
--- a/es.json
+++ b/es.json
@@ -1,57 +1,57 @@
 {
-"faq": {
-   "path": "#faq",
-   "control": "faq",
-   "label": "Preguntas más frecuentes"
-},
-"tbb": {
-   "path": "\n#tbb",
-   "control": "tbb",
-   "label": "Navegador Tor"
-},
-"tormessenger": {
-   "path": "#tormessenger",
-   "control": "tormessenger",
-   "label": "Tor Messenger"
-},
-"tormobile": {
-   "path": "#tormobile",
-   "control": "tormobile",
-   "label": "Tor Mobile"
-},
-"gettor": {
-   "path": "#gettor",
-   "control": "gettor",
-   "label": "GetTor"
-},
-"connecting": {
-   "path": "#connectingtotor",
-   "control": "connectingtotor",
-   "label": "Conectar a Tor"
-},
-"censorship": {
-   "path": "#censorship",
-   "control": "censorship",
-   "label": "Censura"
-},
-"https": {
-   "path": "#https",
-   "control": "https",
-   "label": "HTTPS"
-},
-"operators": {
-   "path": "#operators",
-   "control": "operators",
-   "label": "Operadores"
-},
-"onionservices": {
-   "path": "#onionservices",
-   "control": "servicios onion",
-   "label": "Servicios onion"
-},
-"misc": {
-   "path": "#misc",
-   "control": "misc",
-   "label": "Misc"
-}
+  "faq": {
+"path": "#faq",
+"control": "faq",
+"label": "Preguntas más frecuentes"
+  },
+  "tbb": {
+"path": "\n#tbb",
+"control": "tbb",
+"label": "Navegador Tor"
+  },
+  "tormessenger": {
+"path": "#tormessenger",
+"control": "tormessenger",
+"label": "Tor Messenger"
+  },
+  "tormobile": {
+"path": "#tormobile",
+"control": "tormobile",
+"label": "Tor Mobile"
+  },
+  "gettor": {
+"path": "#gettor",
+"control": "gettor",
+"label": "GetTor"
+  },
+  "connecting": {
+"path": "#connectingtotor",
+"control": "connectingtotor",
+"label": "Conectar a Tor"
+  },
+  "censorship": {
+"path": "#censorship",
+"control": "censorship",
+"label": "Censura"
+  },
+  "https": {
+"path": "#https",
+"control": "https",
+"label": "HTTPS"
+  },
+  "operators": {
+"path": "#operators",
+"control": "operators",
+"label": "Operadores"
+  },
+  "onionservices": {
+"path": "#onionservices",
+"control": "servicios onion",
+"label": "Servicios onion"
+  },
+  "misc": {
+"path": "#misc",
+"control": "misc",
+"label": "Misc"
+  }
 }

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


[tor-commits] [translation/support-topics] Update translations for support-topics

2018-07-11 Thread translation
commit f51db707e68fe69e60ffc62bd31a858ffb3c8809
Author: Translation commit bot 
Date:   Wed Jul 11 10:49:44 2018 +

Update translations for support-topics
---
 es.json | 110 
 1 file changed, 55 insertions(+), 55 deletions(-)

diff --git a/es.json b/es.json
index 86813a614..951832313 100644
--- a/es.json
+++ b/es.json
@@ -1,57 +1,57 @@
 {
-"faq": {
-   "path": "#faq",
-   "control": "faq",
-   "label": "Preguntas más frecuentes"
-},
-"tbb": {
-   "path": "\n#tbb",
-   "control": "tbb",
-   "label": "Navegador Tor"
-},
-"tormessenger": {
-   "path": "#tormessenger",
-   "control": "tormessenger",
-   "label": "Tor Messenger"
-},
-"tormobile": {
-   "path": "#tormobile",
-   "control": "tormobile",
-   "label": "Tor Mobile"
-},
-"gettor": {
-   "path": "#gettor",
-   "control": "gettor",
-   "label": "GetTor"
-},
-"connecting": {
-   "path": "#connectingtotor",
-   "control": "connectingtotor",
-   "label": "Conectar a Tor"
-},
-"censorship": {
-   "path": "#censorship",
-   "control": "censorship",
-   "label": "Censura"
-},
-"https": {
-   "path": "#https",
-   "control": "https",
-   "label": "HTTPS"
-},
-"operators": {
-   "path": "#operators",
-   "control": "operators",
-   "label": "Operadores"
-},
-"onionservices": {
-   "path": "#onionservices",
-   "control": "servicios onion",
-   "label": "Servicios onion"
-},
-"misc": {
-   "path": "#misc",
-   "control": "misc",
-   "label": "Misc"
-}
+  "faq": {
+"path": "#faq",
+"control": "faq",
+"label": "Preguntas más frecuentes"
+  },
+  "tbb": {
+"path": "\n#tbb",
+"control": "tbb",
+"label": "Navegador Tor"
+  },
+  "tormessenger": {
+"path": "#tormessenger",
+"control": "tormessenger",
+"label": "Tor Messenger"
+  },
+  "tormobile": {
+"path": "#tormobile",
+"control": "tormobile",
+"label": "Tor Mobile"
+  },
+  "gettor": {
+"path": "#gettor",
+"control": "gettor",
+"label": "GetTor"
+  },
+  "connecting": {
+"path": "#connectingtotor",
+"control": "connectingtotor",
+"label": "Conectar a Tor"
+  },
+  "censorship": {
+"path": "#censorship",
+"control": "censorship",
+"label": "Censura"
+  },
+  "https": {
+"path": "#https",
+"control": "https",
+"label": "HTTPS"
+  },
+  "operators": {
+"path": "#operators",
+"control": "operators",
+"label": "Operadores"
+  },
+  "onionservices": {
+"path": "#onionservices",
+"control": "servicios onion",
+"label": "Servicios onion"
+  },
+  "misc": {
+"path": "#misc",
+"control": "misc",
+"label": "Misc"
+  }
 }

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


[tor-commits] [tor/master] Merge branch 'unify_microrevision_users'

2018-07-11 Thread nickm
commit 66074ad1e21cfe6c98a70b279ed690e357d1c41c
Merge: 537092cdb 5aee26ee4
Author: Nick Mathewson 
Date:   Wed Jul 11 10:20:39 2018 -0400

Merge branch 'unify_microrevision_users'

 src/app/config/config.c |  2 +-
 src/core/include.am |  6 --
 src/{core/or => lib/log}/git_revision.c | 10 +-
 src/{core/or => lib/log}/git_revision.h |  2 +-
 src/lib/log/include.am  |  9 +++--
 src/lib/log/log.c   | 14 --
 6 files changed, 22 insertions(+), 21 deletions(-)

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


[tor-commits] [tor/master] Move all use cases of micro-revision.i to a single place

2018-07-11 Thread nickm
commit 5aee26ee46d8d38759713d00ce4310a3aef4a559
Author: Nick Mathewson 
Date:   Wed Jul 11 09:52:39 2018 -0400

Move all use cases of micro-revision.i to a single place

That place is git-revision.c; git-revision.c now lives in lib/log.

Also fix the compilation rules so that all object files that need
micro-revision.i depend on it.
---
 src/app/config/config.c |  2 +-
 src/core/include.am |  6 --
 src/{core/or => lib/log}/git_revision.c | 10 +-
 src/{core/or => lib/log}/git_revision.h |  2 +-
 src/lib/log/include.am  |  9 +++--
 src/lib/log/log.c   | 14 --
 6 files changed, 22 insertions(+), 21 deletions(-)

diff --git a/src/app/config/config.c b/src/app/config/config.c
index 1be1803f2..74aa64ded 100644
--- a/src/app/config/config.c
+++ b/src/app/config/config.c
@@ -85,7 +85,7 @@
 #include "feature/relay/dns.h"
 #include "core/or/dos.h"
 #include "feature/client/entrynodes.h"
-#include "core/or/git_revision.h"
+#include "lib/log/git_revision.h"
 #include "feature/stats/geoip.h"
 #include "feature/hibernate/hibernate.h"
 #include "core/mainloop/main.h"
diff --git a/src/core/include.am b/src/core/include.am
index 1f37044e9..cd9edc449 100644
--- a/src/core/include.am
+++ b/src/core/include.am
@@ -34,7 +34,6 @@ LIBTOR_APP_A_SOURCES =\
src/core/or/connection_edge.c   \
src/core/or/connection_or.c \
src/core/or/dos.c   \
-   src/core/or/git_revision.c  \
src/core/or/policies.c  \
src/core/or/protover.c  \
src/core/or/reasons.c   \
@@ -135,10 +134,6 @@ else
 src_core_libtor_app_testing_a_SOURCES =
 endif
 
-src/core/or/git_revision.$(OBJEXT) \
-  src/core/or/src_core_libtor_app_testing_a-git_revision.$(OBJEXT): \
-   micro-revision.i
-
 AM_CPPFLAGS += -DSHARE_DATADIR="\"$(datadir)\""\
-DLOCALSTATEDIR="\"$(localstatedir)\""  \
-DBINDIR="\"$(bindir)\""
@@ -190,7 +185,6 @@ noinst_HEADERS +=   \
src/core/or/entry_connection_st.h   \
src/core/or/entry_port_cfg_st.h \
src/core/or/extend_info_st.h\
-   src/core/or/git_revision.h  \
src/core/or/listener_connection_st.h\
src/core/or/or.h\
src/core/or/or_circuit_st.h \
diff --git a/src/core/or/git_revision.c b/src/lib/log/git_revision.c
similarity index 73%
rename from src/core/or/git_revision.c
rename to src/lib/log/git_revision.c
index 28ec1a793..9d29ecd2a 100644
--- a/src/core/or/git_revision.c
+++ b/src/lib/log/git_revision.c
@@ -3,7 +3,8 @@
  * Copyright (c) 2007-2018, The Tor Project, Inc. */
 /* See LICENSE for licensing information */
 
-#include "core/or/git_revision.h"
+#include "orconfig.h"
+#include "lib/log/git_revision.h"
 
 /** String describing which Tor Git repository version the source was
  * built from.  This string is generated by a bit of shell kludging in
@@ -14,3 +15,10 @@ const char tor_git_revision[] =
 #include "micro-revision.i"
 #endif
   "";
+
+const char tor_bug_suffix[] = " (on Tor " VERSION
+#ifndef _MSC_VER
+  " "
+#include "micro-revision.i"
+#endif
+  ")";
diff --git a/src/core/or/git_revision.h b/src/lib/log/git_revision.h
similarity index 90%
rename from src/core/or/git_revision.h
rename to src/lib/log/git_revision.h
index 02070cfd5..0ce119079 100644
--- a/src/core/or/git_revision.h
+++ b/src/lib/log/git_revision.h
@@ -7,6 +7,6 @@
 #define TOR_GIT_REVISION_H
 
 extern const char tor_git_revision[];
+extern const char tor_bug_suffix[];
 
 #endif /* !defined(TOR_GIT_REVISION_H) */
-
diff --git a/src/lib/log/include.am b/src/lib/log/include.am
index b5a1c5ca2..4a6c9b368 100644
--- a/src/lib/log/include.am
+++ b/src/lib/log/include.am
@@ -7,6 +7,7 @@ endif
 
 src_lib_libtor_log_a_SOURCES = \
src/lib/log/escape.c\
+src/lib/log/git_revision.c  \
src/lib/log/ratelim.c   \
src/lib/log/log.c   \
src/lib/log/util_bug.c
@@ -20,11 +21,15 @@ src_lib_libtor_log_testing_a_SOURCES = \
 src_lib_libtor_log_testing_a_CPPFLAGS = $(AM_CPPFLAGS) $(TEST_CPPFLAGS)
 src_lib_libtor_log_testing_a_CFLAGS = $(AM_CFLAGS) $(TEST_CFLAGS)
 
-src/lib/log/torlog.$(OBJEXT) \
-  src/lib/log/src_lib_libtor_log_testing_a-torlog.$(OBJEXT): micro-revision.i
+# Declare that these object files depend on micro-revision.i.  Without this
+# rule, we could try to build them before micro-revision.i was created.
+src/lib/log/git_revision.$(OBJEXT) \
+  src/lib/log/src_lib_libtor_log_testing_a-git_revision.$(OBJEXT): \
+   micro-revision.i
 
 noinst_HEADERS +=  

[tor-commits] [sbws/master] Move test coverage paragraph

2018-07-11 Thread pastly
commit 10bfaac548e5be30ba1bea7ca5b6cef13e23e9bb
Author: Matt Traudt 
Date:   Mon Jun 25 15:13:19 2018 -0400

Move test coverage paragraph
---
 CONTRIBUTING.rst | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst
index d286e98..bdbdd99 100644
--- a/CONTRIBUTING.rst
+++ b/CONTRIBUTING.rst
@@ -26,6 +26,9 @@ Pull requests are welcome, especially if they address open 
issues.
 We use flake8 to check some PEP8 errors/warnings. This will be checked with
 ``tox`` and Travis.
 
+Simple Bandwidth Scanner is moving towards 100% test coverage. Please help us
+reach that goal, or at least not move us away from it.
+
 **Write good commit messages** that at least follow the spirit of
 :ref:`this example `.
 
@@ -33,8 +36,6 @@ We use flake8 to check some PEP8 errors/warnings. This will 
be checked with
 large mega-commit. This not only makes code review easier, but it also makes
 commits that show up in ``git blame`` 10 years from now make more sense.
 
-Simple Bandwidth Scanner is moving towards 100% test coverage. Please help us
-reach that goal, or at least not move us away from it.
 
 Coding Guidelines
 =



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


[tor-commits] [sbws/master] Update scale-v3bw-with-budget.py to handle new v3bw format

2018-07-11 Thread pastly
commit d00fae040fb252ecb22de3516e2280bf0b554c5e
Author: Matt Traudt 
Date:   Tue Jun 26 12:31:59 2018 -0400

Update scale-v3bw-with-budget.py to handle new v3bw format
---
 scripts/tools/scale-v3bw-with-budget.py | 10 +-
 1 file changed, 1 insertion(+), 9 deletions(-)

diff --git a/scripts/tools/scale-v3bw-with-budget.py 
b/scripts/tools/scale-v3bw-with-budget.py
index 3229e1e..62b17b4 100755
--- a/scripts/tools/scale-v3bw-with-budget.py
+++ b/scripts/tools/scale-v3bw-with-budget.py
@@ -24,18 +24,10 @@ def line_into_dict(line):
 def main(args):
 total_input_weight = 0
 line_dicts = []
-is_first_line = True
 for line in args.input:
-if is_first_line:
-# First line is special and is supposed to be a timestamp
-try:
-int(line)
-except ValueError as e:
-fail_hard('First line should be an int.', e)
-is_first_line = False
+if 'node_id=' not in line:
 args.output.write(line)
 continue
-# All lines but the first go through this
 d = line_into_dict(line)
 # Check that the required parts of the line are here
 if 'node_id' not in d:



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


[tor-commits] [sbws/master] Add git/github guidelines

2018-07-11 Thread pastly
commit 1b7453a6918ea63d5aad9fffd9f5e8c5163e2f87
Author: Matt Traudt 
Date:   Mon Jun 25 15:14:03 2018 -0400

Add git/github guidelines
---
 CONTRIBUTING.rst | 21 ++---
 1 file changed, 18 insertions(+), 3 deletions(-)

diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst
index b72d118..8336add 100644
--- a/CONTRIBUTING.rst
+++ b/CONTRIBUTING.rst
@@ -29,13 +29,28 @@ We use flake8 to check some PEP8 errors/warnings. This will 
be checked with
 Simple Bandwidth Scanner is moving towards 100% test coverage. Please help us
 reach that goal, or at least not move us away from it.
 
+Git and GitHub Guidelines
+=
+
 **Write good commit messages** that at least follow the spirit of
 :ref:`this example `.
 
-**Write many small commits** each containing an atomic change instead of one
-large mega-commit. This not only makes code review easier, but it also makes
-commits that show up in ``git blame`` 10 years from now make more sense.
+Strive to **write many small commits** each containing an atomic change instead
+of one large mega-commit. This not only makes code review easier, but it also
+makes commits that show up in ``git blame`` 10 years from now make more sense.
+
+**Prefer a rebase workflow instead of merge**. Incorporating PRs should be done
+with fast-forward merge, if easily possible. The larger the topic branch, the
+harder this may be, so merge commits are allowed.
+
+If, while working on a topic branch, some changes are made to master that
+conflict with your work or that you need to incorporate into your work, **do
+not merge master into your topic branch**; instead, rebase your topic branch on
+top of master or cherry-pick the changes.
 
+**Do not force push lightly** unless branches are clearly labeled as ones that
+may get overwritten (for example: "transient\_" prefix). Instead of overwriting
+a branch, add a version suffix (for example: "_02").
 
 Coding Guidelines
 =



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


[tor-commits] [sbws/master] Allow datetime objects

2018-07-11 Thread pastly
commit 32e37a12f0255ee5fd5028f5e0a9181f597d35d3
Author: Matt Traudt 
Date:   Mon Jun 25 15:13:35 2018 -0400

Allow datetime objects
---
 CONTRIBUTING.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst
index bdbdd99..b72d118 100644
--- a/CONTRIBUTING.rst
+++ b/CONTRIBUTING.rst
@@ -40,7 +40,7 @@ commits that show up in ``git blame`` 10 years from now make 
more sense.
 Coding Guidelines
 =
 
-**Strongly prefer Unix timestamps** over ``datetime`` structures and always
+**Strongly prefer Unix timestamps or datetime objects in UTC** and always
 work in UTC for as long as possible. When reading/writing/manipulating results
 from some period of time in the past, always err on the side of caution. For
 example, open an extra file into the past just in case it happens to include



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


[tor-commits] [sbws/master] Add changelog entry for contributing additions

2018-07-11 Thread pastly
commit 0f82e0b41446ca6b40fe7dc78139349543f8a447
Author: Matt Traudt 
Date:   Mon Jun 25 15:16:29 2018 -0400

Add changelog entry for contributing additions
---
 CHANGELOG.md | 1 +
 1 file changed, 1 insertion(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index a8bbd36..77fb16a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -34,6 +34,7 @@ Summary of changes:
 - Maintenance script to help us find functions that are (probably) no longer
   being called.
 - Integration test(s) for RelayPrioritizer (GHPR#206)
+- Git/GitHub usage guidelines to CONTRIBUTING document (GH#208 GHPR#215)
 
 ### Fixed
 



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


[tor-commits] [sbws/master] Require python version from 3.4.5

2018-07-11 Thread pastly
commit c21c6e9e9ba8b36280cb5469e8c1c87aa25864c0
Author: juga0 
Date:   Sun Jul 1 10:35:47 2018 +

Require python version from 3.4.5

Since version 3.4.2 gives error on install_layout and it is not
the default in stable OS distributions
---
 setup.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/setup.py b/setup.py
index 206526c..b7be0f7 100755
--- a/setup.py
+++ b/setup.py
@@ -64,7 +64,7 @@ setup(
 },
 data_files=get_data_files(),
 keywords='',
-python_requires='>=3.4',
+python_requires='>=3.4.5',
 # test_suite='test',
 entry_points={
 'console_scripts': [



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


[tor-commits] [sbws/master] Measure Exit+BadExit relays as non-exits

2018-07-11 Thread pastly
commit 305e75d40b12054e23ac19eba2e4828f48bd7252
Author: Matt Traudt 
Date:   Fri Jun 29 09:17:59 2018 -0400

Measure Exit+BadExit relays as non-exits
---
 CHANGELOG.md  | 4 
 sbws/core/scanner.py  | 3 ++-
 sbws/lib/relaylist.py | 4 
 3 files changed, 10 insertions(+), 1 deletion(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 77fb16a..1c3e372 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,10 @@ and this project adheres to [Semantic 
Versioning](http://semver.org/spec/v2.0.0.
 
 ## [Unreleased]
 
+### Fixed
+
+- Measure relays that have both Exit and BadExit as non-exits, which is how
+  clients would use them. (GH#217)
 
 
 ## [0.5.0] - 2018-06-26
diff --git a/sbws/core/scanner.py b/sbws/core/scanner.py
index 25c1dd3..249d8d4 100644
--- a/sbws/core/scanner.py
+++ b/sbws/core/scanner.py
@@ -178,7 +178,8 @@ def measure_relay(args, conf, destinations, cb, rl, relay):
 # exit, then pick a non-exit. Otherwise pick an exit.
 helper = None
 circ_fps = None
-if relay.can_exit_to(dest.hostname, dest.port):
+if relay.can_exit_to(dest.hostname, dest.port) and \
+relay not in rl.bad_exits:
 helper = _pick_ideal_second_hop(
 relay, dest, rl, cb.controller, is_exit=False)
 if helper:
diff --git a/sbws/lib/relaylist.py b/sbws/lib/relaylist.py
index ddd982a..c3bb745 100644
--- a/sbws/lib/relaylist.py
+++ b/sbws/lib/relaylist.py
@@ -164,6 +164,10 @@ class RelayList:
 return self._relays_with_flag(Flag.EXIT)
 
 @property
+def bad_exits(self):
+return self._relays_without_flag(Flag.BADEXIT)
+
+@property
 def non_exits(self):
 return self._relays_without_flag(Flag.EXIT)
 



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


[tor-commits] [sbws/master] Fix dumb logic error in RelayList.bad_exits(); Thanks @teor2345

2018-07-11 Thread pastly
commit d1537ac69df8d744053f8334c99f7126ad317dab
Author: Matt Traudt 
Date:   Mon Jul 2 08:39:41 2018 -0400

Fix dumb logic error in RelayList.bad_exits(); Thanks @teor2345

GH: closes #218
---
 sbws/lib/relaylist.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sbws/lib/relaylist.py b/sbws/lib/relaylist.py
index c3bb745..11390de 100644
--- a/sbws/lib/relaylist.py
+++ b/sbws/lib/relaylist.py
@@ -165,7 +165,7 @@ class RelayList:
 
 @property
 def bad_exits(self):
-return self._relays_without_flag(Flag.BADEXIT)
+return self._relays_with_flag(Flag.BADEXIT)
 
 @property
 def non_exits(self):



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


[tor-commits] [sbws/master] Check that there are exits

2018-07-11 Thread pastly
commit a00625b036dbff58d2038deea91782e0ba664549
Author: juga0 
Date:   Mon Jun 25 10:55:53 2018 +

Check that there are exits

to perform usability tests. This will avoid raising IndexError
when choosing an exit.
---
 sbws/lib/destination.py | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/sbws/lib/destination.py b/sbws/lib/destination.py
index 84dc580..ed1bc9b 100644
--- a/sbws/lib/destination.py
+++ b/sbws/lib/destination.py
@@ -186,6 +186,9 @@ class DestinationList:
 possible_exits = sorted(
 possible_exits, key=lambda e: e.bandwidth, reverse=True)
 exits = possible_exits[0:num_keep]
+if len(exits) < 1:
+log.warning("There are no exits to perform usability tests.")
+continue
 # Try three times to build a circuit to test this destination
 circ_id = None
 for _ in range(0, 3):



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


[tor-commits] [sbws/master] Reword sentences about flake8

2018-07-11 Thread pastly
commit 7586585de8e065da70d7b4a064a4398173ccf0c4
Author: Matt Traudt 
Date:   Mon Jun 25 15:12:52 2018 -0400

Reword sentences about flake8
---
 CONTRIBUTING.rst | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/CONTRIBUTING.rst b/CONTRIBUTING.rst
index 31d0324..d286e98 100644
--- a/CONTRIBUTING.rst
+++ b/CONTRIBUTING.rst
@@ -23,8 +23,8 @@ Pull requests are welcome, especially if they address open 
issues.
 #. Commit your changes and push them to a branch in your sbws GitHub repo
 #. Open a `pull request`_
 
-We use flake8 to enforce standard python coding style. This will be checked
-with ``tox``.
+We use flake8 to check some PEP8 errors/warnings. This will be checked with
+``tox`` and Travis.
 
 **Write good commit messages** that at least follow the spirit of
 :ref:`this example `.



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


[tor-commits] [sbws/master] Catch other possible exception

2018-07-11 Thread pastly
commit 58934941b20cdcc583e17bdafd10265d7c2a6927
Author: juga0 
Date:   Wed Jul 4 08:51:34 2018 +

Catch other possible exception
---
 sbws/lib/circuitbuilder.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sbws/lib/circuitbuilder.py b/sbws/lib/circuitbuilder.py
index 8791656..e3b3950 100644
--- a/sbws/lib/circuitbuilder.py
+++ b/sbws/lib/circuitbuilder.py
@@ -95,7 +95,7 @@ class CircuitBuilder:
 c.get_circuit(circ_id, default=None)
 try:
 c.close_circuit(circ_id)
-except InvalidArguments:
+except (InvalidArguments, InvalidRequest):
 pass
 except (ControllerError, InvalidArguments) as e:
 log.exception("Exception trying to get circuit to delete: %s",



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


[tor-commits] [sbws/master] Replace Exception by the possible exceptions

2018-07-11 Thread pastly
commit 218da1c5243c4c9d95eb91f44be15a155b56e848
Author: juga0 
Date:   Wed Jul 4 08:26:14 2018 +

Replace Exception by the possible exceptions
---
 sbws/util/stem.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sbws/util/stem.py b/sbws/util/stem.py
index b4190ef..e09f23c 100644
--- a/sbws/util/stem.py
+++ b/sbws/util/stem.py
@@ -195,7 +195,7 @@ def launch_tor(conf):
 try:
 cont.set_conf('__DisablePredictedCircuits', '1')
 cont.set_conf('__LeaveStreamsUnattached', '1')
-except Exception as e:
+except (ControllerError, InvalidArguments, InvalidRequest) as e:
 log.exception("Error trying to launch tor: %s. "
   "Maybe the tor directory is being used by other "
   "sbws instance?", e)



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


[tor-commits] [sbws/master] Replace Exception by the possible exceptions

2018-07-11 Thread pastly
commit 3036638b9ebe69bd36ab312b9eb5b275a39d89a8
Author: juga0 
Date:   Wed Jul 4 08:32:05 2018 +

Replace Exception by the possible exceptions
---
 sbws/lib/circuitbuilder.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sbws/lib/circuitbuilder.py b/sbws/lib/circuitbuilder.py
index f143b6a..faa73cf 100644
--- a/sbws/lib/circuitbuilder.py
+++ b/sbws/lib/circuitbuilder.py
@@ -1,5 +1,5 @@
 from stem import CircuitExtensionFailed, InvalidRequest, ProtocolError, Timeout
-from stem import InvalidArguments
+from stem import InvalidArguments, ControllerError
 import random
 from .relaylist import Relay
 import logging
@@ -64,7 +64,7 @@ class CircuitBuilder:
 except InvalidArguments:
 pass
 self.built_circuits.discard(circ_id)
-except Exception as e:
+except (ControllerError, ValueError) as e:
 log.exception("Error trying to get circuit to close it: %s.", e)
 
 def _build_circuit_impl(self, path):



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


[tor-commits] [sbws/master] Add format to default config file

2018-07-11 Thread pastly
commit 031a808d9d1bda37659ecde82aa4890840f09950
Author: juga0 
Date:   Tue Jul 10 07:59:37 2018 +

Add format to default config file
---
 sbws/config.default.ini | 1 +
 1 file changed, 1 insertion(+)

diff --git a/sbws/config.default.ini b/sbws/config.default.ini
index 04bdd61..e08b3b9 100644
--- a/sbws/config.default.ini
+++ b/sbws/config.default.ini
@@ -104,5 +104,6 @@ to_stdout_level = ${level}
 format = [%(asctime)s] [%(name)s] [%(levelname)s] %(message)s
 to_file_format = ${format}
 to_stdout_format = ${format}
+to_syslog_format = %(module)s[%(process)s]: <%(levelname)s> %(message)s
 # verbose formatter useful for debugging
 #format = %(asctime)s %(levelname)s %(threadName)s %(filename)s:%(lineno)s - 
%(funcName)s - %(message)s



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


[tor-commits] [sbws/master] Replace Exception by the possible exceptions

2018-07-11 Thread pastly
commit c20f90acd6c7a10888b3dc4d48045d436ad957d8
Author: juga0 
Date:   Wed Jul 4 08:52:55 2018 +

Replace Exception by the possible exceptions
---
 sbws/lib/relaylist.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sbws/lib/relaylist.py b/sbws/lib/relaylist.py
index f674b62..f177a96 100644
--- a/sbws/lib/relaylist.py
+++ b/sbws/lib/relaylist.py
@@ -198,7 +198,7 @@ class RelayList:
 try:
 relays = [Relay(ns.fingerprint, c, ns=ns)
   for ns in c.get_network_statuses()]
-except Exception as e:
+except ControllerError as e:
 log.exception("Exception trying to init relays %s", e)
 return []
 return relays



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


[tor-commits] [sbws/master] Add changelog entry for system log

2018-07-11 Thread pastly
commit 4d01e9ae705b5491c2b36b6ccf99c7ed4def2db7
Author: juga0 
Date:   Sat Jul 7 16:28:28 2018 +

Add changelog entry for system log
---
 CHANGELOG.md | 1 +
 1 file changed, 1 insertion(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index e7a18b9..8608b1a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -12,6 +12,7 @@ and this project adheres to [Semantic 
Versioning](http://semver.org/spec/v2.0.0.
 - UML diagrams to documentation. In docs/ run `make umlsvg` to rebuild them.
   Requires graphviz to be installed.(GHPR#226)
 - Add metadata to setup.py, useful for source/binary distributions.
+- Add possibility to log to system log. (#26683)
 
 ### Fixed
 



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


[tor-commits] [sbws/master] Add metadata entry to changelog

2018-07-11 Thread pastly
commit d67772bae4474b6a4468ab98fdc5a045fd7d5ce8
Author: juga0 
Date:   Fri Jul 6 16:14:59 2018 +

Add metadata entry to changelog
---
 CHANGELOG.md | 1 +
 1 file changed, 1 insertion(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9c35713..62f16d8 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,7 @@ and this project adheres to [Semantic 
Versioning](http://semver.org/spec/v2.0.0.
 
 - UML diagrams to documentation. In docs/ run `make umlsvg` to rebuild them.
   Requires graphviz to be installed.(GHPR#226)
+- Add metadata to setup.py, useful for source/binary distributions.
 
 ### Fixed
 



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


[tor-commits] [sbws/master] Add package metadata

2018-07-11 Thread pastly
commit bab1f33c54c29244cb33f169acf3a047c1e1a683
Author: juga0 
Date:   Fri Jul 6 09:22:56 2018 +

Add package metadata

and add a simple first sentence about what this program does.
---
 README.md |  3 +++
 setup.py  | 29 -
 2 files changed, 19 insertions(+), 13 deletions(-)

diff --git a/README.md b/README.md
index a066d0c..74da116 100644
--- a/README.md
+++ b/README.md
@@ -2,6 +2,9 @@
 
 [![Build 
Status](https://travis-ci.org/pastly/simple-bw-scanner.svg?branch=master)](https://travis-ci.org/pastly/simple-bw-scanner)
 
+`simple-bw-scanner` (also called `sbws`) is a Tor bandwidth scanner that 
+produces bandwidth measurements files to be used by Directory Authorities.
+
 It doesn't get simpler than this, folks.
 
 The scanner builds two hop circuits consisting of the relay being measured and
diff --git a/setup.py b/setup.py
index 738be70..e009a7b 100755
--- a/setup.py
+++ b/setup.py
@@ -8,10 +8,10 @@ import os
 
 here = os.path.abspath(os.path.dirname(__file__))
 
-# Causes the lint Travis builds to fail for some reason, so just going to
-# remove the long description for now.
-# with open(os.path.join(here, 'README.md'), encoding='utf-8') as f:
-# long_description = f.read()
+
+def long_description():
+with open(os.path.join(here, 'README.md'), encoding='utf-8') as f:
+return f.read()
 
 
 def get_package_data():
@@ -44,18 +44,22 @@ setup(
 name='sbws',
 version=find_version(),
 description='Simple Bandwidth Scanner',
-# long_description=long_description,
+long_description=long_description(),
+long_description_content_type="text/markdown",
 author='Matt Traudt',
 author_email='pas...@torproject.org',
 license='CC0',
-# https://packaging.python.org/tutorials/distributing-packages/#id48
-# https://pypi.python.org/pypi?%3Aaction=list_classifiers
+url="https://gitweb.torproject.org/sbws.git;,
 classifiers=[
-# How mature is this project? Common values are
-#   3 - Alpha
-#   4 - Beta
-#   5 - Production/Stable
 'Development Status :: 4 - Beta',
+"Environment :: Console",
+'Intended Audience :: Developers',
+'Intended Audience :: System Administrators',
+'Operating System :: OS Independent',
+'Programming Language :: Python :: 3.4',
+'Programming Language :: Python :: 3.5',
+'Programming Language :: Python :: 3.6',
+'Topic :: System :: Networking',
 ],
 packages=find_packages(),
 include_package_data=True,
@@ -63,9 +67,8 @@ setup(
 'sbws': get_package_data(),
 },
 data_files=get_data_files(),
-keywords='',
+keywords='tor onion bandwidth measurements scanner relay circuit',
 python_requires='>=3.4.5',
-# test_suite='test',
 entry_points={
 'console_scripts': [
 'sbws = sbws.sbws:main',



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


[tor-commits] [sbws/master] Include target to build diagrams

2018-07-11 Thread pastly
commit c3264df50c685da7dd0160a51efced5b8e2b5690
Author: juga0 
Date:   Thu Jul 5 20:23:55 2018 +

Include target to build diagrams
---
 docs/Makefile | 13 +
 setup.py  |  2 +-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/docs/Makefile b/docs/Makefile
index 66feed2..eee14f8 100644
--- a/docs/Makefile
+++ b/docs/Makefile
@@ -7,6 +7,12 @@ SPHINXBUILD   = sphinx-build
 SPHINXPROJ= simple-bw-scanner
 SOURCEDIR = source
 BUILDDIR  = build
+# generate SVG
+IMAGEDIRS   = $(SOURCEDIR)/images
+BUILDDIRIMAGES  = $(BUILDDIR)/html/_images
+PYREVERSE = pyreverse
+PYREVERSE_FLAGS = -o svg -p sbws ../sbws
+UMLSVG := $(PYREVERSE) $(PYREVERSE_FLAGS);mv *.svg $(IMAGEDIRS);mkdir -p 
$(BUILDDIRIMAGES);cp $(IMAGEDIRS)/*.svg $(BUILDDIRIMAGES)
 
 # Put it first so that "make" without argument is like "make help".
 help:
@@ -14,7 +20,14 @@ help:
 
 .PHONY: help Makefile
 
+umlsvg:
+   @echo "Generating UML SVG"
+   $(UMLSVG)
+
 # Catch-all target: route all unknown targets to Sphinx using the new
 # "make mode" option.  $(O) is meant as a shortcut for $(SPHINXOPTS).
 %: Makefile
+   # commented because if system packages invoke make html, it'll 
automatically
+   # recreate the svg on every build, and it's not deterministic.
+   #$(UMLSVG)
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
diff --git a/setup.py b/setup.py
index b7be0f7..738be70 100755
--- a/setup.py
+++ b/setup.py
@@ -82,6 +82,6 @@ setup(
 'dev': ['flake8'],
 'test': ['tox', 'pytest', 'coverage'],
 # recommonmark: to make sphinx render markdown
-'doc': ['sphinx', 'recommonmark'],
+'doc': ['sphinx', 'recommonmark', 'pylint'],
 },
 )



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


[tor-commits] [sbws/master] Replace Exception by the possible exceptions

2018-07-11 Thread pastly
commit af869ad0701064600c9f1d161c8cb6300bb023f3
Author: juga0 
Date:   Wed Jul 4 08:50:29 2018 +

Replace Exception by the possible exceptions
---
 sbws/lib/circuitbuilder.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sbws/lib/circuitbuilder.py b/sbws/lib/circuitbuilder.py
index c2c9b97..8791656 100644
--- a/sbws/lib/circuitbuilder.py
+++ b/sbws/lib/circuitbuilder.py
@@ -97,7 +97,7 @@ class CircuitBuilder:
 c.close_circuit(circ_id)
 except InvalidArguments:
 pass
-except Exception as e:
+except (ControllerError, InvalidArguments) as e:
 log.exception("Exception trying to get circuit to delete: %s",
   e)
 self.built_circuits.clear()



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


[tor-commits] [sbws/master] Remove format from default log file

2018-07-11 Thread pastly
commit c80d4ecd9cbe9dbd09d6f5998a3e3463a1c0374e
Author: juga0 
Date:   Tue Jul 10 07:59:08 2018 +

Remove format from default log file
---
 sbws/config.log.default.ini | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/sbws/config.log.default.ini b/sbws/config.log.default.ini
index d841ccf..80f7172 100644
--- a/sbws/config.log.default.ini
+++ b/sbws/config.log.default.ini
@@ -38,7 +38,4 @@ args = ('/dev/log',)
 
 [formatter_to_file]
 
-# syslog-like formatter
 [formatter_to_syslog]
-format = %(asctime)s %(module)s[%(process)s]: <%(levelname)s> %(message)s
-datefmt = %b %d %H:%M:%S



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


[tor-commits] [sbws/master] Remove two v3bw parsing/plotting scripts

2018-07-11 Thread pastly
commit 250c7e62a2d131eef86780fdedcb0a9eb1e16dc6
Author: Matt Traudt 
Date:   Thu Jul 5 22:09:59 2018 -0400

Remove two v3bw parsing/plotting scripts

GH: ref #201
---
 CHANGELOG.md  |   4 ++
 scripts/tools/plot-v3bw-xy.py | 156 --
 scripts/tools/v3bw-into-xy.py |  53 --
 3 files changed, 4 insertions(+), 209 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index ecd79f2..9c35713 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -24,6 +24,10 @@ and this project adheres to [Semantic 
Versioning](http://semver.org/spec/v2.0.0.
 - Remove is_controller_ok. Instead catch possible controller exceptions and 
 log them
 
+### Removed
+
+- Two parsing/plotting scripts in scripts/tools/ that can now be found at
+
 
 ## [0.5.0] - 2018-06-26
 
diff --git a/scripts/tools/plot-v3bw-xy.py b/scripts/tools/plot-v3bw-xy.py
deleted file mode 100755
index 861894a..000
--- a/scripts/tools/plot-v3bw-xy.py
+++ /dev/null
@@ -1,156 +0,0 @@
-#!/usr/bin/env python3
-# File: plot-v3bw-xy.py
-# Author: Matt Traudt
-# License: CC0
-#
-# Requires matplotlib; pip install matplotlib
-from argparse import ArgumentDefaultsHelpFormatter, ArgumentParser
-import matplotlib; matplotlib.use('Agg')  # noqa; for systems without X11
-from matplotlib.backends.backend_pdf import PdfPages
-import pylab as plt
-
-colors = "krbgcmy"
-
-plt.rcParams.update({
-'axes.grid': True,
-})
-
-
-def get_all_values_from_fd(fd):
-values = []
-for line in fd:
-try:
-x, y = line.strip().split()
-x, y = str(x), float(y)
-assert len(x) == 40
-values.append((x, y))
-except ValueError:
-print('ignoring', line)
-continue
-return values
-
-
-def common_elements(l1, l2):
-ret = set()
-for item in l1:
-if item in l2:
-ret.add(item)
-return ret
-
-
-def main(args, pdf):
-plt.figure()
-data = {}
-# Read all data in
-all_labels = []
-for fname, label in args.input:
-with open(fname, 'rt') as fd:
-data[label] = {
-'label': label,
-'data': get_all_values_from_fd(fd)
-}
-all_labels.append(label)
-# Determine what relay fingerprints have data from all input sources
-common_fingerprints = None
-for label1 in data:
-fp_list1 = set([point[0] for point in data[label1]['data']])
-for label2 in data:
-if label2 == label1:
-continue
-fp_list2 = set([point[0] for point in data[label2]['data']])
-fp_list1 = common_elements(fp_list1, fp_list2)
-common_fingerprints = fp_list1
-break
-# Remove unneeded data, then
-# sort by fingerprint
-for label in data:
-points = [p for p in data[label]['data']
-  if p[0] in common_fingerprints]
-points = sorted(points, key=lambda p: p[0])
-data[label]['data'] = points
-# combine the y values for each fingerprint
-# {
-#'fp1': {'label1': 10, 'label2': 30},
-#'fp2': {'label1': 20, 'label2': 15},
-# }
-# and change dict data's structure to that
-new_data = {}
-for fp in common_fingerprints:
-new_data[fp] = {}
-for label in data:
-y = [p[1] for p in data[label]['data'] if p[0] == fp]
-assert len(y) == 1
-y = y[0]
-new_data[fp].update({label: y})
-data = new_data
-sort_label = all_labels[0]
-all_labels_sorted = sorted(all_labels)
-# Sort the data points such that sort_label's highest value is first.
-# Assuming sort_label is label1, then turn into this list
-# [
-#{'label1': 20, 'label2': 15},
-#{'label1': 10, 'label2': 30},
-# ]
-# and change dict data's structure to that
-new_data = []
-for fp in data:
-new_data.append(data[fp])
-new_data = sorted(new_data, key=lambda k: k[sort_label], reverse=True)
-data = new_data
-# Plot data
-for label_i, label in enumerate(all_labels_sorted):
-x = []
-y = []
-for point_i, point in enumerate(data):
-x.append(point_i)
-if 'sbws' in label:
-y.append(point[label] / 1000)
-else:
-y.append(point[label])
-plt.scatter(x, y, c=colors[label_i], s=args.size, label=label)
-plt.legend(loc='upper right')
-plt.xlabel(args.xlabel)
-plt.ylabel(args.ylabel)
-if args.xmin is not None:
-plt.xlim(xmin=args.xmin)
-if args.ymin is not None:
-plt.ylim(ymin=args.ymin)
-if args.xmax is not None:
-plt.xlim(xmax=args.xmax)
-if args.ymax is not None:
-plt.ylim(ymax=args.ymax)
-plt.title(args.title)
-pdf.savefig()
-
-
-if __name__ == '__main__':
-d = 'Takes one or more lists of (fingerprint, bandwidth) 

[tor-commits] [sbws/master] Replace Exception by the possible exceptions

2018-07-11 Thread pastly
commit 026330bcfc2b7ab256d7aeef6bf249a05d9f113c
Author: juga0 
Date:   Wed Jul 4 08:57:48 2018 +

Replace Exception by the possible exceptions
---
 sbws/util/stem.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sbws/util/stem.py b/sbws/util/stem.py
index bbd4e7a..85fd7e6 100644
--- a/sbws/util/stem.py
+++ b/sbws/util/stem.py
@@ -211,7 +211,7 @@ def get_socks_info(controller):
 try:
 socks_ports = controller.get_listeners(Listener.SOCKS)
 return socks_ports[0]
-except Exception as e:
+except ControllerError as e:
 log.exception("Exception trying to get socks info: %e.", e)
 exit(1)
 



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


[tor-commits] [sbws/master] Validate and use syslog format

2018-07-11 Thread pastly
commit 15e6cdb718f470762451562b43877e6d720947df
Author: juga0 
Date:   Tue Jul 10 08:00:32 2018 +

Validate and use syslog format
---
 sbws/util/config.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/sbws/util/config.py b/sbws/util/config.py
index 6917033..585d23c 100644
--- a/sbws/util/config.py
+++ b/sbws/util/config.py
@@ -134,6 +134,7 @@ def configure_logging(args, conf):
 # Set some stuff that needs config parser's interpolation
 conf['formatter_to_file']['format'] = conf['logging']['to_file_format']
 conf['formatter_to_stdout']['format'] = conf['logging']['to_stdout_format']
+conf['formatter_to_syslog']['format'] = conf['logging']['to_syslog_format']
 conf[logger]['level'] = conf['logging']['level'].upper()
 conf['handler_to_file']['level'] = conf['logging']['to_file_level'].upper()
 conf['handler_to_stdout']['level'] = \
@@ -294,7 +295,8 @@ def _validate_logging(conf):
 'to_file_max_bytes': {'minimum': 0, 'maximum': None},
 'to_file_num_backups': {'minimum': 0, 'maximum': None},
 }
-unvalidated = ['format', 'to_file_format', 'to_stdout_format']
+unvalidated = ['format', 'to_file_format', 'to_stdout_format',
+   'to_syslog_format']
 all_valid_keys = list(bools.keys()) + list(enums.keys()) + \
 list(ints.keys()) + unvalidated
 errors.extend(_validate_section_keys(conf, sec, all_valid_keys, err_tmpl))



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


[tor-commits] [sbws/master] Remove level from default log config file

2018-07-11 Thread pastly
commit 9b9baad50e9fab6195d75ec931b063137aa82798
Author: juga0 
Date:   Tue Jul 10 08:01:20 2018 +

Remove level from default log config file
---
 sbws/config.log.default.ini | 1 -
 1 file changed, 1 deletion(-)

diff --git a/sbws/config.log.default.ini b/sbws/config.log.default.ini
index 80f7172..deb6275 100644
--- a/sbws/config.log.default.ini
+++ b/sbws/config.log.default.ini
@@ -31,7 +31,6 @@ args = ('/dev/null', )
 [handler_to_syslog]
 class=handlers.SysLogHandler
 formatter=to_syslog
-level = INFO
 args = ('/dev/log',)
 
 [formatter_to_stdout]



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


[tor-commits] [sbws/master] Add changelog entry for uml diagrams

2018-07-11 Thread pastly
commit 5f5911f558b57197897be790983b1dedf7f0cc86
Author: Matt Traudt 
Date:   Thu Jul 5 20:23:08 2018 -0400

Add changelog entry for uml diagrams
---
 CHANGELOG.md | 5 +
 1 file changed, 5 insertions(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index feaff96..ecd79f2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,11 @@ and this project adheres to [Semantic 
Versioning](http://semver.org/spec/v2.0.0.
 
 ## [Unreleased]
 
+### Added
+
+- UML diagrams to documentation. In docs/ run `make umlsvg` to rebuild them.
+  Requires graphviz to be installed.(GHPR#226)
+
 ### Fixed
 
 - Measure relays that have both Exit and BadExit as non-exits, which is how



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


[tor-commits] [sbws/master] Replace log message by checking bootstrap

2018-07-11 Thread pastly
commit 36b0cd82619adaa382ef8d2a68029064244e5137
Author: juga0 
Date:   Wed Jul 4 08:13:05 2018 +

Replace log message by checking bootstrap
---
 sbws/util/stem.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sbws/util/stem.py b/sbws/util/stem.py
index 8d4989e..c4497b1 100644
--- a/sbws/util/stem.py
+++ b/sbws/util/stem.py
@@ -80,7 +80,7 @@ def is_bootstrapped(c):
 try:
 line = c.get_info('status/bootstrap-phase')
 except Exception as e:
-log.exception("Exception bootstrapping %s", e)
+log.exception("Error trying to check bootstrap phase %s", e)
 return False
 state, _, progress, *_ = line.split()
 progress = int(progress.split('=')[1])



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


[tor-commits] [sbws/master] Add changelog entry about V3BWFile class method

2018-07-11 Thread pastly
commit d3bf951f5e7d30b00422bf83b8581027b0db563c
Author: juga0 
Date:   Fri Jul 6 17:05:52 2018 +

Add changelog entry about V3BWFile class method
---
 CHANGELOG.md | 1 +
 1 file changed, 1 insertion(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 62f16d8..fc2b07a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,6 +19,7 @@ and this project adheres to [Semantic 
Versioning](http://semver.org/spec/v2.0.0.
   clients would use them. (GH#217)
 - Could not init sbws because of a catch-22 related to logging configuration.
   Overhaul how logging is configured. (GH#186 GHPR#224)
+- Call write method of V3BWFile class from the object instance. (#26671)
 
 ### Changed
 



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


[tor-commits] [sbws/master] Add 2 conf opts for logging to file, but not used yet

2018-07-11 Thread pastly
commit d111af98e18a176590bffd9f80cb8c0b7ca3601b
Author: Matt Traudt 
Date:   Wed Jul 4 11:32:18 2018 -0400

Add 2 conf opts for logging to file, but not used yet
---
 sbws/config.default.ini | 7 +++
 sbws/util/config.py | 7 ++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/sbws/config.default.ini b/sbws/config.default.ini
index dbe46a2..d9e2622 100644
--- a/sbws/config.default.ini
+++ b/sbws/config.default.ini
@@ -87,6 +87,13 @@ min_relays = 50
 to_file = yes
 # Whether or not to log to stdout
 to_stdout = no
+# If logging to file, how large (in bytes) should the file be allowed to get
+# before rotating to a new one. 10485760 is 10 MiB. If zero or number of
+# backups is zero, never rotate the log file.
+to_file_max_bytes = 10485760
+# If logging to file, how many backups to keep. If zero or max bytes is zero,
+# never rotate the log file.
+to_file_num_backups = 50
 # Level to log at. Debug, info, warning, error, critical.
 level = info
 to_file_level = ${level}
diff --git a/sbws/util/config.py b/sbws/util/config.py
index bf73540..8953d92 100644
--- a/sbws/util/config.py
+++ b/sbws/util/config.py
@@ -282,8 +282,13 @@ def _validate_logging(conf):
 'to_file': {},
 'to_stdout': {},
 }
+ints = {
+'to_file_max_bytes': {'minimum': 0, 'maximum': None},
+'to_file_num_backups': {'minimum': 0, 'maximum': None},
+}
 unvalidated = ['format', 'to_file_format', 'to_stdout_format']
-all_valid_keys = list(bools.keys()) + list(enums.keys()) + unvalidated
+all_valid_keys = list(bools.keys()) + list(enums.keys()) + \
+list(ints.keys()) + unvalidated
 errors.extend(_validate_section_keys(conf, sec, all_valid_keys, err_tmpl))
 errors.extend(_validate_section_bools(conf, sec, bools, err_tmpl))
 errors.extend(_validate_section_enums(conf, sec, enums, err_tmpl))



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


[tor-commits] [sbws/master] With --log-level, override the right thing

2018-07-11 Thread pastly
commit f52bc5b0ac6e5c5e529ed8655038be4a5dc27f97
Author: Matt Traudt 
Date:   Wed Jul 4 11:32:50 2018 -0400

With --log-level, override the right thing
---
 sbws/util/config.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sbws/util/config.py b/sbws/util/config.py
index 8953d92..274e87b 100644
--- a/sbws/util/config.py
+++ b/sbws/util/config.py
@@ -100,7 +100,7 @@ def configure_logging(args, conf):
 assert isinstance(conf, ConfigParser)
 logger = 'logger_sbws'
 if args.log_level:
-conf[logger]['level'] = args.log_level.upper()
+conf['logging']['level'] = args.log_level.upper()
 # Set the correct handler(s) based on [logging] options
 handlers = set()
 can_log_to_file, reason = _can_log_to_file(conf)



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


[tor-commits] [sbws/master] Move is_controller_ok changelog entry to unreleased

2018-07-11 Thread pastly
commit 2cf477274125a18b6a6b1140b51e4e9074dbfea8
Author: juga0 
Date:   Tue Jul 3 17:28:39 2018 +

Move is_controller_ok changelog entry to unreleased
---
 CHANGELOG.md | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 360d76a..feaff96 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,11 @@ and this project adheres to [Semantic 
Versioning](http://semver.org/spec/v2.0.0.
 - Could not init sbws because of a catch-22 related to logging configuration.
   Overhaul how logging is configured. (GH#186 GHPR#224)
 
+### Changed
+
+- Remove is_controller_ok. Instead catch possible controller exceptions and 
+log them
+
 
 ## [0.5.0] - 2018-06-26
 
@@ -64,8 +69,6 @@ generated ones are kept. A `latest.v3bw` symlink is updated. 
(GH#179 GHPR#190)
 - Code refactoring in the v3bw classes and generation area
 - Replace v3bw-into-xy bash script with python script to handle a more complex
   v3bw file format (GH#182)
-- Remove is_controller_ok. Instead catch possible controller exceptions and 
- log them
 
 ## [0.4.1] - 2018-06-14
 



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


[tor-commits] [sbws/master] Update comment: we do more things here now

2018-07-11 Thread pastly
commit ee720405b0f532138d0ba6a11e6eeb4097991852
Author: Matt Traudt 
Date:   Wed Jul 4 11:33:07 2018 -0400

Update comment: we do more things here now
---
 sbws/util/config.py | 21 +
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/sbws/util/config.py b/sbws/util/config.py
index 274e87b..5813878 100644
--- a/sbws/util/config.py
+++ b/sbws/util/config.py
@@ -112,18 +112,23 @@ def configure_logging(args, conf):
 # Collect the handlers in the appropriate config option
 conf[logger]['handlers'] = ','.join(handlers)
 if 'to_file' in handlers:
-# Because of the way python's standard logging library works, we can't
-# tell this handler that the file it should log to is
-# ${paths:log_dname}/foo.log. It evals() the string stored in the args,
-# therefore not allowing the config parser to change that to
-# ~/.sbws/log/foo.log. So we set it here.
+# This is weird.
 #
-# Also we set files to rotate at 10 MiB in size and to keep 100 backups
+# Python's logging library expects 'args' to be a tuple ... but it has
+# to be stored as a string and it evals() the string.
+#
+# The first argument is the file name to which it should log. Set it to
+# the sbws command (like 'scanner' or 'generate') if possible, or to
+# 'sbws' failing that.
 dname = conf['paths']['log_dname']
 os.makedirs(dname, exist_ok=True)
 fname = os.path.join(dname, '{}.log'.format(args.command or 'sbws'))
-conf['handler_to_file']['args'] = \
-"('{}', 'a', 10*1024*1024, 100)".format(fname)
+# The second argument is the number of backups to keep, and the third
+# is the maximum file size (in bytes) each log file should be.
+max_bytes = conf.getint('logging', 'to_file_max_bytes')
+num_backups = conf.getint('logging', 'to_file_num_backups')
+# Now store those things as a string in the config. So dumb.
+conf['handler_to_file']['args'] = str((fname, num_backups, max_bytes))
 # Set some stuff that needs config parser's interpolation
 conf['formatter_to_file']['format'] = conf['logging']['to_file_format']
 conf['formatter_to_stdout']['format'] = conf['logging']['to_stdout_format']



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


[tor-commits] [sbws/master] Remove comment that doesn't really apply anymore

2018-07-11 Thread pastly
commit a316ff667e0128c5ad9252d0e130141bee953129
Author: Matt Traudt 
Date:   Wed Jul 4 11:31:41 2018 -0400

Remove comment that doesn't really apply anymore
---
 sbws/config.log.default.ini | 4 
 1 file changed, 4 deletions(-)

diff --git a/sbws/config.log.default.ini b/sbws/config.log.default.ini
index 6cfcf88..82e483e 100644
--- a/sbws/config.log.default.ini
+++ b/sbws/config.log.default.ini
@@ -25,10 +25,6 @@ args = (sys.stdout,)
 [handler_to_file]
 class = handlers.RotatingFileHandler
 formatter = to_file
-# There doesn't seem to be a way to put ${paths:log_filepath} here since the
-# logging library eval()s this, which doesn't give the ini parsing library a
-# chance to replace the text. So we do it in configure_logging() in
-# sbws/util/config.py instead.
 args = ('/dev/null', )
 
 ## for logging to system log



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


[tor-commits] [sbws/master] s/DEBUG/debug/

2018-07-11 Thread pastly
commit 9bb2913035c1c4e786a5cdd76c46a1c03191642a
Author: Matt Traudt 
Date:   Wed Jul 4 12:02:23 2018 -0400

s/DEBUG/debug/
---
 tests/integration/conftest.py  |  2 +-
 tests/integration/core/test_scanner.py |  2 +-
 tests/integration/lib/test_relayprioritizer.py |  2 +-
 tests/unit/conftest.py |  2 +-
 tests/unit/core/test_cleanup.py| 20 ++--
 tests/unit/core/test_stats.py  | 12 ++--
 6 files changed, 20 insertions(+), 20 deletions(-)

diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py
index 94b2433..cfd0e28 100644
--- a/tests/integration/conftest.py
+++ b/tests/integration/conftest.py
@@ -19,7 +19,7 @@ def persistent_empty_dotsbws(parser):
 '''
 d = TemporaryDirectory()
 args = parser.parse_args(
-'-d {} --log-level DEBUG init'.format(d.name).split())
+'-d {} --log-level debug init'.format(d.name).split())
 conf = get_config(args)
 sbws.core.init.main(args, conf)
 os.makedirs(os.path.join(d.name, 'datadir'))
diff --git a/tests/integration/core/test_scanner.py 
b/tests/integration/core/test_scanner.py
index 152e939..e7e0d86 100644
--- a/tests/integration/core/test_scanner.py
+++ b/tests/integration/core/test_scanner.py
@@ -22,7 +22,7 @@ def assert_within(value, target, radius):
 
 def get_everything_to_measure(dotsbws, cont, parser):
 args = parser.parse_args(
-'-d {} --log-level DEBUG scanner'.format(dotsbws).split())
+'-d {} --log-level debug scanner'.format(dotsbws).split())
 conf = get_config(args)
 conf['destinations']['foo'] = 'on'
 conf['destinations.foo'] = {}
diff --git a/tests/integration/lib/test_relayprioritizer.py 
b/tests/integration/lib/test_relayprioritizer.py
index 237a139..d626fe0 100644
--- a/tests/integration/lib/test_relayprioritizer.py
+++ b/tests/integration/lib/test_relayprioritizer.py
@@ -14,7 +14,7 @@ def static_time(value):
 
 def get_global_stuff(dotsbws, cont, parser):
 args = parser.parse_args(
-'-d {} --log-level DEBUG'.format(dotsbws).split())
+'-d {} --log-level debug'.format(dotsbws).split())
 conf = get_config(args)
 rl = RelayList(args, conf, cont)
 return {
diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py
index 002987c..8915669 100644
--- a/tests/unit/conftest.py
+++ b/tests/unit/conftest.py
@@ -95,7 +95,7 @@ def empty_dotsbws(parser):
 '''
 d = TemporaryDirectory()
 args = parser.parse_args(
-'-d {} --log-level DEBUG init'.format(d.name).split())
+'-d {} --log-level debug init'.format(d.name).split())
 conf = get_config(args)
 sbws.core.init.main(args, conf)
 return d
diff --git a/tests/unit/core/test_cleanup.py b/tests/unit/core/test_cleanup.py
index 0f6fc41..3278e00 100644
--- a/tests/unit/core/test_cleanup.py
+++ b/tests/unit/core/test_cleanup.py
@@ -13,7 +13,7 @@ def test_cleanup_no_dotsbws(tmpdir, caplog, parser):
 caplog.set_level(logging.DEBUG)
 dotsbws = tmpdir
 args = parser.parse_args(
-'-d {} --log-level DEBUG cleanup'.format(dotsbws).split())
+'-d {} --log-level debug cleanup'.format(dotsbws).split())
 conf = get_config(args)
 try:
 sbws.core.cleanup.main(args, conf)
@@ -27,7 +27,7 @@ def test_cleanup_no_dotsbws(tmpdir, caplog, parser):
 def test_cleanup_no_datadir(empty_dotsbws, caplog, parser):
 dotsbws = empty_dotsbws
 args = parser.parse_args(
-'-d {} --log-level DEBUG cleanup'.format(dotsbws.name).split())
+'-d {} --log-level debug cleanup'.format(dotsbws.name).split())
 conf = get_config(args)
 try:
 sbws.core.cleanup.main(args, conf)
@@ -42,7 +42,7 @@ def test_cleanup_no_datadir(empty_dotsbws, caplog, parser):
 def test_cleanup_small_stale(empty_dotsbws_datadir, caplog, parser):
 dotsbws = empty_dotsbws_datadir
 args = parser.parse_args(
-'-d {} --log-level DEBUG cleanup'.format(dotsbws.name).split())
+'-d {} --log-level debug cleanup'.format(dotsbws.name).split())
 conf = get_config(args)
 conf['general']['data_period'] = '1'
 conf['cleanup']['stale_days'] = '2'
@@ -60,7 +60,7 @@ def test_cleanup_small_stale(empty_dotsbws_datadir, caplog, 
parser):
 def test_cleanup_small_rotten(empty_dotsbws_datadir, caplog, parser):
 dotsbws = empty_dotsbws_datadir
 args = parser.parse_args(
-'-d {} --log-level DEBUG cleanup'.format(dotsbws.name).split())
+'-d {} --log-level debug cleanup'.format(dotsbws.name).split())
 conf = get_config(args)
 conf['general']['data_period'] = '1'
 conf['cleanup']['stale_days'] = '5'
@@ -78,7 +78,7 @@ def test_cleanup_small_rotten(empty_dotsbws_datadir, caplog, 
parser):
 def test_cleanup_medium_stale(empty_dotsbws_datadir, caplog, parser):
 dotsbws = empty_dotsbws_datadir
 args = parser.parse_args(
-'-d {} --log-level DEBUG cleanup'.format(dotsbws.name).split())
+'-d {} 

[tor-commits] [sbws/master] config.log.ini no longer exists

2018-07-11 Thread pastly
commit dca6e408fd760b294b2402665e1ffa0eaf1c5122
Author: Matt Traudt 
Date:   Mon Jun 25 11:10:45 2018 -0400

config.log.ini no longer exists
---
 sbws/globals.py | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/sbws/globals.py b/sbws/globals.py
index 3ae7d60..a00cfb1 100644
--- a/sbws/globals.py
+++ b/sbws/globals.py
@@ -35,8 +35,7 @@ def is_initted(d):
 if not os.path.isdir(d):
 log.debug('%s not initialized: %s doesn\'t exist', d, d)
 return False
-conf_fnames = [os.path.join(d, 'config.ini'),
-   os.path.join(d, 'config.log.ini')]
+conf_fnames = [os.path.join(d, 'config.ini')]
 for fname in conf_fnames:
 if not os.path.isfile(fname):
 log.debug('%s not initialized: missing %s', d, fname)



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


[tor-commits] [sbws/master] Replace ns by desc in log message

2018-07-11 Thread pastly
commit e6fb529cbd79c56b5b6f457ed3779991b0af2cc7
Author: juga0 
Date:   Wed Jul 4 08:02:46 2018 +

Replace ns by desc in log message
---
 sbws/lib/relaylist.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sbws/lib/relaylist.py b/sbws/lib/relaylist.py
index e623ab7..d0c903c 100644
--- a/sbws/lib/relaylist.py
+++ b/sbws/lib/relaylist.py
@@ -40,7 +40,7 @@ class Relay:
 try:
 self._desc = cont.get_server_descriptor(fp, default=None)
 except Exception as e:
-log.exception("Exception trying to get ns %s", e)
+log.exception("Exception trying to get desc %s", e)
 
 def _from_desc(self, attr):
 if not self._desc:



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


[tor-commits] [sbws/master] Change capitalization of --log-level values

2018-07-11 Thread pastly
commit 9fea5c1c8d9c6b10aece0157dbac5dacef1665dc
Author: Matt Traudt 
Date:   Mon Jun 25 11:11:02 2018 -0400

Change capitalization of --log-level values
---
 sbws/util/parser.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sbws/util/parser.py b/sbws/util/parser.py
index bbc6a18..f2fc828 100644
--- a/sbws/util/parser.py
+++ b/sbws/util/parser.py
@@ -20,7 +20,7 @@ def create_parser():
 '--version', action='version', help='sbws version',
 version='{}'.format(__version__))
 p.add_argument('--log-level',
-   choices=['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'],
+   choices=['debug', 'info', 'warning', 'error', 'critical'],
help='Override the sbws log level')
 p.add_argument('-d', '--directory', default=_default_dot_sbws_dname(),
help='Name of the .sbws directory')



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


[tor-commits] [sbws/master] Replace Exception by the possible exceptions

2018-07-11 Thread pastly
commit e7c51a10daf6ab718e25075814b68bee975e2704
Author: juga0 
Date:   Wed Jul 4 08:15:58 2018 +

Replace Exception by the possible exceptions
---
 sbws/util/stem.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/sbws/util/stem.py b/sbws/util/stem.py
index c4497b1..0c36d61 100644
--- a/sbws/util/stem.py
+++ b/sbws/util/stem.py
@@ -1,6 +1,7 @@
 from stem.control import (Controller, Listener)
 from stem import (SocketError, InvalidRequest, UnsatisfiableRequest,
-  OperationFailed)
+  OperationFailed, ControllerError, InvalidArguments,
+  ProtocolError)
 from stem.connection import IncorrectSocketType
 import stem.process
 from configparser import ConfigParser
@@ -79,7 +80,7 @@ def init_controller(port=None, path=None, 
set_custom_stream_settings=True):
 def is_bootstrapped(c):
 try:
 line = c.get_info('status/bootstrap-phase')
-except Exception as e:
+except (ControllerError, InvalidArguments, ProtocolError) as e:
 log.exception("Error trying to check bootstrap phase %s", e)
 return False
 state, _, progress, *_ = line.split()



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


[tor-commits] [sbws/master] Add changelog entry about using median on empty lists

2018-07-11 Thread pastly
commit c0e6945045ab6f77d29982278e761695706ae200
Author: juga0 
Date:   Fri Jul 6 19:51:08 2018 +

Add changelog entry about using median on empty lists
---
 CHANGELOG.md | 1 +
 1 file changed, 1 insertion(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index fc2b07a..e7a18b9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -20,6 +20,7 @@ and this project adheres to [Semantic 
Versioning](http://semver.org/spec/v2.0.0.
 - Could not init sbws because of a catch-22 related to logging configuration.
   Overhaul how logging is configured. (GH#186 GHPR#224)
 - Call write method of V3BWFile class from the object instance. (#26671)
+- Stop calculating median on empty list .(#2)
 
 ### Changed
 



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


[tor-commits] [sbws/master] Replace Exception by the possible exceptions

2018-07-11 Thread pastly
commit 0bb09a896bb4fc7a2535cf08833388ea1444e3bb
Author: juga0 
Date:   Wed Jul 4 08:58:59 2018 +

Replace Exception by the possible exceptions
---
 sbws/util/stem.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sbws/util/stem.py b/sbws/util/stem.py
index 85fd7e6..32c9b8c 100644
--- a/sbws/util/stem.py
+++ b/sbws/util/stem.py
@@ -245,7 +245,7 @@ def circuit_str(controller, circ_id):
 log.warning('Circuit %s no longer seems to exist so can\'t return '
 'a valid circuit string for it: %s', circ_id, e)
 return None
-except Exception as e:
+except ControllerError as e:
 log.exception("Exception trying to get circuit string %s", e)
 return None
 return '[' +\



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


[tor-commits] [sbws/master] Stop calculating median on empty list

2018-07-11 Thread pastly
commit fd74a4c4832847b6d77fc0a87788316fa894ffbf
Author: juga0 
Date:   Fri Jul 6 19:49:37 2018 +

Stop calculating median on empty list
---
 sbws/lib/v3bwfile.py | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/sbws/lib/v3bwfile.py b/sbws/lib/v3bwfile.py
index 1d7ec61..c1dc890 100644
--- a/sbws/lib/v3bwfile.py
+++ b/sbws/lib/v3bwfile.py
@@ -320,13 +320,13 @@ class V3BWLine(object):
 # Note how this isn't some measured-by-us average of bandwidth. It's
 # the first value on the 'bandwidth' line in the relay's server
 # descriptor.
-relay_average_bw = median([
-r.relay_average_bandwidth for r in results
-if r.relay_average_bandwidth is not None])
-if median_bw > relay_average_bw:
-bw = relay_average_bw
-else:
-bw = median_bw
+bw = median_bw
+relay_average_bw = [r.relay_average_bandwidth for r in results
+if r.relay_average_bandwidth is not None]
+if relay_average_bw:
+median_relay_average_bw = median(relay_average_bw)
+if median_bw > median_relay_average_bw:
+bw = median_relay_average_bw
 # convert to KB and ensure it's at least 1
 bw_kb = max(round(bw / 1024), 1)
 return bw_kb



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


[tor-commits] [sbws/master] Replace Exception by the possible exceptions

2018-07-11 Thread pastly
commit a398aaffedaa4270aa16a4e25cbba71c910cb7fa
Author: juga0 
Date:   Wed Jul 4 08:04:14 2018 +

Replace Exception by the possible exceptions
---
 sbws/lib/relaylist.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sbws/lib/relaylist.py b/sbws/lib/relaylist.py
index d0c903c..f674b62 100644
--- a/sbws/lib/relaylist.py
+++ b/sbws/lib/relaylist.py
@@ -39,7 +39,7 @@ class Relay:
 else:
 try:
 self._desc = cont.get_server_descriptor(fp, default=None)
-except Exception as e:
+except (DescriptorUnavailable, ControllerError) as e:
 log.exception("Exception trying to get desc %s", e)
 
 def _from_desc(self, attr):



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


[tor-commits] [sbws/master] Replace Exception by the possible exceptions

2018-07-11 Thread pastly
commit 3ee931dbdb43386fec8274c311e33ca94d93293f
Author: juga0 
Date:   Wed Jul 4 08:01:56 2018 +

Replace Exception by the possible exceptions
---
 sbws/lib/relaylist.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sbws/lib/relaylist.py b/sbws/lib/relaylist.py
index bb59a3b..e623ab7 100644
--- a/sbws/lib/relaylist.py
+++ b/sbws/lib/relaylist.py
@@ -1,6 +1,6 @@
 from stem.descriptor.router_status_entry import RouterStatusEntryV3
 from stem.descriptor.server_descriptor import ServerDescriptor
-from stem import Flag
+from stem import Flag, DescriptorUnavailable, ControllerError
 from stem.util.connection import is_valid_ipv4_address
 from stem.util.connection import is_valid_ipv6_address
 import random
@@ -30,7 +30,7 @@ class Relay:
 else:
 try:
 self._ns = cont.get_network_status(fp, default=None)
-except Exception as e:
+except (DescriptorUnavailable, ControllerError) as e:
 log.exception("Exception trying to get ns %s", e)
 self._ns = None
 if desc is not None:



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


[tor-commits] [sbws/master] Replace Exception by the possible exception

2018-07-11 Thread pastly
commit 8ca26840f210438d5dc049007547fabfb054b0ff
Author: juga0 
Date:   Wed Jul 4 08:09:46 2018 +

Replace Exception by the possible exception
---
 sbws/util/stem.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/sbws/util/stem.py b/sbws/util/stem.py
index d52fea2..8d4989e 100644
--- a/sbws/util/stem.py
+++ b/sbws/util/stem.py
@@ -1,5 +1,6 @@
 from stem.control import (Controller, Listener)
-from stem import (SocketError, InvalidRequest, UnsatisfiableRequest)
+from stem import (SocketError, InvalidRequest, UnsatisfiableRequest,
+  OperationFailed)
 from stem.connection import IncorrectSocketType
 import stem.process
 from configparser import ConfigParser
@@ -27,7 +28,7 @@ def attach_stream_to_circuit_listener(controller, circ_id):
 except (UnsatisfiableRequest, InvalidRequest) as e:
 log.warning('Couldn\'t attach stream to circ %s: %s',
 circ_id, e)
-except Exception as e:
+except OperationFailed as e:
 log.exception("Error attaching stream %s to circ %s: %s",
   st.id, circ_id, e)
 else:



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


[tor-commits] [sbws/master] Replace Exception by the possible exceptions

2018-07-11 Thread pastly
commit d1aebaf48960fe7e85299213ff49fc02b71521ae
Author: juga0 
Date:   Wed Jul 4 08:54:53 2018 +

Replace Exception by the possible exceptions
---
 sbws/util/stem.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sbws/util/stem.py b/sbws/util/stem.py
index b62de82..bbd4e7a 100644
--- a/sbws/util/stem.py
+++ b/sbws/util/stem.py
@@ -47,7 +47,7 @@ def add_event_listener(controller, func, event):
 def remove_event_listener(controller, func):
 try:
 controller.remove_event_listener(func)
-except Exception as e:
+except ProtocolError as e:
 log.exception("Exception trying to remove event %s", e)
 
 



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


[tor-commits] [sbws/master] Replace log message, unify with previous log

2018-07-11 Thread pastly
commit db7ebb39df4bc34341eea870a27704c87a75db70
Author: juga0 
Date:   Wed Jul 4 08:24:26 2018 +

Replace log message, unify with previous log
---
 sbws/util/stem.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/sbws/util/stem.py b/sbws/util/stem.py
index 255ce22..b4190ef 100644
--- a/sbws/util/stem.py
+++ b/sbws/util/stem.py
@@ -196,7 +196,9 @@ def launch_tor(conf):
 cont.set_conf('__DisablePredictedCircuits', '1')
 cont.set_conf('__LeaveStreamsUnattached', '1')
 except Exception as e:
-log.exception("Exception trying to launch tor %s", e)
+log.exception("Error trying to launch tor: %s. "
+  "Maybe the tor directory is being used by other "
+  "sbws instance?", e)
 exit(1)
 log.info('Started and connected to Tor %s via %s', cont.get_version(),
  conf['tor']['control_socket'])



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


[tor-commits] [sbws/master] Replace Exception by the possible exceptions

2018-07-11 Thread pastly
commit 4776f2e3c1d2929ce61110c6a6d10d73c827c6fa
Author: juga0 
Date:   Wed Jul 4 08:42:22 2018 +

Replace Exception by the possible exceptions
---
 sbws/lib/circuitbuilder.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sbws/lib/circuitbuilder.py b/sbws/lib/circuitbuilder.py
index faa73cf..caca3eb 100644
--- a/sbws/lib/circuitbuilder.py
+++ b/sbws/lib/circuitbuilder.py
@@ -61,7 +61,7 @@ class CircuitBuilder:
 c.get_circuit(circ_id, default=None)
 try:
 c.close_circuit(circ_id)
-except InvalidArguments:
+except (InvalidArguments, InvalidRequest):
 pass
 self.built_circuits.discard(circ_id)
 except (ControllerError, ValueError) as e:



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


[tor-commits] [sbws/master] Remove not needed exception

2018-07-11 Thread pastly
commit 6064cbae49f7995971a176ad01be75a819973781
Author: juga0 
Date:   Wed Jul 4 08:48:26 2018 +

Remove not needed exception
---
 sbws/lib/circuitbuilder.py | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/sbws/lib/circuitbuilder.py b/sbws/lib/circuitbuilder.py
index caca3eb..c2c9b97 100644
--- a/sbws/lib/circuitbuilder.py
+++ b/sbws/lib/circuitbuilder.py
@@ -82,9 +82,6 @@ class CircuitBuilder:
 ProtocolError, Timeout) as e:
 log.warning(e)
 continue
-except Exception as e:
-log.exception("Exception trying to build circuit: %s.", e)
-continue
 else:
 return circ_id
 return None



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


[tor-commits] [sbws/master] Remove docstring about removed get_circuit_path

2018-07-11 Thread pastly
commit 46b64f7283867572e08fa55df64faf4b06d81047
Author: juga0 
Date:   Wed Jul 4 08:28:48 2018 +

Remove docstring about removed get_circuit_path
---
 sbws/lib/circuitbuilder.py | 1 -
 1 file changed, 1 deletion(-)

diff --git a/sbws/lib/circuitbuilder.py b/sbws/lib/circuitbuilder.py
index b806a9d..f143b6a 100644
--- a/sbws/lib/circuitbuilder.py
+++ b/sbws/lib/circuitbuilder.py
@@ -27,7 +27,6 @@ class CircuitBuilder:
 ''' The CircuitBuilder interface.
 
 Subclasses must implement their own build_circuit() function.
-Subclasses probably shouldn't implement their own get_circuit_path().
 Subclasses may keep additional state if they'd find it helpful.
 
 The primary way to use a CircuitBuilder of any type is to simply create it



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


[tor-commits] [sbws/master] Replace log message by which stream/circuit failed

2018-07-11 Thread pastly
commit e5dca77d1c788cb97bf4beb4273be93b60481d81
Author: juga0 
Date:   Wed Jul 4 08:08:36 2018 +

Replace log message by which stream/circuit failed
---
 sbws/util/stem.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/sbws/util/stem.py b/sbws/util/stem.py
index 7224c10..d52fea2 100644
--- a/sbws/util/stem.py
+++ b/sbws/util/stem.py
@@ -28,7 +28,8 @@ def attach_stream_to_circuit_listener(controller, circ_id):
 log.warning('Couldn\'t attach stream to circ %s: %s',
 circ_id, e)
 except Exception as e:
-log.exception("Exception trying to get ns %s", e)
+log.exception("Error attaching stream %s to circ %s: %s",
+  st.id, circ_id, e)
 else:
 pass
 return closure_stream_event_listener



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


[tor-commits] [sbws/master] Move the exception where it actually would happen

2018-07-11 Thread pastly
commit 03ba568621bcce04a4dce8156a9d26cf5090c654
Author: juga0 
Date:   Wed Jul 4 08:23:43 2018 +

Move the exception where it actually would happen
---
 sbws/util/stem.py | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/sbws/util/stem.py b/sbws/util/stem.py
index 0c36d61..255ce22 100644
--- a/sbws/util/stem.py
+++ b/sbws/util/stem.py
@@ -192,14 +192,15 @@ def launch_tor(conf):
 # And return a controller to it
 cont = _init_controller_socket(conf['tor']['control_socket'])
 # Because we build things by hand and can't set these before Tor bootstraps
-cont.set_conf('__DisablePredictedCircuits', '1')
-cont.set_conf('__LeaveStreamsUnattached', '1')
 try:
-log.info('Started and connected to Tor %s via %s', cont.get_version(),
- conf['tor']['control_socket'])
-return cont
+cont.set_conf('__DisablePredictedCircuits', '1')
+cont.set_conf('__LeaveStreamsUnattached', '1')
 except Exception as e:
 log.exception("Exception trying to launch tor %s", e)
+exit(1)
+log.info('Started and connected to Tor %s via %s', cont.get_version(),
+ conf['tor']['control_socket'])
+return cont
 
 
 def get_socks_info(controller):



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


[tor-commits] [sbws/master] Remove unused method get_circuit_path

2018-07-11 Thread pastly
commit 3b92990816c9d8613488b3680dc5a5977555fc94
Author: juga0 
Date:   Wed Jul 4 07:53:46 2018 +

Remove unused method get_circuit_path
---
 sbws/lib/circuitbuilder.py | 10 --
 1 file changed, 10 deletions(-)

diff --git a/sbws/lib/circuitbuilder.py b/sbws/lib/circuitbuilder.py
index b8d4db7..b806a9d 100644
--- a/sbws/lib/circuitbuilder.py
+++ b/sbws/lib/circuitbuilder.py
@@ -56,16 +56,6 @@ class CircuitBuilder:
 its (str) ID. If it cannot be built, it should return None. '''
 raise NotImplementedError()
 
-def get_circuit_path(self, circ_id):
-c = self.controller
-try:
-circ = c.get_circuit(circ_id, default=None)
-except Exception as e:
-log.exception("Exception trying to get circuit: %s.", e)
-else:
-return [relay[0] for relay in circ.path]
-return None
-
 def close_circuit(self, circ_id):
 c = self.controller
 try:



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


[tor-commits] [sbws/master] Move back write function to V3BWFile

2018-07-11 Thread pastly
commit 666b9d7f57f2080146c9ee14aa8ee59e9228849b
Author: juga0 
Date:   Mon Jun 25 15:52:16 2018 +

Move back write function to V3BWFile

but not allowing /dev/stdout
---
 sbws/core/generate.py | 28 +---
 sbws/lib/v3bwfile.py  | 23 ++-
 2 files changed, 23 insertions(+), 28 deletions(-)

diff --git a/sbws/core/generate.py b/sbws/core/generate.py
index 827058e..6492423 100644
--- a/sbws/core/generate.py
+++ b/sbws/core/generate.py
@@ -4,7 +4,6 @@ from sbws.lib.resultdump import load_recent_results_in_datadir
 from argparse import ArgumentDefaultsHelpFormatter
 import os
 import logging
-from sbws.util.filelock import DirectoryLock
 from sbws.util.timestamp import now_fname
 
 log = logging.getLogger(__name__)
@@ -33,31 +32,6 @@ def gen_parser(sub):
'out, and we do so proportionally')
 
 
-def _write_v3bw_file(v3bwfile, output):
-log.info('Writing v3bw file to %s', output)
-out_dir = os.path.dirname(output)
-out_link = os.path.join(out_dir, 'latest.v3bw')
-if os.path.exists(out_link):
-log.debug('Deleting existing symlink before creating a new one.')
-os.remove(out_link)
-# to keep test_generate.py working
-if output != '/dev/stdout':
-with DirectoryLock(out_dir):
-with open(output, 'wt') as fd:
-fd.write(str(v3bwfile.header))
-for line in v3bwfile.bw_lines:
-fd.write(str(line))
-output_basename = os.path.basename(output)
-log.debug('Creating symlink from {} to {}.'
-  .format(output_basename, out_link))
-os.symlink(output_basename, out_link)
-else:
-with open(output, 'wt') as fd:
-fd.write(str(v3bwfile.header))
-for line in v3bwfile.bw_lines:
-fd.write(str(line))
-
-
 def main(args, conf):
 if not is_initted(args.directory):
 fail_hard('Sbws isn\'t initialized.  Try sbws init')
@@ -83,5 +57,5 @@ def main(args, conf):
 return
 bw_file = V3BWFile.from_arg_results(args, conf, results)
 output = args.output or conf['paths']['v3bw_fname'].format(now_fname())
-_write_v3bw_file(bw_file, output)
+V3BWFile.write(output)
 log.info('Mean bandwidth per line: %f "KiB"', bw_file.avg_bw)
diff --git a/sbws/lib/v3bwfile.py b/sbws/lib/v3bwfile.py
index 64395ef..fb9e3d3 100644
--- a/sbws/lib/v3bwfile.py
+++ b/sbws/lib/v3bwfile.py
@@ -3,12 +3,13 @@
 (v3bw) used by bandwidth authorities."""
 
 import logging
+import os
 from statistics import median
 
 from sbws import __version__
 from sbws.globals import SPEC_VERSION, BW_LINE_SIZE
 from sbws.lib.resultdump import ResultSuccess, _ResultType
-from sbws.util.filelock import FileLock
+from sbws.util.filelock import FileLock, DirectoryLock
 from sbws.util.timestamp import now_isodt_str, unixts_to_isodt_str
 
 log = logging.getLogger(__name__)
@@ -405,3 +406,23 @@ class V3BWFile(object):
 header = V3BWHeader.from_results(conf, results)
 f = cls(header, bw_lines)
 return f
+
+def write(self, output):
+if output == '/dev/stdout':
+log.info("Writing to stdout is not supported.")
+return
+log.info('Writing v3bw file to %s', output)
+out_dir = os.path.dirname(output)
+out_link = os.path.join(out_dir, 'latest.v3bw')
+if os.path.exists(out_link):
+log.debug('Deleting existing symlink before creating a new one.')
+os.remove(out_link)
+with DirectoryLock(out_dir):
+with open(output, 'wt') as fd:
+fd.write(str(self.header))
+for line in self.bw_lines:
+fd.write(str(line))
+output_basename = os.path.basename(output)
+log.debug('Creating symlink from {} to {}.'
+  .format(output_basename, out_link))
+os.symlink(output_basename, out_link)



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


[tor-commits] [sbws/master] Logging config overhaul ...

2018-07-11 Thread pastly
commit 7db1887f1c33e8202a796d2ca38c5242bcd27b9d
Author: Matt Traudt 
Date:   Mon Jun 25 11:18:43 2018 -0400

Logging config overhaul ...

User should configure logging via the [logging] section
in their config.ini.

User can change the log level using --log-level, or in the config
with level, to_file_level, and to_stdout_level.

User can change the log format in the config with format,
to_file_format, and to_stdout_format

An example debugging format is included as a comment in config.default.ini

config.log.default.ini is majorly reorganized. For the most part, if
something doesn't need to be specified in this file, it has been removed.
For example, we don't have to specify any args to handler_to_file. The
beginnings of syslog configuration stuff remain as comments.

As part of configure_logging, force logging to stdout if we don't think
we can log to file.

Actually set some parameters to RotatingFileHandler so it rotates when
files reach 10 MiB and keeps 100 backups.

Each sbws command (like scanner and generate) gets its own log file. I
did this because I didn't want 'sbws scanner' to be running 24/7 and an
'sbws generate' call to log to the same file. That would get confusing.
---
 sbws/config.default.ini | 10 +--
 sbws/config.log.default.ini | 65 +
 sbws/sbws.py|  2 +-
 sbws/util/config.py | 70 -
 4 files changed, 98 insertions(+), 49 deletions(-)

diff --git a/sbws/config.default.ini b/sbws/config.default.ini
index 10a2fb3..3e49052 100644
--- a/sbws/config.default.ini
+++ b/sbws/config.default.ini
@@ -84,11 +84,17 @@ fraction_relays = 0.05
 min_relays = 50
 
 [logging]
-# Level to log at. Debug, info, warning, error.
-level = debug
 # Whether or not to log to a rotating file the directory paths.log_dname
 to_file = yes
 # Whether or not to log to stdout
 to_stdout = no
+# Level to log at. Debug, info, warning, error, critical.
+level = info
+to_file_level = ${level}
+to_stdout_level = ${level}
 # Format string to use when logging
 format = [%(asctime)s] [%(name)s] [%(levelname)s] %(message)s
+to_file_format = ${format}
+to_stdout_format = ${format}
+# verbose formatter useful for debugging
+#format = %(asctime)s %(levelname)s %(threadName)s %(filename)s:%(lineno)s - 
%(funcName)s - %(message)s
diff --git a/sbws/config.log.default.ini b/sbws/config.log.default.ini
index 4bae7aa..606ff16 100644
--- a/sbws/config.log.default.ini
+++ b/sbws/config.log.default.ini
@@ -2,62 +2,49 @@
 keys = root,sbws
 
 [handlers]
-keys = sbwsdefault,sbwsdebug,sbwsfile
+keys = to_file,to_stdout
 
 [formatters]
-keys = sbwsdefault,sbwsdebug,sbwssys
+keys = to_file,to_stdout
 
 [logger_root]
 level = WARNING
-handlers = sbwsdefault
+handlers = to_file
 propagate = 1
 qualname=root
 
 [logger_sbws]
-level = INFO
-# add here sbwssys for also logging to system log
-handlers = sbwsdefault,sbwsfile
 propagate = 0
 qualname=sbws
 
-[handler_sbwsdefault]
+[handler_to_stdout]
 class = StreamHandler
-formatter = sbwsdefault
+formatter = to_stdout
 args = (sys.stdout,)
 
-[formatter_sbwsdefault]
-format =  [%(asctime)s] [%(name)s] [%(levelname)s] %(message)s
-
-# this is not needed, but here to do not modify sbwsdefault
-[handler_sbwsdebug]
-class = StreamHandler
-formatter = sbwsdebug
-args = (sys.stdout,)
-level = DEBUG
-
-# verbose formatter useful for debugging
-[formatter_sbwsdebug]
-format = %(asctime)s %(levelname)s %(threadName)s %(filename)s:%(lineno)s - 
%(funcName)s - %(message)s
-datefmt = %Y-%m-%d %H:%M:%S
-
-# for logging to system log
-[handler_sbwssys]
-class=handlers.SysLogHandler
-formatter=sbwssys
-level = INFO
-
-# syslog-like formater
-[formatter_sbwssys]
-# hostname should be added here with a context filter, dunno if there is a way
-# to add it here
-format = %(asctime)s %(module)s[%(process)s]: <%(levelname)s> %(message)s
-datefmt = %b %d %H:%M:%S
-
-[handler_sbwsfile]
+[handler_to_file]
 class = handlers.RotatingFileHandler
-formatter = sbwssys
+formatter = to_file
 # There doesn't seem to be a way to put ${paths:log_filepath} here since the
 # logging library eval()s this, which doesn't give the ini parsing library a
 # chance to replace the text. So we do it in configure_logging() in
 # sbws/util/config.py instead.
-args = ('/nonexist',)
+args =
+
+## for logging to system log
+#[handler_to_syslog]
+#class=handlers.SysLogHandler
+#formatter=to_syslog
+#level = INFO
+#args = ()
+
+[formatter_to_stdout]
+
+[formatter_to_file]
+
+## syslog-like formater
+#[formatter_to_syslog]
+## hostname should be added here with a context filter, dunno if there is a way
+## to add it here
+#format = %(asctime)s %(module)s[%(process)s]: <%(levelname)s> %(message)s
+#datefmt = %b %d %H:%M:%S
diff --git a/sbws/sbws.py b/sbws/sbws.py
index 584ce02..5688cea 100644
--- a/sbws/sbws.py
+++ b/sbws/sbws.py
@@ 

[tor-commits] [sbws/master] Add funcs for validating enums

2018-07-11 Thread pastly
commit 11fac0c6581158586f26e94a1ac2dfe6e4ca140d
Author: Matt Traudt 
Date:   Mon Jun 25 09:57:49 2018 -0400

Add funcs for validating enums
---
 sbws/util/config.py | 21 +
 1 file changed, 21 insertions(+)

diff --git a/sbws/util/config.py b/sbws/util/config.py
index faedbd5..0bfa072 100644
--- a/sbws/util/config.py
+++ b/sbws/util/config.py
@@ -368,6 +368,27 @@ def _validate_section_urls(conf, sec, urls, tmpl):
 return errors
 
 
+def _validate_section_enums(conf, sec, enums, tmpl):
+errors = []
+section = conf[sec]
+for key in enums:
+choices = enums[key]['choices']
+valid, error = _validate_enum(section, key, choices)
+if not valid:
+errors.append(tmpl.substitute(
+sec=sec, key=key, val=section[key],
+e='Not a valid enum choice ({})'.format(', '.join(choices
+return errors
+
+
+def _validate_enum(section, key, choices):
+value = section[key]
+if value not in choices:
+return False, '{} not in allowed choices: {}'.format(
+value, ', '.join(choices))
+return True, ''
+
+
 def _validate_url(section, key):
 value = section[key]
 if not value.startswith(('http://', 'https://')):



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


[tor-commits] [sbws/master] Create generator_started line only when it is known

2018-07-11 Thread pastly
commit de0a46cbf1dba509d68a429f51ac7763d4658bbc
Author: juga0 
Date:   Mon Jun 25 16:13:25 2018 +

Create generator_started line only when it is known
---
 sbws/lib/v3bwfile.py | 7 ---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/sbws/lib/v3bwfile.py b/sbws/lib/v3bwfile.py
index fb9e3d3..1d7ec61 100644
--- a/sbws/lib/v3bwfile.py
+++ b/sbws/lib/v3bwfile.py
@@ -76,14 +76,14 @@ def read_started_ts(conf):
 try:
 filepath = conf['paths']['started_filepath']
 except TypeError:
-return ''
+return None
 try:
 with FileLock(filepath):
 with open(filepath, 'r') as fd:
 generator_started = fd.read()
 except FileNotFoundError as e:
 log.warn('File %s not found.%s', filepath, e)
-return ''
+return None
 return generator_started
 
 
@@ -229,7 +229,8 @@ class V3BWHeader(object):
 timestamp = str(latest_bandwidth)
 kwargs['latest_bandwidth'] = unixts_to_isodt_str(latest_bandwidth)
 kwargs['earliest_bandwidth'] = unixts_to_isodt_str(earliest_bandwidth)
-kwargs['generator_started'] = generator_started
+if generator_started is not None:
+kwargs['generator_started'] = generator_started
 h = cls(timestamp, **kwargs)
 return h
 



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


[tor-commits] [sbws/master] Add unit tests for writing v3bw file

2018-07-11 Thread pastly
commit 6912a1fb2aa42cdd221b189fb0c1bf8e44043630
Author: juga0 
Date:   Mon Jun 25 16:12:29 2018 +

Add unit tests for writing v3bw file
---
 tests/unit/lib/test_v3bwfile.py | 24 
 1 file changed, 24 insertions(+)

diff --git a/tests/unit/lib/test_v3bwfile.py b/tests/unit/lib/test_v3bwfile.py
index bfe9d9b..bede4ff 100644
--- a/tests/unit/lib/test_v3bwfile.py
+++ b/tests/unit/lib/test_v3bwfile.py
@@ -1,6 +1,7 @@
 # -*- coding: utf-8 -*-
 """Test generation of bandwidth measurements document (v3bw)"""
 import json
+import os.path
 
 from sbws import __version__ as version
 from sbws.globals import SPEC_VERSION, RESULT_VERSION
@@ -8,6 +9,7 @@ from sbws.lib.resultdump import Result, load_result_file
 from sbws.lib.v3bwfile import (V3BWHeader, V3BWLine, TERMINATOR, LINE_SEP,
KEYVALUE_SEP_V110, num_results_of_type,
V3BWFile)
+from sbws.util.timestamp import now_fname
 
 timestamp = 1523974147
 timestamp_l = str(timestamp)
@@ -168,3 +170,25 @@ def test_v3bwfile(datadir, tmpdir):
 bwls = [V3BWLine.from_results(results[fp]) for fp in results]
 f = V3BWFile(header, bwls)
 assert v3bw == str(f)
+
+
+def test_from_arg_results(datadir, tmpdir, unittest_conf, unittest_args):
+results = load_result_file(str(datadir.join("results.txt")))
+expected_header = V3BWHeader(timestamp_l,
+ earliest_bandwidth=earliest_bandwidth,
+ latest_bandwidth=latest_bandwidth)
+expected_bwls = [V3BWLine.from_results(results[fp]) for fp in results]
+expected_f = V3BWFile(expected_header, expected_bwls)
+v3bwfile = V3BWFile.from_arg_results(unittest_args, unittest_conf, results)
+assert str(expected_f)[1:] == str(v3bwfile)[1:]
+output = os.path.join(unittest_args.output, now_fname())
+print(output)
+v3bwfile.write(output)
+
+
+def test_from_arg_results_write(datadir, tmpdir, unittest_conf, unittest_args):
+results = load_result_file(str(datadir.join("results.txt")))
+v3bwfile = V3BWFile.from_arg_results(unittest_args, unittest_conf, results)
+output = os.path.join(unittest_args.output, now_fname())
+v3bwfile.write(output)
+assert os.path.isfile(output)



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


[tor-commits] [sbws/master] Add fixtures for unit tests

2018-07-11 Thread pastly
commit 89ed8ace6ef2d6e3d0dd68ee5d671fcdf96005fd
Author: juga0 
Date:   Mon Jun 25 16:09:41 2018 +

Add fixtures for unit tests
---
 tests/unit/conftest.py | 35 ++-
 1 file changed, 34 insertions(+), 1 deletion(-)

diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py
index c9002eb..002987c 100644
--- a/tests/unit/conftest.py
+++ b/tests/unit/conftest.py
@@ -2,7 +2,7 @@ from sbws.lib.resultdump import ResultError
 from sbws.lib.resultdump import ResultSuccess
 from sbws.lib.resultdump import Result
 from sbws.lib.resultdump import write_result_to_datadir
-from sbws.util.config import get_config
+from sbws.util.config import get_config, _get_default_config
 from sbws.util.parser import create_parser
 import sbws.core.init
 from tempfile import TemporaryDirectory
@@ -50,6 +50,39 @@ def datadir(request):
 return D(request.fspath.dirpath("data"))
 
 
+@pytest.fixture
+def tmpdir(tmpdir_factory, request):
+"""Create a tmp dir for the tests"""
+base = str(hash(request.node.nodeid))[:3]
+bn = tmpdir_factory.mktemp(base)
+return bn
+
+
+@pytest.fixture
+def tmpdir_sbwshome(tmpdir):
+"""Create .sbws inside of the tests tmp dir"""
+home = tmpdir.join('.sbws')
+os.makedirs(home.strpath, exist_ok=True)
+return home
+
+
+@pytest.fixture()
+def unittest_args(tmpdir_sbwshome, parser):
+"""Args with sbws home in the tests tmp dir"""
+return _PseudoArguments(directory=tmpdir_sbwshome.strpath,
+output=tmpdir_sbwshome.strpath,
+scale=False)
+
+
+@pytest.fixture()
+def unittest_conf(tmpdir_sbwshome):
+"""Default configuration with sbws home in the tmp test dir"""
+conf = _get_default_config()
+conf['paths']['sbwshome'] = tmpdir_sbwshome.strpath
+conf['paths']['started_filepath'] = ""
+return conf
+
+
 @pytest.fixture(scope='session')
 def parser():
 return create_parser()



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


[tor-commits] [sbws/master] Add [logging] section to config and validate it

2018-07-11 Thread pastly
commit f3a487bd8fd950fb2f9e41d1a944bc87aca49e44
Author: Matt Traudt 
Date:   Mon Jun 25 09:58:30 2018 -0400

Add [logging] section to config and validate it
---
 sbws/config.default.ini | 11 +++
 sbws/util/config.py | 22 +-
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/sbws/config.default.ini b/sbws/config.default.ini
index 80ddc8b..10a2fb3 100644
--- a/sbws/config.default.ini
+++ b/sbws/config.default.ini
@@ -4,6 +4,7 @@ v3bw_dname = ${sbws_home}/v3bw
 v3bw_fname = ${v3bw_dname}/{}.v3bw
 started_filepath = ${sbws_home}/started_at
 log_filepath = ${sbws_home}/sbws.log
+log_dname = ${sbws_home}/log
 
 [destinations]
 # How often to check if a destional is usable
@@ -81,3 +82,13 @@ measure_authorities = off
 fraction_relays = 0.05
 # The minimum number of best priority relays we are willing to return
 min_relays = 50
+
+[logging]
+# Level to log at. Debug, info, warning, error.
+level = debug
+# Whether or not to log to a rotating file the directory paths.log_dname
+to_file = yes
+# Whether or not to log to stdout
+to_stdout = no
+# Format string to use when logging
+format = [%(asctime)s] [%(name)s] [%(levelname)s] %(message)s
diff --git a/sbws/util/config.py b/sbws/util/config.py
index 0bfa072..c24ac23 100644
--- a/sbws/util/config.py
+++ b/sbws/util/config.py
@@ -109,6 +109,7 @@ def validate_config(conf):
 errors.extend(_validate_paths(conf))
 errors.extend(_validate_destinations(conf))
 errors.extend(_validate_relayprioritizer(conf))
+errors.extend(_validate_logging(conf))
 return len(errors) < 1, errors
 
 
@@ -156,7 +157,7 @@ def _validate_paths(conf):
 err_tmpl = Template('$sec/$key ($val): $e')
 unvalidated_keys = [
 'datadir', 'sbws_home', 'v3bw_fname', 'v3bw_dname',
-'started_filepath', 'log_filepath']
+'started_filepath', 'log_filepath', 'log_dname']
 all_valid_keys = unvalidated_keys
 allow_missing = ['sbws_home']
 errors.extend(_validate_section_keys(conf, sec, all_valid_keys, err_tmpl,
@@ -227,6 +228,25 @@ def _validate_relayprioritizer(conf):
 return errors
 
 
+def _validate_logging(conf):
+errors = []
+sec = 'logging'
+err_tmpl = Template('$sec/$key ($val): $e')
+enums = {
+'level': {'choices': ['debug', 'info', 'warning', 'error']},
+}
+bools = {
+'to_file': {},
+'to_stdout': {},
+}
+unvalidated = ['format']
+all_valid_keys = list(bools.keys()) + list(enums.keys()) + unvalidated
+errors.extend(_validate_section_keys(conf, sec, all_valid_keys, err_tmpl))
+errors.extend(_validate_section_bools(conf, sec, bools, err_tmpl))
+errors.extend(_validate_section_enums(conf, sec, enums, err_tmpl))
+return errors
+
+
 def _validate_destinations(conf):
 errors = []
 sec = 'destinations'



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


[tor-commits] [sbws/master] Log exception and exit when launching tor fails

2018-07-11 Thread pastly
commit 2fce34d0adc0bd3704f35339f6b75d8171920b45
Author: juga0 
Date:   Tue Jul 3 08:56:50 2018 +

Log exception and exit when launching tor fails
---
 sbws/util/stem.py | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/sbws/util/stem.py b/sbws/util/stem.py
index 54779fd..7224c10 100644
--- a/sbws/util/stem.py
+++ b/sbws/util/stem.py
@@ -181,8 +181,11 @@ def launch_tor(conf):
 existing_val.append(value)
 torrc.update({key: existing_val})
 # Finally launch Tor
-stem.process.launch_tor_with_config(
-torrc, init_msg_handler=log.debug, take_ownership=True)
+try:
+stem.process.launch_tor_with_config(
+torrc, init_msg_handler=log.debug, take_ownership=True)
+except Exception as e:
+fail_hard('Error trying to launch tor: %s', e)
 # And return a controller to it
 cont = _init_controller_socket(conf['tor']['control_socket'])
 # Because we build things by hand and can't set these before Tor bootstraps



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


[tor-commits] [sbws/master] Remove is_controller_ok and log exceptions

2018-07-11 Thread pastly
commit b5d3fb4fc8d1d2edb9c48a7a6d9996f7b37912b9
Author: juga0 
Date:   Tue Jul 3 08:26:40 2018 +

Remove is_controller_ok and log exceptions
---
 sbws/core/scanner.py|  1 -
 sbws/lib/circuitbuilder.py  | 32 -
 sbws/lib/relaylist.py   | 21 +-
 sbws/util/stem.py   | 57 +
 tests/integration/util/test_stem.py |  1 -
 5 files changed, 66 insertions(+), 46 deletions(-)

diff --git a/sbws/core/scanner.py b/sbws/core/scanner.py
index 249d8d4..5bcf276 100644
--- a/sbws/core/scanner.py
+++ b/sbws/core/scanner.py
@@ -347,7 +347,6 @@ def run_speedtest(args, conf):
 'exists for sbws developers. It is expected to be broken and may '
 'even lead to messed up results.', conf['tor']['control_socket'])
 time.sleep(15)
-assert stem_utils.is_controller_okay(controller)
 rl = RelayList(args, conf, controller)
 cb = CB(args, conf, controller, rl)
 rd = ResultDump(args, conf, end_event)
diff --git a/sbws/lib/circuitbuilder.py b/sbws/lib/circuitbuilder.py
index d55b929..b8d4db7 100644
--- a/sbws/lib/circuitbuilder.py
+++ b/sbws/lib/circuitbuilder.py
@@ -1,7 +1,6 @@
 from stem import CircuitExtensionFailed, InvalidRequest, ProtocolError, Timeout
 from stem import InvalidArguments
 import random
-import sbws.util.stem as stem_utils
 from .relaylist import Relay
 import logging
 
@@ -59,28 +58,30 @@ class CircuitBuilder:
 
 def get_circuit_path(self, circ_id):
 c = self.controller
-assert stem_utils.is_controller_okay(c)
-circ = c.get_circuit(circ_id, default=None)
-if circ is None:
-return None
-return [relay[0] for relay in circ.path]
+try:
+circ = c.get_circuit(circ_id, default=None)
+except Exception as e:
+log.exception("Exception trying to get circuit: %s.", e)
+else:
+return [relay[0] for relay in circ.path]
+return None
 
 def close_circuit(self, circ_id):
 c = self.controller
-if not stem_utils.is_controller_okay(c):
-return
-if c.get_circuit(circ_id, default=None):
+try:
+c.get_circuit(circ_id, default=None)
 try:
 c.close_circuit(circ_id)
 except InvalidArguments:
 pass
 self.built_circuits.discard(circ_id)
+except Exception as e:
+log.exception("Error trying to get circuit to close it: %s.", e)
 
 def _build_circuit_impl(self, path):
 if not valid_circuit_length(path):
 raise PathLengthException()
 c = self.controller
-assert stem_utils.is_controller_okay(c)
 timeout = self.circuit_timeout
 fp_path = '[' + ' -> '.join([p[0:8] for p in path]) + ']'
 log.debug('Building %s', fp_path)
@@ -92,6 +93,9 @@ class CircuitBuilder:
 ProtocolError, Timeout) as e:
 log.warning(e)
 continue
+except Exception as e:
+log.exception("Exception trying to build circuit: %s.", e)
+continue
 else:
 return circ_id
 return None
@@ -100,14 +104,16 @@ class CircuitBuilder:
 c = self.controller
 if not self.close_circuits_on_exit:
 return
-if not stem_utils.is_controller_okay(c):
-return
 for circ_id in self.built_circuits:
-if c.get_circuit(circ_id, default=None):
+try:
+c.get_circuit(circ_id, default=None)
 try:
 c.close_circuit(circ_id)
 except InvalidArguments:
 pass
+except Exception as e:
+log.exception("Exception trying to get circuit to delete: %s",
+  e)
 self.built_circuits.clear()
 
 
diff --git a/sbws/lib/relaylist.py b/sbws/lib/relaylist.py
index 11390de..bafd7b7 100644
--- a/sbws/lib/relaylist.py
+++ b/sbws/lib/relaylist.py
@@ -1,6 +1,5 @@
 from stem.descriptor.router_status_entry import RouterStatusEntryV3
 from stem.descriptor.server_descriptor import ServerDescriptor
-import sbws.util.stem as stem_utils
 from stem import Flag
 from stem.util.connection import is_valid_ipv4_address
 from stem.util.connection import is_valid_ipv6_address
@@ -25,17 +24,22 @@ class Relay:
 '''
 assert isinstance(fp, str)
 assert len(fp) == 40
-assert stem_utils.is_controller_okay(cont)
 if ns is not None:
 assert isinstance(ns, RouterStatusEntryV3)
 self._ns = ns
 else:
-self._ns = cont.get_network_status(fp, default=None)
+try:
+self._ns = cont.get_network_status(fp, default=None)
+except Exception as e:
+log.exception("Exception trying to get ns %s", 

[tor-commits] [sbws/master] Add changelog for is_controller_ok changes

2018-07-11 Thread pastly
commit bfea21d8e5aeffc0157bea667026bdc9d96dff35
Author: juga0 
Date:   Tue Jul 3 08:56:08 2018 +

Add changelog for is_controller_ok changes
---
 CHANGELOG.md | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index a8acfb9..360d76a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -64,6 +64,8 @@ generated ones are kept. A `latest.v3bw` symlink is updated. 
(GH#179 GHPR#190)
 - Code refactoring in the v3bw classes and generation area
 - Replace v3bw-into-xy bash script with python script to handle a more complex
   v3bw file format (GH#182)
+- Remove is_controller_ok. Instead catch possible controller exceptions and 
+ log them
 
 ## [0.4.1] - 2018-06-14
 



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


[tor-commits] [sbws/master] Add test that calls sbws init

2018-07-11 Thread pastly
commit 43856fdbe3d242396b3c9f6533bd20b9d1c5ec27
Author: Matt Traudt 
Date:   Wed Jul 4 12:33:13 2018 -0400

Add test that calls sbws init
---
 tests/integration/test_sbws.py | 22 ++
 1 file changed, 22 insertions(+)

diff --git a/tests/integration/test_sbws.py b/tests/integration/test_sbws.py
new file mode 100644
index 000..5122f38
--- /dev/null
+++ b/tests/integration/test_sbws.py
@@ -0,0 +1,22 @@
+from tempfile import TemporaryFile
+import subprocess
+import os
+
+
+def test_simple_init(tmpdir):
+# out = None
+err = None
+with TemporaryFile('w+t') as stdout, TemporaryFile('w+t') as stderr:
+retcode = subprocess.call(
+'sbws -d {} --log-level debug init'.format(tmpdir).split(),
+stdout=stdout, stderr=stderr)
+stdout.seek(0, 0)
+stderr.seek(0, 0)
+# out = stdout.read()
+err = stderr.read()
+assert retcode == 0
+assert len(err) == 0
+conf_fname = os.path.join(str(tmpdir), 'config.ini')
+assert os.path.exists(conf_fname)
+with open(conf_fname, 'rt') as fd:
+assert len(fd.read()) > 0



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


[tor-commits] [sbws/master] Update example config.ini

2018-07-11 Thread pastly
commit 813c1198a7048b769f6befb9aa4baed491f7bfd6
Author: Matt Traudt 
Date:   Wed Jul 4 11:52:18 2018 -0400

Update example config.ini
---
 docs/source/config.ini | 4 
 1 file changed, 4 deletions(-)

diff --git a/docs/source/config.ini b/docs/source/config.ini
index 640b3a9..1b4cf26 100644
--- a/docs/source/config.ini
+++ b/docs/source/config.ini
@@ -1,6 +1,2 @@
 [paths]
-datadir = ${sbws_home}/datadir
 sbws_home = /home/user/.sbws
-
-[scanner]
-nickname = IDidntEditTheSBWSConfig



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


[tor-commits] [sbws/master] Update docs about the config files that are read

2018-07-11 Thread pastly
commit 65978ba49b1e91c776fbb52e2d1a8d026d38ebe9
Author: Matt Traudt 
Date:   Wed Jul 4 11:52:34 2018 -0400

Update docs about the config files that are read
---
 docs/source/config.rst | 15 ---
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/docs/source/config.rst b/docs/source/config.rst
index 69bc012..723949d 100644
--- a/docs/source/config.rst
+++ b/docs/source/config.rst
@@ -1,7 +1,7 @@
 Simple Bandwidth Scanner Configuration Files
 
 
-Sbws has four config files it reads: two general, and two specific to logging.
+Sbws has three config files it reads: two general, and one specific to logging.
 They all get combined internally to the same ``conf`` structure, so technically
 you can put any option in any file, but you need to pay attention to the order
 in which they are read. Options specified in multiple files will take the
@@ -25,12 +25,7 @@ Sbws then reads your custom config file. By default, after 
running ``sbws
 init``, it is located in ``~/.sbws/config.ini``. Options in this
 file overwrite options set in previously read config files.
 
-Finally, sbws reads your custom logging config file. By default, after running
-``sbws init``, it is located in ``~/.sbws/config.log.ini``. Options set in 
this file
-overwrite options set in all other config files.
-
-After running ``sbws init``, your ``~/.sbws/config.ini`` might look like this. 
Your
-``~/.sbws/config.log.ini`` will be empty.
+After running ``sbws init``, your ``~/.sbws/config.ini`` might look like this.
 
 .. _init-config:
 
@@ -49,5 +44,11 @@ Default Config
 
 .. _default-log-config:
 
+If you know how to use
+`Python's logging configuration file format`_,
+then you can override or add to what is listed here by editing your config.ini.
+
 .. literalinclude:: config.log.default.ini
 :caption: config.log.default.ini
+
+.. _Python's logging configuration file format: 
https://docs.python.org/3.5/library/logging.config.html#logging-config-fileformat



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


[tor-commits] [sbws/master] This needs a valid file name or sbws can't start

2018-07-11 Thread pastly
commit 82ad8983f54630ab19cacd76ef33e76658522778
Author: Matt Traudt 
Date:   Wed Jul 4 11:31:09 2018 -0400

This needs a valid file name or sbws can't start
---
 sbws/config.log.default.ini | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sbws/config.log.default.ini b/sbws/config.log.default.ini
index 606ff16..6cfcf88 100644
--- a/sbws/config.log.default.ini
+++ b/sbws/config.log.default.ini
@@ -29,7 +29,7 @@ formatter = to_file
 # logging library eval()s this, which doesn't give the ini parsing library a
 # chance to replace the text. So we do it in configure_logging() in
 # sbws/util/config.py instead.
-args =
+args = ('/dev/null', )
 
 ## for logging to system log
 #[handler_to_syslog]



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


[tor-commits] [sbws/master] Remove unused import to make flake8 happy

2018-07-11 Thread pastly
commit 5254ea6d75797d63ebf046b7c31aafb36145d627
Author: Matt Traudt 
Date:   Wed Jul 4 12:01:46 2018 -0400

Remove unused import to make flake8 happy
---
 sbws/core/init.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sbws/core/init.py b/sbws/core/init.py
index ea415a3..39d4c17 100644
--- a/sbws/core/init.py
+++ b/sbws/core/init.py
@@ -1,4 +1,4 @@
-from sbws.globals import (is_initted, fail_hard, touch_file)
+from sbws.globals import (is_initted, fail_hard)
 from sbws.util.config import get_user_example_config
 from sbws.util.userquery import query_yes_no
 from argparse import ArgumentDefaultsHelpFormatter



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


[tor-commits] [sbws/master] Remove config.log.ini

2018-07-11 Thread pastly
commit 10c7b9e0034a26c7f65948573724ea7723acf588
Author: Matt Traudt 
Date:   Mon Jun 25 10:01:30 2018 -0400

Remove config.log.ini
---
 sbws/core/init.py   |  3 ---
 sbws/sbws.py|  2 +-
 sbws/util/config.py | 13 -
 3 files changed, 1 insertion(+), 17 deletions(-)

diff --git a/sbws/core/init.py b/sbws/core/init.py
index e7e839e..ea415a3 100644
--- a/sbws/core/init.py
+++ b/sbws/core/init.py
@@ -24,9 +24,6 @@ def main(args, conf):
 log.info('Creating %s', args.directory)
 os.makedirs(args.directory, exist_ok=False)
 
-# Create config.log.ini 
-touch_file(os.path.join(args.directory, 'config.log.ini'))
-
 # Create config.ini 
 fname = os.path.join(args.directory, 'config.ini')
 if os.path.exists(fname) and not os.path.isfile(fname):
diff --git a/sbws/sbws.py b/sbws/sbws.py
index b95f738..584ce02 100644
--- a/sbws/sbws.py
+++ b/sbws/sbws.py
@@ -28,7 +28,7 @@ def main():
 for e in conf_errors:
 log.critical(e)
 exit(1)
-configure_logging(conf)
+# configure_logging(conf)
 def_args = [args, conf]
 def_kwargs = {}
 known_commands = {
diff --git a/sbws/util/config.py b/sbws/util/config.py
index c24ac23..25df375 100644
--- a/sbws/util/config.py
+++ b/sbws/util/config.py
@@ -46,18 +46,6 @@ def _get_user_config(args, conf=None):
 return conf
 
 
-def _get_user_logging_config(args, conf=None):
-if not conf:
-conf = ConfigParser(interpolation=ExtendedInterpolation())
-else:
-assert isinstance(conf, ConfigParser)
-fname = os.path.join(args.directory, 'config.log.ini')
-if not os.path.isfile(fname):
-return conf
-conf = _read_config_file(conf, fname)
-return conf
-
-
 def _get_default_logging_config(args, conf=None):
 if not conf:
 conf = ConfigParser(interpolation=ExtendedInterpolation())
@@ -73,7 +61,6 @@ def get_config(args):
 conf = _get_default_config()
 conf = _get_default_logging_config(args, conf=conf)
 conf = _get_user_config(args, conf=conf)
-conf = _get_user_logging_config(args, conf=conf)
 return conf
 
 



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


[tor-commits] [sbws/master] Set _ns to None when there's an exception

2018-07-11 Thread pastly
commit 5bbb344c420c2b6102e3d927b95fb8b47fa93876
Author: juga0 
Date:   Wed Jul 4 07:55:28 2018 +

Set _ns to None when there's an exception
---
 sbws/lib/relaylist.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/sbws/lib/relaylist.py b/sbws/lib/relaylist.py
index bafd7b7..bb59a3b 100644
--- a/sbws/lib/relaylist.py
+++ b/sbws/lib/relaylist.py
@@ -32,6 +32,7 @@ class Relay:
 self._ns = cont.get_network_status(fp, default=None)
 except Exception as e:
 log.exception("Exception trying to get ns %s", e)
+self._ns = None
 if desc is not None:
 assert isinstance(desc, ServerDescriptor)
 self._desc = desc



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


[tor-commits] [sbws/master] Add changelog entry for logging overhaul

2018-07-11 Thread pastly
commit ae7f5d8c65a14f6361eddb63907a697ac57e2cb2
Author: Matt Traudt 
Date:   Wed Jul 4 12:24:33 2018 -0400

Add changelog entry for logging overhaul
---
 CHANGELOG.md | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 1c3e372..a8acfb9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,8 @@ and this project adheres to [Semantic 
Versioning](http://semver.org/spec/v2.0.0.
 
 - Measure relays that have both Exit and BadExit as non-exits, which is how
   clients would use them. (GH#217)
+- Could not init sbws because of a catch-22 related to logging configuration.
+  Overhaul how logging is configured. (GH#186 GHPR#224)
 
 
 ## [0.5.0] - 2018-06-26



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


[tor-commits] [sbws/master] Remove unused config option log_filepath

2018-07-11 Thread pastly
commit fa105e14697d30c624fe79cdd2c2d9fe2efbe139
Author: Matt Traudt 
Date:   Mon Jun 25 11:22:41 2018 -0400

Remove unused config option log_filepath
---
 sbws/config.default.ini | 1 -
 sbws/util/config.py | 2 +-
 2 files changed, 1 insertion(+), 2 deletions(-)

diff --git a/sbws/config.default.ini b/sbws/config.default.ini
index 3e49052..dbe46a2 100644
--- a/sbws/config.default.ini
+++ b/sbws/config.default.ini
@@ -3,7 +3,6 @@ datadir = ${sbws_home}/datadir
 v3bw_dname = ${sbws_home}/v3bw
 v3bw_fname = ${v3bw_dname}/{}.v3bw
 started_filepath = ${sbws_home}/started_at
-log_filepath = ${sbws_home}/sbws.log
 log_dname = ${sbws_home}/log
 
 [destinations]
diff --git a/sbws/util/config.py b/sbws/util/config.py
index 0e6f308..bf73540 100644
--- a/sbws/util/config.py
+++ b/sbws/util/config.py
@@ -198,7 +198,7 @@ def _validate_paths(conf):
 err_tmpl = Template('$sec/$key ($val): $e')
 unvalidated_keys = [
 'datadir', 'sbws_home', 'v3bw_fname', 'v3bw_dname',
-'started_filepath', 'log_filepath', 'log_dname']
+'started_filepath', 'log_dname']
 all_valid_keys = unvalidated_keys
 allow_missing = ['sbws_home']
 errors.extend(_validate_section_keys(conf, sec, all_valid_keys, err_tmpl,



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


[tor-commits] [sbws/master] Add possibility to log to system log

2018-07-11 Thread pastly
commit f0977a682c1c68e94ef47b7e2630b81d319056ba
Author: juga0 
Date:   Sat Jul 7 16:26:02 2018 +

Add possibility to log to system log

Since sbws migth be run as a system service, it should give some
information to the system log.
There are no new options to configure for the user, and it's
disabled by default.
---
 sbws/config.default.ini |  2 ++
 sbws/config.log.default.ini | 26 --
 sbws/util/config.py |  3 +++
 3 files changed, 17 insertions(+), 14 deletions(-)

diff --git a/sbws/config.default.ini b/sbws/config.default.ini
index d9e2622..04bdd61 100644
--- a/sbws/config.default.ini
+++ b/sbws/config.default.ini
@@ -87,6 +87,8 @@ min_relays = 50
 to_file = yes
 # Whether or not to log to stdout
 to_stdout = no
+# Whether or not to log to syslog
+to_syslog = no
 # If logging to file, how large (in bytes) should the file be allowed to get
 # before rotating to a new one. 10485760 is 10 MiB. If zero or number of
 # backups is zero, never rotate the log file.
diff --git a/sbws/config.log.default.ini b/sbws/config.log.default.ini
index 82e483e..d841ccf 100644
--- a/sbws/config.log.default.ini
+++ b/sbws/config.log.default.ini
@@ -2,10 +2,10 @@
 keys = root,sbws
 
 [handlers]
-keys = to_file,to_stdout
+keys = to_file,to_stdout,to_syslog
 
 [formatters]
-keys = to_file,to_stdout
+keys = to_file,to_stdout,to_syslog
 
 [logger_root]
 level = WARNING
@@ -27,20 +27,18 @@ class = handlers.RotatingFileHandler
 formatter = to_file
 args = ('/dev/null', )
 
-## for logging to system log
-#[handler_to_syslog]
-#class=handlers.SysLogHandler
-#formatter=to_syslog
-#level = INFO
-#args = ()
+# for logging to system log
+[handler_to_syslog]
+class=handlers.SysLogHandler
+formatter=to_syslog
+level = INFO
+args = ('/dev/log',)
 
 [formatter_to_stdout]
 
 [formatter_to_file]
 
-## syslog-like formater
-#[formatter_to_syslog]
-## hostname should be added here with a context filter, dunno if there is a way
-## to add it here
-#format = %(asctime)s %(module)s[%(process)s]: <%(levelname)s> %(message)s
-#datefmt = %b %d %H:%M:%S
+# syslog-like formatter
+[formatter_to_syslog]
+format = %(asctime)s %(module)s[%(process)s]: <%(levelname)s> %(message)s
+datefmt = %b %d %H:%M:%S
diff --git a/sbws/util/config.py b/sbws/util/config.py
index 5813878..6917033 100644
--- a/sbws/util/config.py
+++ b/sbws/util/config.py
@@ -109,6 +109,8 @@ def configure_logging(args, conf):
 handlers.add('to_stdout')
 if can_log_to_file and conf.getboolean('logging', 'to_file'):
 handlers.add('to_file')
+if conf.getboolean('logging', 'to_syslog'):
+handlers.add('to_syslog')
 # Collect the handlers in the appropriate config option
 conf[logger]['handlers'] = ','.join(handlers)
 if 'to_file' in handlers:
@@ -286,6 +288,7 @@ def _validate_logging(conf):
 bools = {
 'to_file': {},
 'to_stdout': {},
+'to_syslog': {},
 }
 ints = {
 'to_file_max_bytes': {'minimum': 0, 'maximum': None},



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


[tor-commits] [sbws/master] Use args, conf fixtures

2018-07-11 Thread pastly
commit 8a3bc1afbd9d89b9211ee2f63cc1edb81a43c0db
Author: juga0 
Date:   Thu Jul 5 15:04:22 2018 +

Use args, conf fixtures
---
 tests/unit/core/test_cleanup.py | 93 ++---
 1 file changed, 31 insertions(+), 62 deletions(-)

diff --git a/tests/unit/core/test_cleanup.py b/tests/unit/core/test_cleanup.py
index 3278e00..63735e2 100644
--- a/tests/unit/core/test_cleanup.py
+++ b/tests/unit/core/test_cleanup.py
@@ -1,4 +1,5 @@
-from sbws.util.config import get_config
+import pytest
+
 from sbws.globals import touch_file
 import sbws.core.cleanup
 from tests.unit.globals import monotonic_time
@@ -9,12 +10,8 @@ import os
 log = logging.getLogger(__name__)
 
 
-def test_cleanup_no_dotsbws(tmpdir, caplog, parser):
+def test_cleanup_no_dotsbws(caplog,  args, conf):
 caplog.set_level(logging.DEBUG)
-dotsbws = tmpdir
-args = parser.parse_args(
-'-d {} --log-level debug cleanup'.format(dotsbws).split())
-conf = get_config(args)
 try:
 sbws.core.cleanup.main(args, conf)
 except SystemExit as e:
@@ -24,26 +21,22 @@ def test_cleanup_no_dotsbws(tmpdir, caplog, parser):
 assert 'Try sbws init' in caplog.records[-1].getMessage()
 
 
-def test_cleanup_no_datadir(empty_dotsbws, caplog, parser):
-dotsbws = empty_dotsbws
-args = parser.parse_args(
-'-d {} --log-level debug cleanup'.format(dotsbws.name).split())
-conf = get_config(args)
+def test_cleanup_no_datadir(sbwshome_config, args, conf, caplog):
+'''
+An initialized but rather empty .sbws directory should fail about missing
+~/.sbws/datadir
+'''
 try:
-sbws.core.cleanup.main(args, conf)
+sbws.core.stats.main(args, conf)
 except SystemExit as e:
 assert e.code == 1
 else:
 assert None, 'Should have failed'
-dd = conf['paths']['datadir']
-assert '{} does not exist'.format(dd) in caplog.records[-1].getMessage()
+assert '{}/datadir does not exist'.format(
+os.path.abspath(sbwshome_config)) == caplog.records[-1].getMessage()
 
 
-def test_cleanup_small_stale(empty_dotsbws_datadir, caplog, parser):
-dotsbws = empty_dotsbws_datadir
-args = parser.parse_args(
-'-d {} --log-level debug cleanup'.format(dotsbws.name).split())
-conf = get_config(args)
+def test_cleanup_small_stale(sbwshome, caplog, args, conf):
 conf['general']['data_period'] = '1'
 conf['cleanup']['stale_days'] = '2'
 conf['cleanup']['rotten_days'] = '3'
@@ -57,11 +50,7 @@ def test_cleanup_small_stale(empty_dotsbws_datadir, caplog, 
parser):
 'general/data_period (1)' in caplog.records[-1].getMessage()
 
 
-def test_cleanup_small_rotten(empty_dotsbws_datadir, caplog, parser):
-dotsbws = empty_dotsbws_datadir
-args = parser.parse_args(
-'-d {} --log-level debug cleanup'.format(dotsbws.name).split())
-conf = get_config(args)
+def test_cleanup_small_rotten(sbwshome, caplog, args, conf):
 conf['general']['data_period'] = '1'
 conf['cleanup']['stale_days'] = '5'
 conf['cleanup']['rotten_days'] = '4'
@@ -75,11 +64,8 @@ def test_cleanup_small_rotten(empty_dotsbws_datadir, caplog, 
parser):
 'cleanup/stale_days (5)' in caplog.records[-1].getMessage()
 
 
-def test_cleanup_medium_stale(empty_dotsbws_datadir, caplog, parser):
-dotsbws = empty_dotsbws_datadir
-args = parser.parse_args(
-'-d {} --log-level debug cleanup'.format(dotsbws.name).split())
-conf = get_config(args)
+def test_cleanup_medium_stale(sbwshome, caplog, args, conf):
+args.dry_run = False
 conf['general']['data_period'] = '10'
 conf['cleanup']['stale_days'] = '19'
 conf['cleanup']['rotten_days'] = '50'
@@ -88,21 +74,18 @@ def test_cleanup_medium_stale(empty_dotsbws_datadir, 
caplog, parser):
 'general/data_period (10).' in caplog.records[-1].getMessage()
 
 
+@pytest.mark.skip(reason="FIXME")
 @patch('time.time')
-def test_cleanup_only_compress_stale(time_mock, empty_dotsbws_datadir, caplog,
- parser):
+def test_cleanup_only_compress_stale(time_mock, sbwshome, caplog, args, conf):
+args.dry_run = True
 caplog.set_level(logging.DEBUG)
-dotsbws = empty_dotsbws_datadir
-args = parser.parse_args(
-'-d {} --log-level debug cleanup'.format(dotsbws.name).split())
-conf = get_config(args)
 conf['general']['data_period'] = '1'
 conf['cleanup']['stale_days'] = '10'
 conf['cleanup']['rotten_days'] = str(365*2)
 now = 1041379200  # 1,041,379,200 is 1 Jan 2003 00:00:00 UTC
 time_mock.side_effect = monotonic_time(start=now)
 j = os.path.join
-dd = j(dotsbws.name, 'datadir')
+dd = j(sbwshome, 'datadir')
 sub_a = j(dd, 'a')
 sub_b = j(dd, 'b')
 sub_ab = j(dd, 'a', 'b')
@@ -135,20 +118,16 @@ def test_cleanup_only_compress_stale(time_mock, 
empty_dotsbws_datadir, caplog,
 
 
 @patch('time.time')
-def test_cleanup_only_delete_rotten(time_mock, empty_dotsbws_datadir, 

[tor-commits] [sbws/master] Validate syslog level

2018-07-11 Thread pastly
commit ec0d7db70923540ffb0e1cc37417133bbdf957ba
Author: juga0 
Date:   Tue Jul 10 08:03:16 2018 +

Validate syslog level
---
 sbws/util/config.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/sbws/util/config.py b/sbws/util/config.py
index 585d23c..c75eef3 100644
--- a/sbws/util/config.py
+++ b/sbws/util/config.py
@@ -285,6 +285,7 @@ def _validate_logging(conf):
 'level': {'choices': _LOG_LEVELS},
 'to_file_level': {'choices': _LOG_LEVELS},
 'to_stdout_level': {'choices': _LOG_LEVELS},
+'to_syslog_level': {'choices': _LOG_LEVELS},
 }
 bools = {
 'to_file': {},



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


[tor-commits] [sbws/master] Replace variables for results' fixtures

2018-07-11 Thread pastly
commit f1b2d205ead05bf9a0d46bed867c6d5fe2eec2a8
Author: juga0 
Date:   Thu Jul 5 15:02:00 2018 +

Replace variables for results' fixtures
---
 tests/unit/lib/test_results.py | 137 +++--
 1 file changed, 9 insertions(+), 128 deletions(-)

diff --git a/tests/unit/lib/test_results.py b/tests/unit/lib/test_results.py
index 328d90a..3c2a52e 100644
--- a/tests/unit/lib/test_results.py
+++ b/tests/unit/lib/test_results.py
@@ -10,25 +10,14 @@ from sbws.lib.resultdump import _ResultType
 from tests.unit.globals import monotonic_time
 
 
-@patch('time.time')
-def test_Result(time_mock):
+def test_Result(result):
 '''
 A standard Result should not be convertible to a string because Result.type
 is not implemented.
 '''
-time_mock.side_effect = monotonic_time()
-fp1 = 'A' * 40
-fp2 = 'Z' * 40
-ed25519 = 'g+Shk00y9Md0hg1S6ptnuc/wWKbADBgdjT0Kg+TSF3s'
-circ = [fp1, fp2]
-dest_url = 'http://example.com/sbws.bin'
-scanner_nick = 'sbwsscanner'
-nick = 'Mooo'
-relay_ip = '169.254.100.1'
-relay = Result.Relay(fp1, nick, relay_ip, ed25519)
-r = Result(relay, circ, dest_url, scanner_nick)
 try:
-str(r)
+str(result)
+print(str(result))
 except NotImplementedError:
 pass
 else:
@@ -59,124 +48,16 @@ def test_Result_from_dict_bad_type():
 assert None, 'Should have failed'
 
 
-@patch('time.time')
-def test_ResultSuccess(time_mock):
-t = 2000
-time_mock.side_effect = monotonic_time(start=t)
-fp1 = 'A' * 40
-fp2 = 'Z' * 40
-ed25519 = 'g+Shk00y9Md0hg1S6ptnuc/wWKbADBgdjT0Kg+TSF3s'
-circ = [fp1, fp2]
-dest_url = 'http://example.com/sbws.bin'
-scanner_nick = 'sbwsscanner'
-nick = 'Mooo'
-relay_ip = '169.254.100.1'
-relay = Result.Relay(fp1, nick, relay_ip, ed25519)
-rtts = [5, 25]
-downloads = [{'duration': 4, 'amount': 40}]
-r1 = ResultSuccess(rtts, downloads, relay, circ, dest_url, scanner_nick)
-r2 = ResultSuccess(rtts, downloads, relay, circ, dest_url, scanner_nick,
-   t=t)
-assert r1.downloads == downloads
-assert r1.rtts == rtts
-assert r1.nickname == nick
-assert r1.time == t
-assert r1.fingerprint == fp1
-assert r1.scanner == scanner_nick
-assert r1.type == _ResultType.Success
-assert r1.address == relay_ip
-assert r1.circ == circ
-assert r1.dest_url == dest_url
-assert r1.version == RESULT_VERSION
-assert str(r1) == str(r2)
-
-
-@patch('time.time')
-def test_ResultSuccess_from_dict(time_mock):
-t = 2000
-time_mock.side_effect = monotonic_time(start=t)
-fp1 = 'A' * 40
-fp2 = 'Z' * 40
-ed25519 = 'g+Shk00y9Md0hg1S6ptnuc/wWKbADBgdjT0Kg+TSF3s'
-circ = [fp1, fp2]
-dest_url = 'http://example.com/sbws.bin'
-scanner_nick = 'sbwsscanner'
-nick = 'Mooo'
-relay_ip = '169.254.100.1'
-relay_average_bandwidth = 1 * 1024 * 1024
-relay = Result.Relay(fp1, nick, relay_ip, ed25519, relay_average_bandwidth)
-rtts = [5, 25]
-downloads = [{'duration': 4, 'amount': 40}]
-r1 = ResultSuccess(rtts, downloads, relay, circ, dest_url, scanner_nick)
-d = {
-'rtts': rtts, 'downloads': downloads, 'fingerprint': fp1,
-'nickname': nick, 'address': relay_ip, 'circ': circ,
-'dest_url': dest_url, 'scanner': scanner_nick,
-'version': RESULT_VERSION, 'type': _ResultType.Success, 'time': t,
-'master_key_ed25519': ed25519,
-'relay_average_bandwidth': relay_average_bandwidth,
-}
-r2 = Result.from_dict(d)
-assert isinstance(r1, ResultSuccess)
+def test_ResultSuccess_from_dict(result_success, result_success_dict):
+r2 = Result.from_dict(result_success_dict)
 assert isinstance(r2, ResultSuccess)
-assert str(r1) == str(r2)
-
-
-@patch('time.time')
-def test_ResultError(time_mock):
-t = 2000
-time_mock.side_effect = monotonic_time(start=t)
-fp1 = 'A' * 40
-fp2 = 'Z' * 40
-ed25519 = 'g+Shk00y9Md0hg1S6ptnuc/wWKbADBgdjT0Kg+TSF3s'
-circ = [fp1, fp2]
-dest_url = 'http://example.com/sbws.bin'
-scanner_nick = 'sbwsscanner'
-nick = 'Mooo'
-relay_ip = '169.254.100.1'
-relay = Result.Relay(fp1, nick, relay_ip, ed25519)
-msg = 'ayy bb'
-r1 = ResultError(relay, circ, dest_url, scanner_nick, msg=msg)
-r2 = ResultError(relay, circ, dest_url, scanner_nick, msg=msg, t=t)
-assert r1.msg == msg
-assert r1.nickname == nick
-assert r1.time == t
-assert r1.fingerprint == fp1
-assert r1.scanner == scanner_nick
-assert r1.type == _ResultType.Error
-assert r1.address == relay_ip
-assert r1.circ == circ
-assert r1.dest_url == dest_url
-assert r1.version == RESULT_VERSION
-assert str(r1) == str(r2)
+assert str(result_success) == str(r2)
 
 
-@patch('time.time')
-def test_ResultError_from_dict(time_mock):
-t = 2000
-time_mock.side_effect = 

[tor-commits] [sbws/master] Add common conftest

2018-07-11 Thread pastly
commit 77d639d8eee6557739037140db966ed3c48ad3d3
Author: juga0 
Date:   Thu Jul 5 14:51:31 2018 +

Add common conftest
---
 tests/conftest.py | 31 +++
 1 file changed, 31 insertions(+)

diff --git a/tests/conftest.py b/tests/conftest.py
new file mode 100644
index 000..1d5da5b
--- /dev/null
+++ b/tests/conftest.py
@@ -0,0 +1,31 @@
+"""Common pytest configuration for unit and integration tests."""
+import pytest
+from sbws.util.parser import create_parser
+
+
+@pytest.fixture(scope='session')
+def parser():
+return create_parser()
+
+
+@pytest.fixture()
+def datadir(request):
+"""get, read, open test files from the tests "data" directory."""
+class D:
+def __init__(self, basepath):
+self.basepath = basepath
+
+def open(self, name, mode="r"):
+return self.basepath.join(name).open(mode)
+
+def join(self, name):
+return self.basepath.join(name).strpath
+
+def read(self, name):
+with self.open(name, "r") as f:
+return f.read()
+
+def readlines(self, name):
+with self.open(name, "r") as f:
+return f.readlines()
+return D(request.fspath.dirpath("data"))



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


[tor-commits] [sbws/master] Stop calling write method from the class

2018-07-11 Thread pastly
commit 67b8850ce7d1cbc9dc72f0be674c6e687bcadd1d
Author: juga0 
Date:   Fri Jul 6 17:04:10 2018 +

Stop calling write method from the class

and call it from object instance, otherwise generate would fail.
write method should not be a classinstance since a Class won't
have useful information to write, and can't be an static method
since it requires an argument.
---
 sbws/core/generate.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sbws/core/generate.py b/sbws/core/generate.py
index 6492423..c0e7c8b 100644
--- a/sbws/core/generate.py
+++ b/sbws/core/generate.py
@@ -57,5 +57,5 @@ def main(args, conf):
 return
 bw_file = V3BWFile.from_arg_results(args, conf, results)
 output = args.output or conf['paths']['v3bw_fname'].format(now_fname())
-V3BWFile.write(output)
+bw_file.write(output)
 log.info('Mean bandwidth per line: %f "KiB"', bw_file.avg_bw)



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


[tor-commits] [sbws/master] Create fixtures for results, rename/cleanup

2018-07-11 Thread pastly
commit 6e8fd96f9dd4d8e3dddabb7b67f26e46b7d2
Author: juga0 
Date:   Thu Jul 5 14:53:30 2018 +

Create fixtures for results, rename/cleanup
---
 tests/unit/conftest.py | 347 +++--
 1 file changed, 164 insertions(+), 183 deletions(-)

diff --git a/tests/unit/conftest.py b/tests/unit/conftest.py
index 8915669..4eab658 100644
--- a/tests/unit/conftest.py
+++ b/tests/unit/conftest.py
@@ -1,56 +1,98 @@
-from sbws.lib.resultdump import ResultError
-from sbws.lib.resultdump import ResultSuccess
-from sbws.lib.resultdump import Result
-from sbws.lib.resultdump import write_result_to_datadir
-from sbws.util.config import get_config, _get_default_config
-from sbws.util.parser import create_parser
-import sbws.core.init
-from tempfile import TemporaryDirectory
+"""pytest configuration for unit tests."""
+import argparse
 import pytest
+from datetime import datetime
 import os
-import time
-import argparse
+
+from sbws.core import init
+from sbws.globals import RESULT_VERSION
+from sbws.lib.resultdump import (ResultErrorStream, ResultSuccess, Result)
+from sbws.lib.resultdump import write_result_to_datadir
+from sbws.util.config import _get_default_config
+
+
+TIME1 = 1529232277.9028733
+TIME2 = datetime.utcnow().timestamp()
+FP1 = 'A' * 40
+FP2 = 'B' * 40
+ED25519 = 'g+Shk00y9Md0hg1S6ptnuc/wWKbADBgdjT0Kg+TSF3s'
+CIRC12 = [FP1, FP2]
+CIRC21 = [FP2, FP1]
+DEST_URL = 'http://example.com/sbws.bin'
+NICK1 = 'A'
+NICK2 = 'B'
+IP1 = '169.254.100.1'
+IP2 = '169.254.100.2'
+RTTS = [5, 25]
+DOWNLOADS = [{'duration': 4, 'amount': 40}]
+SCANNER = "test"
+AVG_BW = 1024 * 1024
+
+RELAY1 = Result.Relay(FP1, NICK1, IP1, ED25519,
+  average_bandwidth=AVG_BW)
+RELAY2 = Result.Relay(FP1, NICK2, IP2, ED25519)
+
+RESULT = Result(RELAY1, CIRC12, DEST_URL, SCANNER, t=TIME1)
+RESULT_SUCCESS1 = ResultSuccess(RTTS, DOWNLOADS, RELAY1, CIRC12, DEST_URL,
+SCANNER, t=TIME1)
+RESULT_SUCCESS2 = ResultSuccess(RTTS, DOWNLOADS, RELAY2, CIRC21, DEST_URL,
+SCANNER, t=TIME2)
+RESULT_ERROR_STREAM = ResultErrorStream(RELAY1, CIRC12, DEST_URL, SCANNER,
+t=TIME1, msg="Something bad")
+
+RESULTDICT_IP_CHANGED = {FP1: [RESULT_SUCCESS1, RESULT_SUCCESS2]}
+RESULTDICT_IP_NOT_CHANGED = {FP1: [RESULT_SUCCESS1, RESULT_SUCCESS1]}
+
+RELAY_DICT = {
+"fingerprint": FP1,
+"address": IP1,
+"nickname": NICK1,
+"master_key_ed25519": ED25519,
+"relay_average_bandwidth": AVG_BW
+}
+
+BASE_RESULT_NO_RELAY_DICT = {
+"dest_url": DEST_URL,
+"time": TIME1,
+"circ": CIRC12,
+"version": RESULT_VERSION,
+"scanner": SCANNER,
+}
+
+BASE_RESULT_DICT = RELAY_DICT.copy()
+BASE_RESULT_DICT.update(BASE_RESULT_NO_RELAY_DICT)
+
+RESULT_ERROR_STREAM_DICT = BASE_RESULT_DICT.copy()
+RESULT_ERROR_STREAM_DICT.update({
+"type": "error-stream",
+"msg": "Something bad",
+})
+
+RESULT_SUCCESS_DICT = BASE_RESULT_DICT.copy()
+RESULT_SUCCESS_DICT.update({
+"rtts": RTTS,
+"type": "success",
+"downloads": DOWNLOADS,
+})
 
 
 class _PseudoArguments(argparse.Namespace):
-'''
-Just enough of the argparse.Namespace (what you get when you do
+
+"""Just enough of the argparse.Namespace (what you get when you do
 args = parser.parse_args()) to make get_config() happy
 
 >>> args = _PseudoArguments(directory='/home/matt/.sbws')
 >>> args.directory
 '/home/matt/.sbws'
 
-'''
+"""
+
 def __init__(self, **kw):
 for key in kw:
 setattr(self, key, kw[key])
 
 
-@pytest.fixture()
-def datadir(request):
-""" get, read, open test files from the "data" directory. """
-class D:
-def __init__(self, basepath):
-self.basepath = basepath
-
-def open(self, name, mode="r"):
-return self.basepath.join(name).open(mode)
-
-def join(self, name):
-return self.basepath.join(name).strpath
-
-def read(self, name):
-with self.open(name, "r") as f:
-return f.read()
-
-def readlines(self, name):
-with self.open(name, "r") as f:
-return f.readlines()
-return D(request.fspath.dirpath("data"))
-
-
-@pytest.fixture
+@pytest.fixture(scope='function')
 def tmpdir(tmpdir_factory, request):
 """Create a tmp dir for the tests"""
 base = str(hash(request.node.nodeid))[:3]
@@ -58,193 +100,132 @@ def tmpdir(tmpdir_factory, request):
 return bn
 
 
-@pytest.fixture
-def tmpdir_sbwshome(tmpdir):
-"""Create .sbws inside of the tests tmp dir"""
+@pytest.fixture(scope='function')
+def sbwshome_empty(tmpdir):
+"""Create sbws home inside of the tests tmp dir without initializing."""
 home = tmpdir.join('.sbws')
 os.makedirs(home.strpath, exist_ok=True)
-return home
+return home.strpath
 
 
-@pytest.fixture()
-def unittest_args(tmpdir_sbwshome, parser):
-"""Args with sbws home in the 

[tor-commits] [sbws/master] Add level to default conf file

2018-07-11 Thread pastly
commit d6e26d77e2c05191c773f9ea92cbfff93387fffb
Author: juga0 
Date:   Tue Jul 10 08:02:02 2018 +

Add level to default conf file
---
 sbws/config.default.ini | 1 +
 1 file changed, 1 insertion(+)

diff --git a/sbws/config.default.ini b/sbws/config.default.ini
index e08b3b9..b21ba0b 100644
--- a/sbws/config.default.ini
+++ b/sbws/config.default.ini
@@ -100,6 +100,7 @@ to_file_num_backups = 50
 level = info
 to_file_level = ${level}
 to_stdout_level = ${level}
+to_syslog_level = ${level}
 # Format string to use when logging
 format = [%(asctime)s] [%(name)s] [%(levelname)s] %(message)s
 to_file_format = ${format}



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


[tor-commits] [sbws/master] Use result fixtures

2018-07-11 Thread pastly
commit 6b39431b7c6b90c468e0646327eb599d18a68de8
Author: juga0 
Date:   Thu Jul 5 15:01:25 2018 +

Use result fixtures
---
 tests/unit/lib/test_v3bwfile.py | 70 +++--
 1 file changed, 12 insertions(+), 58 deletions(-)

diff --git a/tests/unit/lib/test_v3bwfile.py b/tests/unit/lib/test_v3bwfile.py
index bede4ff..9a9a0a5 100644
--- a/tests/unit/lib/test_v3bwfile.py
+++ b/tests/unit/lib/test_v3bwfile.py
@@ -4,7 +4,7 @@ import json
 import os.path
 
 from sbws import __version__ as version
-from sbws.globals import SPEC_VERSION, RESULT_VERSION
+from sbws.globals import SPEC_VERSION
 from sbws.lib.resultdump import Result, load_result_file
 from sbws.lib.v3bwfile import (V3BWHeader, V3BWLine, TERMINATOR, LINE_SEP,
KEYVALUE_SEP_V110, num_results_of_type,
@@ -44,48 +44,6 @@ bwl_str = "bw=54 error_circ=0 error_misc=0 error_stream=1 " \
 
 v3bw_str = header_extra_str + bwl_str
 
-RESULT_ERROR_STREAM_DICT = {
-"fingerprint": "",
-"address": "111.111.111.111",
-"dest_url": "http://y.z;,
-"time": 1526894062.6408398,
-"circ": ["",
- ""],
-"version": RESULT_VERSION,
-"scanner": "IDidntEditTheSBWSConfig",
-"type": "error-stream",
-"msg": "Something bad happened while measuring bandwidth",
-"nickname": "A",
-"master_key_ed25519": "g+Shk00y9Md0hg1S6ptnuc/wWKbADBgdjT0Kg+TSF3s"
-}
-
-RESULT_SUCCESS_DICT = {
-"fingerprint": "",
-"address": "111.111.111.111",
-"dest_url": "http://y.z;,
-"time": 1526894062.6408398,
-"rtts": [0.4596822261810303, 0.44872617721557617, 0.4563450813293457,
- 0.44872212409973145, 0.4561030864715576, 0.4765200614929199,
- 0.4495084285736084, 0.45711588859558105, 0.45520496368408203,
- 0.4635589122772217],
-"circ": ["",
- ""],
-"version": RESULT_VERSION,
-"scanner": "IDidntEditTheSBWSConfig",
-"type": "success",
-"downloads": [
-{"amount": 590009, "duration": 6.1014368534088135},
-{"amount": 590009, "duration": 8.391342878341675},
-{"amount": 321663, "duration": 7.064587831497192},
-{"amount": 321663, "duration": 8.266003131866455},
-{"amount": 321663, "duration": 5.779450178146362}],
-"nickname": "A",
-"master_key_ed25519": "g+Shk00y9Md0hg1S6ptnuc/wWKbADBgdjT0Kg+TSF3s",
-"relay_average_bandwidth": 1 * 1024 * 1024,
-}
-RESULT_SUCCESS_STR = str(RESULT_SUCCESS_DICT)
-RESULT_ERROR_STREAM_STR = str(RESULT_ERROR_STREAM_DICT)
-
 
 def test_v3bwheader_str():
 """Test header str"""
@@ -134,15 +92,11 @@ def test_v3bwheader_from_file(datadir):
 assert str(h) == str(header)
 
 
-def test_num_results_of_type():
-assert num_results_of_type([Result.from_dict(RESULT_SUCCESS_DICT)],
-   'success') == 1
-assert num_results_of_type([Result.from_dict(RESULT_ERROR_STREAM_DICT)],
-   'success') == 0
-assert num_results_of_type([Result.from_dict(RESULT_SUCCESS_DICT)],
-   'error-stream') == 0
-assert num_results_of_type([Result.from_dict(RESULT_ERROR_STREAM_DICT)],
-   'error-stream') == 1
+def test_num_results_of_type(result_success, result_error_stream):
+assert num_results_of_type([result_success], 'success') == 1
+assert num_results_of_type([result_error_stream], 'success') == 0
+assert num_results_of_type([result_success], 'error-stream') == 0
+assert num_results_of_type([result_error_stream], 'error-stream') == 1
 
 
 def test_v3bwline_from_results_file(datadir):
@@ -172,23 +126,23 @@ def test_v3bwfile(datadir, tmpdir):
 assert v3bw == str(f)
 
 
-def test_from_arg_results(datadir, tmpdir, unittest_conf, unittest_args):
+def test_from_arg_results(datadir, tmpdir, conf, args):
 results = load_result_file(str(datadir.join("results.txt")))
 expected_header = V3BWHeader(timestamp_l,
  earliest_bandwidth=earliest_bandwidth,
  latest_bandwidth=latest_bandwidth)
 expected_bwls = [V3BWLine.from_results(results[fp]) for fp in results]
 expected_f = V3BWFile(expected_header, expected_bwls)
-v3bwfile = V3BWFile.from_arg_results(unittest_args, unittest_conf, results)
+v3bwfile = V3BWFile.from_arg_results(args, conf, results)
 assert str(expected_f)[1:] == str(v3bwfile)[1:]
-output = os.path.join(unittest_args.output, now_fname())
+output = os.path.join(args.output, now_fname())
 print(output)
 v3bwfile.write(output)
 
 
-def test_from_arg_results_write(datadir, tmpdir, unittest_conf, unittest_args):
+def test_from_arg_results_write(datadir, tmpdir, conf, args):
 

[tor-commits] [sbws/master] Bump to 0.6.1-dev

2018-07-11 Thread pastly
commit c3ce3bb537b303102eed4c923a92c659eaa8a37e
Author: Matt Traudt 
Date:   Wed Jul 11 10:57:49 2018 -0400

Bump to 0.6.1-dev
---
 sbws/__init__.py  | 2 +-
 tests/unit/lib/data/v3bw/20180425_131057.v3bw | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/sbws/__init__.py b/sbws/__init__.py
index ef7eb44..270c7bf 100644
--- a/sbws/__init__.py
+++ b/sbws/__init__.py
@@ -1 +1 @@
-__version__ = '0.6.0'
+__version__ = '0.6.1-dev'
diff --git a/tests/unit/lib/data/v3bw/20180425_131057.v3bw 
b/tests/unit/lib/data/v3bw/20180425_131057.v3bw
index 602943b..365be98 100644
--- a/tests/unit/lib/data/v3bw/20180425_131057.v3bw
+++ b/tests/unit/lib/data/v3bw/20180425_131057.v3bw
@@ -5,6 +5,6 @@ file_created=2018-04-25T13:10:57
 generator_started=2018-04-16T14:09:05
 latest_bandwidth=2018-04-17T14:09:07
 software=sbws
-software_version=0.6.0
+software_version=0.6.1-dev
 
 bw=54 error_circ=0 error_misc=0 error_stream=1 
master_key_ed25519=g+Shk00y9Md0hg1S6ptnuc/wWKbADBgdjT0Kg+TSF3s nick=A 
node_id=$ rtt=456 success=1 
time=2018-04-17T14:09:07

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


[tor-commits] [sbws/master] Add unit test for init

2018-07-11 Thread pastly
commit 63e5ac172b6b66d1046474aefaf2ad1b19e63fc1
Author: juga0 
Date:   Thu Jul 5 19:08:07 2018 +

Add unit test for init
---
 tests/unit/core/test_init.py | 45 
 1 file changed, 45 insertions(+)

diff --git a/tests/unit/core/test_init.py b/tests/unit/core/test_init.py
new file mode 100644
index 000..77f3b0a
--- /dev/null
+++ b/tests/unit/core/test_init.py
@@ -0,0 +1,45 @@
+"""Unit tests for sbws.core.init."""
+import logging
+import os.path
+
+import sbws
+
+
+def test_sbwshome_only_datadir(sbwshome_only_datadir, args, conf, caplog):
+caplog.set_level(logging.DEBUG)
+sbws.core.init.main(args, conf)
+print(caplog.records[-1].getMessage())
+assert "Creating {} based on example config".format(
+os.path.join(conf['paths']['sbws_home'], 'config.ini')) \
+in caplog.records[-1].getMessage()
+assert os.path.isdir(conf['paths']['sbws_home'])
+assert os.path.isdir(conf['paths']['datadir'])
+assert os.path.isfile(os.path.join(conf['paths']['sbws_home'],
+  'config.ini'))
+
+
+def test_sbwshome_empty(args, conf, caplog):
+caplog.set_level(logging.DEBUG)
+sbws.core.init.main(args, conf)
+assert "Creating {} based on example config".format(
+os.path.join(conf['paths']['sbws_home'], 'config.ini')) \
+in caplog.records[-1].getMessage()
+assert os.path.isdir(conf['paths']['sbws_home'])
+assert os.path.isfile(os.path.join(conf['paths']['sbws_home'],
+  'config.ini'))
+
+
+def test_sbwshome(sbwshome, args, conf, caplog):
+caplog.set_level(logging.DEBUG)
+try:
+sbws.core.init.main(args, conf)
+except SystemExit as e:
+assert e.code == 1
+else:
+assert None, 'Should have failed'
+assert "Directory already seems to be initted" \
+in caplog.records[-1].getMessage()
+assert os.path.isdir(conf['paths']['sbws_home'])
+assert os.path.isdir(conf['paths']['datadir'])
+assert os.path.isfile(os.path.join(conf['paths']['sbws_home'],
+  'config.ini'))



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


[tor-commits] [sbws/master] Use args, conf, results' fixtures

2018-07-11 Thread pastly
commit 184afd0912f30675436283fb5d335ef36a843048
Author: juga0 
Date:   Thu Jul 5 15:07:06 2018 +

Use args, conf, results' fixtures
---
 tests/unit/core/test_stats.py | 178 +-
 1 file changed, 55 insertions(+), 123 deletions(-)

diff --git a/tests/unit/core/test_stats.py b/tests/unit/core/test_stats.py
index 4bac862..b8b3fff 100644
--- a/tests/unit/core/test_stats.py
+++ b/tests/unit/core/test_stats.py
@@ -1,71 +1,16 @@
-import pytest
+import os.path
 
-from sbws.util.parser import create_parser
-from sbws.util.config import get_config
-from sbws.lib.resultdump import ResultError
-from sbws.lib.resultdump import ResultSuccess
-from sbws.lib.resultdump import Result
-from sbws.lib.resultdump import write_result_to_datadir
 import sbws.core.init
 import sbws.core.stats
 from tests.unit.globals import monotonic_time
 from unittest.mock import patch
-from datetime import datetime
-import os
-import time
 import logging
 
 
-def init_directory(dname):
-p = create_parser()
-args = p.parse_args('-d {} --log-level debug init'.format(dname).split())
-conf = get_config(args)
-sbws.core.init.main(args, conf)
-
-
-def add_single_stale_result(dname):
-r = ResultError(
-Result.Relay('DEADBEEF', 'CowSayWhat', '127.0.0.1', 'ed25519key'),
-['DEADBEEF', 'BEADDEEF'],
-'127.0.1.1', 'SBWSscanner', t=19950216)
-dd = os.path.join(str(dname), 'datadir')
-os.makedirs(dd)
-write_result_to_datadir(r, dd)
-
-
-def add_single_fresh_result(dname):
-r = ResultError(
-Result.Relay('DEADBEEF', 'CowSayWhat', '127.0.0.1', 'ed25519key'),
-['DEADBEEF', 'BEADDEEF'],
-'127.0.1.1', 'SBWSscanner', t=time.time())
-dd = os.path.join(str(dname), 'datadir')
-os.makedirs(dd)
-write_result_to_datadir(r, dd)
-
-
-def add_two_fresh_results(dname, t):
-r1 = ResultError(
-Result.Relay('DEADBEEF', 'CowSayWhat', '127.0.0.1', 'ed25519key'),
-['DEADBEEF', 'BEADDEEF'],
-'127.0.1.1', 'SBWSscanner', t=t)
-r2 = ResultSuccess(
-[1, 2, 3], [{'amount': 100, 'duration': 1}],
-Result.Relay('DEADBEEF', 'CowSayWhat', '127.0.0.1', 'ed25519key'),
-['DEADBEEF', 'BEADDEEF'],
-'127.0.1.1', 'SBWSscanner', t=t)
-dd = os.path.join(str(dname), 'datadir')
-os.makedirs(dd)
-write_result_to_datadir(r1, dd)
-write_result_to_datadir(r2, dd)
-
-
-def test_stats_uninitted(tmpdir, caplog):
+def test_stats_uninitted(sbwshome_empty, args, conf, caplog):
 '''
 An un-initialized .sbws directory should fail hard and exit immediately
 '''
-p = create_parser()
-args = p.parse_args('-d {} --log-level debug stats'.format(tmpdir).split())
-conf = get_config(args)
 try:
 sbws.core.stats.main(args, conf)
 except SystemExit as e:
@@ -76,108 +21,95 @@ def test_stats_uninitted(tmpdir, caplog):
 caplog.records[-1].getMessage()
 
 
-def test_stats_initted(tmpdir, caplog):
+def test_stats_initted(sbwshome_config, args, conf, caplog):
 '''
 An initialized but rather empty .sbws directory should fail about missing
 ~/.sbws/datadir
 '''
-init_directory(tmpdir)
-p = create_parser()
-args = p.parse_args('-d {} --log-level debug stats'.format(tmpdir).split())
-conf = get_config(args)
 try:
 sbws.core.stats.main(args, conf)
 except SystemExit as e:
 assert e.code == 1
 else:
 assert None, 'Should have failed'
-assert '{}/datadir does not exist'.format(tmpdir) == \
-caplog.records[-1].getMessage()
+assert '{}/datadir does not exist'.format(
+os.path.abspath(sbwshome_config)) == caplog.records[-1].getMessage()
 
 
-def test_stats_stale_result(tmpdir, caplog):
+def test_stats_stale_result(sbwshome, args, conf, caplog,
+sbwshome_success_result):
 '''
 An initialized .sbws directory with no fresh results should say so and
 exit cleanly
 '''
-init_directory(tmpdir)
-add_single_stale_result(tmpdir)
-p = create_parser()
-args = p.parse_args('-d {} --log-level debug stats'.format(tmpdir).split())
-conf = get_config(args)
+caplog.set_level(logging.DEBUG)
 sbws.core.stats.main(args, conf)
 assert 'No fresh results' == caplog.records[-1].getMessage()
 
 
-# FIXME
-@pytest.mark.skip(reason="freshness needs to be adjusted to timestamp meaning")
-def test_stats_fresh_result(tmpdir, capsys, caplog):
+@patch('time.time')
+def test_stats_fresh_result(time_mock, sbwshome_error_result, args, conf,
+capsys, caplog):
 '''
 An initialized .sbws directory with a fresh error result should have some
 boring stats and exit cleanly
 '''
-caplog.set_level(logging.DEBUG)
-init_directory(tmpdir)
-add_single_fresh_result(tmpdir)
-p = create_parser()
-args = p.parse_args(
-'-d {} --log-level 

[tor-commits] [sbws/master] Use args, conf fixtures

2018-07-11 Thread pastly
commit 72acff552b2316e0bb97c231381b7f47b0bb1bf9
Author: juga0 
Date:   Thu Jul 5 15:09:23 2018 +

Use args, conf fixtures
---
 tests/integration/core/test_scanner.py | 51 ++
 1 file changed, 8 insertions(+), 43 deletions(-)

diff --git a/tests/integration/core/test_scanner.py 
b/tests/integration/core/test_scanner.py
index e7e0d86..fc9a6c5 100644
--- a/tests/integration/core/test_scanner.py
+++ b/tests/integration/core/test_scanner.py
@@ -1,8 +1,4 @@
 from sbws.core.scanner import measure_relay
-from sbws.lib.circuitbuilder import GapsCircuitBuilder as CB
-from sbws.util.config import get_config
-from sbws.lib.relaylist import RelayList
-from sbws.lib.destination import DestinationList
 from sbws.lib.resultdump import ResultSuccess
 import logging
 
@@ -20,40 +16,18 @@ def assert_within(value, target, radius):
 '{} of {}'.format(value, radius, target)
 
 
-def get_everything_to_measure(dotsbws, cont, parser):
-args = parser.parse_args(
-'-d {} --log-level debug scanner'.format(dotsbws).split())
-conf = get_config(args)
-conf['destinations']['foo'] = 'on'
-conf['destinations.foo'] = {}
-conf['destinations.foo']['url'] = 'http://127.0.0.1:2/sbws.bin'
-rl = RelayList(args, conf, cont)
-cb = CB(args, conf, cont, rl)
-dests, error_msg = DestinationList.from_config(conf, cb, rl, cont)
-assert dests, error_msg
-return {
-'args': args,
-'conf': conf,
-'rl': rl,
-'cb': cb,
-'dests': dests
-}
-
-
 def test_measure_relay_with_maxadvertisedbandwidth(
-persistent_launch_tor, parser, persistent_empty_dotsbws, caplog):
+persistent_launch_tor, sbwshome, args, conf,
+dests, cb, rl, caplog):
 caplog.set_level(logging.DEBUG)
-cont = persistent_launch_tor
-dotsbws = persistent_empty_dotsbws.name
-d = get_everything_to_measure(dotsbws, cont, parser)
-args = d['args']
-conf = d['conf']
-rl = d['rl']
-dests = d['dests']
-cb = d['cb']
+# d = get_everything_to_measure(sbwshome, cont, args, conf)
+# rl = d['rl']
+# dests = d['dests']
+# cb = d['cb']
 # 117A456C94076BEB4E757AC48B16CC0CCC5F is relay1mbyteMAB
 relay = [r for r in rl.relays
  if r.nickname == 'relay1mbyteMAB'][0]
+# d['relay'] = relay
 result = measure_relay(args, conf, dests, cb, rl, relay)
 assert len(result) == 1
 result = result[0]
@@ -69,16 +43,7 @@ def test_measure_relay_with_maxadvertisedbandwidth(
 
 
 def test_measure_relay_with_relaybandwidthrate(
-persistent_launch_tor, parser, persistent_empty_dotsbws):
-cont = persistent_launch_tor
-dotsbws = persistent_empty_dotsbws.name
-d = get_everything_to_measure(dotsbws, cont, parser)
-args = d['args']
-conf = d['conf']
-rl = d['rl']
-dests = d['dests']
-cb = d['cb']
-# relay1mbyteRBR 934E06F38A391CB71DF83ECDE05DFF5CDE3AC49D
+persistent_launch_tor, args, conf, dests, cb, rl):
 relay = [r for r in rl.relays
  if r.nickname == 'relay1mbyteRBR'][0]
 result = measure_relay(args, conf, dests, cb, rl, relay)



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


[tor-commits] [sbws/master] Replace variables for results' fixtures

2018-07-11 Thread pastly
commit 4999ed64dfdeb693f2e72d4b5675c07d1e5a9746
Author: juga0 
Date:   Thu Jul 5 15:03:10 2018 +

Replace variables for results' fixtures
---
 tests/unit/lib/test_resultdump.py | 61 +--
 1 file changed, 20 insertions(+), 41 deletions(-)

diff --git a/tests/unit/lib/test_resultdump.py 
b/tests/unit/lib/test_resultdump.py
index 13b0db8..c956dea 100644
--- a/tests/unit/lib/test_resultdump.py
+++ b/tests/unit/lib/test_resultdump.py
@@ -1,53 +1,32 @@
 # -*- coding: utf-8 -*-
 """Unit tests for resultdump."""
-from sbws.lib.resultdump import trim_results_ip_changed, Result, ResultSuccess
-
-
-TIME1 = 1529232277.9028733
-TIME2 = 1529232278.9028733
-FP1 = 'A' * 40
-FP2 = 'Z' * 40
-ED25519 = 'g+Shk00y9Md0hg1S6ptnuc/wWKbADBgdjT0Kg+TSF3s'
-CIRC = [FP1, FP2]
-DEST_URL = 'http://example.com/sbws.bin'
-NICK = 'A'
-RELAY_IP1 = '169.254.100.1'
-RELAY_IP2 = '169.254.100.2'
-RELAY1 = Result.Relay(FP1, NICK, RELAY_IP1, ED25519)
-RELAY2 = Result.Relay(FP1, NICK, RELAY_IP2, ED25519)
-RTTS = [5, 25]
-DOWNLOADS = [{'duration': 4, 'amount': 40}]
-
-RESULTSUCCESS1 = ResultSuccess(RTTS, DOWNLOADS, RELAY1, CIRC, DEST_URL,
-   'sbws', t=TIME1)
-RESULTSUCCESS2 = ResultSuccess(RTTS, DOWNLOADS, RELAY2, CIRC, DEST_URL,
-   'sbws', t=TIME2)
-RESULTDICT_IP_CHANGED = {FP1: [RESULTSUCCESS1, RESULTSUCCESS2]}
-RESULTDICT_IP_NOT_CHANGED = {FP1: [RESULTSUCCESS1, RESULTSUCCESS1]}
-
-
-def test_trim_results_ip_changed_defaults():
-results_dict = trim_results_ip_changed(RESULTDICT_IP_NOT_CHANGED)
-assert RESULTDICT_IP_NOT_CHANGED == results_dict
-
-
-def test_trim_results_ip_changed_on_changed_ipv4_changed():
-expected_results_dict = {FP1: [RESULTSUCCESS2]}
-results_dict = trim_results_ip_changed(RESULTDICT_IP_CHANGED,
+from sbws.lib.resultdump import trim_results_ip_changed
+
+
+def test_trim_results_ip_changed_defaults(resultdict_ip_not_changed):
+results_dict = trim_results_ip_changed(resultdict_ip_not_changed)
+assert resultdict_ip_not_changed == results_dict
+
+
+def test_trim_results_ip_changed_on_changed_ipv4_changed(
+resultdict_ip_changed, resultdict_ip_changed_trimmed):
+results_dict = trim_results_ip_changed(resultdict_ip_changed,
on_changed_ipv4=True)
-assert expected_results_dict == results_dict
+assert resultdict_ip_changed_trimmed == results_dict
 
 
-def test_trim_results_ip_changed_on_changed_ipv4_no_changed():
-results_dict = trim_results_ip_changed(RESULTDICT_IP_NOT_CHANGED,
+def test_trim_results_ip_changed_on_changed_ipv4_no_changed(
+resultdict_ip_not_changed):
+results_dict = trim_results_ip_changed(resultdict_ip_not_changed,
on_changed_ipv4=True)
-assert RESULTDICT_IP_NOT_CHANGED == results_dict
+assert resultdict_ip_not_changed == results_dict
 
 
-def test_trim_results_ip_changed_on_changed_ipv6(caplog):
-results_dict = trim_results_ip_changed(RESULTDICT_IP_NOT_CHANGED,
+def test_trim_results_ip_changed_on_changed_ipv6(caplog,
+ resultdict_ip_not_changed):
+results_dict = trim_results_ip_changed(resultdict_ip_not_changed,
on_changed_ipv6=True)
-assert RESULTDICT_IP_NOT_CHANGED == results_dict
+assert resultdict_ip_not_changed == results_dict
 for record in caplog.records:
 assert record.levelname == 'WARNING'
 assert 'Reseting bandwidth results when IPv6 changes, ' \



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


[tor-commits] [sbws/master] Create args, confs and other fixtures

2018-07-11 Thread pastly
commit 4f5fd8f5729ef8f734efb8a96b7adbcb585c1252
Author: juga0 
Date:   Thu Jul 5 14:58:32 2018 +

Create args, confs and other fixtures
---
 tests/integration/conftest.py | 115 +-
 1 file changed, 91 insertions(+), 24 deletions(-)

diff --git a/tests/integration/conftest.py b/tests/integration/conftest.py
index cfd0e28..1294624 100644
--- a/tests/integration/conftest.py
+++ b/tests/integration/conftest.py
@@ -1,37 +1,72 @@
+"""pytest configuration for integration tests."""
+import argparse
 import pytest
-from tempfile import TemporaryDirectory
-from sbws.util.parser import create_parser
-from sbws.util.config import get_config
-from sbws.util.stem import launch_tor
-import sbws.core.init
 import os
 
+from sbws.core import init
+from sbws.lib.circuitbuilder import GapsCircuitBuilder as CB
+from sbws.lib.destination import DestinationList
+from sbws.lib.relaylist import RelayList
+from sbws.util.config import _get_default_config
+from sbws.util.stem import launch_tor
+
+
+class _PseudoArguments(argparse.Namespace):
+
+"""Just enough of the argparse.Namespace (what you get when you do
+args = parser.parse_args()) to make get_config() happy
+
+>>> args = _PseudoArguments(directory='/home/matt/.sbws')
+>>> args.directory
+'/home/matt/.sbws'
+
+"""
+
+def __init__(self, **kw):
+for key in kw:
+setattr(self, key, kw[key])
+
+
+@pytest.fixture(scope='session')
+def tmpdir(tmpdir_factory, request):
+"""Create a tmp dir for the tests"""
+base = str(hash(request.node.nodeid))[:3]
+bn = tmpdir_factory.mktemp(base)
+return bn
+
 
 @pytest.fixture(scope='session')
-def parser():
-return create_parser()
+def sbwshome_empty(tmpdir):
+"""Create sbws home inside of the tests tmp dir without initializing."""
+home = tmpdir.join('.sbws')
+os.makedirs(home.strpath, exist_ok=True)
+return home.strpath
 
 
 @pytest.fixture(scope='session')
-def persistent_empty_dotsbws(parser):
-'''
-Creates a ~/.sbws with nothing in it but a config.ini and a datadir/
-'''
-d = TemporaryDirectory()
-args = parser.parse_args(
-'-d {} --log-level debug init'.format(d.name).split())
-conf = get_config(args)
-sbws.core.init.main(args, conf)
-os.makedirs(os.path.join(d.name, 'datadir'))
-return d
+def sbwshome_dir(sbwshome_empty):
+"""Create sbws home inside of the tests tmp dir without initializing."""
+os.makedirs(os.path.join(sbwshome_empty, 'datadir'), exist_ok=True)
+return sbwshome_empty
 
 
 @pytest.fixture(scope='session')
-def persistent_launch_tor(parser, persistent_empty_dotsbws):
-d = persistent_empty_dotsbws
-args = parser.parse_args('-d {}'.format(d.name).split())
-conf = get_config(args)
-conf['tor']['extra_lines'] = '''  # noqa: E501
+def args(sbwshome_dir, parser):
+"""Args with sbws home in the tests tmp dir."""
+args = _PseudoArguments(directory=sbwshome_dir, output=sbwshome_dir,
+scale=False, log_level='debug')
+return args
+
+
+@pytest.fixture(scope='session')
+def conf(sbwshome_dir):
+"""Default configuration with sbws home in the tmp test dir."""
+conf = _get_default_config()
+conf['paths']['sbws_home'] = sbwshome_dir
+conf['destinations']['foo'] = 'on'
+conf['destinations.foo'] = {}
+conf['destinations.foo']['url'] = 'http://127.0.0.1:2/sbws.bin'
+conf['tor']['extra_lines'] = """  # noqa: E501
 DirAuthority auth1 orport=2002 no-v2 
v3ident=D7DBC517EFD2BA1A5012CF1BD0BB38F17C8160BD 127.10.0.1:2003 
AA45C13025C037F056E734169891878ED0880231
 DirAuthority auth2 orport=2002 no-v2 
v3ident=4EE103A081F400E6622F5461D51782B876BB5C24 127.10.0.2:2003 
E7B3C9A0040D628DAC88B0251AE6334D28E8F531
 DirAuthority auth3 orport=2002 no-v2 
v3ident=8B85069C7FC0593801E6491A34100264FCE28980 127.10.0.3:2003 
35E3B8BB71C81355649AEC5862ECB7ED7EFDBC5C
@@ -39,6 +74,38 @@ TestingTorNetwork 1
 NumCPUs 1
 LogTimeGranularity 1
 SafeLogging 0
-'''
+"""
+return conf
+
+
+@pytest.fixture(scope='session')
+def sbwshome(sbwshome_dir, args, conf):
+init.main(args, conf)
+return sbwshome_dir
+
+
+@pytest.fixture(scope='session')
+def persistent_launch_tor(conf):
 cont = launch_tor(conf)
 return cont
+
+
+@pytest.fixture(scope='session')
+def rl(args, conf, persistent_launch_tor):
+return RelayList(args, conf, persistent_launch_tor)
+
+
+@pytest.fixture(scope='session')
+def cb(args, conf, persistent_launch_tor, rl):
+return CB(args, conf, persistent_launch_tor, rl)
+
+
+@pytest.fixture(scope='session')
+def dests(args, conf, persistent_launch_tor, cb, rl):
+dests, error_msg = DestinationList.from_config(conf, cb, rl,
+   persistent_launch_tor)
+assert dests, error_msg
+return dests
+
+
+# @pytest.fixture(scope='session')



___
tor-commits mailing list

[tor-commits] [sbws/master] Check that args has attribute

2018-07-11 Thread pastly
commit 3e398b31e05b74097033e3cdcb640bf02a807b0c
Author: juga0 
Date:   Thu Jul 5 15:05:18 2018 +

Check that args has attribute
---
 sbws/core/stats.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sbws/core/stats.py b/sbws/core/stats.py
index 881f3c7..2b497ce 100644
--- a/sbws/core/stats.py
+++ b/sbws/core/stats.py
@@ -130,7 +130,7 @@ def print_stats(args, data):
 fastest_transfer/1024))
 print('Results come from', first, 'to', last, 'over a period of',
   duration)
-if args.error_types:
+if getattr(args, 'error_types', False) is True:
 _print_stats_error_types(data)
 
 



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


[tor-commits] [sbws/master] Use fixtures

2018-07-11 Thread pastly
commit 3f6e83aaf366766543f5fccb9258c8fcd3b4990e
Author: juga0 
Date:   Thu Jul 5 15:08:56 2018 +

Use fixtures
---
 tests/integration/lib/test_relayprioritizer.py | 72 +-
 1 file changed, 25 insertions(+), 47 deletions(-)

diff --git a/tests/integration/lib/test_relayprioritizer.py 
b/tests/integration/lib/test_relayprioritizer.py
index d626fe0..d5464b8 100644
--- a/tests/integration/lib/test_relayprioritizer.py
+++ b/tests/integration/lib/test_relayprioritizer.py
@@ -1,8 +1,6 @@
 from sbws.lib.resultdump import ResultDump
-from sbws.lib.resultdump import (ResultSuccess, ResultErrorCircuit)
-from sbws.lib.relaylist import RelayList
+from sbws.lib.resultdump import ResultSuccess, ResultErrorCircuit
 from sbws.lib.relayprioritizer import RelayPrioritizer
-from sbws.util.config import get_config
 from threading import Event
 from unittest.mock import patch
 
@@ -12,66 +10,46 @@ def static_time(value):
 yield value
 
 
-def get_global_stuff(dotsbws, cont, parser):
-args = parser.parse_args(
-'-d {} --log-level debug'.format(dotsbws).split())
-conf = get_config(args)
-rl = RelayList(args, conf, cont)
-return {
-'args': args,
-'conf': conf,
-'rl': rl,
-'end': Event(),
-}
-
-
-def _build_result_for_relay(relay_nick, result_type, timestamp, rl):
+def _build_result_for_relay(conf, rl, result_type, relay_nick,
+timestamp):
 relay = [r for r in rl.relays if r.nickname == relay_nick]
 assert len(relay) == 1
 relay = relay[0]
 other = [r for r in rl.relays if r.nickname != relay_nick][0]
 circ = [relay.fingerprint, other.fingerprint]
-url = 'http://example.com/sbws.bin'
-nick = 'sbws_scanner'
+rtts = [0.5, 0.5, 0.5]
+dls = [
+{'amount': 1024, 'duration': 1},
+{'amount': 1024, 'duration': 1},
+{'amount': 1024, 'duration': 1},
+]
 if result_type == ResultSuccess:
-rtts = [0.5, 0.5, 0.5]
-dls = [
-{'amount': 1024, 'duration': 1},
-{'amount': 1024, 'duration': 1},
-{'amount': 1024, 'duration': 1},
-]
-return ResultSuccess(rtts, dls, relay, circ, url, nick, t=timestamp)
+return ResultSuccess(rtts, dls, relay, circ,
+ conf['destinations.foo']['url'],
+ 'test', t=timestamp)
+
 elif result_type == ResultErrorCircuit:
-return ResultErrorCircuit(
-relay, circ, url, nick, msg='Test error circ message', t=timestamp)
+return ResultErrorCircuit(relay, circ,
+  conf['destinations.foo']['url'],
+  'test', msg='Test error circ message',
+  t=timestamp)
 
 
 @patch('time.time')
-def test_relayprioritizer_general(
-time_mock, persistent_empty_dotsbws, parser, persistent_launch_tor):
+def test_relayprioritizer_general(time_mock, sbwshome_empty, args,
+  conf, rl,
+  persistent_launch_tor):
 now = 100
 time_mock.side_effect = static_time(now)
-cont = persistent_launch_tor
-dotsbws = persistent_empty_dotsbws.name
-d = get_global_stuff(dotsbws, cont, parser)
-args = d['args']
-conf = d['conf']
-end_event = d['end']
-rl = d['rl']
+end_event = Event()
 rd = ResultDump(args, conf, end_event)
 try:
 rp = RelayPrioritizer(args, conf, rl, rd)
+results = []
 results = [
-_build_result_for_relay(
-'relay1', ResultSuccess, now - 100, rl),
-_build_result_for_relay(
-'relay2', ResultSuccess, now - 200, rl),
-_build_result_for_relay(
-'relay3', ResultSuccess, now - 300, rl),
-_build_result_for_relay(
-'relay4', ResultSuccess, now - 400, rl),
-_build_result_for_relay(
-'relay5', ResultSuccess, now - 500, rl),
+_build_result_for_relay(conf, rl, ResultSuccess,
+'relay{}'.format(i), now - (i * 100))
+for i in range(1, 6)
 ]
 for result in results:
 rd.store_result(result)



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


[tor-commits] [sbws/master] Replace Exception by the possible exceptions

2018-07-11 Thread pastly
commit 9ed1fbb9426ceb707a13c6d7a5093ec6a02660fc
Author: juga0 
Date:   Wed Jul 4 08:54:31 2018 +

Replace Exception by the possible exceptions
---
 sbws/util/stem.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/sbws/util/stem.py b/sbws/util/stem.py
index e09f23c..b62de82 100644
--- a/sbws/util/stem.py
+++ b/sbws/util/stem.py
@@ -40,7 +40,7 @@ def attach_stream_to_circuit_listener(controller, circ_id):
 def add_event_listener(controller, func, event):
 try:
 controller.add_event_listener(func, event)
-except Exception as e:
+except ProtocolError as e:
 log.exception("Exception trying to add event listener %s", e)
 
 



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


[tor-commits] [sbws/master] Use syslog level

2018-07-11 Thread pastly
commit 0306526e2a83968d3383bf8df5c06b41c0ee71ab
Author: juga0 
Date:   Tue Jul 10 08:03:38 2018 +

Use syslog level
---
 sbws/util/config.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/sbws/util/config.py b/sbws/util/config.py
index c75eef3..bfd828c 100644
--- a/sbws/util/config.py
+++ b/sbws/util/config.py
@@ -139,6 +139,8 @@ def configure_logging(args, conf):
 conf['handler_to_file']['level'] = conf['logging']['to_file_level'].upper()
 conf['handler_to_stdout']['level'] = \
 conf['logging']['to_stdout_level'].upper()
+conf['handler_to_syslog']['level'] = \
+conf['logging']['to_syslog_level'].upper()
 # Now we configure the standard python logging system
 with NamedTemporaryFile('w+t') as fd:
 conf.write(fd)



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


[tor-commits] [sbws/master] Add UML diagrams to doc

2018-07-11 Thread pastly
commit 93bb4575f558dbba7e98d8260f5a25c204eba1aa
Author: juga0 
Date:   Thu Jul 5 19:35:47 2018 +

Add UML diagrams to doc
---
 docs/source/diagrams.rst |  16 ++
 docs/source/images/classes_sbws.svg  | 379 +++
 docs/source/images/packages_sbws.svg | 318 +
 docs/source/index.rst|   1 +
 4 files changed, 714 insertions(+)

diff --git a/docs/source/diagrams.rst b/docs/source/diagrams.rst
new file mode 100644
index 000..92652c5
--- /dev/null
+++ b/docs/source/diagrams.rst
@@ -0,0 +1,16 @@
+Diagrams
+=
+
+UML Class Diagram
+
+
+.. image:: ./images/classes_sbws.*
+
+`classes_sbws.svg <./_images/classes_sbws.svg>`_
+
+Packages diagram
+-
+
+.. image:: ./images/packages_sbws.*
+
+`packages_sbws.svg <./_images/packages_sbws.svg>`_
\ No newline at end of file
diff --git a/docs/source/images/classes_sbws.svg 
b/docs/source/images/classes_sbws.svg
new file mode 100644
index 000..81aee3c
--- /dev/null
+++ b/docs/source/images/classes_sbws.svg
@@ -0,0 +1,379 @@
+
+http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd;>
+
+
+http://www.w3.org/2000/svg; 
xmlns:xlink="http://www.w3.org/1999/xlink;>
+
+classes_sbws
+
+
+0
+
+CircuitBuilder
+
+built_circuits : set
+circuit_timeout
+close_circuits_on_exit : bool
+controller
+relay_list
+relays
+rng : SystemRandom
+
+build_circuit()
+close_circuit()
+get_circuit_path()
+
+
+1
+
+Destination
+
+hostname
+port
+url
+verify
+
+from_config()
+is_usable()
+
+
+2
+
+DestinationList
+
+
+from_config()
+next()
+
+
+3
+
+DirectoryLock
+
+
+ 
+
+
+21
+
+_FLock
+
+
+ 
+
+
+321
+
+
+
+
+4
+
+FileLock
+
+
+ 
+
+
+421
+
+
+
+
+5
+
+GapsCircuitBuilder
+
+
+build_circuit()
+
+
+50
+
+
+
+
+6
+
+PathLengthException
+
+errors : NoneType
+
+ 
+
+
+7
+
+Relay
+
+address
+average_bandwidth : NoneType
+fingerprint
+master_key_ed25519
+nickname
+
+ 
+
+
+11
+
+Result
+
+address
+circ
+dest_url
+fingerprint
+master_key_ed25519
+nickname
+relay_average_bandwidth
+scanner
+time
+type
+version
+
+from_dict()
+to_dict()
+
+
+711
+
+
+_relay
+
+
+8
+
+Relay
+
+address
+average_bandwidth
+bandwidth
+exit_policy
+fingerprint
+flags
+master_key_ed25519
+nickname
+
+can_exit_to()
+
+
+9
+
+RelayList
+
+REFRESH_INTERVAL : int
+authorities
+bad_exits
+exits
+fast
+guards
+non_exits
+relays
+rng : SystemRandom
+
+random_relay()
+
+
+10
+
+RelayPrioritizer
+
+fraction_to_return
+fresh_seconds
+measure_authorities
+min_to_return
+relay_list
+result_dump
+
+best_priority()
+
+
+12
+
+ResultDump
+
+conf
+data : dict
+data_lock : RLock, _RLock
+datadir
+end_event
+fresh_days
+queue : Queue
+thread : Thread
+
+enter()
+handle_result()
+results_for_relay()
+store_result()
+
+
+13
+
+ResultError
+
+freshness_reduction_factor
+msg
+type
+
+from_dict()
+to_dict()
+
+
+1311
+
+
+
+
+14
+
+ResultErrorAuth
+
+freshness_reduction_factor
+type
+
+from_dict()
+to_dict()
+
+
+1413
+
+
+
+
+15
+
+ResultErrorCircuit
+
+freshness_reduction_factor
+type
+
+from_dict()
+to_dict()
+
+
+1513
+
+
+
+
+16
+
+ResultErrorStream
+
+type
+
+from_dict()
+to_dict()
+
+
+1613
+
+
+
+
+17
+
+ResultSuccess
+
+downloads
+rtts
+type
+
+from_dict()
+to_dict()
+
+
+1711
+
+
+
+
+18
+
+V3BWFile
+
+avg_bw
+bw_lines
+header
+num_lines
+total_bw
+
+from_arg_results()
+write()
+
+
+19
+
+V3BWHeader
+
+file_created
+keyvalue_tuple_ls
+keyvalue_unordered_tuple_ls
+keyvalue_v110str_ls
+keyvalue_v200_ls
+latest_bandwidth
+num_lines
+software
+software_version
+strv110
+strv200
+timestamp
+version
+
+earliest_bandwidth_from_results()
+from_lines_v110()
+from_results()
+from_text_v110()
+generator_started_from_file()
+latest_bandwidth_from_results()
+
+
+20
+
+V3BWLine
+
+bw
+bw_keyvalue_tuple_ls
+bw_keyvalue_v110str_ls
+bw_strv110
+node_id
+
+bw_from_results()
+from_bw_line_v110()
+from_data()
+from_results()
+last_time_from_results()
+result_types_from_results()
+rtt_from_results()
+
+
+22
+
+_ResultType
+
+Error : str
+ErrorAuth : str
+ErrorCircuit : str
+ErrorStream : str
+Success : str
+
+ 
+
+
+23
+
+_StrEnum
+
+
+ 
+
+
+2223
+
+
+
+
+
diff --git a/docs/source/images/packages_sbws.svg 
b/docs/source/images/packages_sbws.svg
new file mode 100644
index 000..526f4c8
--- /dev/null
+++ b/docs/source/images/packages_sbws.svg
@@ -0,0 +1,318 @@
+
+http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd;>
+
+
+http://www.w3.org/2000/svg; 
xmlns:xlink="http://www.w3.org/1999/xlink;>
+
+packages_sbws
+
+
+0
+
+sbws
+
+
+1
+
+sbws.core
+
+
+2
+
+sbws.core.cleanup
+
+
+7
+
+sbws.globals
+
+
+27
+
+
+
+
+18
+
+sbws.util.filelock
+
+
+218
+
+
+
+
+3
+
+sbws.core.generate
+
+
+37
+
+
+
+
+13
+
+sbws.lib.resultdump
+
+
+313
+
+
+
+
+14
+
+sbws.lib.v3bwfile
+
+
+314
+
+
+
+
+22
+
+sbws.util.timestamp
+
+
+322
+
+
+
+
+4
+
+sbws.core.init
+
+
+47
+
+
+
+
+17
+
+sbws.util.config
+
+
+417
+
+
+
+
+23
+
+sbws.util.userquery
+
+
+423
+
+
+
+
+5
+
+sbws.core.scanner
+
+
+57
+
+
+
+
+20
+
+sbws.util.requests
+
+
+520
+
+
+
+
+21
+

[tor-commits] [sbws/master] Release 0.6.0

2018-07-11 Thread pastly
commit e14928509b2170cc5921a46015d553baa00248ca
Author: Matt Traudt 
Date:   Wed Jul 11 10:55:27 2018 -0400

Release 0.6.0

**Important changes**:

- The way users configure logging has changed. No longer are most users
  expected to be familiar with how to configure python's standard logging
library with a config file. Instead we've abstracted out the setting of log
level, format, and destinations to make these settings more accessible to
users. Expert users familiar with [the logging config file 
format][logconffmt]
can still make tweaks.

Summary of changes:

- Make logging configuration easier for the user.
- Add UML diagrams to documentation. They can be found in 
docs/source/images/
  and regenerated with `make umlsvg` in docs/.

[logconffmt]: 
https://docs.python.org/3/library/logging.config.html#logging-config-fileformat
---
 CHANGELOG.md  | 22 +-
 sbws/__init__.py  |  2 +-
 tests/unit/lib/data/v3bw/20180425_131057.v3bw |  2 +-
 3 files changed, 23 insertions(+), 3 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8608b1a..c94761d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,25 @@ and this project adheres to [Semantic 
Versioning](http://semver.org/spec/v2.0.0.
 
 ## [Unreleased]
 
+## [0.6.0] - 2018-07-11
+
+**Important changes**:
+
+- The way users configure logging has changed. No longer are most users
+  expected to be familiar with how to configure python's standard logging
+library with a config file. Instead we've abstracted out the setting of log
+level, format, and destinations to make these settings more accessible to
+users. Expert users familiar with [the logging config file format][logconffmt]
+can still make tweaks.
+
+Summary of changes:
+
+- Make logging configuration easier for the user.
+- Add UML diagrams to documentation. They can be found in docs/source/images/
+  and regenerated with `make umlsvg` in docs/.
+
+[logconffmt]: 
https://docs.python.org/3/library/logging.config.html#logging-config-fileformat
+
 ### Added
 
 - UML diagrams to documentation. In docs/ run `make umlsvg` to rebuild them.
@@ -109,6 +128,7 @@ So fix that.
 - `earliest_bandwidth` being the newest bw not the oldest (thanks juga0)
 - `node_id` was missing the character "$" at the beginning
 
-[Unreleased]: 
https://github.com/pastly/simple-bw-scanner/compare/v0.5.0...master
+[Unreleased]: 
https://github.com/pastly/simple-bw-scanner/compare/v0.6.0...master
+[0.6.0]: https://github.com/pastly/simple-bw-scanner/compare/v0.5.0...v0.6.0
 [0.5.0]: https://github.com/pastly/simple-bw-scanner/compare/v0.4.1...v0.5.0
 [0.4.1]: https://github.com/pastly/simple-bw-scanner/compare/v0.4.0...v0.4.1
diff --git a/sbws/__init__.py b/sbws/__init__.py
index 1cb6639..ef7eb44 100644
--- a/sbws/__init__.py
+++ b/sbws/__init__.py
@@ -1 +1 @@
-__version__ = '0.5.1-dev'
+__version__ = '0.6.0'
diff --git a/tests/unit/lib/data/v3bw/20180425_131057.v3bw 
b/tests/unit/lib/data/v3bw/20180425_131057.v3bw
index 911d483..602943b 100644
--- a/tests/unit/lib/data/v3bw/20180425_131057.v3bw
+++ b/tests/unit/lib/data/v3bw/20180425_131057.v3bw
@@ -5,6 +5,6 @@ file_created=2018-04-25T13:10:57
 generator_started=2018-04-16T14:09:05
 latest_bandwidth=2018-04-17T14:09:07
 software=sbws
-software_version=0.5.1-dev
+software_version=0.6.0
 
 bw=54 error_circ=0 error_misc=0 error_stream=1 
master_key_ed25519=g+Shk00y9Md0hg1S6ptnuc/wWKbADBgdjT0Kg+TSF3s nick=A 
node_id=$ rtt=456 success=1 
time=2018-04-17T14:09:07



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


[tor-commits] [onionoo/master] Avoid IllegalStateException when descriptors are missing.

2018-07-11 Thread karsten
commit b6e3a1d51722f02f2d391295a676c7b241090213
Author: Karsten Loesing 
Date:   Wed Jul 11 09:35:07 2018 +0200

Avoid IllegalStateException when descriptors are missing.

A missing descriptor directory has caused an IllegalStateException
when we attempted to write our parse history files. Let's be more
careful about this case and skip this history file if there is no such
directory.

Fixes #26711.
---
 CHANGELOG.md  | 2 ++
 src/main/java/org/torproject/onionoo/updater/DescriptorQueue.java | 5 +
 2 files changed, 7 insertions(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index ca0142b..d4cfb82 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,8 @@
  * Minor changes
- Index relays with no known country code or autonomous system
  number using the special values "xz" and "AS0" respectively.
+   - Avoid running into an IllegalStateException when CollecTor is
+ missing a whole descriptor directory.
 
 
 # Changes in version 6.0-1.14.0 - 2018-05-29
diff --git a/src/main/java/org/torproject/onionoo/updater/DescriptorQueue.java 
b/src/main/java/org/torproject/onionoo/updater/DescriptorQueue.java
index c19fabd..d00b8b2 100644
--- a/src/main/java/org/torproject/onionoo/updater/DescriptorQueue.java
+++ b/src/main/java/org/torproject/onionoo/updater/DescriptorQueue.java
@@ -108,6 +108,11 @@ class DescriptorQueue {
 if (this.historyFile == null) {
   return;
 }
+if (null == this.descriptors) {
+  log.debug("Not writing history file {}, because we did not read a single 
"
+  + "descriptor from {}.", this.historyFile, this.directory);
+  return;
+}
 SortedMap excludedAndParsedFiles = new TreeMap<>();
 excludedAndParsedFiles.putAll(
 this.descriptorReader.getExcludedFiles());

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


[tor-commits] [tor-browser-build/master] Merge remote-tracking branch 'azadi/bug-26251-rev1'

2018-07-11 Thread boklm
commit 82a0bd2d85fe53b61460a3e3b833f10a0bb01519
Merge: 6d63b2e 6d3f0f5
Author: Nicolas Vigier 
Date:   Wed Jul 11 12:58:51 2018 +0200

Merge remote-tracking branch 'azadi/bug-26251-rev1'

 projects/webrtc/build| 10 -
 projects/webrtc/webrtc-mac.patch | 45 ++--
 rbm.conf |  2 +-
 3 files changed, 8 insertions(+), 49 deletions(-)

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


[tor-commits] [translation/https_everywhere] Update translations for https_everywhere

2018-07-11 Thread translation
commit b54b350b232ca88e5cf0e9be6fe526ff62c2e863
Author: Translation commit bot 
Date:   Wed Jul 11 12:45:30 2018 +

Update translations for https_everywhere
---
 uk/https-everywhere.dtd | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/uk/https-everywhere.dtd b/uk/https-everywhere.dtd
index ed56c0bb1..d79eda646 100644
--- a/uk/https-everywhere.dtd
+++ b/uk/https-everywhere.dtd
@@ -2,7 +2,7 @@
 
 
 
-
+
 
 
 
@@ -17,13 +17,13 @@
 
 
 
-
+
 
 
 
 
 
-
+
 
 
 
@@ -36,6 +36,6 @@
 
 
 
-
+
 
 

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


  1   2   >