Skip to content

Commit

Permalink
forward
Browse files Browse the repository at this point in the history
  • Loading branch information
alexadhy committed Dec 6, 2021
1 parent b881ef9 commit 21726b3
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pkg/router/route_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,25 +414,27 @@ func (rg *RouteGroup) rttServiceFn(_ time.Duration) {
func (rg *RouteGroup) sendRTT(isResp uint16) error {
rg.mu.Lock()

rg.logger.Debug("SENDING RTT Packet")

if len(rg.tps) == 0 || len(rg.fwd) == 0 || len(rg.rvs) == 0 {
rg.mu.Unlock()
// if no transports, no rules, then no latency probe
return nil
}

var tp *transport.ManagedTransport
var rule routing.Rule
rule := rg.fwd[0]

if isResp == 1 {
rule = rg.rvs[0]
rg.logger.Debug("RTT is of type response")
if len(rg.tps) == 1 {
tp = rg.tps[0]
} else {
tp = rg.tps[len(rg.tps)-1]
}
} else {
rg.logger.Debug("RTT is not of type response")
tp = rg.tps[0]
rule = rg.fwd[0]
}

rg.mu.Unlock()
Expand Down Expand Up @@ -672,9 +674,10 @@ func (rg *RouteGroup) handleRTTPacket(packet routing.Packet) error {
isResp = 1
return rg.sendRTT(isResp)
}
sentAtMs := binary.BigEndian.Uint64(payload)
sentAtMs := binary.BigEndian.Uint64(payload[:8])
sentAt := time.Unix(int64(sentAtMs/1000), int64(sentAtMs)*int64(time.Millisecond)).UTC()
rtt := time.Now().UTC().Sub(sentAt)
rg.logger.Debugf("received rtt: %d", rg.networkStats.rtt)
rg.networkStats.SetRTT(rtt)
return nil
}
Expand Down

0 comments on commit 21726b3

Please sign in to comment.