Skip to content

Commit 00bd906

Browse files
authored
prober: remove DERP pub key copying overheads in qd and non-tun measures (tailscale#14659)
Updates tailscale/corp#25883 Signed-off-by: Jordan Whited <[email protected]>
1 parent 84b0379 commit 00bd906

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

prober/derp.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ func runDerpProbeQueuingDelayContinously(ctx context.Context, from, to *tailcfg.
431431
t := time.NewTicker(time.Second / time.Duration(packetsPerSecond))
432432
defer t.Stop()
433433

434+
toDERPPubKey := toc.SelfPublicKey()
434435
seq := uint64(0)
435436
for {
436437
select {
@@ -446,7 +447,7 @@ func runDerpProbeQueuingDelayContinously(ctx context.Context, from, to *tailcfg.
446447
txRecordsMu.Unlock()
447448
binary.BigEndian.PutUint64(pkt, seq)
448449
seq++
449-
if err := fromc.Send(toc.SelfPublicKey(), pkt); err != nil {
450+
if err := fromc.Send(toDERPPubKey, pkt); err != nil {
450451
sendErrC <- fmt.Errorf("sending packet %w", err)
451452
return
452453
}
@@ -460,6 +461,7 @@ func runDerpProbeQueuingDelayContinously(ctx context.Context, from, to *tailcfg.
460461
go func() {
461462
defer wg.Done()
462463
defer close(recvFinishedC) // to break out of 'select' below.
464+
fromDERPPubKey := fromc.SelfPublicKey()
463465
for {
464466
m, err := toc.Recv()
465467
if err != nil {
@@ -469,7 +471,7 @@ func runDerpProbeQueuingDelayContinously(ctx context.Context, from, to *tailcfg.
469471
switch v := m.(type) {
470472
case derp.ReceivedPacket:
471473
now := time.Now()
472-
if v.Source != fromc.SelfPublicKey() {
474+
if v.Source != fromDERPPubKey {
473475
recvFinishedC <- fmt.Errorf("got data packet from unexpected source, %v", v.Source)
474476
return
475477
}
@@ -767,9 +769,10 @@ func runDerpProbeNodePair(ctx context.Context, from, to *tailcfg.DERPNode, fromc
767769
// Send the packets.
768770
sendc := make(chan error, 1)
769771
go func() {
772+
toDERPPubKey := toc.SelfPublicKey()
770773
for idx, pkt := range pkts {
771774
inFlight.AcquireContext(ctx)
772-
if err := fromc.Send(toc.SelfPublicKey(), pkt); err != nil {
775+
if err := fromc.Send(toDERPPubKey, pkt); err != nil {
773776
sendc <- fmt.Errorf("sending packet %d: %w", idx, err)
774777
return
775778
}
@@ -781,6 +784,7 @@ func runDerpProbeNodePair(ctx context.Context, from, to *tailcfg.DERPNode, fromc
781784
go func() {
782785
defer close(recvc) // to break out of 'select' below.
783786
idx := 0
787+
fromDERPPubKey := fromc.SelfPublicKey()
784788
for {
785789
m, err := toc.Recv()
786790
if err != nil {
@@ -790,7 +794,7 @@ func runDerpProbeNodePair(ctx context.Context, from, to *tailcfg.DERPNode, fromc
790794
switch v := m.(type) {
791795
case derp.ReceivedPacket:
792796
inFlight.Release()
793-
if v.Source != fromc.SelfPublicKey() {
797+
if v.Source != fromDERPPubKey {
794798
recvc <- fmt.Errorf("got data packet %d from unexpected source, %v", idx, v.Source)
795799
return
796800
}
@@ -925,7 +929,7 @@ func derpProbeBandwidthTUN(ctx context.Context, transferTimeSeconds, totalBytesT
925929

926930
destinationAddrBytes := destinationAddr.AsSlice()
927931
scratch := make([]byte, 4)
928-
toPubDERPKey := toc.SelfPublicKey()
932+
toDERPPubKey := toc.SelfPublicKey()
929933
for {
930934
n, err := dev.Read(bufs, sizes, tunStartOffset)
931935
if err != nil {
@@ -954,7 +958,7 @@ func derpProbeBandwidthTUN(ctx context.Context, transferTimeSeconds, totalBytesT
954958
copy(pkt[12:16], pkt[16:20])
955959
copy(pkt[16:20], scratch)
956960

957-
if err := fromc.Send(toPubDERPKey, pkt); err != nil {
961+
if err := fromc.Send(toDERPPubKey, pkt); err != nil {
958962
tunReadErrC <- err
959963
return
960964
}

0 commit comments

Comments
 (0)