{"action":"created","comment":{"url":"https://api.github.com/repos/uProxy/uproxy/pulls/comments/91882394","pull_request_review_id":12390776,"id":91882394,"diff_hunk":"@@ -0,0 +1,378 @@\n+/// <reference path='../../../third_party/wrtc/wrtc.d.ts' />\n+\n+/*\n+ * Pure Node implementation of zork (no freedomjs).\n+ * Rough lifecycle is to process single word commands such as \"ping\" until\n+ * \"give\" or \"get\" is received, at which point a p2p proxy session is\n+ * established and further input is treated as signaling channel messages.\n+ * This logic can be found in `handleMsg()` below.\n+ */\n+\n+\n+// TODO: Use any specified `transform` settings once they are supported.\n+//       Currently we stash them in the context but then ignore them.\n+// TODO: Verify p2p proxy connection setup is sane:\n+//       - dummy IGNORED datachannel necessary? (see \"IGNORED\" TODO below)\n+//       - all required states or messages handled?\n+//         (see \"event.candidate -> TODO\" below)\n+//       - no resource leaks (see \"cleanup\" TODO below)\n+// TODO: Implement backpressure (see \"backpressure\" TODO below)\n+// TODO: Factor out logic duplicated in ../socks/bin/webrtc.ts\n+// TODO: Replace console log calls with something more structured?\n+// TODO: Do error states ever need to be indicated to clients rather than\n+//       just logged locally?\n+\n+\n+import * as constants from '../../generic_core/constants';\n+import * as net from 'net';\n+import * as node_server from '../socks/node/server';\n+import * as node_socket from '../socks/node/socket';\n+import * as socks_session from '../socks/session';\n+import * as wrtc from 'wrtc';\n+\n+const RTC_PEER_CONFIG = {\n+  iceServers: [\n+    {url: 'stun:stun.l.google.com:19302'},\n+    {url: 'stun:stun1.l.google.com:19302'},\n+    {url: 'stun:stun.services.mozilla.com'}\n+  ]\n+};\n+\n+// The delimiter for Zork messages is just \\n, but we use \\r?\\n for\n+// MSG_DELIM_RE so that \\r\\n sent by e.g. a telnet client will also be treated\n+// as a delimiter. https://en.wikipedia.org/wiki/Robustness_principle\n+// \"Be conservative in what you send, be liberal in what you accept.\"\n+const MSG_DELIM_RE = /\\r?\\n/;\n+\n+const SOCKS_HOST = '0.0.0.0';\n+const SOCKS_PORT = 9999;\n+\n+const ZORK_SERVER_PORT_START = 9000;\n+const ZORK_SERVER_PORT_INCREMENT = 10;\n+const ZORK_SERVER_BIND_MAXTRIES = 3;\n+let zorkServerPort = ZORK_SERVER_PORT_START;\n+let zorkServerBindNtries = 0;\n+let nconnectionsMade = 0;\n+let npeersGetting = 0;\n+\n+interface ParsedCmd {\n+  id: string;        // e.g. 'ping', 'give', 'get', 'transform', etc.\n+  source: string;    // e.g. 'transform with caesar'\n+  tokens: string[];  // e.g. ['transform', 'with', 'caesar']\n+}\n+\n+interface Context {\n+  clientId: number;\n+  socket: net.Socket;\n+  mode: string;  // 'give', 'get', or null (still awaiting a 'give' or 'get' command)\n+  peerConn: any; // using wrtc.RTCPeerConnection upsets tsc\n+  transformer: any;\n+}\n+\n+\n+// Command handlers:\n+\n+const handleCmdInvalid = (ctx: Context, cmd: ParsedCmd) => {\n+  ctx.socket.write(`I don't understand that command. (${cmd.id})\\n`);\n+};\n+\n+const handleCmdPing = (ctx: Context) => {\n+  ctx.socket.write(`ping\\n`);\n+};\n+\n+const handleCmdXyzzy = (ctx: Context) => {\n+  ctx.socket.write(`Nothing happens.\\n`);\n+};\n+\n+const handleCmdVersion = (ctx: Context) => {\n+  ctx.socket.write(`${constants.MESSAGE_VERSION}\\n`);\n+};\n+\n+const handleCmdQuit = (ctx: Context) => {\n+  ctx.socket.end();\n+};\n+\n+const handleCmdGetters = (ctx: Context) => {\n+  ctx.socket.write(`${npeersGetting}\\n`);\n+};\n+\n+const handleCmdTransform = (ctx: Context, cmd: ParsedCmd) => {\n+  const t1 = cmd.tokens[1];\n+  if (t1 === 'with') {\n+    ctx.transformer = {name: cmd.tokens[2]};\n+  } else if (t1 === 'config') {\n+    const idx = cmd.source.indexOf(' config ') + ' config '.length;\n+    const config = cmd.source.substring(idx);\n+    ctx.transformer = {config: config};\n+  } else {\n+    ctx.socket.write(`usage: transform (with name|config json)\\n`);\n+  }\n+};\n+\n+/*\n+ * Start giving access to the peer.\n+ * Create a local socks server and connect it to the peer connection.\n+ */\n+const handleCmdGive = (ctx: Context) => {","path":"src/lib/zork/zork.ts","position":null,"original_position":116,"commit_id":"ffe0b6ac0619e9fed9c001605be9c07d7e55af80","original_commit_id":"d79c5dfe5ddfe07808f1d25bcc278a0e166beed4","user":{"login":"jab","id":64992,"avatar_url":"https://avatars.githubusercontent.com/u/64992?v=3","gravatar_id":"","url":"https://api.github.com/users/jab","html_url":"https://github.com/jab","followers_url":"https://api.github.com/users/jab/followers","following_url":"https://api.github.com/users/jab/following{/other_user}","gists_url":"https://api.github.com/users/jab/gists{/gist_id}","starred_url":"https://api.github.com/users/jab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jab/subscriptions","organizations_url":"https://api.github.com/users/jab/orgs","repos_url":"https://api.github.com/users/jab/repos","events_url":"https://api.github.com/users/jab/events{/privacy}","received_events_url":"https://api.github.com/users/jab/received_events","type":"User","site_admin":false},"body":"This logic was actually wrong in the version you reviewed. Corrected in ffe0b6a.","created_at":"2016-12-12T04:39:38Z","updated_at":"2016-12-12T04:39:38Z","html_url":"https://github.com/uProxy/uproxy/pull/2837#discussion_r91882394","pull_request_url":"https://api.github.com/repos/uProxy/uproxy/pulls/2837","_links":{"self":{"href":"https://api.github.com/repos/uProxy/uproxy/pulls/comments/91882394"},"html":{"href":"https://github.com/uProxy/uproxy/pull/2837#discussion_r91882394"},"pull_request":{"href":"https://api.github.com/repos/uProxy/uproxy/pulls/2837"}}},"pull_request":{"url":"https://api.github.com/repos/uProxy/uproxy/pulls/2837","id":96370277,"html_url":"https://github.com/uProxy/uproxy/pull/2837","diff_url":"https://github.com/uProxy/uproxy/pull/2837.diff","patch_url":"https://github.com/uProxy/uproxy/pull/2837.patch","issue_url":"https://api.github.com/repos/uProxy/uproxy/issues/2837","number":2837,"state":"open","locked":false,"title":"initial progress toward freedomless zork implementation","user":{"login":"jab","id":64992,"avatar_url":"https://avatars.githubusercontent.com/u/64992?v=3","gravatar_id":"","url":"https://api.github.com/users/jab","html_url":"https://github.com/jab","followers_url":"https://api.github.com/users/jab/followers","following_url":"https://api.github.com/users/jab/following{/other_user}","gists_url":"https://api.github.com/users/jab/gists{/gist_id}","starred_url":"https://api.github.com/users/jab/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jab/subscriptions","organizations_url":"https://api.github.com/users/jab/orgs","repos_url":"https://api.github.com/users/jab/repos","events_url":"https://api.github.com/users/jab/events{/privacy}","received_events_url":"https://api.github.com/users/jab/received_events","type":"User","site_admin":false},"body":"As discussed. Look forward to your comments!\n\n<!-- Reviewable:start -->\n---\nThis change is [<img src=\"https://reviewable.io/review_button.svg\" height=\"34\" align=\"absmiddle\" alt=\"Reviewable\"/>](https://reviewable.io/reviews/uproxy/uproxy/2837)\n<!-- Reviewable:end -->\n","created_at":"2016-12-02T23:19:17Z","updated_at":"2016-12-12T04:39:38Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5b35e0cdc564866b070a31b96dd771e4c880e928","assignee":{"login":"trevj","id":5142116,"avatar_url":"https://avatars.githubusercontent.com/u/5142116?v=3","gravatar_id":"","url":"https://api.github.com/users/trevj","html_url":"https://github.com/trevj","followers_url":"https://api.github.com/users/trevj/followers","following_url":"https://api.github.com/users/trevj/following{/other_user}","gists_url":"https://api.github.com/users/trevj/gists{/gist_id}","starred_url":"https://api.github.com/users/trevj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/trevj/subscriptions","organizations_url":"https://api.github.com/users/trevj/orgs","repos_url":"https://api.github.com/users/trevj/repos","events_url":"https://api.github.com/users/trevj/events{/privacy}","received_events_url":"https://api.github.com/users/trevj/received_events","type":"User","site_admin":false},"assignees":[{"login":"trevj","id":5142116,"avatar_url":"https://avatars.githubusercontent.com/u/5142116?v=3","gravatar_id":"","url":"https://api.github.com/users/trevj","html_url":"https://github.com/trevj","followers_url":"https://api.github.com/users/trevj/followers","following_url":"https://api.github.com/users/trevj/following{/other_user}","gists_url":"https://api.github.com/users/trevj/gists{/gist_id}","starred_url":"https://api.github.com/users/trevj/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/trevj/subscriptions","organizations_url":"https://api.github.com/users/trevj/orgs","repos_url":"https://api.github.com/users/trevj/repos","events_url":"https://api.github.com/users/trevj/events{/privacy}","received_events_url":"https://api.github.com/users/trevj/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/uProxy/uproxy/pulls/2837/commits","review_comments_url":"https://api.github.com/repos/uProxy/uproxy/pulls/2837/comments","review_comment_url":"https://api.github.com/repos/uProxy/uproxy/pulls/comments{/number}","comments_url":"https://api.github.com/repos/uProxy/uproxy/issues/2837/comments","statuses_url":"https://api.github.com/repos/uProxy/uproxy/statuses/ffe0b6ac0619e9fed9c001605be9c07d7e55af80","head":{"label":"uProxy:jab-zork-refactor","ref":"jab-zork-refactor","sha":"ffe0b6ac0619e9fed9c001605be9c07d7e55af80","user":{"login":"uProxy","id":6548286,"avatar_url":"https://avatars.githubusercontent.com/u/6548286?v=3","gravatar_id":"","url":"https://api.github.com/users/uProxy","html_url":"https://github.com/uProxy","followers_url":"https://api.github.com/users/uProxy/followers","following_url":"https://api.github.com/users/uProxy/following{/other_user}","gists_url":"https://api.github.com/users/uProxy/gists{/gist_id}","starred_url":"https://api.github.com/users/uProxy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uProxy/subscriptions","organizations_url":"https://api.github.com/users/uProxy/orgs","repos_url":"https://api.github.com/users/uProxy/repos","events_url":"https://api.github.com/users/uProxy/events{/privacy}","received_events_url":"https://api.github.com/users/uProxy/received_events","type":"Organization","site_admin":false},"repo":{"id":18533350,"name":"uproxy","full_name":"uProxy/uproxy","owner":{"login":"uProxy","id":6548286,"avatar_url":"https://avatars.githubusercontent.com/u/6548286?v=3","gravatar_id":"","url":"https://api.github.com/users/uProxy","html_url":"https://github.com/uProxy","followers_url":"https://api.github.com/users/uProxy/followers","following_url":"https://api.github.com/users/uProxy/following{/other_user}","gists_url":"https://api.github.com/users/uProxy/gists{/gist_id}","starred_url":"https://api.github.com/users/uProxy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uProxy/subscriptions","organizations_url":"https://api.github.com/users/uProxy/orgs","repos_url":"https://api.github.com/users/uProxy/repos","events_url":"https://api.github.com/users/uProxy/events{/privacy}","received_events_url":"https://api.github.com/users/uProxy/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/uProxy/uproxy","description":"Internet without borders","fork":false,"url":"https://api.github.com/repos/uProxy/uproxy","forks_url":"https://api.github.com/repos/uProxy/uproxy/forks","keys_url":"https://api.github.com/repos/uProxy/uproxy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/uProxy/uproxy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/uProxy/uproxy/teams","hooks_url":"https://api.github.com/repos/uProxy/uproxy/hooks","issue_events_url":"https://api.github.com/repos/uProxy/uproxy/issues/events{/number}","events_url":"https://api.github.com/repos/uProxy/uproxy/events","assignees_url":"https://api.github.com/repos/uProxy/uproxy/assignees{/user}","branches_url":"https://api.github.com/repos/uProxy/uproxy/branches{/branch}","tags_url":"https://api.github.com/repos/uProxy/uproxy/tags","blobs_url":"https://api.github.com/repos/uProxy/uproxy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/uProxy/uproxy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/uProxy/uproxy/git/refs{/sha}","trees_url":"https://api.github.com/repos/uProxy/uproxy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/uProxy/uproxy/statuses/{sha}","languages_url":"https://api.github.com/repos/uProxy/uproxy/languages","stargazers_url":"https://api.github.com/repos/uProxy/uproxy/stargazers","contributors_url":"https://api.github.com/repos/uProxy/uproxy/contributors","subscribers_url":"https://api.github.com/repos/uProxy/uproxy/subscribers","subscription_url":"https://api.github.com/repos/uProxy/uproxy/subscription","commits_url":"https://api.github.com/repos/uProxy/uproxy/commits{/sha}","git_commits_url":"https://api.github.com/repos/uProxy/uproxy/git/commits{/sha}","comments_url":"https://api.github.com/repos/uProxy/uproxy/comments{/number}","issue_comment_url":"https://api.github.com/repos/uProxy/uproxy/issues/comments{/number}","contents_url":"https://api.github.com/repos/uProxy/uproxy/contents/{+path}","compare_url":"https://api.github.com/repos/uProxy/uproxy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/uProxy/uproxy/merges","archive_url":"https://api.github.com/repos/uProxy/uproxy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/uProxy/uproxy/downloads","issues_url":"https://api.github.com/repos/uProxy/uproxy/issues{/number}","pulls_url":"https://api.github.com/repos/uProxy/uproxy/pulls{/number}","milestones_url":"https://api.github.com/repos/uProxy/uproxy/milestones{/number}","notifications_url":"https://api.github.com/repos/uProxy/uproxy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/uProxy/uproxy/labels{/name}","releases_url":"https://api.github.com/repos/uProxy/uproxy/releases{/id}","deployments_url":"https://api.github.com/repos/uProxy/uproxy/deployments","created_at":"2014-04-07T20:34:40Z","updated_at":"2016-12-11T10:32:54Z","pushed_at":"2016-12-12T04:38:13Z","git_url":"git://github.com/uProxy/uproxy.git","ssh_url":"git@github.com:uProxy/uproxy.git","clone_url":"https://github.com/uProxy/uproxy.git","svn_url":"https://github.com/uProxy/uproxy","homepage":"https://www.uproxy.org/","size":29387,"stargazers_count":472,"watchers_count":472,"language":"TypeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":110,"mirror_url":null,"open_issues_count":76,"forks":110,"open_issues":76,"watchers":472,"default_branch":"master"}},"base":{"label":"uProxy:trevj-socks-refactor","ref":"trevj-socks-refactor","sha":"54faf2861f5c84f741a40b4ed6936cdbea826c79","user":{"login":"uProxy","id":6548286,"avatar_url":"https://avatars.githubusercontent.com/u/6548286?v=3","gravatar_id":"","url":"https://api.github.com/users/uProxy","html_url":"https://github.com/uProxy","followers_url":"https://api.github.com/users/uProxy/followers","following_url":"https://api.github.com/users/uProxy/following{/other_user}","gists_url":"https://api.github.com/users/uProxy/gists{/gist_id}","starred_url":"https://api.github.com/users/uProxy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uProxy/subscriptions","organizations_url":"https://api.github.com/users/uProxy/orgs","repos_url":"https://api.github.com/users/uProxy/repos","events_url":"https://api.github.com/users/uProxy/events{/privacy}","received_events_url":"https://api.github.com/users/uProxy/received_events","type":"Organization","site_admin":false},"repo":{"id":18533350,"name":"uproxy","full_name":"uProxy/uproxy","owner":{"login":"uProxy","id":6548286,"avatar_url":"https://avatars.githubusercontent.com/u/6548286?v=3","gravatar_id":"","url":"https://api.github.com/users/uProxy","html_url":"https://github.com/uProxy","followers_url":"https://api.github.com/users/uProxy/followers","following_url":"https://api.github.com/users/uProxy/following{/other_user}","gists_url":"https://api.github.com/users/uProxy/gists{/gist_id}","starred_url":"https://api.github.com/users/uProxy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/uProxy/subscriptions","organizations_url":"https://api.github.com/users/uProxy/orgs","repos_url":"https://api.github.com/users/uProxy/repos","events_url":"https://api.github.com/users/uProxy/events{/privacy}","received_events_url":"https://api.github.com/users/uProxy/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/uProxy/uproxy","description":"Internet without borders","fork":false,"url":"https://api.github.com/repos/uProxy/uproxy","forks_url":"https://api.github.com/repos/uProxy/uproxy/forks","keys_url":"https://api.github.com/repos/uProxy/uproxy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/uProxy/uproxy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/uProxy/uproxy/teams","hooks_url":"https://api.github.com/repos/uProxy/uproxy/hooks","issue_events_url":"https://api.github.com/repos/uProxy/uproxy/issues/events{/number}","events_url":"https://api.github.com/repos/uProxy/uproxy/events","assignees_url":"https://api.github.com/repos/uProxy/uproxy/assignees{/user}","branches_url":"https://api.github.com/repos/uProxy/uproxy/branches{/branch}","tags_url":"https://api.github.com/repos/uProxy/uproxy/tags","blobs_url":"https://api.github.com/repos/uProxy/uproxy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/uProxy/uproxy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/uProxy/uproxy/git/refs{/sha}","trees_url":"https://api.github.com/repos/uProxy/uproxy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/uProxy/uproxy/statuses/{sha}","languages_url":"https://api.github.com/repos/uProxy/uproxy/languages","stargazers_url":"https://api.github.com/repos/uProxy/uproxy/stargazers","contributors_url":"https://api.github.com/repos/uProxy/uproxy/contributors","subscribers_url":"https://api.github.com/repos/uProxy/uproxy/subscribers","subscription_url":"https://api.github.com/repos/uProxy/uproxy/subscription","commits_url":"https://api.github.com/repos/uProxy/uproxy/commits{/sha}","git_commits_url":"https://api.github.com/repos/uProxy/uproxy/git/commits{/sha}","comments_url":"https://api.github.com/repos/uProxy/uproxy/comments{/number}","issue_comment_url":"https://api.github.com/repos/uProxy/uproxy/issues/comments{/number}","contents_url":"https://api.github.com/repos/uProxy/uproxy/contents/{+path}","compare_url":"https://api.github.com/repos/uProxy/uproxy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/uProxy/uproxy/merges","archive_url":"https://api.github.com/repos/uProxy/uproxy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/uProxy/uproxy/downloads","issues_url":"https://api.github.com/repos/uProxy/uproxy/issues{/number}","pulls_url":"https://api.github.com/repos/uProxy/uproxy/pulls{/number}","milestones_url":"https://api.github.com/repos/uProxy/uproxy/milestones{/number}","notifications_url":"https://api.github.com/repos/uProxy/uproxy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/uProxy/uproxy/labels{/name}","releases_url":"https://api.github.com/repos/uProxy/uproxy/releases{/id}","deployments_url":"https://api.github.com/repos/uProxy/uproxy/deployments","created_at":"2014-04-07T20:34:40Z","updated_at":"2016-12-11T10:32:54Z","pushed_at":"2016-12-12T04:38:13Z","git_url":"git://github.com/uProxy/uproxy.git","ssh_url":"git@github.com:uProxy/uproxy.git","clone_url":"https://github.com/uProxy/uproxy.git","svn_url":"https://github.com/uProxy/uproxy","homepage":"https://www.uproxy.org/","size":29387,"stargazers_count":472,"watchers_count":472,"language":"TypeScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":110,"mirror_url":null,"open_issues_count":76,"forks":110,"open_issues":76,"watchers":472,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/uProxy/uproxy/pulls/2837"},"html":{"href":"https://github.com/uProxy/uproxy/pull/2837"},"issue":{"href":"https://api.github.com/repos/uProxy/uproxy/issues/2837"},"comments":{"href":"https://api.github.com/repos/uProxy/uproxy/issues/2837/comments"},"review_comments":{"href":"https://api.github.com/repos/uProxy/uproxy/pulls/2837/comments"},"review_comment":{"href":"https://api.github.com/repos/uProxy/uproxy/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/uProxy/uproxy/pulls/2837/commits"},"statuses":{"href":"https://api.github.com/repos/uProxy/uproxy/statuses/ffe0b6ac0619e9fed9c001605be9c07d7e55af80"}}}}
{"actor":{"display_login":"jab"}}