2021-06-09 09:42:31 +02:00
|
|
|
package dialer_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
|
|
|
|
"github.com/apex/log"
|
|
|
|
"github.com/ooni/probe-cli/v3/internal/engine/netx/dialer"
|
|
|
|
"github.com/ooni/probe-cli/v3/internal/engine/netx/trace"
|
2022-01-07 18:33:37 +01:00
|
|
|
"github.com/ooni/probe-cli/v3/internal/netxlite"
|
2021-06-09 09:42:31 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func Example() {
|
|
|
|
saver := &trace.Saver{}
|
|
|
|
|
|
|
|
dlr := dialer.New(&dialer.Config{
|
|
|
|
DialSaver: saver,
|
|
|
|
Logger: log.Log,
|
|
|
|
ReadWriteSaver: saver,
|
2022-01-07 18:33:37 +01:00
|
|
|
}, netxlite.DefaultResolver)
|
2021-06-09 09:42:31 +02:00
|
|
|
|
|
|
|
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()
|
|
|
|
}
|