mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-03 20:27:35 +03:00
sync: quic-go 0.42.0
Signed-off-by: Gaukas Wang <i@gaukas.wang>
This commit is contained in:
parent
d40dde9b9b
commit
4973374ea5
252 changed files with 13121 additions and 5437 deletions
|
@ -141,7 +141,7 @@ var _ = Describe("QUIC Proxy", func() {
|
|||
Context("Proxy tests", func() {
|
||||
var (
|
||||
serverConn *net.UDPConn
|
||||
serverNumPacketsSent int32
|
||||
serverNumPacketsSent atomic.Int32
|
||||
serverReceivedPackets chan packetData
|
||||
clientConn *net.UDPConn
|
||||
proxy *QuicProxy
|
||||
|
@ -159,9 +159,9 @@ var _ = Describe("QUIC Proxy", func() {
|
|||
BeforeEach(func() {
|
||||
stoppedReading = make(chan struct{})
|
||||
serverReceivedPackets = make(chan packetData, 100)
|
||||
atomic.StoreInt32(&serverNumPacketsSent, 0)
|
||||
serverNumPacketsSent.Store(0)
|
||||
|
||||
// setup a dump UDP server
|
||||
// set up a dump UDP server
|
||||
// in production this would be a QUIC server
|
||||
raddr, err := net.ResolveUDPAddr("udp", "127.0.0.1:0")
|
||||
Expect(err).ToNot(HaveOccurred())
|
||||
|
@ -181,7 +181,7 @@ var _ = Describe("QUIC Proxy", func() {
|
|||
data := buf[0:n]
|
||||
serverReceivedPackets <- packetData(data)
|
||||
// echo the packet
|
||||
atomic.AddInt32(&serverNumPacketsSent, 1)
|
||||
serverNumPacketsSent.Add(1)
|
||||
serverConn.WriteToUDP(data, addr)
|
||||
}
|
||||
}()
|
||||
|
@ -236,7 +236,7 @@ var _ = Describe("QUIC Proxy", func() {
|
|||
}()
|
||||
|
||||
Eventually(serverReceivedPackets).Should(HaveLen(2))
|
||||
Expect(atomic.LoadInt32(&serverNumPacketsSent)).To(BeEquivalentTo(2))
|
||||
Expect(serverNumPacketsSent.Load()).To(BeEquivalentTo(2))
|
||||
Eventually(clientReceivedPackets).Should(HaveLen(2))
|
||||
Expect(string(<-clientReceivedPackets)).To(ContainSubstring("foobar"))
|
||||
Expect(string(<-clientReceivedPackets)).To(ContainSubstring("decafbad"))
|
||||
|
@ -245,14 +245,14 @@ var _ = Describe("QUIC Proxy", func() {
|
|||
|
||||
Context("Drop Callbacks", func() {
|
||||
It("drops incoming packets", func() {
|
||||
var counter int32
|
||||
var counter atomic.Int32
|
||||
opts := &Opts{
|
||||
RemoteAddr: serverConn.LocalAddr().String(),
|
||||
DropPacket: func(d Direction, _ []byte) bool {
|
||||
if d != DirectionIncoming {
|
||||
return false
|
||||
}
|
||||
return atomic.AddInt32(&counter, 1)%2 == 1
|
||||
return counter.Add(1)%2 == 1
|
||||
},
|
||||
}
|
||||
startProxy(opts)
|
||||
|
@ -267,14 +267,14 @@ var _ = Describe("QUIC Proxy", func() {
|
|||
|
||||
It("drops outgoing packets", func() {
|
||||
const numPackets = 6
|
||||
var counter int32
|
||||
var counter atomic.Int32
|
||||
opts := &Opts{
|
||||
RemoteAddr: serverConn.LocalAddr().String(),
|
||||
DropPacket: func(d Direction, _ []byte) bool {
|
||||
if d != DirectionOutgoing {
|
||||
return false
|
||||
}
|
||||
return atomic.AddInt32(&counter, 1)%2 == 1
|
||||
return counter.Add(1)%2 == 1
|
||||
},
|
||||
}
|
||||
startProxy(opts)
|
||||
|
@ -315,7 +315,7 @@ var _ = Describe("QUIC Proxy", func() {
|
|||
}
|
||||
|
||||
It("delays incoming packets", func() {
|
||||
var counter int32
|
||||
var counter atomic.Int32
|
||||
opts := &Opts{
|
||||
RemoteAddr: serverConn.LocalAddr().String(),
|
||||
// delay packet 1 by 200 ms
|
||||
|
@ -325,7 +325,7 @@ var _ = Describe("QUIC Proxy", func() {
|
|||
if d == DirectionOutgoing {
|
||||
return 0
|
||||
}
|
||||
p := atomic.AddInt32(&counter, 1)
|
||||
p := counter.Add(1)
|
||||
return time.Duration(p) * delay
|
||||
},
|
||||
}
|
||||
|
@ -349,7 +349,7 @@ var _ = Describe("QUIC Proxy", func() {
|
|||
})
|
||||
|
||||
It("handles reordered packets", func() {
|
||||
var counter int32
|
||||
var counter atomic.Int32
|
||||
opts := &Opts{
|
||||
RemoteAddr: serverConn.LocalAddr().String(),
|
||||
// delay packet 1 by 600 ms
|
||||
|
@ -359,7 +359,7 @@ var _ = Describe("QUIC Proxy", func() {
|
|||
if d == DirectionOutgoing {
|
||||
return 0
|
||||
}
|
||||
p := atomic.AddInt32(&counter, 1)
|
||||
p := counter.Add(1)
|
||||
return 600*time.Millisecond - time.Duration(p-1)*delay
|
||||
},
|
||||
}
|
||||
|
@ -407,7 +407,7 @@ var _ = Describe("QUIC Proxy", func() {
|
|||
|
||||
It("delays outgoing packets", func() {
|
||||
const numPackets = 3
|
||||
var counter int32
|
||||
var counter atomic.Int32
|
||||
opts := &Opts{
|
||||
RemoteAddr: serverConn.LocalAddr().String(),
|
||||
// delay packet 1 by 200 ms
|
||||
|
@ -417,7 +417,7 @@ var _ = Describe("QUIC Proxy", func() {
|
|||
if d == DirectionIncoming {
|
||||
return 0
|
||||
}
|
||||
p := atomic.AddInt32(&counter, 1)
|
||||
p := counter.Add(1)
|
||||
return time.Duration(p) * delay
|
||||
},
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import (
|
|||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
quic "github.com/refraction-networking/uquic"
|
||||
"github.com/refraction-networking/uquic/internal/utils"
|
||||
|
@ -14,13 +15,21 @@ import (
|
|||
"github.com/refraction-networking/uquic/qlog"
|
||||
)
|
||||
|
||||
func NewQlogger(logger io.Writer) func(context.Context, logging.Perspective, quic.ConnectionID) *logging.ConnectionTracer {
|
||||
func QlogTracer(logger io.Writer) *logging.Tracer {
|
||||
filename := fmt.Sprintf("log_%s_transport.qlog", time.Now().Format("2006-01-02T15:04:05"))
|
||||
fmt.Fprintf(logger, "Creating %s.\n", filename)
|
||||
f, err := os.Create(filename)
|
||||
if err != nil {
|
||||
log.Fatalf("failed to create qlog file: %s", err)
|
||||
return nil
|
||||
}
|
||||
bw := bufio.NewWriter(f)
|
||||
return qlog.NewTracer(utils.NewBufferedWriteCloser(bw, f))
|
||||
}
|
||||
|
||||
func NewQlogConnectionTracer(logger io.Writer) func(context.Context, logging.Perspective, quic.ConnectionID) *logging.ConnectionTracer {
|
||||
return func(_ context.Context, p logging.Perspective, connID quic.ConnectionID) *logging.ConnectionTracer {
|
||||
role := "server"
|
||||
if p == logging.PerspectiveClient {
|
||||
role = "client"
|
||||
}
|
||||
filename := fmt.Sprintf("log_%x_%s.qlog", connID.Bytes(), role)
|
||||
filename := fmt.Sprintf("log_%s_%s.qlog", connID, p.String())
|
||||
fmt.Fprintf(logger, "Creating %s.\n", filename)
|
||||
f, err := os.Create(filename)
|
||||
if err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue