{"action":"created","comment":{"url":"https://api.github.com/repos/bitcoin/bitcoin/pulls/comments/33354739","id":33354739,"diff_hunk":"@@ -2107,3 +2173,119 @@ void CNode::EndMessage() UNLOCK_FUNCTION(cs_vSend)\n \n     LEAVE_CRITICAL_SECTION(cs_vSend);\n }\n+\n+//\n+// CBanDB\n+//\n+\n+CBanDB::CBanDB()\n+{\n+    pathBanlist = GetDataDir() / \"banlist.dat\";\n+}\n+\n+bool CBanDB::Write(const std::map<CSubNet, int64_t>& banSet)\n+{\n+    // Generate random temporary filename\n+    unsigned short randv = 0;\n+    GetRandBytes((unsigned char*)&randv, sizeof(randv));\n+    std::string tmpfn = strprintf(\"banlist.dat.%04x\", randv);\n+\n+    // serialize banlist, checksum data up to that point, then append csum\n+    CDataStream ssBanlist(SER_DISK, CLIENT_VERSION);\n+    ssBanlist << FLATDATA(Params().MessageStart());\n+    ssBanlist << banSet;\n+    uint256 hash = Hash(ssBanlist.begin(), ssBanlist.end());\n+    ssBanlist << hash;\n+\n+    // open temp output file, and associate with CAutoFile\n+    boost::filesystem::path pathTmp = GetDataDir() / tmpfn;\n+    FILE *file = fopen(pathTmp.string().c_str(), \"wb\");\n+    CAutoFile fileout(file, SER_DISK, CLIENT_VERSION);\n+    if (fileout.IsNull())\n+        return error(\"%s: Failed to open file %s\", __func__, pathTmp.string());\n+\n+    // Write and commit header, data\n+    try {\n+        fileout << ssBanlist;\n+    }\n+    catch (const std::exception& e) {\n+        return error(\"%s: Serialize or I/O error - %s\", __func__, e.what());\n+    }\n+    FileCommit(fileout.Get());\n+    fileout.fclose();\n+\n+    // replace existing banlist.dat, if any, with new banlist.dat.XXXX\n+    if (!RenameOver(pathTmp, pathBanlist))\n+        return error(\"%s: Rename-into-place failed\", __func__);\n+\n+    return true;\n+}\n+\n+bool CBanDB::Read(std::map<CSubNet, int64_t>& banSet)\n+{\n+    // open input file, and associate with CAutoFile\n+    FILE *file = fopen(pathBanlist.string().c_str(), \"rb\");\n+    CAutoFile filein(file, SER_DISK, CLIENT_VERSION);\n+    if (filein.IsNull())\n+        return error(\"%s: Failed to open file %s\", __func__, pathBanlist.string());\n+\n+    // use file size to size memory buffer\n+    int fileSize = boost::filesystem::file_size(pathBanlist);","path":"src/net.cpp","position":null,"original_position":193,"commit_id":"1fe466170443857196462e704bb07f0dab719989","original_commit_id":"9c4b16b843c25d9741cbae5a7ec9e6ac11fbd846","user":{"login":"jonasschnelli","id":178464,"avatar_url":"https://avatars.githubusercontent.com/u/178464?v=3","gravatar_id":"","url":"https://api.github.com/users/jonasschnelli","html_url":"https://github.com/jonasschnelli","followers_url":"https://api.github.com/users/jonasschnelli/followers","following_url":"https://api.github.com/users/jonasschnelli/following{/other_user}","gists_url":"https://api.github.com/users/jonasschnelli/gists{/gist_id}","starred_url":"https://api.github.com/users/jonasschnelli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jonasschnelli/subscriptions","organizations_url":"https://api.github.com/users/jonasschnelli/orgs","repos_url":"https://api.github.com/users/jonasschnelli/repos","events_url":"https://api.github.com/users/jonasschnelli/events{/privacy}","received_events_url":"https://api.github.com/users/jonasschnelli/received_events","type":"User","site_admin":false},"body":"Agreed. Changed from `int` to `uint64_t` (also in `CAddDB`).","created_at":"2015-06-26T13:22:34Z","updated_at":"2015-06-26T13:22:34Z","html_url":"https://github.com/bitcoin/bitcoin/pull/6310#discussion_r33354739","pull_request_url":"https://api.github.com/repos/bitcoin/bitcoin/pulls/6310","_links":{"self":{"href":"https://api.github.com/repos/bitcoin/bitcoin/pulls/comments/33354739"},"html":{"href":"https://github.com/bitcoin/bitcoin/pull/6310#discussion_r33354739"},"pull_request":{"href":"https://api.github.com/repos/bitcoin/bitcoin/pulls/6310"}}},"pull_request":{"url":"https://api.github.com/repos/bitcoin/bitcoin/pulls/6310","id":38121127,"html_url":"https://github.com/bitcoin/bitcoin/pull/6310","diff_url":"https://github.com/bitcoin/bitcoin/pull/6310.diff","patch_url":"https://github.com/bitcoin/bitcoin/pull/6310.patch","issue_url":"https://api.github.com/repos/bitcoin/bitcoin/issues/6310","number":6310,"state":"open","locked":false,"title":"banlist.dat: store banlist on disk","user":{"login":"jonasschnelli","id":178464,"avatar_url":"https://avatars.githubusercontent.com/u/178464?v=3","gravatar_id":"","url":"https://api.github.com/users/jonasschnelli","html_url":"https://github.com/jonasschnelli","followers_url":"https://api.github.com/users/jonasschnelli/followers","following_url":"https://api.github.com/users/jonasschnelli/following{/other_user}","gists_url":"https://api.github.com/users/jonasschnelli/gists{/gist_id}","starred_url":"https://api.github.com/users/jonasschnelli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jonasschnelli/subscriptions","organizations_url":"https://api.github.com/users/jonasschnelli/orgs","repos_url":"https://api.github.com/users/jonasschnelli/repos","events_url":"https://api.github.com/users/jonasschnelli/events{/privacy}","received_events_url":"https://api.github.com/users/jonasschnelli/received_events","type":"User","site_admin":false},"body":"Currently, the list of banned nodes are only held in memory. A restart of bitcoind would reset the set of banned nodes.\r\n\r\nThis PR introduces a new filestore (`banlist.dat`) which stores the IPs/Subnets of the banned nodes more or less identical to the CAddrDB (`peers.dat`).\r\n\r\nAlso added within this PR is a feature that removes unused banned node entries because the `banned_till` time has expired.\r\n\r\nincludes tests for the banlist disk storage.\r\n\r\nUnsure if we should introduce a new cmd arg `-storebanlist` to optionally allow storing of banned node data. It could be, that some users expecting a sweep of all banned nodes when they restart bitcoind.","created_at":"2015-06-19T15:50:55Z","updated_at":"2015-06-26T13:22:34Z","closed_at":null,"merged_at":null,"merge_commit_sha":"14237d858b5471466e060083a68c9d7f40c39b72","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/bitcoin/bitcoin/pulls/6310/commits","review_comments_url":"https://api.github.com/repos/bitcoin/bitcoin/pulls/6310/comments","review_comment_url":"https://api.github.com/repos/bitcoin/bitcoin/pulls/comments{/number}","comments_url":"https://api.github.com/repos/bitcoin/bitcoin/issues/6310/comments","statuses_url":"https://api.github.com/repos/bitcoin/bitcoin/statuses/1fe466170443857196462e704bb07f0dab719989","head":{"label":"jonasschnelli:2015/06/store_ban_list","ref":"2015/06/store_ban_list","sha":"1fe466170443857196462e704bb07f0dab719989","user":{"login":"jonasschnelli","id":178464,"avatar_url":"https://avatars.githubusercontent.com/u/178464?v=3","gravatar_id":"","url":"https://api.github.com/users/jonasschnelli","html_url":"https://github.com/jonasschnelli","followers_url":"https://api.github.com/users/jonasschnelli/followers","following_url":"https://api.github.com/users/jonasschnelli/following{/other_user}","gists_url":"https://api.github.com/users/jonasschnelli/gists{/gist_id}","starred_url":"https://api.github.com/users/jonasschnelli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jonasschnelli/subscriptions","organizations_url":"https://api.github.com/users/jonasschnelli/orgs","repos_url":"https://api.github.com/users/jonasschnelli/repos","events_url":"https://api.github.com/users/jonasschnelli/events{/privacy}","received_events_url":"https://api.github.com/users/jonasschnelli/received_events","type":"User","site_admin":false},"repo":{"id":9264454,"name":"bitcoin","full_name":"jonasschnelli/bitcoin","owner":{"login":"jonasschnelli","id":178464,"avatar_url":"https://avatars.githubusercontent.com/u/178464?v=3","gravatar_id":"","url":"https://api.github.com/users/jonasschnelli","html_url":"https://github.com/jonasschnelli","followers_url":"https://api.github.com/users/jonasschnelli/followers","following_url":"https://api.github.com/users/jonasschnelli/following{/other_user}","gists_url":"https://api.github.com/users/jonasschnelli/gists{/gist_id}","starred_url":"https://api.github.com/users/jonasschnelli/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jonasschnelli/subscriptions","organizations_url":"https://api.github.com/users/jonasschnelli/orgs","repos_url":"https://api.github.com/users/jonasschnelli/repos","events_url":"https://api.github.com/users/jonasschnelli/events{/privacy}","received_events_url":"https://api.github.com/users/jonasschnelli/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/jonasschnelli/bitcoin","description":"Bitcoin integration/staging tree","fork":true,"url":"https://api.github.com/repos/jonasschnelli/bitcoin","forks_url":"https://api.github.com/repos/jonasschnelli/bitcoin/forks","keys_url":"https://api.github.com/repos/jonasschnelli/bitcoin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jonasschnelli/bitcoin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jonasschnelli/bitcoin/teams","hooks_url":"https://api.github.com/repos/jonasschnelli/bitcoin/hooks","issue_events_url":"https://api.github.com/repos/jonasschnelli/bitcoin/issues/events{/number}","events_url":"https://api.github.com/repos/jonasschnelli/bitcoin/events","assignees_url":"https://api.github.com/repos/jonasschnelli/bitcoin/assignees{/user}","branches_url":"https://api.github.com/repos/jonasschnelli/bitcoin/branches{/branch}","tags_url":"https://api.github.com/repos/jonasschnelli/bitcoin/tags","blobs_url":"https://api.github.com/repos/jonasschnelli/bitcoin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jonasschnelli/bitcoin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jonasschnelli/bitcoin/git/refs{/sha}","trees_url":"https://api.github.com/repos/jonasschnelli/bitcoin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jonasschnelli/bitcoin/statuses/{sha}","languages_url":"https://api.github.com/repos/jonasschnelli/bitcoin/languages","stargazers_url":"https://api.github.com/repos/jonasschnelli/bitcoin/stargazers","contributors_url":"https://api.github.com/repos/jonasschnelli/bitcoin/contributors","subscribers_url":"https://api.github.com/repos/jonasschnelli/bitcoin/subscribers","subscription_url":"https://api.github.com/repos/jonasschnelli/bitcoin/subscription","commits_url":"https://api.github.com/repos/jonasschnelli/bitcoin/commits{/sha}","git_commits_url":"https://api.github.com/repos/jonasschnelli/bitcoin/git/commits{/sha}","comments_url":"https://api.github.com/repos/jonasschnelli/bitcoin/comments{/number}","issue_comment_url":"https://api.github.com/repos/jonasschnelli/bitcoin/issues/comments{/number}","contents_url":"https://api.github.com/repos/jonasschnelli/bitcoin/contents/{+path}","compare_url":"https://api.github.com/repos/jonasschnelli/bitcoin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jonasschnelli/bitcoin/merges","archive_url":"https://api.github.com/repos/jonasschnelli/bitcoin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jonasschnelli/bitcoin/downloads","issues_url":"https://api.github.com/repos/jonasschnelli/bitcoin/issues{/number}","pulls_url":"https://api.github.com/repos/jonasschnelli/bitcoin/pulls{/number}","milestones_url":"https://api.github.com/repos/jonasschnelli/bitcoin/milestones{/number}","notifications_url":"https://api.github.com/repos/jonasschnelli/bitcoin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jonasschnelli/bitcoin/labels{/name}","releases_url":"https://api.github.com/repos/jonasschnelli/bitcoin/releases{/id}","created_at":"2013-04-06T18:21:51Z","updated_at":"2015-04-28T12:20:21Z","pushed_at":"2015-06-26T13:22:06Z","git_url":"git://github.com/jonasschnelli/bitcoin.git","ssh_url":"git@github.com:jonasschnelli/bitcoin.git","clone_url":"https://github.com/jonasschnelli/bitcoin.git","svn_url":"https://github.com/jonasschnelli/bitcoin","homepage":"http://www.bitcoin.org","size":56260,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":true,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":2,"forks":0,"open_issues":2,"watchers":0,"default_branch":"master"}},"base":{"label":"bitcoin:master","ref":"master","sha":"41076aad0cbdfa4c4cf376e345114a5c29086f81","user":{"login":"bitcoin","id":528860,"avatar_url":"https://avatars.githubusercontent.com/u/528860?v=3","gravatar_id":"","url":"https://api.github.com/users/bitcoin","html_url":"https://github.com/bitcoin","followers_url":"https://api.github.com/users/bitcoin/followers","following_url":"https://api.github.com/users/bitcoin/following{/other_user}","gists_url":"https://api.github.com/users/bitcoin/gists{/gist_id}","starred_url":"https://api.github.com/users/bitcoin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bitcoin/subscriptions","organizations_url":"https://api.github.com/users/bitcoin/orgs","repos_url":"https://api.github.com/users/bitcoin/repos","events_url":"https://api.github.com/users/bitcoin/events{/privacy}","received_events_url":"https://api.github.com/users/bitcoin/received_events","type":"Organization","site_admin":false},"repo":{"id":1181927,"name":"bitcoin","full_name":"bitcoin/bitcoin","owner":{"login":"bitcoin","id":528860,"avatar_url":"https://avatars.githubusercontent.com/u/528860?v=3","gravatar_id":"","url":"https://api.github.com/users/bitcoin","html_url":"https://github.com/bitcoin","followers_url":"https://api.github.com/users/bitcoin/followers","following_url":"https://api.github.com/users/bitcoin/following{/other_user}","gists_url":"https://api.github.com/users/bitcoin/gists{/gist_id}","starred_url":"https://api.github.com/users/bitcoin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bitcoin/subscriptions","organizations_url":"https://api.github.com/users/bitcoin/orgs","repos_url":"https://api.github.com/users/bitcoin/repos","events_url":"https://api.github.com/users/bitcoin/events{/privacy}","received_events_url":"https://api.github.com/users/bitcoin/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/bitcoin/bitcoin","description":"Bitcoin Core integration/staging tree","fork":false,"url":"https://api.github.com/repos/bitcoin/bitcoin","forks_url":"https://api.github.com/repos/bitcoin/bitcoin/forks","keys_url":"https://api.github.com/repos/bitcoin/bitcoin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/bitcoin/bitcoin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/bitcoin/bitcoin/teams","hooks_url":"https://api.github.com/repos/bitcoin/bitcoin/hooks","issue_events_url":"https://api.github.com/repos/bitcoin/bitcoin/issues/events{/number}","events_url":"https://api.github.com/repos/bitcoin/bitcoin/events","assignees_url":"https://api.github.com/repos/bitcoin/bitcoin/assignees{/user}","branches_url":"https://api.github.com/repos/bitcoin/bitcoin/branches{/branch}","tags_url":"https://api.github.com/repos/bitcoin/bitcoin/tags","blobs_url":"https://api.github.com/repos/bitcoin/bitcoin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/bitcoin/bitcoin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/bitcoin/bitcoin/git/refs{/sha}","trees_url":"https://api.github.com/repos/bitcoin/bitcoin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/bitcoin/bitcoin/statuses/{sha}","languages_url":"https://api.github.com/repos/bitcoin/bitcoin/languages","stargazers_url":"https://api.github.com/repos/bitcoin/bitcoin/stargazers","contributors_url":"https://api.github.com/repos/bitcoin/bitcoin/contributors","subscribers_url":"https://api.github.com/repos/bitcoin/bitcoin/subscribers","subscription_url":"https://api.github.com/repos/bitcoin/bitcoin/subscription","commits_url":"https://api.github.com/repos/bitcoin/bitcoin/commits{/sha}","git_commits_url":"https://api.github.com/repos/bitcoin/bitcoin/git/commits{/sha}","comments_url":"https://api.github.com/repos/bitcoin/bitcoin/comments{/number}","issue_comment_url":"https://api.github.com/repos/bitcoin/bitcoin/issues/comments{/number}","contents_url":"https://api.github.com/repos/bitcoin/bitcoin/contents/{+path}","compare_url":"https://api.github.com/repos/bitcoin/bitcoin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/bitcoin/bitcoin/merges","archive_url":"https://api.github.com/repos/bitcoin/bitcoin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/bitcoin/bitcoin/downloads","issues_url":"https://api.github.com/repos/bitcoin/bitcoin/issues{/number}","pulls_url":"https://api.github.com/repos/bitcoin/bitcoin/pulls{/number}","milestones_url":"https://api.github.com/repos/bitcoin/bitcoin/milestones{/number}","notifications_url":"https://api.github.com/repos/bitcoin/bitcoin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/bitcoin/bitcoin/labels{/name}","releases_url":"https://api.github.com/repos/bitcoin/bitcoin/releases{/id}","created_at":"2010-12-19T15:16:43Z","updated_at":"2015-06-26T03:35:21Z","pushed_at":"2015-06-26T13:22:10Z","git_url":"git://github.com/bitcoin/bitcoin.git","ssh_url":"git@github.com:bitcoin/bitcoin.git","clone_url":"https://github.com/bitcoin/bitcoin.git","svn_url":"https://github.com/bitcoin/bitcoin","homepage":"https://bitcoin.org/en/download","size":130194,"stargazers_count":7061,"watchers_count":7061,"language":"C++","has_issues":true,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":4924,"mirror_url":null,"open_issues_count":426,"forks":4924,"open_issues":426,"watchers":7061,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/bitcoin/bitcoin/pulls/6310"},"html":{"href":"https://github.com/bitcoin/bitcoin/pull/6310"},"issue":{"href":"https://api.github.com/repos/bitcoin/bitcoin/issues/6310"},"comments":{"href":"https://api.github.com/repos/bitcoin/bitcoin/issues/6310/comments"},"review_comments":{"href":"https://api.github.com/repos/bitcoin/bitcoin/pulls/6310/comments"},"review_comment":{"href":"https://api.github.com/repos/bitcoin/bitcoin/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/bitcoin/bitcoin/pulls/6310/commits"},"statuses":{"href":"https://api.github.com/repos/bitcoin/bitcoin/statuses/1fe466170443857196462e704bb07f0dab719989"}}}}