refactor: move bytecounter to internal (#391)

It's generic enough to live outside of engine/netx.

Occurred to me while working on https://github.com/ooni/probe/issues/1687.
This commit is contained in:
Simone Basso 2021-06-22 13:00:29 +02:00 committed by GitHub
parent 520398dd8e
commit 23bc261464
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 23 additions and 20 deletions

View File

@ -1,11 +1,18 @@
// Package bytecounter contains code to track the number of
// bytes sent and received by a probe.
package bytecounter package bytecounter
import "github.com/ooni/probe-cli/v3/internal/atomicx" import "github.com/ooni/probe-cli/v3/internal/atomicx"
// Counter counts bytes sent and received. // Counter counts bytes sent and received.
type Counter struct { type Counter struct {
// Received contains the bytes received. You MUST initialize
// this field, or you can just use the New factory.
Received *atomicx.Int64 Received *atomicx.Int64
Sent *atomicx.Int64
// Sent contains the bytes sent. You MUST initialize
// this field, or you can just use the New factory.
Sent *atomicx.Int64
} }
// New creates a new Counter. // New creates a new Counter.

View File

@ -1,13 +1,9 @@
package bytecounter_test package bytecounter
import ( import "testing"
"testing"
"github.com/ooni/probe-cli/v3/internal/engine/netx/bytecounter"
)
func TestGood(t *testing.T) { func TestGood(t *testing.T) {
counter := bytecounter.New() counter := New()
counter.CountBytesReceived(16384) counter.CountBytesReceived(16384)
counter.CountKibiBytesReceived(10) counter.CountKibiBytesReceived(10)
counter.CountBytesSent(2048) counter.CountBytesSent(2048)

View File

@ -9,9 +9,9 @@ import (
"os" "os"
"time" "time"
"github.com/ooni/probe-cli/v3/internal/bytecounter"
"github.com/ooni/probe-cli/v3/internal/engine/geolocate" "github.com/ooni/probe-cli/v3/internal/engine/geolocate"
"github.com/ooni/probe-cli/v3/internal/engine/model" "github.com/ooni/probe-cli/v3/internal/engine/model"
"github.com/ooni/probe-cli/v3/internal/engine/netx/bytecounter"
"github.com/ooni/probe-cli/v3/internal/engine/netx/dialer" "github.com/ooni/probe-cli/v3/internal/engine/netx/dialer"
"github.com/ooni/probe-cli/v3/internal/engine/netx/httptransport" "github.com/ooni/probe-cli/v3/internal/engine/netx/httptransport"
"github.com/ooni/probe-cli/v3/internal/engine/probeservices" "github.com/ooni/probe-cli/v3/internal/engine/probeservices"

View File

@ -6,8 +6,8 @@ import (
"time" "time"
"github.com/apex/log" "github.com/apex/log"
"github.com/ooni/probe-cli/v3/internal/bytecounter"
"github.com/ooni/probe-cli/v3/internal/engine/netx" "github.com/ooni/probe-cli/v3/internal/engine/netx"
"github.com/ooni/probe-cli/v3/internal/engine/netx/bytecounter"
) )
// resolvemaker contains rules for making a resolver. // resolvemaker contains rules for making a resolver.

View File

@ -6,7 +6,7 @@ import (
"testing" "testing"
"github.com/apex/log" "github.com/apex/log"
"github.com/ooni/probe-cli/v3/internal/engine/netx/bytecounter" "github.com/ooni/probe-cli/v3/internal/bytecounter"
) )
func TestDefaultByteCounter(t *testing.T) { func TestDefaultByteCounter(t *testing.T) {

View File

@ -33,7 +33,7 @@ import (
"sync" "sync"
"time" "time"
"github.com/ooni/probe-cli/v3/internal/engine/netx/bytecounter" "github.com/ooni/probe-cli/v3/internal/bytecounter"
"github.com/ooni/probe-cli/v3/internal/multierror" "github.com/ooni/probe-cli/v3/internal/multierror"
"github.com/ooni/probe-cli/v3/internal/runtimex" "github.com/ooni/probe-cli/v3/internal/runtimex"
) )

View File

@ -4,7 +4,7 @@ import (
"context" "context"
"net" "net"
"github.com/ooni/probe-cli/v3/internal/engine/netx/bytecounter" "github.com/ooni/probe-cli/v3/internal/bytecounter"
) )
// byteCounterDialer is a byte-counting-aware dialer. To perform byte counting, you // byteCounterDialer is a byte-counting-aware dialer. To perform byte counting, you

View File

@ -8,7 +8,7 @@ import (
"net/http" "net/http"
"testing" "testing"
"github.com/ooni/probe-cli/v3/internal/engine/netx/bytecounter" "github.com/ooni/probe-cli/v3/internal/bytecounter"
"github.com/ooni/probe-cli/v3/internal/engine/netx/mockablex" "github.com/ooni/probe-cli/v3/internal/engine/netx/mockablex"
"github.com/ooni/probe-cli/v3/internal/iox" "github.com/ooni/probe-cli/v3/internal/iox"
) )

View File

@ -4,7 +4,7 @@ import (
"io" "io"
"net/http" "net/http"
"github.com/ooni/probe-cli/v3/internal/engine/netx/bytecounter" "github.com/ooni/probe-cli/v3/internal/bytecounter"
) )
// ByteCountingTransport is a RoundTripper that counts bytes. // ByteCountingTransport is a RoundTripper that counts bytes.

View File

@ -8,7 +8,7 @@ import (
"strings" "strings"
"testing" "testing"
"github.com/ooni/probe-cli/v3/internal/engine/netx/bytecounter" "github.com/ooni/probe-cli/v3/internal/bytecounter"
"github.com/ooni/probe-cli/v3/internal/engine/netx/httptransport" "github.com/ooni/probe-cli/v3/internal/engine/netx/httptransport"
"github.com/ooni/probe-cli/v3/internal/iox" "github.com/ooni/probe-cli/v3/internal/iox"
) )

View File

@ -7,8 +7,8 @@ import (
"testing" "testing"
"github.com/apex/log" "github.com/apex/log"
"github.com/ooni/probe-cli/v3/internal/bytecounter"
"github.com/ooni/probe-cli/v3/internal/engine/netx" "github.com/ooni/probe-cli/v3/internal/engine/netx"
"github.com/ooni/probe-cli/v3/internal/engine/netx/bytecounter"
"github.com/ooni/probe-cli/v3/internal/engine/netx/errorx" "github.com/ooni/probe-cli/v3/internal/engine/netx/errorx"
"github.com/ooni/probe-cli/v3/internal/engine/netx/trace" "github.com/ooni/probe-cli/v3/internal/engine/netx/trace"
"github.com/ooni/probe-cli/v3/internal/iox" "github.com/ooni/probe-cli/v3/internal/iox"

View File

@ -31,7 +31,7 @@ import (
"net/url" "net/url"
"github.com/lucas-clemente/quic-go" "github.com/lucas-clemente/quic-go"
"github.com/ooni/probe-cli/v3/internal/engine/netx/bytecounter" "github.com/ooni/probe-cli/v3/internal/bytecounter"
"github.com/ooni/probe-cli/v3/internal/engine/netx/dialer" "github.com/ooni/probe-cli/v3/internal/engine/netx/dialer"
"github.com/ooni/probe-cli/v3/internal/engine/netx/httptransport" "github.com/ooni/probe-cli/v3/internal/engine/netx/httptransport"
"github.com/ooni/probe-cli/v3/internal/engine/netx/quicdialer" "github.com/ooni/probe-cli/v3/internal/engine/netx/quicdialer"

View File

@ -8,8 +8,8 @@ import (
"testing" "testing"
"github.com/apex/log" "github.com/apex/log"
"github.com/ooni/probe-cli/v3/internal/bytecounter"
"github.com/ooni/probe-cli/v3/internal/engine/netx" "github.com/ooni/probe-cli/v3/internal/engine/netx"
"github.com/ooni/probe-cli/v3/internal/engine/netx/bytecounter"
"github.com/ooni/probe-cli/v3/internal/engine/netx/httptransport" "github.com/ooni/probe-cli/v3/internal/engine/netx/httptransport"
"github.com/ooni/probe-cli/v3/internal/engine/netx/resolver" "github.com/ooni/probe-cli/v3/internal/engine/netx/resolver"
"github.com/ooni/probe-cli/v3/internal/engine/netx/tlsdialer" "github.com/ooni/probe-cli/v3/internal/engine/netx/tlsdialer"

View File

@ -11,11 +11,11 @@ import (
"sync" "sync"
"github.com/ooni/probe-cli/v3/internal/atomicx" "github.com/ooni/probe-cli/v3/internal/atomicx"
"github.com/ooni/probe-cli/v3/internal/bytecounter"
"github.com/ooni/probe-cli/v3/internal/engine/geolocate" "github.com/ooni/probe-cli/v3/internal/engine/geolocate"
"github.com/ooni/probe-cli/v3/internal/engine/internal/sessionresolver" "github.com/ooni/probe-cli/v3/internal/engine/internal/sessionresolver"
"github.com/ooni/probe-cli/v3/internal/engine/model" "github.com/ooni/probe-cli/v3/internal/engine/model"
"github.com/ooni/probe-cli/v3/internal/engine/netx" "github.com/ooni/probe-cli/v3/internal/engine/netx"
"github.com/ooni/probe-cli/v3/internal/engine/netx/bytecounter"
"github.com/ooni/probe-cli/v3/internal/engine/probeservices" "github.com/ooni/probe-cli/v3/internal/engine/probeservices"
"github.com/ooni/probe-cli/v3/internal/kvstore" "github.com/ooni/probe-cli/v3/internal/kvstore"
"github.com/ooni/probe-cli/v3/internal/platform" "github.com/ooni/probe-cli/v3/internal/platform"