diff --git a/internal/engine/experiment/torsf/torsf.go b/internal/engine/experiment/torsf/torsf.go index 858ed2ede2..d3d65e2549 100644 --- a/internal/engine/experiment/torsf/torsf.go +++ b/internal/engine/experiment/torsf/torsf.go @@ -199,18 +199,15 @@ func (m *Measurer) bootstrap(ctx context.Context, sess model.ExperimentSession, // // This function aims to _only_ include: // -// 1. information on the tor version by intercepting the line that -// writes which tor version is opening a log file; -// -// 2. notices (more detailed debug messages may contain information +// 1. notices (more detailed debug messages may contain information // that we'd rather not include into the logs?); // -// 3. information about bootstrap (by looking at the progress of +// 2. information about bootstrap (by looking at the progress of // the bootstrap we understand where it blocks and we also know the // amount of work tor needs to do, hence we know the cache status // because a working cache includes much less messages); // -// 4. information about bridges being used (from there we know +// 3. information about bridges being used (from there we know // if the bridge was cached of fresh, by the way). // // Tor is know to be good software that does not break its output @@ -233,7 +230,7 @@ func (m *Measurer) readTorLogs(logger model.Logger, tk *TestKeys, logFilePath st return } for _, bline := range bytes.Split(data, []byte("\n")) { - sline := string(bline) // avoid IP addresses in logs + sline := string(bline) if !strings.Contains(sline, "[notice]") { continue } diff --git a/internal/ptx/ptx.go b/internal/ptx/ptx.go index 41cb640c97..51daa41adb 100644 --- a/internal/ptx/ptx.go +++ b/internal/ptx/ptx.go @@ -135,8 +135,6 @@ func (lst *Listener) forward(ctx context.Context, left, right net.Conn, done cha // function TAKES OWNERSHIP of the two connections and ensures // that they are closed when we are done. func (lst *Listener) forwardWithContext(ctx context.Context, left, right net.Conn) { - left = bytecounter.MaybeWrap(left, lst.SessionByteCounter) - left = bytecounter.MaybeWrap(left, lst.ExperimentByteCounter) defer left.Close() defer right.Close() done := make(chan struct{}) @@ -162,6 +160,11 @@ func (lst *Listener) handleSocksConn(ctx context.Context, socksConn ptxSocksConn lst.logger().Warnf("ptx: ContextDialer.DialContext error: %s", err) return err // used for testing } + // We _must_ wrap the ptConn. Wrapping the socks conn leads us to + // count the sent bytes as received and the received bytes as sent: + // bytes flow in the opposite direction there for the socks conn. + ptConn = bytecounter.MaybeWrap(ptConn, lst.SessionByteCounter) + ptConn = bytecounter.MaybeWrap(ptConn, lst.ExperimentByteCounter) lst.forwardWithContext(ctx, socksConn, ptConn) // transfer ownership return nil // used for testing } diff --git a/internal/tunnel/tor.go b/internal/tunnel/tor.go index 00bbc5e0a0..9a6c6d9da1 100644 --- a/internal/tunnel/tor.go +++ b/internal/tunnel/tor.go @@ -25,9 +25,6 @@ type torTunnel struct { // instance is the running tor instance instance torProcess - // logFilePath is the path to the logfile. - logFilePath string - // proxy is the SOCKS5 proxy URL proxy *url.URL } @@ -119,7 +116,6 @@ func torStart(ctx context.Context, config *Config) (Tunnel, DebugInfo, error) { return &torTunnel{ bootstrapTime: stop.Sub(start), instance: instance, - logFilePath: logfile, proxy: &url.URL{Scheme: "socks5", Host: proxyAddress}, }, debugInfo, nil } diff --git a/internal/tunnel/tunnel.go b/internal/tunnel/tunnel.go index 1a90eb174a..4a23451730 100644 --- a/internal/tunnel/tunnel.go +++ b/internal/tunnel/tunnel.go @@ -63,7 +63,7 @@ type Tunnel interface { SOCKS5ProxyURL() *url.URL // Stop stops the tunnel. You should not attempt to - // use the tunnel once this function is called. + // use any other tunnel method after Stop. Stop() }