You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There should be a way to check if the time on the computer is the same as the NTP time before any tx, and warn user if time isn't sync.
Here is an example of a check proposed by ChatGPT:
package main
import (
"fmt"
"net"
"time"
"github.com/beevik/ntp"
)
func compareTimeWithNTPServer(ntpServer string) (time.Duration, time.Duration, error) {
startTime := time.Now()
// Get the current time from the NTP server
ntpTime, err := ntp.Time(ntpServer)
if err != nil {
return 0, 0, err
}
endTime := time.Now()
// Calculate the round-trip request time
requestTime := endTime.Sub(startTime)
// Calculate the difference between system time and NTP server time
timeDifference := ntpTime.Sub(endTime)
return requestTime, timeDifference, nil
}
func main() {
ntpServer := "pool.ntp.org"
requestTime, timeDifference, err := compareTimeWithNTPServer(ntpServer)
if err != nil {
fmt.Println("Error comparing clocks:", err)
return
}
fmt.Println("Request Time:", requestTime)
fmt.Println("Difference between system time and NTP server time:", timeDifference)
}
In this example, we use the github.com/beevik/ntp library to interact with the NTP server and obtain the current time. Make sure to install this library by running the command go get github.com/beevik/ntp before running the code.
The compareTimeWithNTPServer function takes the NTP server name as a parameter and returns the round-trip request time (requestTime), the difference between system time and NTP server time (timeDifference), and any potential errors.
The text was updated successfully, but these errors were encountered:
Regularly, internal clock synchronization problems block transfers.
There should be a way to check if the time on the computer is the same as the NTP time before any tx, and warn user if time isn't sync.
Here is an example of a check proposed by ChatGPT:
In this example, we use the github.com/beevik/ntp library to interact with the NTP server and obtain the current time. Make sure to install this library by running the command go get github.com/beevik/ntp before running the code.
The compareTimeWithNTPServer function takes the NTP server name as a parameter and returns the round-trip request time (requestTime), the difference between system time and NTP server time (timeDifference), and any potential errors.
The text was updated successfully, but these errors were encountered: