refactor: merge dnsx and errorsx into netxlite (#517)

When preparing a tutorial for netxlite, I figured it is easier
to tell people "hey, this is the package you should use for all
low-level networking stuff" rather than introducing people to
a set of packages working together where some piece of functionality
is here and some other piece is there.

Part of https://github.com/ooni/probe/issues/1591
This commit is contained in:
Simone Basso 2021-09-28 12:42:01 +02:00 committed by GitHub
commit 6d3a4f1db8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
169 changed files with 575 additions and 671 deletions

View file

@ -6,8 +6,6 @@ import (
"net"
"sync"
"time"
"github.com/ooni/probe-cli/v3/internal/netxlite/errorsx"
)
// Dialer establishes network connections.
@ -229,8 +227,7 @@ var _ Dialer = &dialerErrWrapper{}
func (d *dialerErrWrapper) DialContext(ctx context.Context, network, address string) (net.Conn, error) {
conn, err := d.Dialer.DialContext(ctx, network, address)
if err != nil {
return nil, errorsx.NewErrWrapper(
errorsx.ClassifyGenericError, errorsx.ConnectOperation, err)
return nil, NewErrWrapper(ClassifyGenericError, ConnectOperation, err)
}
return &dialerErrWrapperConn{Conn: conn}, nil
}
@ -245,8 +242,7 @@ var _ net.Conn = &dialerErrWrapperConn{}
func (c *dialerErrWrapperConn) Read(b []byte) (int, error) {
count, err := c.Conn.Read(b)
if err != nil {
return 0, errorsx.NewErrWrapper(
errorsx.ClassifyGenericError, errorsx.ReadOperation, err)
return 0, NewErrWrapper(ClassifyGenericError, ReadOperation, err)
}
return count, nil
}
@ -254,8 +250,7 @@ func (c *dialerErrWrapperConn) Read(b []byte) (int, error) {
func (c *dialerErrWrapperConn) Write(b []byte) (int, error) {
count, err := c.Conn.Write(b)
if err != nil {
return 0, errorsx.NewErrWrapper(
errorsx.ClassifyGenericError, errorsx.WriteOperation, err)
return 0, NewErrWrapper(ClassifyGenericError, WriteOperation, err)
}
return count, nil
}
@ -263,8 +258,7 @@ func (c *dialerErrWrapperConn) Write(b []byte) (int, error) {
func (c *dialerErrWrapperConn) Close() error {
err := c.Conn.Close()
if err != nil {
return errorsx.NewErrWrapper(
errorsx.ClassifyGenericError, errorsx.CloseOperation, err)
return NewErrWrapper(ClassifyGenericError, CloseOperation, err)
}
return nil
}