Skip to content

Commit 6de2619

Browse files
authored
appquic: silence quic-go warnings (#202)
* appquic: silence quic-go warnings quic-go wants to set the read buffer size for the Conn, but snet and the dispatcher setup does not support this. Faking the operations to set the read buffer size does not work, as quic-go also checks directly with a system call whether the operation was successful. As a hacky workaround, we simply silence the logger during the quic.Dial and quic.Listen calls. * ci: bump image version to get go-1.16 And btw remove workaround for go-1.15 in circleci config.
1 parent be84cbd commit 6de2619

File tree

2 files changed

+47
-9
lines changed

2 files changed

+47
-9
lines changed

.circleci/config.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232

3333
integration:
3434
machine:
35-
image: ubuntu-2004:202101-01
35+
image: ubuntu-2004:202107-02
3636

3737
steps:
3838
- checkout
@@ -92,9 +92,6 @@ jobs:
9292
- run:
9393
name: Integration tests
9494
command: |
95-
# XXX: hack, don't build skip here, needs go-1.16, currently this runs on go-1.15.
96-
# As there are currently no integration tests for scion-skip, we don't need it here.
97-
sed -i '/^\s*scion-skip\s*\\$/d' Makefile
9895
make integration
9996
- store_artifacts:
10097
path: /tmp/scion-apps-integration/

pkg/appnet/appquic/appquic.go

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@ package appquic
2020
import (
2121
"crypto/tls"
2222
"fmt"
23+
"io"
24+
"log"
2325
"net"
2426
"sync"
27+
"sync/atomic"
2528

2629
"github.com/lucas-clemente/quic-go"
2730

@@ -86,6 +89,10 @@ func DialAddr(raddr *snet.UDPAddr, host string, tlsConf *tls.Config, quicConf *q
8689
return nil, err
8790
}
8891
host = appnet.MangleSCIONAddr(host)
92+
// HACK: we silence the log here to shut up quic-go's warning about trying to
93+
// set receive buffer size (it's not a UDPConn, we know).
94+
silenceLog()
95+
defer unsilenceLog()
8996
session, err := quic.Dial(sconn, raddr, host, tlsConf, quicConf)
9097
if err != nil {
9198
return nil, err
@@ -113,6 +120,10 @@ func DialAddrEarly(raddr *snet.UDPAddr, host string, tlsConf *tls.Config, quicCo
113120
return nil, err
114121
}
115122
host = appnet.MangleSCIONAddr(host)
123+
// HACK: we silence the log here to shut up quic-go's warning about trying to
124+
// set receive buffer size (it's not a UDPConn, we know).
125+
silenceLog()
126+
defer unsilenceLog()
116127
session, err := quic.DialEarly(sconn, raddr, host, tlsConf, quicConf)
117128
if err != nil {
118129
return nil, err
@@ -132,18 +143,18 @@ func ensurePathDefined(raddr *snet.UDPAddr) error {
132143
//
133144
// See note on wildcard addresses in the appnet package documentation.
134145
func ListenPort(port uint16, tlsConf *tls.Config, quicConfig *quic.Config) (quic.Listener, error) {
135-
sconn, err := appnet.ListenPort(port)
136-
if err != nil {
137-
return nil, err
138-
}
139-
return quic.Listen(sconn, tlsConf, quicConfig)
146+
return Listen(&net.UDPAddr{Port: int(port)}, tlsConf, quicConfig)
140147
}
141148

142149
func Listen(listen *net.UDPAddr, tlsConf *tls.Config, quicConfig *quic.Config) (quic.Listener, error) {
143150
sconn, err := appnet.Listen(listen)
144151
if err != nil {
145152
return nil, err
146153
}
154+
// HACK: we silence the log here to shut up quic-go's warning about trying to
155+
// set receive buffer size (it's not a UDPConn, we know).
156+
silenceLog()
157+
defer unsilenceLog()
147158
return quic.Listen(sconn, tlsConf, quicConfig)
148159
}
149160

@@ -163,3 +174,33 @@ func GetDummyTLSCerts() []tls.Certificate {
163174
}
164175
return srvTLSDummyCerts
165176
}
177+
178+
var logSilencerCount int32
179+
var logSilencerOriginal io.Writer
180+
181+
// silenceLog redirects the log.Default writer to a black hole.
182+
// It can be reenabled by calling unsilenceLog.
183+
// These functions can safely be called from multiple goroutines concurrently;
184+
// the log will remain silenced until unsilenceLog was called for each
185+
// silenceLog call.
186+
func silenceLog() {
187+
count := atomic.AddInt32(&logSilencerCount, 1)
188+
if count == 1 {
189+
logSilencerOriginal = log.Default().Writer()
190+
log.Default().SetOutput(blackhole{})
191+
}
192+
}
193+
194+
func unsilenceLog() {
195+
count := atomic.AddInt32(&logSilencerCount, -1)
196+
if count == 0 {
197+
log.Default().SetOutput(logSilencerOriginal)
198+
logSilencerOriginal = nil
199+
}
200+
}
201+
202+
type blackhole struct{}
203+
204+
func (w blackhole) Write(p []byte) (n int, err error) {
205+
return len(p), nil
206+
}

0 commit comments

Comments
 (0)