Skip to content

Commit

Permalink
Fix tcp latency measurement (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
Evertras authored Oct 12, 2023
1 parent 0373a96 commit 02bec9e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/sender/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"sync"
"time"

"github.com/evertras/cynomys/pkg/constants"
"github.com/evertras/cynomys/pkg/metrics"
)

Expand Down Expand Up @@ -63,6 +64,17 @@ func (s *TCPSender) Send(data []byte) error {
return fmt.Errorf("s.conn.Write: %w", err)
}

reply := make([]byte, 16)
_, err = s.conn.Read(reply)

if err != nil {
return fmt.Errorf("waiting for ping reply s.conn.Read: %w", err)
}

if reply[0] != constants.PingReply[0] {
return fmt.Errorf("ping reply was not %q: %q", constants.PingReply, string(reply))
}

latency := time.Since(sent)

if err := s.sink.SendLatencyMeasurement(s.conn.LocalAddr().String(), s.conn.RemoteAddr().String(), latency); err != nil {
Expand Down

0 comments on commit 02bec9e

Please sign in to comment.