{"action":"created","comment":{"url":"https://api.github.com/repos/paritytech/rust-libp2p/pulls/comments/153169646","pull_request_review_id":79134975,"id":153169646,"diff_hunk":"@@ -0,0 +1,525 @@\n+extern crate bytes;\n+extern crate futures;\n+extern crate libp2p_stream_muxer;\n+extern crate tokio_io;\n+extern crate varint;\n+extern crate num_bigint;\n+extern crate num_traits;\n+extern crate parking_lot;\n+extern crate arrayvec;\n+extern crate rand;\n+#[macro_use]\n+extern crate error_chain;\n+\n+mod read;\n+mod write;\n+mod shared;\n+mod header;\n+\n+\n+use bytes::Bytes;\n+use futures::prelude::*;\n+use header::{MultiplexHeader, MultiplexEnd};\n+use libp2p_stream_muxer::StreamMuxer;\n+use parking_lot::Mutex;\n+use read::{MultiplexReadState, read_stream};\n+use shared::{MultiplexShared, ByteBuf, buf_from_slice};\n+use std::io::{self, Read, Write};\n+use std::sync::Arc;\n+use std::hash::Hash;\n+use tokio_io::{AsyncRead, AsyncWrite};\n+use write::write_stream;\n+\n+// So the multiplex is essentially a distributed finite state machine.\n+//\n+// In the first state the header must be read so that we know which substream to hand off the\n+// upcoming packet to. This is first-come, first-served - whichever substream begins reading the\n+// packet will be locked into reading the header until it ihttps://gitlab.com/huia-lang/stack-vms consumed (this may be changed in the","path":"multiplex-rs/src/lib.rs","position":37,"original_position":37,"commit_id":"15c1da06ee1b08ad42e6f6651117ccb849b5cb7d","original_commit_id":"15c1da06ee1b08ad42e6f6651117ccb849b5cb7d","user":{"login":"tomaka","id":1412254,"avatar_url":"https://avatars1.githubusercontent.com/u/1412254?v=4","gravatar_id":"","url":"https://api.github.com/users/tomaka","html_url":"https://github.com/tomaka","followers_url":"https://api.github.com/users/tomaka/followers","following_url":"https://api.github.com/users/tomaka/following{/other_user}","gists_url":"https://api.github.com/users/tomaka/gists{/gist_id}","starred_url":"https://api.github.com/users/tomaka/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tomaka/subscriptions","organizations_url":"https://api.github.com/users/tomaka/orgs","repos_url":"https://api.github.com/users/tomaka/repos","events_url":"https://api.github.com/users/tomaka/events{/privacy}","received_events_url":"https://api.github.com/users/tomaka/received_events","type":"User","site_admin":false},"body":"Typo?","created_at":"2017-11-27T11:20:54Z","updated_at":"2017-11-27T11:20:54Z","html_url":"https://github.com/paritytech/rust-libp2p/pull/48#discussion_r153169646","pull_request_url":"https://api.github.com/repos/paritytech/rust-libp2p/pulls/48","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/paritytech/rust-libp2p/pulls/comments/153169646"},"html":{"href":"https://github.com/paritytech/rust-libp2p/pull/48#discussion_r153169646"},"pull_request":{"href":"https://api.github.com/repos/paritytech/rust-libp2p/pulls/48"}}},"pull_request":{"url":"https://api.github.com/repos/paritytech/rust-libp2p/pulls/48","id":154770050,"html_url":"https://github.com/paritytech/rust-libp2p/pull/48","diff_url":"https://github.com/paritytech/rust-libp2p/pull/48.diff","patch_url":"https://github.com/paritytech/rust-libp2p/pull/48.patch","issue_url":"https://api.github.com/repos/paritytech/rust-libp2p/issues/48","number":48,"state":"open","locked":false,"title":"Add multiplex","user":{"login":"Vurich","id":29733394,"avatar_url":"https://avatars0.githubusercontent.com/u/29733394?v=4","gravatar_id":"","url":"https://api.github.com/users/Vurich","html_url":"https://github.com/Vurich","followers_url":"https://api.github.com/users/Vurich/followers","following_url":"https://api.github.com/users/Vurich/following{/other_user}","gists_url":"https://api.github.com/users/Vurich/gists{/gist_id}","starred_url":"https://api.github.com/users/Vurich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Vurich/subscriptions","organizations_url":"https://api.github.com/users/Vurich/orgs","repos_url":"https://api.github.com/users/Vurich/repos","events_url":"https://api.github.com/users/Vurich/events{/privacy}","received_events_url":"https://api.github.com/users/Vurich/received_events","type":"User","site_admin":false},"body":"Multiplex implementation. It's not completely finished, as such, but it's a functional implementation and shows that you don't need a \"driver\" function to write a protocol like this. After writing it this way I do wonder whether or not it would be better to use a \"driver\" function, since this requires unnecessary synchronisation overhead, although the fact that a lot of code is required to get anything done is not a function of the coordination. Another alternative would be to use `Cell`s for the single-threaded case and allow the user to choose whether or not to incur the synchronisation burden necessary to synchronise.\r\n\r\n### TODO:\r\n\r\n* Currently streams are closed locally when they are dropped (and therefore packets are dropped), but the remote endpoint is not notified. This isn't necessary in order to satisfy the protocol but is part of being a good network citizen.\r\n* As mentioned above, we can do better optimisations for single-threaded async code.\r\n* Currently IDs are generated by hashing an increasing nonce in order to avoid collisions between the two endpoints and by different instances of `OutboundStream`. This wastes a couple bytes over using small increasing nonces.","created_at":"2017-11-27T10:16:04Z","updated_at":"2017-11-27T11:20:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"380019e3256217923453acfbf284b4ae071a6ed1","assignee":null,"assignees":[],"requested_reviewers":[],"milestone":null,"commits_url":"https://api.github.com/repos/paritytech/rust-libp2p/pulls/48/commits","review_comments_url":"https://api.github.com/repos/paritytech/rust-libp2p/pulls/48/comments","review_comment_url":"https://api.github.com/repos/paritytech/rust-libp2p/pulls/comments{/number}","comments_url":"https://api.github.com/repos/paritytech/rust-libp2p/issues/48/comments","statuses_url":"https://api.github.com/repos/paritytech/rust-libp2p/statuses/15c1da06ee1b08ad42e6f6651117ccb849b5cb7d","head":{"label":"Vurich:master","ref":"master","sha":"15c1da06ee1b08ad42e6f6651117ccb849b5cb7d","user":{"login":"Vurich","id":29733394,"avatar_url":"https://avatars0.githubusercontent.com/u/29733394?v=4","gravatar_id":"","url":"https://api.github.com/users/Vurich","html_url":"https://github.com/Vurich","followers_url":"https://api.github.com/users/Vurich/followers","following_url":"https://api.github.com/users/Vurich/following{/other_user}","gists_url":"https://api.github.com/users/Vurich/gists{/gist_id}","starred_url":"https://api.github.com/users/Vurich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Vurich/subscriptions","organizations_url":"https://api.github.com/users/Vurich/orgs","repos_url":"https://api.github.com/users/Vurich/repos","events_url":"https://api.github.com/users/Vurich/events{/privacy}","received_events_url":"https://api.github.com/users/Vurich/received_events","type":"User","site_admin":false},"repo":{"id":110240039,"name":"libp2p-rs","full_name":"Vurich/libp2p-rs","owner":{"login":"Vurich","id":29733394,"avatar_url":"https://avatars0.githubusercontent.com/u/29733394?v=4","gravatar_id":"","url":"https://api.github.com/users/Vurich","html_url":"https://github.com/Vurich","followers_url":"https://api.github.com/users/Vurich/followers","following_url":"https://api.github.com/users/Vurich/following{/other_user}","gists_url":"https://api.github.com/users/Vurich/gists{/gist_id}","starred_url":"https://api.github.com/users/Vurich/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Vurich/subscriptions","organizations_url":"https://api.github.com/users/Vurich/orgs","repos_url":"https://api.github.com/users/Vurich/repos","events_url":"https://api.github.com/users/Vurich/events{/privacy}","received_events_url":"https://api.github.com/users/Vurich/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/Vurich/libp2p-rs","description":"LibP2P (IPFS) networking library written in Rust","fork":true,"url":"https://api.github.com/repos/Vurich/libp2p-rs","forks_url":"https://api.github.com/repos/Vurich/libp2p-rs/forks","keys_url":"https://api.github.com/repos/Vurich/libp2p-rs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Vurich/libp2p-rs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Vurich/libp2p-rs/teams","hooks_url":"https://api.github.com/repos/Vurich/libp2p-rs/hooks","issue_events_url":"https://api.github.com/repos/Vurich/libp2p-rs/issues/events{/number}","events_url":"https://api.github.com/repos/Vurich/libp2p-rs/events","assignees_url":"https://api.github.com/repos/Vurich/libp2p-rs/assignees{/user}","branches_url":"https://api.github.com/repos/Vurich/libp2p-rs/branches{/branch}","tags_url":"https://api.github.com/repos/Vurich/libp2p-rs/tags","blobs_url":"https://api.github.com/repos/Vurich/libp2p-rs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Vurich/libp2p-rs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Vurich/libp2p-rs/git/refs{/sha}","trees_url":"https://api.github.com/repos/Vurich/libp2p-rs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Vurich/libp2p-rs/statuses/{sha}","languages_url":"https://api.github.com/repos/Vurich/libp2p-rs/languages","stargazers_url":"https://api.github.com/repos/Vurich/libp2p-rs/stargazers","contributors_url":"https://api.github.com/repos/Vurich/libp2p-rs/contributors","subscribers_url":"https://api.github.com/repos/Vurich/libp2p-rs/subscribers","subscription_url":"https://api.github.com/repos/Vurich/libp2p-rs/subscription","commits_url":"https://api.github.com/repos/Vurich/libp2p-rs/commits{/sha}","git_commits_url":"https://api.github.com/repos/Vurich/libp2p-rs/git/commits{/sha}","comments_url":"https://api.github.com/repos/Vurich/libp2p-rs/comments{/number}","issue_comment_url":"https://api.github.com/repos/Vurich/libp2p-rs/issues/comments{/number}","contents_url":"https://api.github.com/repos/Vurich/libp2p-rs/contents/{+path}","compare_url":"https://api.github.com/repos/Vurich/libp2p-rs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Vurich/libp2p-rs/merges","archive_url":"https://api.github.com/repos/Vurich/libp2p-rs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Vurich/libp2p-rs/downloads","issues_url":"https://api.github.com/repos/Vurich/libp2p-rs/issues{/number}","pulls_url":"https://api.github.com/repos/Vurich/libp2p-rs/pulls{/number}","milestones_url":"https://api.github.com/repos/Vurich/libp2p-rs/milestones{/number}","notifications_url":"https://api.github.com/repos/Vurich/libp2p-rs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Vurich/libp2p-rs/labels{/name}","releases_url":"https://api.github.com/repos/Vurich/libp2p-rs/releases{/id}","deployments_url":"https://api.github.com/repos/Vurich/libp2p-rs/deployments","created_at":"2017-11-10T11:30:37Z","updated_at":"2017-11-10T11:30:39Z","pushed_at":"2017-11-27T10:14:23Z","git_url":"git://github.com/Vurich/libp2p-rs.git","ssh_url":"git@github.com:Vurich/libp2p-rs.git","clone_url":"https://github.com/Vurich/libp2p-rs.git","svn_url":"https://github.com/Vurich/libp2p-rs","homepage":null,"size":213,"stargazers_count":0,"watchers_count":0,"language":"Rust","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"paritytech:master","ref":"master","sha":"710dec31108385e43e871aab50c385d1abdd0e24","user":{"login":"paritytech","id":14176906,"avatar_url":"https://avatars2.githubusercontent.com/u/14176906?v=4","gravatar_id":"","url":"https://api.github.com/users/paritytech","html_url":"https://github.com/paritytech","followers_url":"https://api.github.com/users/paritytech/followers","following_url":"https://api.github.com/users/paritytech/following{/other_user}","gists_url":"https://api.github.com/users/paritytech/gists{/gist_id}","starred_url":"https://api.github.com/users/paritytech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paritytech/subscriptions","organizations_url":"https://api.github.com/users/paritytech/orgs","repos_url":"https://api.github.com/users/paritytech/repos","events_url":"https://api.github.com/users/paritytech/events{/privacy}","received_events_url":"https://api.github.com/users/paritytech/received_events","type":"Organization","site_admin":false},"repo":{"id":86106381,"name":"rust-libp2p","full_name":"paritytech/rust-libp2p","owner":{"login":"paritytech","id":14176906,"avatar_url":"https://avatars2.githubusercontent.com/u/14176906?v=4","gravatar_id":"","url":"https://api.github.com/users/paritytech","html_url":"https://github.com/paritytech","followers_url":"https://api.github.com/users/paritytech/followers","following_url":"https://api.github.com/users/paritytech/following{/other_user}","gists_url":"https://api.github.com/users/paritytech/gists{/gist_id}","starred_url":"https://api.github.com/users/paritytech/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/paritytech/subscriptions","organizations_url":"https://api.github.com/users/paritytech/orgs","repos_url":"https://api.github.com/users/paritytech/repos","events_url":"https://api.github.com/users/paritytech/events{/privacy}","received_events_url":"https://api.github.com/users/paritytech/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/paritytech/rust-libp2p","description":"LibP2P (IPFS) networking library written in Rust","fork":false,"url":"https://api.github.com/repos/paritytech/rust-libp2p","forks_url":"https://api.github.com/repos/paritytech/rust-libp2p/forks","keys_url":"https://api.github.com/repos/paritytech/rust-libp2p/keys{/key_id}","collaborators_url":"https://api.github.com/repos/paritytech/rust-libp2p/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/paritytech/rust-libp2p/teams","hooks_url":"https://api.github.com/repos/paritytech/rust-libp2p/hooks","issue_events_url":"https://api.github.com/repos/paritytech/rust-libp2p/issues/events{/number}","events_url":"https://api.github.com/repos/paritytech/rust-libp2p/events","assignees_url":"https://api.github.com/repos/paritytech/rust-libp2p/assignees{/user}","branches_url":"https://api.github.com/repos/paritytech/rust-libp2p/branches{/branch}","tags_url":"https://api.github.com/repos/paritytech/rust-libp2p/tags","blobs_url":"https://api.github.com/repos/paritytech/rust-libp2p/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/paritytech/rust-libp2p/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/paritytech/rust-libp2p/git/refs{/sha}","trees_url":"https://api.github.com/repos/paritytech/rust-libp2p/git/trees{/sha}","statuses_url":"https://api.github.com/repos/paritytech/rust-libp2p/statuses/{sha}","languages_url":"https://api.github.com/repos/paritytech/rust-libp2p/languages","stargazers_url":"https://api.github.com/repos/paritytech/rust-libp2p/stargazers","contributors_url":"https://api.github.com/repos/paritytech/rust-libp2p/contributors","subscribers_url":"https://api.github.com/repos/paritytech/rust-libp2p/subscribers","subscription_url":"https://api.github.com/repos/paritytech/rust-libp2p/subscription","commits_url":"https://api.github.com/repos/paritytech/rust-libp2p/commits{/sha}","git_commits_url":"https://api.github.com/repos/paritytech/rust-libp2p/git/commits{/sha}","comments_url":"https://api.github.com/repos/paritytech/rust-libp2p/comments{/number}","issue_comment_url":"https://api.github.com/repos/paritytech/rust-libp2p/issues/comments{/number}","contents_url":"https://api.github.com/repos/paritytech/rust-libp2p/contents/{+path}","compare_url":"https://api.github.com/repos/paritytech/rust-libp2p/compare/{base}...{head}","merges_url":"https://api.github.com/repos/paritytech/rust-libp2p/merges","archive_url":"https://api.github.com/repos/paritytech/rust-libp2p/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/paritytech/rust-libp2p/downloads","issues_url":"https://api.github.com/repos/paritytech/rust-libp2p/issues{/number}","pulls_url":"https://api.github.com/repos/paritytech/rust-libp2p/pulls{/number}","milestones_url":"https://api.github.com/repos/paritytech/rust-libp2p/milestones{/number}","notifications_url":"https://api.github.com/repos/paritytech/rust-libp2p/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/paritytech/rust-libp2p/labels{/name}","releases_url":"https://api.github.com/repos/paritytech/rust-libp2p/releases{/id}","deployments_url":"https://api.github.com/repos/paritytech/rust-libp2p/deployments","created_at":"2017-03-24T20:05:11Z","updated_at":"2017-11-24T08:46:58Z","pushed_at":"2017-11-27T10:16:05Z","git_url":"git://github.com/paritytech/rust-libp2p.git","ssh_url":"git@github.com:paritytech/rust-libp2p.git","clone_url":"https://github.com/paritytech/rust-libp2p.git","svn_url":"https://github.com/paritytech/rust-libp2p","homepage":null,"size":159,"stargazers_count":45,"watchers_count":45,"language":"Rust","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":4,"mirror_url":null,"archived":false,"open_issues_count":14,"forks":4,"open_issues":14,"watchers":45,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/paritytech/rust-libp2p/pulls/48"},"html":{"href":"https://github.com/paritytech/rust-libp2p/pull/48"},"issue":{"href":"https://api.github.com/repos/paritytech/rust-libp2p/issues/48"},"comments":{"href":"https://api.github.com/repos/paritytech/rust-libp2p/issues/48/comments"},"review_comments":{"href":"https://api.github.com/repos/paritytech/rust-libp2p/pulls/48/comments"},"review_comment":{"href":"https://api.github.com/repos/paritytech/rust-libp2p/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/paritytech/rust-libp2p/pulls/48/commits"},"statuses":{"href":"https://api.github.com/repos/paritytech/rust-libp2p/statuses/15c1da06ee1b08ad42e6f6651117ccb849b5cb7d"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"tomaka"}}