cli: upgrade to lucas-clemente/quic-go 0.23.0 (#449)

See https://github.com/ooni/probe/issues/1754 for a comprehensive description.
This commit is contained in:
Simone Basso 2021-08-23 16:49:22 +02:00 committed by GitHub
commit 8f18813e17
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 192 additions and 130 deletions

View file

@ -8,15 +8,16 @@ import (
"time"
"github.com/lucas-clemente/quic-go"
"github.com/ooni/probe-cli/v3/internal/quicx"
)
// QUICListener is a mockable netxlite.QUICListener.
type QUICListener struct {
MockListen func(addr *net.UDPAddr) (quic.OOBCapablePacketConn, error)
MockListen func(addr *net.UDPAddr) (quicx.UDPLikeConn, error)
}
// Listen calls MockListen.
func (ql *QUICListener) Listen(addr *net.UDPAddr) (quic.OOBCapablePacketConn, error) {
func (ql *QUICListener) Listen(addr *net.UDPAddr) (quicx.UDPLikeConn, error) {
return ql.MockListen(addr)
}
@ -132,7 +133,6 @@ func (s *QUICEarlySession) ReceiveMessage() ([]byte, error) {
// QUICUDPConn is an UDP conn used by QUIC.
type QUICUDPConn struct {
MockWriteTo func(p []byte, addr net.Addr) (int, error)
MockReadMsgUDP func(b, oob []byte) (int, int, int, *net.UDPAddr, error)
MockClose func() error
MockLocalAddr func() net.Addr
MockRemoteAddr func() net.Addr
@ -141,21 +141,16 @@ type QUICUDPConn struct {
MockSetWriteDeadline func(t time.Time) error
MockReadFrom func(p []byte) (n int, addr net.Addr, err error)
MockSyscallConn func() (syscall.RawConn, error)
MockWriteMsgUDP func(b, oob []byte, addr *net.UDPAddr) (n, oobn int, err error)
MockSetReadBuffer func(n int) error
}
var _ quic.OOBCapablePacketConn = &QUICUDPConn{}
var _ quicx.UDPLikeConn = &QUICUDPConn{}
// WriteTo calls MockWriteTo.
func (c *QUICUDPConn) WriteTo(p []byte, addr net.Addr) (int, error) {
return c.MockWriteTo(p, addr)
}
// ReadMsgUDP calls MockReadMsgUDP.
func (c *QUICUDPConn) ReadMsgUDP(b, oob []byte) (int, int, int, *net.UDPAddr, error) {
return c.MockReadMsgUDP(b, oob)
}
// Close calls MockClose.
func (c *QUICUDPConn) Close() error {
return c.MockClose()
@ -196,7 +191,7 @@ func (c *QUICUDPConn) SyscallConn() (syscall.RawConn, error) {
return c.MockSyscallConn()
}
// WriteMsgUDP calls MockReadMsgUDP.
func (c *QUICUDPConn) WriteMsgUDP(b, oob []byte, addr *net.UDPAddr) (n, oobn int, err error) {
return c.MockWriteMsgUDP(b, oob, addr)
// SetReadBuffer calls MockSetReadBuffer.
func (c *QUICUDPConn) SetReadBuffer(n int) error {
return c.MockSetReadBuffer(n)
}

View file

@ -12,12 +12,13 @@ import (
"github.com/google/go-cmp/cmp"
"github.com/lucas-clemente/quic-go"
"github.com/ooni/probe-cli/v3/internal/quicx"
)
func TestQUICListenerListen(t *testing.T) {
expected := errors.New("mocked error")
ql := &QUICListener{
MockListen: func(addr *net.UDPAddr) (quic.OOBCapablePacketConn, error) {
MockListen: func(addr *net.UDPAddr) (quicx.UDPLikeConn, error) {
return nil, expected
},
}
@ -287,33 +288,6 @@ func TestQUICUDPConnWriteTo(t *testing.T) {
}
}
func TestQUICUDPConnReadMsgUDP(t *testing.T) {
expected := errors.New("mocked error")
quc := &QUICUDPConn{
MockReadMsgUDP: func(b, oob []byte) (int, int, int, *net.UDPAddr, error) {
return 0, 0, 0, nil, expected
},
}
b := make([]byte, 128)
oob := make([]byte, 128)
n, oobn, flags, addr, err := quc.ReadMsgUDP(b, oob)
if !errors.Is(err, expected) {
t.Fatal("not the error we expected", err)
}
if n != 0 {
t.Fatal("expected zero here")
}
if oobn != 0 {
t.Fatal("expected zero here")
}
if flags != 0 {
t.Fatal("expected zero here")
}
if addr != nil {
t.Fatal("expected nil here")
}
}
func TestQUICUDPConnClose(t *testing.T) {
expected := errors.New("mocked error")
quc := &QUICUDPConn{
@ -434,24 +408,15 @@ func TestQUICUDPConnSyscallConn(t *testing.T) {
}
}
func TestQUICUDPConnWriteMsgUDP(t *testing.T) {
func TestQUICUDPConnSetReadBuffer(t *testing.T) {
expected := errors.New("mocked error")
quc := &QUICUDPConn{
MockWriteMsgUDP: func(b, oob []byte, addr *net.UDPAddr) (n int, oobn int, err error) {
return 0, 0, expected
MockSetReadBuffer: func(n int) error {
return expected
},
}
b := make([]byte, 128)
oob := make([]byte, 128)
addr := &net.UDPAddr{}
n, oobn, err := quc.WriteMsgUDP(b, oob, addr)
err := quc.SetReadBuffer(1 << 10)
if !errors.Is(err, expected) {
t.Fatal("not the error we expected", err)
}
if n != 0 {
t.Fatal("expected 0 here")
}
if oobn != 0 {
t.Fatal("expected 0 here")
}
}