add a method to the sendQueue to send probe packets (#4939)

This commit is contained in:
Marten Seemann 2025-01-27 07:54:30 +01:00 committed by GitHub
parent 6f4c002513
commit bb0b645ce9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 58 additions and 1 deletions

View file

@ -10,6 +10,7 @@
package quic
import (
net "net"
reflect "reflect"
protocol "github.com/quic-go/quic-go/internal/protocol"
@ -188,6 +189,42 @@ func (c *MockSenderSendCall) DoAndReturn(f func(*packetBuffer, uint16, protocol.
return c
}
// SendProbe mocks base method.
func (m *MockSender) SendProbe(arg0 *packetBuffer, arg1 net.Addr) {
m.ctrl.T.Helper()
m.ctrl.Call(m, "SendProbe", arg0, arg1)
}
// SendProbe indicates an expected call of SendProbe.
func (mr *MockSenderMockRecorder) SendProbe(arg0, arg1 any) *MockSenderSendProbeCall {
mr.mock.ctrl.T.Helper()
call := mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "SendProbe", reflect.TypeOf((*MockSender)(nil).SendProbe), arg0, arg1)
return &MockSenderSendProbeCall{Call: call}
}
// MockSenderSendProbeCall wrap *gomock.Call
type MockSenderSendProbeCall struct {
*gomock.Call
}
// Return rewrite *gomock.Call.Return
func (c *MockSenderSendProbeCall) Return() *MockSenderSendProbeCall {
c.Call = c.Call.Return()
return c
}
// Do rewrite *gomock.Call.Do
func (c *MockSenderSendProbeCall) Do(f func(*packetBuffer, net.Addr)) *MockSenderSendProbeCall {
c.Call = c.Call.Do(f)
return c
}
// DoAndReturn rewrite *gomock.Call.DoAndReturn
func (c *MockSenderSendProbeCall) DoAndReturn(f func(*packetBuffer, net.Addr)) *MockSenderSendProbeCall {
c.Call = c.Call.DoAndReturn(f)
return c
}
// WouldBlock mocks base method.
func (m *MockSender) WouldBlock() bool {
m.ctrl.T.Helper()

View file

@ -1,9 +1,14 @@
package quic
import "github.com/quic-go/quic-go/internal/protocol"
import (
"net"
"github.com/quic-go/quic-go/internal/protocol"
)
type sender interface {
Send(p *packetBuffer, gsoSize uint16, ecn protocol.ECN)
SendProbe(*packetBuffer, net.Addr)
Run() error
WouldBlock() bool
Available() <-chan struct{}
@ -57,6 +62,10 @@ func (h *sendQueue) Send(p *packetBuffer, gsoSize uint16, ecn protocol.ECN) {
}
}
func (h *sendQueue) SendProbe(p *packetBuffer, addr net.Addr) {
h.conn.WriteTo(p.Data, addr)
}
func (h *sendQueue) WouldBlock() bool {
return len(h.queue) == sendQueueCapacity
}

View file

@ -2,6 +2,7 @@ package quic
import (
"errors"
"net"
"testing"
"time"
@ -170,3 +171,13 @@ func TestSendQueueWriteError(t *testing.T) {
t.Fatal("timeout")
}
}
func TestSendQueueSendProbe(t *testing.T) {
mockCtrl := gomock.NewController(t)
c := NewMockSendConn(mockCtrl)
q := newSendQueue(c)
addr := &net.UDPAddr{IP: net.IPv4(42, 42, 42, 42), Port: 42}
c.EXPECT().WriteTo([]byte("foobar"), addr)
q.SendProbe(getPacketWithContents([]byte("foobar")), addr)
}