{"action":"created","comment":{"url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/pulls/comments/37094148","id":37094148,"diff_hunk":"@@ -0,0 +1,530 @@\n+//\n+//  OCTActiveFile.m\n+//  objcTox\n+//\n+//  Created by stal on 9/7/2015.\n+//  Copyright © 2015 Zodiac Labs. All rights reserved.\n+//\n+\n+#import \"DDLog.h\"\n+#import \"OCTTox.h\"\n+#import \"OCTActiveFile+Variants.h\"\n+#import \"OCTSubmanagerFiles.h\"\n+#import \"OCTMessageFile.h\"\n+#import \"OCTSubmanagerFiles+Private.h\"\n+#import \"OCTSubmanagerObjects+Private.h\"\n+#import \"OCTRealmManager.h\"\n+\n+#include <mach/clock.h>\n+#include <mach/mach_host.h>\n+#include <mach/mach_port.h>\n+\n+#undef LOG_LEVEL_DEF\n+#define LOG_LEVEL_DEF LOG_LEVEL_DEBUG\n+\n+/* these are annoying, and because we get all file numbers from toxcore,\n+ * casting will never truncate them because they were never longs to begin\n+ * with. */\n+#pragma clang diagnostic push\n+#pragma clang diagnostic ignored \"-Wshorten-64-to-32\"\n+\n+static time_t OCTGetSystemUptime(void)\n+{\n+    clock_serv_t muhclock;\n+    mach_timespec_t machtime;\n+\n+    host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &muhclock);\n+    clock_get_time(muhclock, &machtime);\n+    mach_port_deallocate(mach_task_self(), muhclock);\n+\n+    return machtime.tv_sec;\n+}\n+\n+@implementation OCTActiveFile\n+\n+@dynamic estimatedTimeRemaining;\n+@dynamic progress;\n+@dynamic bytesPerSecond;\n+\n+- (instancetype)init\n+{\n+    self = [super init];\n+    if (! self) {\n+        return nil;\n+    }\n+\n+    self.transferRateCounters = calloc(sizeof(OCTToxFileSize), AVERAGE_SECONDS);\n+    for (int i = 0; i < AVERAGE_SECONDS; ++i) {\n+        self.transferRateCounters[i] = -1;\n+    }\n+\n+    return self;\n+}\n+\n+- (void)dealloc\n+{\n+    DDLogDebug(@\"OCTActiveFile dealloc\");\n+    free(self.transferRateCounters);\n+}\n+\n+#pragma mark - Speed counting stuff\n+\n+- (void)incrementRollingIndex:(long)n\n+{\n+    @synchronized(self) {\n+        for (int i = 0; i < n; ++i) {\n+            self.rollingIndex = (self.rollingIndex + 1) % AVERAGE_SECONDS;\n+            self.transferRateCounters[self.rollingIndex] = 0;\n+        }\n+    }\n+}\n+\n+- (void)countBytes:(NSUInteger)size\n+{\n+    self.bytesMoved += size;\n+\n+    time_t now = OCTGetSystemUptime();\n+    time_t delta = now - self.lastCountedTime;\n+    self.lastCountedTime = now;\n+\n+    NSAssert(delta >= 0, @\"Detected a temporal anomaly. objcTox currently does not support Tox FTL, nor phone-microwave-\"\n+             \"based time travel. Please file a bug.\");\n+\n+    if (delta != 0) {\n+        [self incrementRollingIndex:delta];\n+    }\n+\n+    self.transferRateCounters[self.rollingIndex] += size;","path":"Classes/Private/Manager/Objects/OCTActiveFile.m","position":97,"original_position":97,"commit_id":"53cf508e05de8e26856237ae170af16cab9e085d","original_commit_id":"53cf508e05de8e26856237ae170af16cab9e085d","user":{"login":"stal888","id":774591,"avatar_url":"https://avatars.githubusercontent.com/u/774591?v=3","gravatar_id":"","url":"https://api.github.com/users/stal888","html_url":"https://github.com/stal888","followers_url":"https://api.github.com/users/stal888/followers","following_url":"https://api.github.com/users/stal888/following{/other_user}","gists_url":"https://api.github.com/users/stal888/gists{/gist_id}","starred_url":"https://api.github.com/users/stal888/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stal888/subscriptions","organizations_url":"https://api.github.com/users/stal888/orgs","repos_url":"https://api.github.com/users/stal888/repos","events_url":"https://api.github.com/users/stal888/events{/privacy}","received_events_url":"https://api.github.com/users/stal888/received_events","type":"User","site_admin":false},"body":"It's probably okay. I think a mutex is too heavy-handed for a method that gets called so often. (a rough calculation `6 MB/s -> 6,000,000 bytes in ~1430 byte packets -> 4,195.8 message sends/s, yikes!`, and that's just this method)\r\n\r\nSince this is only ever set from the Tox queue, the worst that could happen is the client gets a wrong estimated time value (and we exclude the current hot-second from the average) which will be wiped in the next progress update.","created_at":"2015-08-14T16:39:03Z","updated_at":"2015-08-14T16:39:03Z","html_url":"https://github.com/Antidote-for-Tox/objcTox/pull/104#discussion_r37094148","pull_request_url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/pulls/104","_links":{"self":{"href":"https://api.github.com/repos/Antidote-for-Tox/objcTox/pulls/comments/37094148"},"html":{"href":"https://github.com/Antidote-for-Tox/objcTox/pull/104#discussion_r37094148"},"pull_request":{"href":"https://api.github.com/repos/Antidote-for-Tox/objcTox/pulls/104"}}},"pull_request":{"url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/pulls/104","id":42382250,"html_url":"https://github.com/Antidote-for-Tox/objcTox/pull/104","diff_url":"https://github.com/Antidote-for-Tox/objcTox/pull/104.diff","patch_url":"https://github.com/Antidote-for-Tox/objcTox/pull/104.patch","issue_url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/issues/104","number":104,"state":"open","locked":false,"title":"File transfers","user":{"login":"stal888","id":774591,"avatar_url":"https://avatars.githubusercontent.com/u/774591?v=3","gravatar_id":"","url":"https://api.github.com/users/stal888","html_url":"https://github.com/stal888","followers_url":"https://api.github.com/users/stal888/followers","following_url":"https://api.github.com/users/stal888/following{/other_user}","gists_url":"https://api.github.com/users/stal888/gists{/gist_id}","starred_url":"https://api.github.com/users/stal888/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stal888/subscriptions","organizations_url":"https://api.github.com/users/stal888/orgs","repos_url":"https://api.github.com/users/stal888/repos","events_url":"https://api.github.com/users/stal888/events{/privacy}","received_events_url":"https://api.github.com/users/stal888/received_events","type":"User","site_admin":false},"body":"Working through the list from the other PR:\r\n\r\n- [x] DDLog macro isn't working (there is no global log level for now, you have to define it manually in each file using DDLog (see example in OCTTox)).\r\n- [x] Generics aren't available yet, so they don't work. Please remove them. I don't think that we should migrate to Xcode 7 as it wasn't released yet.\r\n- [x] Some includes are missing.\r\n- [x] Existing tests don't compile too (OCTTox callback was changed).\r\n- [ ] There are no tests. Code should be covered with tests as much as possible.\r\n- [ ] File transfers aren't implemented in demo project.\r\n- [x] As database changed, migration for Realm should be done.\r\n","created_at":"2015-08-13T18:24:03Z","updated_at":"2015-08-14T16:39:03Z","closed_at":null,"merged_at":null,"merge_commit_sha":"49018c3883a444df4c36d16f3c77ba5ed4ca208a","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/pulls/104/commits","review_comments_url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/pulls/104/comments","review_comment_url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/issues/104/comments","statuses_url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/statuses/53cf508e05de8e26856237ae170af16cab9e085d","head":{"label":"zodiaclabs:ft","ref":"ft","sha":"53cf508e05de8e26856237ae170af16cab9e085d","user":{"login":"zodiaclabs","id":6156255,"avatar_url":"https://avatars.githubusercontent.com/u/6156255?v=3","gravatar_id":"","url":"https://api.github.com/users/zodiaclabs","html_url":"https://github.com/zodiaclabs","followers_url":"https://api.github.com/users/zodiaclabs/followers","following_url":"https://api.github.com/users/zodiaclabs/following{/other_user}","gists_url":"https://api.github.com/users/zodiaclabs/gists{/gist_id}","starred_url":"https://api.github.com/users/zodiaclabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zodiaclabs/subscriptions","organizations_url":"https://api.github.com/users/zodiaclabs/orgs","repos_url":"https://api.github.com/users/zodiaclabs/repos","events_url":"https://api.github.com/users/zodiaclabs/events{/privacy}","received_events_url":"https://api.github.com/users/zodiaclabs/received_events","type":"Organization","site_admin":false},"repo":{"id":38654096,"name":"objcTox","full_name":"zodiaclabs/objcTox","owner":{"login":"zodiaclabs","id":6156255,"avatar_url":"https://avatars.githubusercontent.com/u/6156255?v=3","gravatar_id":"","url":"https://api.github.com/users/zodiaclabs","html_url":"https://github.com/zodiaclabs","followers_url":"https://api.github.com/users/zodiaclabs/followers","following_url":"https://api.github.com/users/zodiaclabs/following{/other_user}","gists_url":"https://api.github.com/users/zodiaclabs/gists{/gist_id}","starred_url":"https://api.github.com/users/zodiaclabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zodiaclabs/subscriptions","organizations_url":"https://api.github.com/users/zodiaclabs/orgs","repos_url":"https://api.github.com/users/zodiaclabs/repos","events_url":"https://api.github.com/users/zodiaclabs/events{/privacy}","received_events_url":"https://api.github.com/users/zodiaclabs/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/zodiaclabs/objcTox","description":"Objective-C wrapper for Tox","fork":true,"url":"https://api.github.com/repos/zodiaclabs/objcTox","forks_url":"https://api.github.com/repos/zodiaclabs/objcTox/forks","keys_url":"https://api.github.com/repos/zodiaclabs/objcTox/keys{/key_id}","collaborators_url":"https://api.github.com/repos/zodiaclabs/objcTox/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/zodiaclabs/objcTox/teams","hooks_url":"https://api.github.com/repos/zodiaclabs/objcTox/hooks","issue_events_url":"https://api.github.com/repos/zodiaclabs/objcTox/issues/events{/number}","events_url":"https://api.github.com/repos/zodiaclabs/objcTox/events","assignees_url":"https://api.github.com/repos/zodiaclabs/objcTox/assignees{/user}","branches_url":"https://api.github.com/repos/zodiaclabs/objcTox/branches{/branch}","tags_url":"https://api.github.com/repos/zodiaclabs/objcTox/tags","blobs_url":"https://api.github.com/repos/zodiaclabs/objcTox/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/zodiaclabs/objcTox/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/zodiaclabs/objcTox/git/refs{/sha}","trees_url":"https://api.github.com/repos/zodiaclabs/objcTox/git/trees{/sha}","statuses_url":"https://api.github.com/repos/zodiaclabs/objcTox/statuses/{sha}","languages_url":"https://api.github.com/repos/zodiaclabs/objcTox/languages","stargazers_url":"https://api.github.com/repos/zodiaclabs/objcTox/stargazers","contributors_url":"https://api.github.com/repos/zodiaclabs/objcTox/contributors","subscribers_url":"https://api.github.com/repos/zodiaclabs/objcTox/subscribers","subscription_url":"https://api.github.com/repos/zodiaclabs/objcTox/subscription","commits_url":"https://api.github.com/repos/zodiaclabs/objcTox/commits{/sha}","git_commits_url":"https://api.github.com/repos/zodiaclabs/objcTox/git/commits{/sha}","comments_url":"https://api.github.com/repos/zodiaclabs/objcTox/comments{/number}","issue_comment_url":"https://api.github.com/repos/zodiaclabs/objcTox/issues/comments{/number}","contents_url":"https://api.github.com/repos/zodiaclabs/objcTox/contents/{+path}","compare_url":"https://api.github.com/repos/zodiaclabs/objcTox/compare/{base}...{head}","merges_url":"https://api.github.com/repos/zodiaclabs/objcTox/merges","archive_url":"https://api.github.com/repos/zodiaclabs/objcTox/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/zodiaclabs/objcTox/downloads","issues_url":"https://api.github.com/repos/zodiaclabs/objcTox/issues{/number}","pulls_url":"https://api.github.com/repos/zodiaclabs/objcTox/pulls{/number}","milestones_url":"https://api.github.com/repos/zodiaclabs/objcTox/milestones{/number}","notifications_url":"https://api.github.com/repos/zodiaclabs/objcTox/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/zodiaclabs/objcTox/labels{/name}","releases_url":"https://api.github.com/repos/zodiaclabs/objcTox/releases{/id}","created_at":"2015-07-07T00:30:49Z","updated_at":"2015-08-13T16:33:53Z","pushed_at":"2015-08-13T21:40:05Z","git_url":"git://github.com/zodiaclabs/objcTox.git","ssh_url":"git@github.com:zodiaclabs/objcTox.git","clone_url":"https://github.com/zodiaclabs/objcTox.git","svn_url":"https://github.com/zodiaclabs/objcTox","homepage":null,"size":30507,"stargazers_count":0,"watchers_count":0,"language":"Objective-C","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":"master"}},"base":{"label":"Antidote-for-Tox:file-transfer","ref":"file-transfer","sha":"c85bee947dbffbc3e40aeff0e9577ea704668c60","user":{"login":"Antidote-for-Tox","id":12895321,"avatar_url":"https://avatars.githubusercontent.com/u/12895321?v=3","gravatar_id":"","url":"https://api.github.com/users/Antidote-for-Tox","html_url":"https://github.com/Antidote-for-Tox","followers_url":"https://api.github.com/users/Antidote-for-Tox/followers","following_url":"https://api.github.com/users/Antidote-for-Tox/following{/other_user}","gists_url":"https://api.github.com/users/Antidote-for-Tox/gists{/gist_id}","starred_url":"https://api.github.com/users/Antidote-for-Tox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Antidote-for-Tox/subscriptions","organizations_url":"https://api.github.com/users/Antidote-for-Tox/orgs","repos_url":"https://api.github.com/users/Antidote-for-Tox/repos","events_url":"https://api.github.com/users/Antidote-for-Tox/events{/privacy}","received_events_url":"https://api.github.com/users/Antidote-for-Tox/received_events","type":"Organization","site_admin":false},"repo":{"id":31480794,"name":"objcTox","full_name":"Antidote-for-Tox/objcTox","owner":{"login":"Antidote-for-Tox","id":12895321,"avatar_url":"https://avatars.githubusercontent.com/u/12895321?v=3","gravatar_id":"","url":"https://api.github.com/users/Antidote-for-Tox","html_url":"https://github.com/Antidote-for-Tox","followers_url":"https://api.github.com/users/Antidote-for-Tox/followers","following_url":"https://api.github.com/users/Antidote-for-Tox/following{/other_user}","gists_url":"https://api.github.com/users/Antidote-for-Tox/gists{/gist_id}","starred_url":"https://api.github.com/users/Antidote-for-Tox/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Antidote-for-Tox/subscriptions","organizations_url":"https://api.github.com/users/Antidote-for-Tox/orgs","repos_url":"https://api.github.com/users/Antidote-for-Tox/repos","events_url":"https://api.github.com/users/Antidote-for-Tox/events{/privacy}","received_events_url":"https://api.github.com/users/Antidote-for-Tox/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Antidote-for-Tox/objcTox","description":"Objective-C wrapper for Tox","fork":false,"url":"https://api.github.com/repos/Antidote-for-Tox/objcTox","forks_url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/forks","keys_url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/teams","hooks_url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/hooks","issue_events_url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/issues/events{/number}","events_url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/events","assignees_url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/assignees{/user}","branches_url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/branches{/branch}","tags_url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/tags","blobs_url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/git/refs{/sha}","trees_url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/statuses/{sha}","languages_url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/languages","stargazers_url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/stargazers","contributors_url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/contributors","subscribers_url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/subscribers","subscription_url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/subscription","commits_url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/commits{/sha}","git_commits_url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/git/commits{/sha}","comments_url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/comments{/number}","issue_comment_url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/issues/comments{/number}","contents_url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/contents/{+path}","compare_url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/merges","archive_url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/downloads","issues_url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/issues{/number}","pulls_url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/pulls{/number}","milestones_url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/milestones{/number}","notifications_url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/labels{/name}","releases_url":"https://api.github.com/repos/Antidote-for-Tox/objcTox/releases{/id}","created_at":"2015-02-28T23:40:19Z","updated_at":"2015-07-22T18:16:57Z","pushed_at":"2015-08-14T16:35:21Z","git_url":"git://github.com/Antidote-for-Tox/objcTox.git","ssh_url":"git@github.com:Antidote-for-Tox/objcTox.git","clone_url":"https://github.com/Antidote-for-Tox/objcTox.git","svn_url":"https://github.com/Antidote-for-Tox/objcTox","homepage":null,"size":31762,"stargazers_count":13,"watchers_count":13,"language":"Objective-C","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":3,"mirror_url":null,"open_issues_count":16,"forks":3,"open_issues":16,"watchers":13,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Antidote-for-Tox/objcTox/pulls/104"},"html":{"href":"https://github.com/Antidote-for-Tox/objcTox/pull/104"},"issue":{"href":"https://api.github.com/repos/Antidote-for-Tox/objcTox/issues/104"},"comments":{"href":"https://api.github.com/repos/Antidote-for-Tox/objcTox/issues/104/comments"},"review_comments":{"href":"https://api.github.com/repos/Antidote-for-Tox/objcTox/pulls/104/comments"},"review_comment":{"href":"https://api.github.com/repos/Antidote-for-Tox/objcTox/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Antidote-for-Tox/objcTox/pulls/104/commits"},"statuses":{"href":"https://api.github.com/repos/Antidote-for-Tox/objcTox/statuses/53cf508e05de8e26856237ae170af16cab9e085d"}}}}