{"action":"created","comment":{"url":"https://api.github.com/repos/ethereum/go-ethereum/pulls/comments/53463240","id":53463240,"diff_hunk":"@@ -369,20 +373,41 @@ func (t *udp) loop() {\n \t\t\t\t\t\tp.errc <- nil\n \t\t\t\t\t\tplist.Remove(el)\n \t\t\t\t\t}\n+\t\t\t\t\t// Reset the continuous timeout counter (time drift detection)\n+\t\t\t\t\tcontTimeouts = 0\n \t\t\t\t}\n \t\t\t}\n \t\t\tr.matched <- matched\n \n \t\tcase now := <-timeout.C:\n \t\t\tnextTimeout = nil\n+\n \t\t\t// Notify and remove callbacks whose deadline is in the past.\n \t\t\tfor el := plist.Front(); el != nil; el = el.Next() {\n \t\t\t\tp := el.Value.(*pending)\n \t\t\t\tif now.After(p.deadline) || now.Equal(p.deadline) {\n \t\t\t\t\tp.errc <- errTimeout\n \t\t\t\t\tplist.Remove(el)\n+\t\t\t\t\tcontTimeouts++\n \t\t\t\t}\n \t\t\t}\n+\t\t\t// If we've accumulated too many timeouts, do an NTP time sync check\n+\t\t\tif contTimeouts > ntpThreshold {\n+\t\t\t\tgo func() {\n+\t\t\t\t\tdrift, err := sntpDrift(3)\n+\t\t\t\t\tswitch {\n+\t\t\t\t\tcase err != nil:\n+\t\t\t\t\t\tglog.V(logger.Warn).Infof(\"No UDP connectivity, maybe blocked by firewall? (%v)\", err)","path":"p2p/discover/udp.go","position":57,"original_position":57,"commit_id":"c2066e0d5359429bb2839be431b25819a0348778","original_commit_id":"c2066e0d5359429bb2839be431b25819a0348778","user":{"login":"karalabe","id":129561,"avatar_url":"https://avatars.githubusercontent.com/u/129561?v=3","gravatar_id":"","url":"https://api.github.com/users/karalabe","html_url":"https://github.com/karalabe","followers_url":"https://api.github.com/users/karalabe/followers","following_url":"https://api.github.com/users/karalabe/following{/other_user}","gists_url":"https://api.github.com/users/karalabe/gists{/gist_id}","starred_url":"https://api.github.com/users/karalabe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/karalabe/subscriptions","organizations_url":"https://api.github.com/users/karalabe/orgs","repos_url":"https://api.github.com/users/karalabe/repos","events_url":"https://api.github.com/users/karalabe/events{/privacy}","received_events_url":"https://api.github.com/users/karalabe/received_events","type":"User","site_admin":false},"body":"K","created_at":"2016-02-19T14:00:16Z","updated_at":"2016-02-19T14:00:16Z","html_url":"https://github.com/ethereum/go-ethereum/pull/2218#discussion_r53463240","pull_request_url":"https://api.github.com/repos/ethereum/go-ethereum/pulls/2218","_links":{"self":{"href":"https://api.github.com/repos/ethereum/go-ethereum/pulls/comments/53463240"},"html":{"href":"https://github.com/ethereum/go-ethereum/pull/2218#discussion_r53463240"},"pull_request":{"href":"https://api.github.com/repos/ethereum/go-ethereum/pulls/2218"}}},"pull_request":{"url":"https://api.github.com/repos/ethereum/go-ethereum/pulls/2218","id":59400075,"html_url":"https://github.com/ethereum/go-ethereum/pull/2218","diff_url":"https://github.com/ethereum/go-ethereum/pull/2218.diff","patch_url":"https://github.com/ethereum/go-ethereum/pull/2218.patch","issue_url":"https://api.github.com/repos/ethereum/go-ethereum/issues/2218","number":2218,"state":"open","locked":false,"title":"p2p/discover: NTP sanity check clock drift in case of expirations","user":{"login":"karalabe","id":129561,"avatar_url":"https://avatars.githubusercontent.com/u/129561?v=3","gravatar_id":"","url":"https://api.github.com/users/karalabe","html_url":"https://github.com/karalabe","followers_url":"https://api.github.com/users/karalabe/followers","following_url":"https://api.github.com/users/karalabe/following{/other_user}","gists_url":"https://api.github.com/users/karalabe/gists{/gist_id}","starred_url":"https://api.github.com/users/karalabe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/karalabe/subscriptions","organizations_url":"https://api.github.com/users/karalabe/orgs","repos_url":"https://api.github.com/users/karalabe/repos","events_url":"https://api.github.com/users/karalabe/events{/privacy}","received_events_url":"https://api.github.com/users/karalabe/received_events","type":"User","site_admin":false},"body":"**Please discuss this PR, don't simply review. I'd like to know your opinions + how to do this properly if we go down this path. The current code is a POC, not necessarily ready for merge.**\r\n\r\nThis is a short term solution to the time sync problem. It connects to the official `ntp.org` servers and polls them 3 times to measure the current time drift. If it's larger than 10 seconds, it displays a warning to the user. No time modification is done, just a warning message.\r\n\r\nLonger term we need a more sophisticated solution, but that's not so trivial due to potentially introducing replay attacks on the discovery protocol allowing bad peers to try and divert traffic from good ones.\r\n\r\nIn sync:\r\n\r\n```\r\nI0215 20:31:25.704154 cmd/geth/main.go:522] measured time drift: 13.443277ms\r\n```\r\n\r\nClock in the past:\r\n\r\n```\r\nI0215 20:29:07.088299 cmd/geth/main.go:522] measured time drift: 1m10.177685159s\r\n\r\n\r\nWarning: Your machine's clock seems to be set incorrectly.\r\nMeasured time drift from atomic servers is 1m10.177685159s.\r\nPlease enable automatic clock synchronization.\r\n```\r\n\r\nClock in the future:\r\n\r\n```\r\nI0215 20:31:35.889457 cmd/geth/main.go:522] measured time drift: -44.518441216s\r\n\r\n\r\nWarning: Your machine's clock seems to be set incorrectly.\r\nMeasured time drift from atomic servers is -44.518441216s.\r\nPlease enable automatic clock synchronization.\r\n```","created_at":"2016-02-15T18:36:47Z","updated_at":"2016-02-19T14:00:16Z","closed_at":null,"merged_at":null,"merge_commit_sha":"2c397fc35a899f80af25406fa50ea5caa5afd1f3","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ethereum/go-ethereum/pulls/2218/commits","review_comments_url":"https://api.github.com/repos/ethereum/go-ethereum/pulls/2218/comments","review_comment_url":"https://api.github.com/repos/ethereum/go-ethereum/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ethereum/go-ethereum/issues/2218/comments","statuses_url":"https://api.github.com/repos/ethereum/go-ethereum/statuses/c2066e0d5359429bb2839be431b25819a0348778","head":{"label":"karalabe:time-drift-warning","ref":"time-drift-warning","sha":"c2066e0d5359429bb2839be431b25819a0348778","user":{"login":"karalabe","id":129561,"avatar_url":"https://avatars.githubusercontent.com/u/129561?v=3","gravatar_id":"","url":"https://api.github.com/users/karalabe","html_url":"https://github.com/karalabe","followers_url":"https://api.github.com/users/karalabe/followers","following_url":"https://api.github.com/users/karalabe/following{/other_user}","gists_url":"https://api.github.com/users/karalabe/gists{/gist_id}","starred_url":"https://api.github.com/users/karalabe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/karalabe/subscriptions","organizations_url":"https://api.github.com/users/karalabe/orgs","repos_url":"https://api.github.com/users/karalabe/repos","events_url":"https://api.github.com/users/karalabe/events{/privacy}","received_events_url":"https://api.github.com/users/karalabe/received_events","type":"User","site_admin":false},"repo":{"id":33668567,"name":"go-ethereum","full_name":"karalabe/go-ethereum","owner":{"login":"karalabe","id":129561,"avatar_url":"https://avatars.githubusercontent.com/u/129561?v=3","gravatar_id":"","url":"https://api.github.com/users/karalabe","html_url":"https://github.com/karalabe","followers_url":"https://api.github.com/users/karalabe/followers","following_url":"https://api.github.com/users/karalabe/following{/other_user}","gists_url":"https://api.github.com/users/karalabe/gists{/gist_id}","starred_url":"https://api.github.com/users/karalabe/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/karalabe/subscriptions","organizations_url":"https://api.github.com/users/karalabe/orgs","repos_url":"https://api.github.com/users/karalabe/repos","events_url":"https://api.github.com/users/karalabe/events{/privacy}","received_events_url":"https://api.github.com/users/karalabe/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/karalabe/go-ethereum","description":"Jeffrey Wilcke's Go implementation of the Ethereum y/w paper","fork":true,"url":"https://api.github.com/repos/karalabe/go-ethereum","forks_url":"https://api.github.com/repos/karalabe/go-ethereum/forks","keys_url":"https://api.github.com/repos/karalabe/go-ethereum/keys{/key_id}","collaborators_url":"https://api.github.com/repos/karalabe/go-ethereum/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/karalabe/go-ethereum/teams","hooks_url":"https://api.github.com/repos/karalabe/go-ethereum/hooks","issue_events_url":"https://api.github.com/repos/karalabe/go-ethereum/issues/events{/number}","events_url":"https://api.github.com/repos/karalabe/go-ethereum/events","assignees_url":"https://api.github.com/repos/karalabe/go-ethereum/assignees{/user}","branches_url":"https://api.github.com/repos/karalabe/go-ethereum/branches{/branch}","tags_url":"https://api.github.com/repos/karalabe/go-ethereum/tags","blobs_url":"https://api.github.com/repos/karalabe/go-ethereum/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/karalabe/go-ethereum/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/karalabe/go-ethereum/git/refs{/sha}","trees_url":"https://api.github.com/repos/karalabe/go-ethereum/git/trees{/sha}","statuses_url":"https://api.github.com/repos/karalabe/go-ethereum/statuses/{sha}","languages_url":"https://api.github.com/repos/karalabe/go-ethereum/languages","stargazers_url":"https://api.github.com/repos/karalabe/go-ethereum/stargazers","contributors_url":"https://api.github.com/repos/karalabe/go-ethereum/contributors","subscribers_url":"https://api.github.com/repos/karalabe/go-ethereum/subscribers","subscription_url":"https://api.github.com/repos/karalabe/go-ethereum/subscription","commits_url":"https://api.github.com/repos/karalabe/go-ethereum/commits{/sha}","git_commits_url":"https://api.github.com/repos/karalabe/go-ethereum/git/commits{/sha}","comments_url":"https://api.github.com/repos/karalabe/go-ethereum/comments{/number}","issue_comment_url":"https://api.github.com/repos/karalabe/go-ethereum/issues/comments{/number}","contents_url":"https://api.github.com/repos/karalabe/go-ethereum/contents/{+path}","compare_url":"https://api.github.com/repos/karalabe/go-ethereum/compare/{base}...{head}","merges_url":"https://api.github.com/repos/karalabe/go-ethereum/merges","archive_url":"https://api.github.com/repos/karalabe/go-ethereum/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/karalabe/go-ethereum/downloads","issues_url":"https://api.github.com/repos/karalabe/go-ethereum/issues{/number}","pulls_url":"https://api.github.com/repos/karalabe/go-ethereum/pulls{/number}","milestones_url":"https://api.github.com/repos/karalabe/go-ethereum/milestones{/number}","notifications_url":"https://api.github.com/repos/karalabe/go-ethereum/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/karalabe/go-ethereum/labels{/name}","releases_url":"https://api.github.com/repos/karalabe/go-ethereum/releases{/id}","deployments_url":"https://api.github.com/repos/karalabe/go-ethereum/deployments","created_at":"2015-04-09T12:51:45Z","updated_at":"2015-04-17T13:40:48Z","pushed_at":"2016-02-19T12:48:49Z","git_url":"git://github.com/karalabe/go-ethereum.git","ssh_url":"git@github.com:karalabe/go-ethereum.git","clone_url":"https://github.com/karalabe/go-ethereum.git","svn_url":"https://github.com/karalabe/go-ethereum","homepage":"","size":52509,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"develop"}},"base":{"label":"ethereum:develop","ref":"develop","sha":"aa36a6ae4f24f07e2c470a21c93ff37ad5861982","user":{"login":"ethereum","id":6250754,"avatar_url":"https://avatars.githubusercontent.com/u/6250754?v=3","gravatar_id":"","url":"https://api.github.com/users/ethereum","html_url":"https://github.com/ethereum","followers_url":"https://api.github.com/users/ethereum/followers","following_url":"https://api.github.com/users/ethereum/following{/other_user}","gists_url":"https://api.github.com/users/ethereum/gists{/gist_id}","starred_url":"https://api.github.com/users/ethereum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ethereum/subscriptions","organizations_url":"https://api.github.com/users/ethereum/orgs","repos_url":"https://api.github.com/users/ethereum/repos","events_url":"https://api.github.com/users/ethereum/events{/privacy}","received_events_url":"https://api.github.com/users/ethereum/received_events","type":"Organization","site_admin":false},"repo":{"id":15452919,"name":"go-ethereum","full_name":"ethereum/go-ethereum","owner":{"login":"ethereum","id":6250754,"avatar_url":"https://avatars.githubusercontent.com/u/6250754?v=3","gravatar_id":"","url":"https://api.github.com/users/ethereum","html_url":"https://github.com/ethereum","followers_url":"https://api.github.com/users/ethereum/followers","following_url":"https://api.github.com/users/ethereum/following{/other_user}","gists_url":"https://api.github.com/users/ethereum/gists{/gist_id}","starred_url":"https://api.github.com/users/ethereum/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ethereum/subscriptions","organizations_url":"https://api.github.com/users/ethereum/orgs","repos_url":"https://api.github.com/users/ethereum/repos","events_url":"https://api.github.com/users/ethereum/events{/privacy}","received_events_url":"https://api.github.com/users/ethereum/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ethereum/go-ethereum","description":"Official golang implementation of the Ethereum protocol","fork":false,"url":"https://api.github.com/repos/ethereum/go-ethereum","forks_url":"https://api.github.com/repos/ethereum/go-ethereum/forks","keys_url":"https://api.github.com/repos/ethereum/go-ethereum/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ethereum/go-ethereum/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ethereum/go-ethereum/teams","hooks_url":"https://api.github.com/repos/ethereum/go-ethereum/hooks","issue_events_url":"https://api.github.com/repos/ethereum/go-ethereum/issues/events{/number}","events_url":"https://api.github.com/repos/ethereum/go-ethereum/events","assignees_url":"https://api.github.com/repos/ethereum/go-ethereum/assignees{/user}","branches_url":"https://api.github.com/repos/ethereum/go-ethereum/branches{/branch}","tags_url":"https://api.github.com/repos/ethereum/go-ethereum/tags","blobs_url":"https://api.github.com/repos/ethereum/go-ethereum/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ethereum/go-ethereum/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ethereum/go-ethereum/git/refs{/sha}","trees_url":"https://api.github.com/repos/ethereum/go-ethereum/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ethereum/go-ethereum/statuses/{sha}","languages_url":"https://api.github.com/repos/ethereum/go-ethereum/languages","stargazers_url":"https://api.github.com/repos/ethereum/go-ethereum/stargazers","contributors_url":"https://api.github.com/repos/ethereum/go-ethereum/contributors","subscribers_url":"https://api.github.com/repos/ethereum/go-ethereum/subscribers","subscription_url":"https://api.github.com/repos/ethereum/go-ethereum/subscription","commits_url":"https://api.github.com/repos/ethereum/go-ethereum/commits{/sha}","git_commits_url":"https://api.github.com/repos/ethereum/go-ethereum/git/commits{/sha}","comments_url":"https://api.github.com/repos/ethereum/go-ethereum/comments{/number}","issue_comment_url":"https://api.github.com/repos/ethereum/go-ethereum/issues/comments{/number}","contents_url":"https://api.github.com/repos/ethereum/go-ethereum/contents/{+path}","compare_url":"https://api.github.com/repos/ethereum/go-ethereum/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ethereum/go-ethereum/merges","archive_url":"https://api.github.com/repos/ethereum/go-ethereum/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ethereum/go-ethereum/downloads","issues_url":"https://api.github.com/repos/ethereum/go-ethereum/issues{/number}","pulls_url":"https://api.github.com/repos/ethereum/go-ethereum/pulls{/number}","milestones_url":"https://api.github.com/repos/ethereum/go-ethereum/milestones{/number}","notifications_url":"https://api.github.com/repos/ethereum/go-ethereum/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ethereum/go-ethereum/labels{/name}","releases_url":"https://api.github.com/repos/ethereum/go-ethereum/releases{/id}","deployments_url":"https://api.github.com/repos/ethereum/go-ethereum/deployments","created_at":"2013-12-26T13:05:46Z","updated_at":"2016-02-19T12:38:37Z","pushed_at":"2016-02-19T13:41:58Z","git_url":"git://github.com/ethereum/go-ethereum.git","ssh_url":"git@github.com:ethereum/go-ethereum.git","clone_url":"https://github.com/ethereum/go-ethereum.git","svn_url":"https://github.com/ethereum/go-ethereum","homepage":"http://ethereum.github.io/go-ethereum/","size":67705,"stargazers_count":970,"watchers_count":970,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":335,"mirror_url":null,"open_issues_count":166,"forks":335,"open_issues":166,"watchers":970,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ethereum/go-ethereum/pulls/2218"},"html":{"href":"https://github.com/ethereum/go-ethereum/pull/2218"},"issue":{"href":"https://api.github.com/repos/ethereum/go-ethereum/issues/2218"},"comments":{"href":"https://api.github.com/repos/ethereum/go-ethereum/issues/2218/comments"},"review_comments":{"href":"https://api.github.com/repos/ethereum/go-ethereum/pulls/2218/comments"},"review_comment":{"href":"https://api.github.com/repos/ethereum/go-ethereum/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ethereum/go-ethereum/pulls/2218/commits"},"statuses":{"href":"https://api.github.com/repos/ethereum/go-ethereum/statuses/c2066e0d5359429bb2839be431b25819a0348778"}}}}