{"action":"created","comment":{"url":"https://api.github.com/repos/google/gopacket/pulls/comments/92000001","pull_request_review_id":12509612,"id":92000001,"diff_hunk":"@@ -0,0 +1,251 @@\n+// Copyright 2012 Google, Inc. All rights reserved.\n+//\n+// Use of this source code is governed by a BSD-style license\n+// that can be found in the LICENSE file in the root of the source\n+// tree.\n+\n+package reassembly\n+\n+import (\n+\t\"flag\"\n+\t\"fmt\"\n+\t\"log\"\n+\t\"sync\"\n+\t\"time\"\n+\n+\t\"github.com/google/gopacket/layers\"\n+)\n+\n+var memLog = flag.Bool(\"assembly_memuse_log\", defaultDebug, \"If true, the github.com/google/gopacket/reassembly library will log information regarding its memory use every once in a while.\")\n+\n+/*\n+ * pageCache\n+ */\n+// pageCache is a concurrency-unsafe store of page objects we use to avoid\n+// memory allocation as much as we can.\n+type pageCache struct {\n+\tfree         []*page\n+\tpcSize       int\n+\tsize, used   int\n+\tpageRequests int64\n+\tops          int\n+\tnextShrink   int\n+}\n+\n+const initialAllocSize = 1024\n+\n+func newPageCache() *pageCache {\n+\tpc := &pageCache{\n+\t\tfree:   make([]*page, 0, initialAllocSize),\n+\t\tpcSize: initialAllocSize,\n+\t}\n+\tpc.grow()\n+\treturn pc\n+}\n+\n+// grow exponentially increases the size of our page cache as much as necessary.\n+func (c *pageCache) grow() {\n+\tpages := make([]page, c.pcSize)\n+\tc.size += c.pcSize\n+\tfor i := range pages {\n+\t\tc.free = append(c.free, &pages[i])\n+\t}\n+\tif *memLog {\n+\t\tlog.Println(\"PageCache: created\", c.pcSize, \"new pages, size:\", c.size, \"cap:\", cap(c.free), \"len:\", len(c.free))\n+\t}\n+\t// control next shrink attempt\n+\tc.nextShrink = c.pcSize\n+\tc.ops = 0\n+\t// prepare for next alloc\n+\tc.pcSize *= 2\n+}\n+\n+// Remove references to unused pages to let GC collect them\n+// Note: memory used by c.free itself it not collected.\n+func (c *pageCache) tryShrink() {\n+\tvar min = c.pcSize / 2\n+\tif min < initialAllocSize {\n+\t\tmin = initialAllocSize\n+\t}\n+\tif len(c.free) <= min {\n+\t\treturn\n+\t}\n+\tfor i := range c.free[min:] {\n+\t\tc.free[min+i] = nil\n+\t}\n+\tc.size -= len(c.free) - min\n+\tc.free = c.free[:min]\n+\tc.pcSize = min\n+}\n+\n+// next returns a clean, ready-to-use page object.\n+func (c *pageCache) next(ts time.Time) (p *page) {\n+\tif *memLog {\n+\t\tc.pageRequests++\n+\t\tif c.pageRequests&0xFFFF == 0 {\n+\t\t\tlog.Println(\"PageCache:\", c.pageRequests, \"requested,\", c.used, \"used,\", len(c.free), \"free\")\n+\t\t}\n+\t}\n+\tif len(c.free) == 0 {\n+\t\tc.grow()\n+\t}\n+\ti := len(c.free) - 1\n+\tp, c.free = c.free[i], c.free[:i]\n+\tp.prev = nil","path":"reassembly/memory.go","position":null,"original_position":94,"commit_id":"776f59d118e73306b436fa721e3892daa5ce8ca0","original_commit_id":"c1a7fb7e2b531d7da297df9730026b9229c8e2f5","user":{"login":"sentryo","id":11715226,"avatar_url":"https://avatars.githubusercontent.com/u/11715226?v=3","gravatar_id":"","url":"https://api.github.com/users/sentryo","html_url":"https://github.com/sentryo","followers_url":"https://api.github.com/users/sentryo/followers","following_url":"https://api.github.com/users/sentryo/following{/other_user}","gists_url":"https://api.github.com/users/sentryo/gists{/gist_id}","starred_url":"https://api.github.com/users/sentryo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sentryo/subscriptions","organizations_url":"https://api.github.com/users/sentryo/orgs","repos_url":"https://api.github.com/users/sentryo/repos","events_url":"https://api.github.com/users/sentryo/events{/privacy}","received_events_url":"https://api.github.com/users/sentryo/received_events","type":"User","site_admin":false},"body":"Done.","created_at":"2016-12-12T17:47:05Z","updated_at":"2016-12-12T17:47:05Z","html_url":"https://github.com/google/gopacket/pull/116#discussion_r92000001","pull_request_url":"https://api.github.com/repos/google/gopacket/pulls/116","_links":{"self":{"href":"https://api.github.com/repos/google/gopacket/pulls/comments/92000001"},"html":{"href":"https://github.com/google/gopacket/pull/116#discussion_r92000001"},"pull_request":{"href":"https://api.github.com/repos/google/gopacket/pulls/116"}}},"pull_request":{"url":"https://api.github.com/repos/google/gopacket/pulls/116","id":43888190,"html_url":"https://github.com/google/gopacket/pull/116","diff_url":"https://github.com/google/gopacket/pull/116.diff","patch_url":"https://github.com/google/gopacket/pull/116.patch","issue_url":"https://api.github.com/repos/google/gopacket/issues/116","number":116,"state":"open","locked":false,"title":"[RFC] Add new reassembly package and accompanying reassemblydump example","user":{"login":"sentryo","id":11715226,"avatar_url":"https://avatars.githubusercontent.com/u/11715226?v=3","gravatar_id":"","url":"https://api.github.com/users/sentryo","html_url":"https://github.com/sentryo","followers_url":"https://api.github.com/users/sentryo/followers","following_url":"https://api.github.com/users/sentryo/following{/other_user}","gists_url":"https://api.github.com/users/sentryo/gists{/gist_id}","starred_url":"https://api.github.com/users/sentryo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sentryo/subscriptions","organizations_url":"https://api.github.com/users/sentryo/orgs","repos_url":"https://api.github.com/users/sentryo/repos","events_url":"https://api.github.com/users/sentryo/events{/privacy}","received_events_url":"https://api.github.com/users/sentryo/received_events","type":"User","site_admin":false},"body":"This is the current state of our new reassembly package which does full\n(IPv4 and TCP) bidirectional reassembly, implements a TCP state machine\nand various security checks on TCP traffic. It is based on the existing\ntcpassembly package. A new reassemblydump program is provided which uses\nthe reassembly package, with support for DNS and HTTP reassembly.\n\nThe code is probably not fit for merging as-is, however all comments and\nfeedback are welcome at this stage.\n\nThe old tcpassembly package and its example programs are removed as the\nreassemblydump tool supersedes them.\n","created_at":"2015-09-01T15:16:46Z","updated_at":"2016-12-12T17:47:05Z","closed_at":null,"merged_at":null,"merge_commit_sha":"90d116fc3905c0d5b1e485bda9002cc6da9a0df7","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/google/gopacket/pulls/116/commits","review_comments_url":"https://api.github.com/repos/google/gopacket/pulls/116/comments","review_comment_url":"https://api.github.com/repos/google/gopacket/pulls/comments{/number}","comments_url":"https://api.github.com/repos/google/gopacket/issues/116/comments","statuses_url":"https://api.github.com/repos/google/gopacket/statuses/776f59d118e73306b436fa721e3892daa5ce8ca0","head":{"label":"sentryo:reassembly","ref":"reassembly","sha":"776f59d118e73306b436fa721e3892daa5ce8ca0","user":{"login":"sentryo","id":11715226,"avatar_url":"https://avatars.githubusercontent.com/u/11715226?v=3","gravatar_id":"","url":"https://api.github.com/users/sentryo","html_url":"https://github.com/sentryo","followers_url":"https://api.github.com/users/sentryo/followers","following_url":"https://api.github.com/users/sentryo/following{/other_user}","gists_url":"https://api.github.com/users/sentryo/gists{/gist_id}","starred_url":"https://api.github.com/users/sentryo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sentryo/subscriptions","organizations_url":"https://api.github.com/users/sentryo/orgs","repos_url":"https://api.github.com/users/sentryo/repos","events_url":"https://api.github.com/users/sentryo/events{/privacy}","received_events_url":"https://api.github.com/users/sentryo/received_events","type":"User","site_admin":false},"repo":{"id":33714430,"name":"gopacket","full_name":"sentryo/gopacket","owner":{"login":"sentryo","id":11715226,"avatar_url":"https://avatars.githubusercontent.com/u/11715226?v=3","gravatar_id":"","url":"https://api.github.com/users/sentryo","html_url":"https://github.com/sentryo","followers_url":"https://api.github.com/users/sentryo/followers","following_url":"https://api.github.com/users/sentryo/following{/other_user}","gists_url":"https://api.github.com/users/sentryo/gists{/gist_id}","starred_url":"https://api.github.com/users/sentryo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sentryo/subscriptions","organizations_url":"https://api.github.com/users/sentryo/orgs","repos_url":"https://api.github.com/users/sentryo/repos","events_url":"https://api.github.com/users/sentryo/events{/privacy}","received_events_url":"https://api.github.com/users/sentryo/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/sentryo/gopacket","description":"Provides packet processing capabilities for Go","fork":true,"url":"https://api.github.com/repos/sentryo/gopacket","forks_url":"https://api.github.com/repos/sentryo/gopacket/forks","keys_url":"https://api.github.com/repos/sentryo/gopacket/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sentryo/gopacket/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sentryo/gopacket/teams","hooks_url":"https://api.github.com/repos/sentryo/gopacket/hooks","issue_events_url":"https://api.github.com/repos/sentryo/gopacket/issues/events{/number}","events_url":"https://api.github.com/repos/sentryo/gopacket/events","assignees_url":"https://api.github.com/repos/sentryo/gopacket/assignees{/user}","branches_url":"https://api.github.com/repos/sentryo/gopacket/branches{/branch}","tags_url":"https://api.github.com/repos/sentryo/gopacket/tags","blobs_url":"https://api.github.com/repos/sentryo/gopacket/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sentryo/gopacket/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sentryo/gopacket/git/refs{/sha}","trees_url":"https://api.github.com/repos/sentryo/gopacket/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sentryo/gopacket/statuses/{sha}","languages_url":"https://api.github.com/repos/sentryo/gopacket/languages","stargazers_url":"https://api.github.com/repos/sentryo/gopacket/stargazers","contributors_url":"https://api.github.com/repos/sentryo/gopacket/contributors","subscribers_url":"https://api.github.com/repos/sentryo/gopacket/subscribers","subscription_url":"https://api.github.com/repos/sentryo/gopacket/subscription","commits_url":"https://api.github.com/repos/sentryo/gopacket/commits{/sha}","git_commits_url":"https://api.github.com/repos/sentryo/gopacket/git/commits{/sha}","comments_url":"https://api.github.com/repos/sentryo/gopacket/comments{/number}","issue_comment_url":"https://api.github.com/repos/sentryo/gopacket/issues/comments{/number}","contents_url":"https://api.github.com/repos/sentryo/gopacket/contents/{+path}","compare_url":"https://api.github.com/repos/sentryo/gopacket/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sentryo/gopacket/merges","archive_url":"https://api.github.com/repos/sentryo/gopacket/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sentryo/gopacket/downloads","issues_url":"https://api.github.com/repos/sentryo/gopacket/issues{/number}","pulls_url":"https://api.github.com/repos/sentryo/gopacket/pulls{/number}","milestones_url":"https://api.github.com/repos/sentryo/gopacket/milestones{/number}","notifications_url":"https://api.github.com/repos/sentryo/gopacket/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sentryo/gopacket/labels{/name}","releases_url":"https://api.github.com/repos/sentryo/gopacket/releases{/id}","deployments_url":"https://api.github.com/repos/sentryo/gopacket/deployments","created_at":"2015-04-10T07:17:49Z","updated_at":"2016-11-24T01:04:42Z","pushed_at":"2016-12-12T17:38:47Z","git_url":"git://github.com/sentryo/gopacket.git","ssh_url":"git@github.com:sentryo/gopacket.git","clone_url":"https://github.com/sentryo/gopacket.git","svn_url":"https://github.com/sentryo/gopacket","homepage":"","size":3949,"stargazers_count":1,"watchers_count":1,"language":"Go","has_issues":false,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"google:master","ref":"master","sha":"58db4386b08b5b4cf105b6ab5a32448173a7637d","user":{"login":"google","id":1342004,"avatar_url":"https://avatars.githubusercontent.com/u/1342004?v=3","gravatar_id":"","url":"https://api.github.com/users/google","html_url":"https://github.com/google","followers_url":"https://api.github.com/users/google/followers","following_url":"https://api.github.com/users/google/following{/other_user}","gists_url":"https://api.github.com/users/google/gists{/gist_id}","starred_url":"https://api.github.com/users/google/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/google/subscriptions","organizations_url":"https://api.github.com/users/google/orgs","repos_url":"https://api.github.com/users/google/repos","events_url":"https://api.github.com/users/google/events{/privacy}","received_events_url":"https://api.github.com/users/google/received_events","type":"Organization","site_admin":false},"repo":{"id":32351944,"name":"gopacket","full_name":"google/gopacket","owner":{"login":"google","id":1342004,"avatar_url":"https://avatars.githubusercontent.com/u/1342004?v=3","gravatar_id":"","url":"https://api.github.com/users/google","html_url":"https://github.com/google","followers_url":"https://api.github.com/users/google/followers","following_url":"https://api.github.com/users/google/following{/other_user}","gists_url":"https://api.github.com/users/google/gists{/gist_id}","starred_url":"https://api.github.com/users/google/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/google/subscriptions","organizations_url":"https://api.github.com/users/google/orgs","repos_url":"https://api.github.com/users/google/repos","events_url":"https://api.github.com/users/google/events{/privacy}","received_events_url":"https://api.github.com/users/google/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/google/gopacket","description":"Provides packet processing capabilities for Go","fork":false,"url":"https://api.github.com/repos/google/gopacket","forks_url":"https://api.github.com/repos/google/gopacket/forks","keys_url":"https://api.github.com/repos/google/gopacket/keys{/key_id}","collaborators_url":"https://api.github.com/repos/google/gopacket/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/google/gopacket/teams","hooks_url":"https://api.github.com/repos/google/gopacket/hooks","issue_events_url":"https://api.github.com/repos/google/gopacket/issues/events{/number}","events_url":"https://api.github.com/repos/google/gopacket/events","assignees_url":"https://api.github.com/repos/google/gopacket/assignees{/user}","branches_url":"https://api.github.com/repos/google/gopacket/branches{/branch}","tags_url":"https://api.github.com/repos/google/gopacket/tags","blobs_url":"https://api.github.com/repos/google/gopacket/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/google/gopacket/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/google/gopacket/git/refs{/sha}","trees_url":"https://api.github.com/repos/google/gopacket/git/trees{/sha}","statuses_url":"https://api.github.com/repos/google/gopacket/statuses/{sha}","languages_url":"https://api.github.com/repos/google/gopacket/languages","stargazers_url":"https://api.github.com/repos/google/gopacket/stargazers","contributors_url":"https://api.github.com/repos/google/gopacket/contributors","subscribers_url":"https://api.github.com/repos/google/gopacket/subscribers","subscription_url":"https://api.github.com/repos/google/gopacket/subscription","commits_url":"https://api.github.com/repos/google/gopacket/commits{/sha}","git_commits_url":"https://api.github.com/repos/google/gopacket/git/commits{/sha}","comments_url":"https://api.github.com/repos/google/gopacket/comments{/number}","issue_comment_url":"https://api.github.com/repos/google/gopacket/issues/comments{/number}","contents_url":"https://api.github.com/repos/google/gopacket/contents/{+path}","compare_url":"https://api.github.com/repos/google/gopacket/compare/{base}...{head}","merges_url":"https://api.github.com/repos/google/gopacket/merges","archive_url":"https://api.github.com/repos/google/gopacket/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/google/gopacket/downloads","issues_url":"https://api.github.com/repos/google/gopacket/issues{/number}","pulls_url":"https://api.github.com/repos/google/gopacket/pulls{/number}","milestones_url":"https://api.github.com/repos/google/gopacket/milestones{/number}","notifications_url":"https://api.github.com/repos/google/gopacket/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/google/gopacket/labels{/name}","releases_url":"https://api.github.com/repos/google/gopacket/releases{/id}","deployments_url":"https://api.github.com/repos/google/gopacket/deployments","created_at":"2015-03-16T20:46:00Z","updated_at":"2016-12-11T07:03:23Z","pushed_at":"2016-12-12T17:38:48Z","git_url":"git://github.com/google/gopacket.git","ssh_url":"git@github.com:google/gopacket.git","clone_url":"https://github.com/google/gopacket.git","svn_url":"https://github.com/google/gopacket","homepage":"","size":4410,"stargazers_count":995,"watchers_count":995,"language":"Go","has_issues":true,"has_downloads":false,"has_wiki":false,"has_pages":false,"forks_count":191,"mirror_url":null,"open_issues_count":45,"forks":191,"open_issues":45,"watchers":995,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/google/gopacket/pulls/116"},"html":{"href":"https://github.com/google/gopacket/pull/116"},"issue":{"href":"https://api.github.com/repos/google/gopacket/issues/116"},"comments":{"href":"https://api.github.com/repos/google/gopacket/issues/116/comments"},"review_comments":{"href":"https://api.github.com/repos/google/gopacket/pulls/116/comments"},"review_comment":{"href":"https://api.github.com/repos/google/gopacket/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/google/gopacket/pulls/116/commits"},"statuses":{"href":"https://api.github.com/repos/google/gopacket/statuses/776f59d118e73306b436fa721e3892daa5ce8ca0"}}}}
{"actor":{"display_login":"sentryo"}}