-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(netxlite): use *Netx for creating UDP sockets (#1250)
This diff is similar to 07a048c but here we use *Netx to create UDP sockets. While there, recognize that UDP code needs its own files and should not live inside quic{,_test}.go. Part of ooni/probe#2531.
- Loading branch information
1 parent
07a048c
commit 8a5edc2
Showing
5 changed files
with
42 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package netxlite | ||
|
||
import ( | ||
"net" | ||
|
||
"github.com/ooni/probe-cli/v3/internal/model" | ||
) | ||
|
||
// NewUDPListener creates a new UDPListener using the underlying | ||
// [*Netx] structure to create listening UDP sockets. | ||
func (netx *Netx) NewUDPListener() model.UDPListener { | ||
return &udpListenerErrWrapper{&udpListenerStdlib{provider: netx.maybeCustomUnderlyingNetwork()}} | ||
} | ||
|
||
// NewUDPListener is equivalent to creating an empty [*Netx] | ||
// and calling its NewUDPListener method. | ||
func NewUDPListener() model.UDPListener { | ||
netx := &Netx{Underlying: nil} | ||
return netx.NewUDPListener() | ||
} | ||
|
||
// udpListenerStdlib is a UDPListener using the standard library. | ||
type udpListenerStdlib struct { | ||
// provider is the OPTIONAL nil-safe [model.UnderlyingNetwork] provider. | ||
provider *MaybeCustomUnderlyingNetwork | ||
} | ||
|
||
var _ model.UDPListener = &udpListenerStdlib{} | ||
|
||
// Listen implements UDPListener.Listen. | ||
func (qls *udpListenerStdlib) Listen(addr *net.UDPAddr) (model.UDPLikeConn, error) { | ||
return qls.provider.Get().ListenUDP("udp", addr) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package netxlite | ||
|
||
import "testing" | ||
|
||
func TestNewUDPListener(t *testing.T) { | ||
ql := NewUDPListener() | ||
qew := ql.(*udpListenerErrWrapper) | ||
_ = qew.UDPListener.(*udpListenerStdlib) | ||
} |