Skip to content

Commit

Permalink
relay stats
Browse files Browse the repository at this point in the history
  • Loading branch information
ingon committed Jan 18, 2025
1 parent dbe804f commit 33dbd1c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
9 changes: 8 additions & 1 deletion client/peer_relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/connet-dev/connet/netc"
"github.com/connet-dev/connet/pb"
"github.com/connet-dev/connet/pbc"
"github.com/connet-dev/connet/quicc"
"github.com/quic-go/quic-go"
"golang.org/x/sync/errgroup"
"google.golang.org/protobuf/types/known/timestamppb"
Expand Down Expand Up @@ -88,14 +89,15 @@ func (r *relayPeer) connect(ctx context.Context) (quic.Connection, error) {

cfg := r.serverConf.Load()
r.logger.Debug("dialing relay", "relay", r.serverHostport, "addr", addr, "server", cfg.name, "cert", cfg.key)
return r.local.direct.transport.Dial(ctx, addr, &tls.Config{
return r.local.direct.transport.Dial(quicc.RTTContext(ctx), addr, &tls.Config{
Certificates: []tls.Certificate{r.local.clientCert},
RootCAs: cfg.cas,
ServerName: cfg.name,
NextProtos: []string{"connet-relay"},
}, &quic.Config{
MaxIdleTimeout: 20 * time.Second,
KeepAlivePeriod: 10 * time.Second,
Tracer: quicc.RTTTracer,
})
}

Expand All @@ -120,6 +122,11 @@ func (r *relayPeer) keepalive(ctx context.Context, conn quic.Connection) error {
if err := r.heartbeat(ctx, stream); err != nil {
return err
}
if rttStats := quicc.RTTStats(conn); rttStats != nil {
r.logger.Debug("rtt-pro", "last", rttStats.LatestRTT(), "smoothed", rttStats.SmoothedRTT())
} else {
r.logger.Debug("no rtt")
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions relay/clients.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/connet-dev/connet/netc"
"github.com/connet-dev/connet/pb"
"github.com/connet-dev/connet/pbc"
"github.com/connet-dev/connet/quicc"
"github.com/klev-dev/kleverr"
"github.com/quic-go/quic-go"
"golang.org/x/sync/errgroup"
Expand Down Expand Up @@ -169,6 +170,7 @@ func (s *clientsServer) run(ctx context.Context, transport *quic.Transport) erro
l, err := transport.Listen(s.tlsConf, &quic.Config{
MaxIdleTimeout: 20 * time.Second,
KeepAlivePeriod: 10 * time.Second,
Tracer: quicc.RTTTracer,
})
if err != nil {
return kleverr.Ret(err)
Expand Down Expand Up @@ -369,6 +371,9 @@ func (c *clientConn) heartbeat(ctx context.Context, stream quic.Stream, hbt *pbc
if err := pb.Write(stream, &pbc.Response{Heartbeat: req.Heartbeat}); err != nil {
return err
}
if rttStats := quicc.RTTStats(c.conn); rttStats != nil {
c.logger.Debug("rtt", "last", rttStats.LatestRTT(), "smoothed", rttStats.SmoothedRTT())
}
}
})

Expand Down
2 changes: 2 additions & 0 deletions relay/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"slices"

"github.com/connet-dev/connet/model"
"github.com/connet-dev/connet/quicc"
"github.com/connet-dev/connet/statusc"
"github.com/klev-dev/kleverr"
"github.com/quic-go/quic-go"
Expand Down Expand Up @@ -94,6 +95,7 @@ func (s *Server) Run(ctx context.Context) error {
Conn: udpConn,
ConnectionIDLength: 8,
StatelessResetKey: s.statelessResetKey,
ConnContext: quicc.RTTContext,
// TODO review other options
}
defer transport.Close()
Expand Down

0 comments on commit 33dbd1c

Please sign in to comment.