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:
parent
3672e14d3e
commit
ee35b10a98
4 changed files with 8 additions and 41 deletions
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue