refactor(netx): dialer does not use legacy/netx anymore (#370)

Part of https://github.com/ooni/probe-engine/issues/897
This commit is contained in:
Simone Basso 2021-06-09 00:29:40 +02:00 committed by GitHub
commit ee35b10a98
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 41 deletions

View file

@ -4,7 +4,6 @@ import (
"context"
"net"
"github.com/ooni/probe-cli/v3/internal/engine/legacy/netx/dialid"
"github.com/ooni/probe-cli/v3/internal/engine/netx/errorx"
)
@ -15,35 +14,26 @@ type ErrorWrapperDialer struct {
// DialContext implements Dialer.DialContext
func (d ErrorWrapperDialer) DialContext(ctx context.Context, network, address string) (net.Conn, error) {
dialID := dialid.ContextDialID(ctx)
conn, err := d.Dialer.DialContext(ctx, network, address)
err = errorx.SafeErrWrapperBuilder{
// ConnID does not make any sense if we've failed and the error
// does not make any sense (and is nil) if we succeeded.
DialID: dialID,
Error: err,
Operation: errorx.ConnectOperation,
}.MaybeBuild()
if err != nil {
return nil, err
}
return &ErrorWrapperConn{
Conn: conn, ConnID: safeConnID(network, conn), DialID: dialID}, nil
return &ErrorWrapperConn{Conn: conn}, nil
}
// ErrorWrapperConn is a net.Conn that performs error wrapping.
type ErrorWrapperConn struct {
net.Conn
ConnID int64
DialID int64
}
// Read implements net.Conn.Read
func (c ErrorWrapperConn) Read(b []byte) (n int, err error) {
n, err = c.Conn.Read(b)
err = errorx.SafeErrWrapperBuilder{
ConnID: c.ConnID,
DialID: c.DialID,
Error: err,
Operation: errorx.ReadOperation,
}.MaybeBuild()
@ -54,8 +44,6 @@ func (c ErrorWrapperConn) Read(b []byte) (n int, err error) {
func (c ErrorWrapperConn) Write(b []byte) (n int, err error) {
n, err = c.Conn.Write(b)
err = errorx.SafeErrWrapperBuilder{
ConnID: c.ConnID,
DialID: c.DialID,
Error: err,
Operation: errorx.WriteOperation,
}.MaybeBuild()
@ -66,8 +54,6 @@ func (c ErrorWrapperConn) Write(b []byte) (n int, err error) {
func (c ErrorWrapperConn) Close() (err error) {
err = c.Conn.Close()
err = errorx.SafeErrWrapperBuilder{
ConnID: c.ConnID,
DialID: c.DialID,
Error: err,
Operation: errorx.CloseOperation,
}.MaybeBuild()