refactor(netx/dialer): hide implementation complexity (#372)
* refactor(netx/dialer): hide implementation complexity This follows the blueprint of `module.Config` and `nodule.New` described at https://github.com/ooni/probe/issues/1591. * fix: ndt7 bug where we were not using the right resolver * fix(legacy/netx): clarify irrelevant implementation change * fix: improve comments * fix(hhfm): do not use dialer.New b/c it breaks it Unclear to me why this is happening. Still, improve upon the previous situation by adding a timeout. It does not seem a priority to look into this issue now.
This commit is contained in:
parent
b7a6dbe47b
commit
06ee0e55a9
30 changed files with 312 additions and 517 deletions
30
internal/engine/netx/dialer/example_test.go
Normal file
30
internal/engine/netx/dialer/example_test.go
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
package dialer_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"net"
|
||||
|
||||
"github.com/apex/log"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/netx/dialer"
|
||||
"github.com/ooni/probe-cli/v3/internal/engine/netx/trace"
|
||||
)
|
||||
|
||||
func Example() {
|
||||
saver := &trace.Saver{}
|
||||
|
||||
dlr := dialer.New(&dialer.Config{
|
||||
DialSaver: saver,
|
||||
Logger: log.Log,
|
||||
ReadWriteSaver: saver,
|
||||
}, &net.Resolver{})
|
||||
|
||||
ctx := context.Background()
|
||||
conn, err := dlr.DialContext(ctx, "tcp", "8.8.8.8:53")
|
||||
if err != nil {
|
||||
log.WithError(err).Fatal("DialContext failed")
|
||||
}
|
||||
|
||||
// ... use the connection ...
|
||||
|
||||
conn.Close()
|
||||
}
|
||||
Loading…
Reference in a new issue