mirror of
https://github.com/xcat2/confluent.git
synced 2024-11-28 20:39:40 +00:00
Increase precision of copernicus time
While it is going to be off by some number of milliseconds, it's better than being off by 250ms on average.
This commit is contained in:
parent
690c871d29
commit
6798e4e848
@ -173,7 +173,10 @@ def snoop(handler, byehandler=None, protocol=None, uuidlookup=None):
|
||||
node = uuidlookup(curruuid)
|
||||
if not node:
|
||||
break
|
||||
reply = 'HTTP/1.1 200 OK\r\nNODENAME: {0}\r\nCURRTIME: {1}\r\n'.format(node, int(time.time()))
|
||||
currtime = time.time()
|
||||
seconds = int(currtime)
|
||||
msecs = int(currtime * 1000 % 1000)
|
||||
reply = 'HTTP/1.1 200 OK\r\nNODENAME: {0}\r\nCURRTIME: {1}\r\nCURRMSECS: {2}\r\n'.format(node, seconds, msecs)
|
||||
if not isinstance(reply, bytes):
|
||||
reply = reply.encode('utf8')
|
||||
s.sendto(reply, peer)
|
||||
|
@ -77,6 +77,7 @@ int main(int argc, char* argv[]) {
|
||||
fd_set rfds;
|
||||
struct timeval tv;
|
||||
int settime = 0;
|
||||
int setusec = 500000;
|
||||
socklen_t dstsize, dst4size;
|
||||
dstsize = sizeof(dst);
|
||||
dst4size = sizeof(dst4);
|
||||
@ -167,6 +168,14 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
settime = strtol(nodename, NULL, 10);
|
||||
}
|
||||
if (nodenameidx = strstr(msg, "CURRMSECS: ")) {
|
||||
nodenameidx += 10;
|
||||
strncpy(nodename, nodenameidx, 1024);
|
||||
if (nodenameidx = strstr(nodename, "\r")) {
|
||||
nodenameidx[0] = 0;
|
||||
}
|
||||
setusec = strtol(nodename, NULL, 10) * 1000;
|
||||
}
|
||||
memset(msg, 0, 1024);
|
||||
inet_ntop(dst4.sin_family, &dst4.sin_addr, msg, dst4size);
|
||||
/* Take measure from printing out the same ip twice in a row */
|
||||
@ -198,6 +207,14 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
settime = strtol(nodename, NULL, 10);
|
||||
}
|
||||
if (nodenameidx = strstr(msg, "CURRMSECS: ")) {
|
||||
nodenameidx += 10;
|
||||
strncpy(nodename, nodenameidx, 1024);
|
||||
if (nodenameidx = strstr(nodename, "\r")) {
|
||||
nodenameidx[0] = 0;
|
||||
}
|
||||
setusec = strtol(nodename, NULL, 10) * 1000;
|
||||
}
|
||||
memset(msg, 0, 1024);
|
||||
inet_ntop(dst.sin6_family, &dst.sin6_addr, msg, dstsize);
|
||||
if (strncmp(last6msg, msg, 1024) != 0) {
|
||||
@ -213,10 +230,12 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
if (settime && argc > 1 && strcmp(argv[1], "-t") == 0) {
|
||||
tv.tv_sec = settime;
|
||||
tv.tv_usec = setusec;
|
||||
settimeofday(&tv, NULL);
|
||||
settime = 0;
|
||||
}
|
||||
tv.tv_sec = 0;
|
||||
tv.tv_usec = 500000;
|
||||
FD_SET(n4, &rfds);
|
||||
FD_SET(ns, &rfds);
|
||||
ifidx = select(FD_SETSIZE, &rfds, NULL, NULL, &tv);
|
||||
|
Loading…
Reference in New Issue
Block a user