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

[tor-commits] [metrics-lib/master] Extend Torperf results to provide error codes.



commit a422aff99f964c04b1c2c9d65f487717eccd882d
Author: Karsten Loesing <karsten.loesing@xxxxxxx>
Date:   Sun May 17 17:22:39 2020 +0200

    Extend Torperf results to provide error codes.
    
    Implements the remaining part of #30602.
---
 CHANGELOG.md                                       |  3 +++
 .../org/torproject/descriptor/TorperfResult.java   |  9 ++++++++
 .../descriptor/impl/TorperfResultImpl.java         | 14 +++++++++++
 .../descriptor/impl/TorperfResultImplTest.java     | 27 ++++++++++++++++++++++
 4 files changed, 53 insertions(+)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 100bed2..7bb22c4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,8 @@
 # Changes in version 2.??.? - 2020-??-??
 
+ * Medium changes
+   - Extend Torperf results to provide error codes.
+
 
 # Changes in version 2.13.0 - 2020-05-16
 
diff --git a/src/main/java/org/torproject/descriptor/TorperfResult.java b/src/main/java/org/torproject/descriptor/TorperfResult.java
index 695be01..ea5b6f4 100644
--- a/src/main/java/org/torproject/descriptor/TorperfResult.java
+++ b/src/main/java/org/torproject/descriptor/TorperfResult.java
@@ -282,5 +282,14 @@ public interface TorperfResult extends Descriptor {
    * @since 1.7.0
    */
   String getSourceAddress();
+
+  /**
+   * Return the combined error code contained in the {@code tgen} client logs
+   * and the {@code tor} client logs, or {@code null} if no error occured or if
+   * the OnionPerf line didn't contain this information.
+   *
+   * @since 2.14.0
+   */
+  String getErrorCode();
 }
 
diff --git a/src/main/java/org/torproject/descriptor/impl/TorperfResultImpl.java b/src/main/java/org/torproject/descriptor/impl/TorperfResultImpl.java
index b2c58cc..571f8b2 100644
--- a/src/main/java/org/torproject/descriptor/impl/TorperfResultImpl.java
+++ b/src/main/java/org/torproject/descriptor/impl/TorperfResultImpl.java
@@ -182,6 +182,9 @@ public class TorperfResultImpl extends DescriptorImpl
         case "SOURCEADDRESS":
           this.parseSourceAddress(value);
           break;
+        case "ERRORCODE":
+          this.parseErrorcode(value);
+          break;
         default:
           if (key.startsWith("DATAPERC")) {
             this.parseDataPercentile(value, keyValue, line);
@@ -444,6 +447,10 @@ public class TorperfResultImpl extends DescriptorImpl
     this.sourceAddress = value;
   }
 
+  private void parseErrorcode(String value) {
+    this.errorCode = value;
+  }
+
   private long parseTimestamp(String value, String keyValue, String line)
       throws DescriptorParseException {
     long timestamp = -1L;
@@ -704,5 +711,12 @@ public class TorperfResultImpl extends DescriptorImpl
   public String getSourceAddress() {
     return this.sourceAddress;
   }
+
+  private String errorCode;
+
+  @Override
+  public String getErrorCode() {
+    return this.errorCode;
+  }
 }
 
diff --git a/src/test/java/org/torproject/descriptor/impl/TorperfResultImplTest.java b/src/test/java/org/torproject/descriptor/impl/TorperfResultImplTest.java
index 0e76c97..c4740f8 100644
--- a/src/test/java/org/torproject/descriptor/impl/TorperfResultImplTest.java
+++ b/src/test/java/org/torproject/descriptor/impl/TorperfResultImplTest.java
@@ -152,5 +152,32 @@ public class TorperfResultImplTest {
     assertEquals("op-us", torperfResult.getHostnameRemote());
     assertEquals("199.119.112.144", torperfResult.getSourceAddress());
   }
+
+  private static final String inputWithErrorcode =
+      "BUILDTIMES=0.0999999046326,0.139999866486,0.240000009537 CIRC_ID=94982 "
+      + "CONNECT=1554235190.26 DATACOMPLETE=0.0 DATAREQUEST=1554235192.60 "
+      + "DATARESPONSE=1554235192.92 DIDTIMEOUT=1 "
+      + "ENDPOINTLOCAL=localhost:127.0.0.1:56560 "
+      + "ENDPOINTPROXY=localhost:127.0.0.1:41204 "
+      + "ENDPOINTREMOTE=ywoeaxadmmsmewf7.onion:0.0.0.0:80 ERRORCODE=TGEN/READ "
+      + "FILESIZE=5242880 HOSTNAMELOCAL=op-ab HOSTNAMEREMOTE=op-ab "
+      + "LAUNCH=1554235084.64 NEGOTIATE=1554235190.26 "
+      + "PATH=$1FC89C159EA0F96D52D8A7092BF938C509DB6984,"
+      + "$EEDF0AF1F892C82F056063827B47283CC9AEAA41,"
+      + "$356B94BAD3096790E409790898144A4030AC225C QUANTILE=0.8 "
+      + "READBYTES=5069130 REQUEST=1554235190.26 RESPONSE=0.0 "
+      + "SOCKET=1554235190.26 SOURCE=cyan SOURCEADDRESS=unknown "
+      + "START=1554235190.26 TIMEOUT=1500 USED_AT=1554235192.92 "
+      + "USED_BY=149138 WRITEBYTES=56";
+
+  @Test
+  public void testErrorcode() throws DescriptorParseException {
+    List<Descriptor> result = TorperfResultImpl.parseTorperfResults(
+        inputWithErrorcode.getBytes(), null);
+    assertEquals(1, result.size());
+    TorperfResultImpl torperfResult = (TorperfResultImpl) result.get(0);
+    assertNull(torperfResult.getUnrecognizedKeys());
+    assertEquals("TGEN/READ", torperfResult.getErrorCode());
+  }
 }
 

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