Repository: quic-go/quic-go
Pull request #4939 (2025-01-27 06:36:02)

add a method to the sendQueue to send probe packets
Part of #234.

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/quic-go/quic-go/pull/4939?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=quic-go) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 83.72%. Comparing base [(`6f4c002`)](https://app.codecov.io/gh/quic-go/quic-go/commit/6f4c0025139765efde1c3b58a2d3ef2761a12348?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=quic-go) to head [(`a4eda10`)](https://app.codecov.io/gh/quic-go/quic-go/commit/a4eda106d3937bf38def330d8517d1b0d98f437f?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=quic-go).

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master    #4939      +/-   ##
==========================================
- Coverage   83.80%   83.72%   -0.08%     
==========================================
  Files         152      149       -3     
  Lines       16374    16031     -343     
==========================================
- Hits        13722    13421     -301     
+ Misses       2127     2103      -24     
+ Partials      525      507      -18     
```

</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/quic-go/quic-go/pull/4939?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=quic-go).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=quic-go).


Patch:
diff --git a/send_queue.go b/send_queue.go
index bde02334..d19762be 100644
--- a/send_queue.go
+++ b/send_queue.go
@@ -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
 }


Test patch:
diff --git a/mock_sender_test.go b/mock_sender_test.go
index ee38ab6c..e396c6d2 100644
--- a/mock_sender_test.go
+++ b/mock_sender_test.go
@@ -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()
diff --git a/send_queue_test.go b/send_queue_test.go
index d8d903b5..623a8149 100644
--- a/send_queue_test.go
+++ b/send_queue_test.go
@@ -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)
+}