{"action":"created","issue":{"url":"https://api.github.com/repos/Fuck-You-GFW/p2pspider/issues/19","repository_url":"https://api.github.com/repos/Fuck-You-GFW/p2pspider","labels_url":"https://api.github.com/repos/Fuck-You-GFW/p2pspider/issues/19/labels{/name}","comments_url":"https://api.github.com/repos/Fuck-You-GFW/p2pspider/issues/19/comments","events_url":"https://api.github.com/repos/Fuck-You-GFW/p2pspider/issues/19/events","html_url":"https://github.com/Fuck-You-GFW/p2pspider/issues/19","id":139181663,"number":19,"title":"防止多个异步请求对同一个 infohash 进行 metadata 下载.","user":{"login":"Fuck-You-GFW","id":5484841,"avatar_url":"https://avatars.githubusercontent.com/u/5484841?v=3","gravatar_id":"","url":"https://api.github.com/users/Fuck-You-GFW","html_url":"https://github.com/Fuck-You-GFW","followers_url":"https://api.github.com/users/Fuck-You-GFW/followers","following_url":"https://api.github.com/users/Fuck-You-GFW/following{/other_user}","gists_url":"https://api.github.com/users/Fuck-You-GFW/gists{/gist_id}","starred_url":"https://api.github.com/users/Fuck-You-GFW/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Fuck-You-GFW/subscriptions","organizations_url":"https://api.github.com/users/Fuck-You-GFW/orgs","repos_url":"https://api.github.com/users/Fuck-You-GFW/repos","events_url":"https://api.github.com/users/Fuck-You-GFW/events{/privacy}","received_events_url":"https://api.github.com/users/Fuck-You-GFW/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/Fuck-You-GFW/p2pspider/labels/enhancement","name":"enhancement","color":"84b6eb"}],"state":"closed","locked":false,"assignee":{"login":"Fuck-You-GFW","id":5484841,"avatar_url":"https://avatars.githubusercontent.com/u/5484841?v=3","gravatar_id":"","url":"https://api.github.com/users/Fuck-You-GFW","html_url":"https://github.com/Fuck-You-GFW","followers_url":"https://api.github.com/users/Fuck-You-GFW/followers","following_url":"https://api.github.com/users/Fuck-You-GFW/following{/other_user}","gists_url":"https://api.github.com/users/Fuck-You-GFW/gists{/gist_id}","starred_url":"https://api.github.com/users/Fuck-You-GFW/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Fuck-You-GFW/subscriptions","organizations_url":"https://api.github.com/users/Fuck-You-GFW/orgs","repos_url":"https://api.github.com/users/Fuck-You-GFW/repos","events_url":"https://api.github.com/users/Fuck-You-GFW/events{/privacy}","received_events_url":"https://api.github.com/users/Fuck-You-GFW/received_events","type":"User","site_admin":false},"milestone":null,"comments":7,"created_at":"2016-03-08T04:57:12Z","updated_at":"2016-03-13T11:20:56Z","closed_at":"2016-03-13T07:03:31Z","body":"比如 A 异步请求正在下载:\r\n````js\r\n{\r\n    infohash: 'e834c096cb8608b9fec9256ec4da8c7aad22d680',\r\n    rinfo: {address: '192.168.1.1', port: 6881}\r\n}\r\n````\r\nA 异步还没成功下载 metadata 或者还没下载完 metadata 的时候, 接着又来了 B 异步请求下载:\r\n````js\r\n{\r\n    infohash: 'e834c096cb8608b9fec9256ec4da8c7aad22d680', // 跟 A 异步请求的 infohash 一样.\r\n    rinfo: {address: '192.168.3.1', port: 6882} // 跟 A 异步请求不一样\r\n}\r\n````\r\n在未实现这个需求的时候, 程序是又会发起 B 异步请求去下载metadata, 这就显得多余(万一 A 请求最终能成功下载 metadata呢?)\r\n\r\n那么, 需要一个机制, 不需要借助外部数据, 防止重复请求下载 metadata (即使借助了数据库, 也没用).\r\n\r\n另外, 有时候, 一个 infohash 多个 peer, 也不一定在第一个 peer 那里就能成功下载 metadata,  那么就从第二个 peer 那里请求下载, 直到下载成功或者不再有下一个 peer 的时候才会停止.\r\n\r\n实现这个的时候 注意内存泄露的问题.\r\n\r\n一旦实现了这个, 将会是质的飞跃! "},"comment":{"url":"https://api.github.com/repos/Fuck-You-GFW/p2pspider/issues/comments/195937727","html_url":"https://github.com/Fuck-You-GFW/p2pspider/issues/19#issuecomment-195937727","issue_url":"https://api.github.com/repos/Fuck-You-GFW/p2pspider/issues/19","id":195937727,"user":{"login":"Fuck-You-GFW","id":5484841,"avatar_url":"https://avatars.githubusercontent.com/u/5484841?v=3","gravatar_id":"","url":"https://api.github.com/users/Fuck-You-GFW","html_url":"https://github.com/Fuck-You-GFW","followers_url":"https://api.github.com/users/Fuck-You-GFW/followers","following_url":"https://api.github.com/users/Fuck-You-GFW/following{/other_user}","gists_url":"https://api.github.com/users/Fuck-You-GFW/gists{/gist_id}","starred_url":"https://api.github.com/users/Fuck-You-GFW/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Fuck-You-GFW/subscriptions","organizations_url":"https://api.github.com/users/Fuck-You-GFW/orgs","repos_url":"https://api.github.com/users/Fuck-You-GFW/repos","events_url":"https://api.github.com/users/Fuck-You-GFW/events{/privacy}","received_events_url":"https://api.github.com/users/Fuck-You-GFW/received_events","type":"User","site_admin":false},"created_at":"2016-03-13T11:20:56Z","updated_at":"2016-03-13T11:20:56Z","body":"刚修复了一个 bug, 可能是这个原因. 你现在再试试看."}}