cleanup: remove ConnID, DialID, TransactionID (#395)

We are not using them anymore. The only nettest still using the
legacy netx implementation is tor, for which setting these fields
is useless, because it performs each measurement into a separate
goroutine. Hence, let us start removing this part of the legacy
netx codebase, which is hampering progress in other areas.

Occurred to me while doing testing for the recent changes in
error mapping (https://github.com/ooni/probe/issues/1505).
This commit is contained in:
Simone Basso
2021-06-23 13:36:45 +02:00
committed by GitHub
parent 1fefe5d9b8
commit c74c94d616
32 changed files with 78 additions and 896 deletions
@@ -71,45 +71,8 @@ type Results struct {
TLSHandshakes []*modelx.TLSHandshakeDoneEvent
}
type connmapper struct {
counter int64
mu sync.Mutex
once sync.Once
table map[int64]int64
}
// scramble maps a ConnID to a different number to avoid emitting
// the port numbers. We preserve the sign because it's used to
// distinguish between TCP (positive) and UDP (negative). A special
// case is zero, which is always mapped to zero, since the zero
// port means "unspecified" in netx code.
func (m *connmapper) scramble(cid int64) int64 {
m.once.Do(func() {
m.table = make(map[int64]int64)
m.table[0] = 0 // means unspecified in netx
})
// See https://stackoverflow.com/a/38140573/4354461
m.mu.Lock()
defer m.mu.Unlock()
if value, found := m.table[cid]; found {
return value
}
var factor int64 = 1
if cid < 0 {
factor = -1
}
m.counter++ // we must never emit zero
value := factor * m.counter
m.table[cid] = value
return value
}
// cm is the global connmapper
var cm connmapper
func (r *Results) onMeasurement(m modelx.Measurement, lowLevel bool) {
if m.Connect != nil {
m.Connect.ConnID = cm.scramble(m.Connect.ConnID)
r.Connects = append(r.Connects, m.Connect)
if lowLevel {
r.NetworkEvents = append(r.NetworkEvents, &m)
@@ -122,17 +85,14 @@ func (r *Results) onMeasurement(m modelx.Measurement, lowLevel bool) {
r.Resolves = append(r.Resolves, m.ResolveDone)
}
if m.TLSHandshakeDone != nil {
m.TLSHandshakeDone.ConnID = cm.scramble(m.TLSHandshakeDone.ConnID)
r.TLSHandshakes = append(r.TLSHandshakes, m.TLSHandshakeDone)
}
if m.Read != nil {
m.Read.ConnID = cm.scramble(m.Read.ConnID)
if lowLevel {
r.NetworkEvents = append(r.NetworkEvents, &m)
}
}
if m.Write != nil {
m.Write.ConnID = cm.scramble(m.Write.ConnID)
if lowLevel {
r.NetworkEvents = append(r.NetworkEvents, &m)
}
@@ -387,22 +387,3 @@ func (txp *faketransport) ClientFactory(stateDir string) (obfs4base.ClientFactor
func (txp *faketransport) ServerFactory(stateDir string, args *goptlib.Args) (obfs4base.ServerFactory, error) {
return txp.txp.ServerFactory(stateDir, args)
}
func TestConnmapper(t *testing.T) {
var mapper connmapper
if mapper.scramble(-1) >= 0 {
t.Fatal("unexpected value for negative input")
}
if mapper.scramble(1234) != 2 {
t.Fatal("unexpected second value")
}
if mapper.scramble(12) != 3 {
t.Fatal("unexpected third value")
}
if mapper.scramble(12) != mapper.scramble(12) {
t.Fatal("not idempotent")
}
if mapper.scramble(0) != 0 {
t.Fatal("unexpected value for zero input")
}
}