mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-29 16:58:34 +00:00
Add quic qlog to debug logs
This commit is contained in:
parent
11518fe089
commit
c9df755426
5 changed files with 40 additions and 0 deletions
|
@ -2,10 +2,13 @@ package quic
|
|||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/lucas-clemente/quic-go"
|
||||
"github.com/lucas-clemente/quic-go/logging"
|
||||
"github.com/lucas-clemente/quic-go/qlog"
|
||||
|
||||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
|
@ -140,6 +143,9 @@ func (s *clientConnections) openConnection(ctx context.Context, destAddr net.Add
|
|||
quicConfig := &quic.Config{
|
||||
ConnectionIDLength: 12,
|
||||
KeepAlive: false,
|
||||
Tracer: qlog.NewTracer(func(_ logging.Perspective, connID []byte) io.WriteCloser {
|
||||
return &QlogWriter{connID: connID}
|
||||
}),
|
||||
}
|
||||
|
||||
udpConn, _ := rawConn.(*net.UDPConn)
|
||||
|
|
|
@ -2,9 +2,12 @@ package quic
|
|||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
"github.com/lucas-clemente/quic-go"
|
||||
"github.com/lucas-clemente/quic-go/logging"
|
||||
"github.com/lucas-clemente/quic-go/qlog"
|
||||
|
||||
"github.com/xtls/xray-core/common"
|
||||
"github.com/xtls/xray-core/common/net"
|
||||
|
@ -106,6 +109,9 @@ func Listen(ctx context.Context, address net.Address, port net.Port, streamSetti
|
|||
KeepAlive: false,
|
||||
MaxIncomingStreams: 32,
|
||||
MaxIncomingUniStreams: -1,
|
||||
Tracer: qlog.NewTracer(func(_ logging.Perspective, connID []byte) io.WriteCloser {
|
||||
return &QlogWriter{connID: connID}
|
||||
}),
|
||||
}
|
||||
|
||||
conn, err := wrapSysConn(rawConn.(*net.UDPConn), config)
|
||||
|
|
26
transport/internet/quic/qlogWriter.go
Normal file
26
transport/internet/quic/qlogWriter.go
Normal file
|
@ -0,0 +1,26 @@
|
|||
package quic
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/xtls/xray-core/common/log"
|
||||
)
|
||||
|
||||
type QlogWriter struct {
|
||||
connID []byte
|
||||
}
|
||||
|
||||
func (w *QlogWriter) Write(b []byte) (int, error) {
|
||||
if len(b) > 1 { // skip line separator "0a" in qlog
|
||||
log.Record(&log.GeneralMessage{
|
||||
Severity: log.Severity_Debug,
|
||||
Content: fmt.Sprintf("[%x] %s", w.connID, b),
|
||||
})
|
||||
}
|
||||
return len(b), nil
|
||||
}
|
||||
|
||||
func (w *QlogWriter) Close() error {
|
||||
// Noop
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue