so we have this function, which is invoked with go so each invocation should be independent, my problem is that when calculating the offset value, which is uint64 derived from a bunch of uint64 timestamps, I get extremely large values, like 9223372036852854358 which is suspiciously close to the half of the uint64 max value, which makes me think it's a torn read issue
logging the timestamp values (t1,t2 etc) and trying to do the calculations myself does not really compute, I've also tried to running the calculation multiple times in a row and it still gets the same value
func synchronizeWithPeer(target string, lrpcGW *lrpc.Gateway) {
fmt.Printf("starting peer synchronization with \"%s\"\n", target)
probesPacket, err := lrpcGW.RequestWithResponse(variables.GetSensorAddress(), "START_PROBE", []byte(target))
if err != nil {
fmt.Println("gettings probes failed", err)
return
}
var probes map[string]uint64
err = json.Unmarshal(probesPacket.Payload, &probes)
if err != nil {
fmt.Println("failed to parse probes", err)
return
}
t1, t2, r1, r2, pt1, pt2 := probes["t1"], probes["t2"], probes["r1"], probes["r2"], probes["pt1"], probes["pt2"]
if !validCodedProbes(t1, t2, r1, r2) {
fmt.Println("invalid probe data")
return
}
newOffSet := getClockOffset(t1, t2, r1, r2, pt1, pt2)
fmt.Printf("new offset: %d\n", newOffSet)
if newOffSet > 10000000 {
fmt.Println(t1, t2, r1, r2, pt1, pt2)
}
}
func validCodedProbes(t1, t2, r1, r2 uint64) bool {
return (r2-r1)-(t2-t1) < 50_000_000 && r2 > r1
}
func getClockOffset(t1, t2, r1, r2, pt1, pt2 uint64) int64 {
o1 := ((pt1 - t1) + (pt1 - r1)) / 2
o2 := ((pt2 - t2) + (pt2 - r2)) / 2
fmt.Println("o1", o1)
fmt.Println("o2", o2)
return int64(float64(o1+o2) / 2)
}
an example of the logged values
1713218130973383900 1713218131028881800 1713218131185150200 1713218131258211300 1713218131077345600 1713218131147361300
o1 9223372036852854358
o2 3814750
new offset: 4611686018428334080
