{"action":"created","comment":{"url":"https://api.github.com/repos/serokell/lootbox/pulls/comments/230587599","pull_request_review_id":171361404,"id":230587599,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIzMDU4NzU5OQ==","diff_hunk":"@@ -212,31 +279,100 @@ termNetCliEnv ZTNetCliEnv{..} = liftIO $ do\n     Z.close ztCliBack\n     adapterRelease ztCliSubAdapter\n     Z.close ztCliSub\n+    -- Free the dealer sockets/adapters for peers we're currently\n+    -- connecting to.\n+    peersResources <-\n+        atomically $ HMap.elems <$> readTVar (ztPeers ^. pivConnecting)\n+    forM_ peersResources $ \\(_,sock,adapter) ->\n+        Z.close sock >> adapterRelease adapter\n+\n+-- Connects/disconnects peers at request.\n+changePeers :: MonadIO m => ZTGlobalEnv -> ZTNetCliEnv -> ZTUpdatePeersReq -> m ()\n+changePeers ZTGlobalEnv{..} ZTNetCliEnv{..} req = liftIO $ do\n+    curTime <- getCurrentTimeMs\n+\n+    -- We pre-create sockets to use them in the STM. The number may be\n+    -- slightly more than the real number used (due to the possibly\n+    -- incorrect request), but we'll cleanup right after.\n+    sockets <- replicateM (length $ req ^. uprAdd) (Z.socket ztContext Z.Dealer)\n+    adapters <- mapM newSocketAdapter sockets\n \n-changePeers :: MonadIO m => ZTNetCliEnv -> ZTUpdatePeersReq -> m ()\n-changePeers ZTNetCliEnv{..} req = liftIO $ do\n-    curTime <- getCurrentTimeMS\n     (toConnect,toDisconnect) <- atomically $ do\n-        peers <- readTVar ztPeers\n-        let (toAdd,toDel) = applyUpdatePeers peers req\n-        let peers' = (peers `Set.difference` toDel) `Set.union` toAdd\n-        writeTVar ztPeers $! peers'\n-        -- 2 seconds heuristical delay before heartbeating worker\n-        -- starts noticing these nodes.\n-        let initHbs = HBState hbIntervalMin hbLivenessMax (curTime + 2000) False\n+        -- Process request\n+        (toAdd,toDel) <- applyUpdatePeers ztPeers req\n+\n+        -- Modify actual variables content.\n+        modifyTVar (ztPeers ^. pivConnected) $! \\p ->\n+            p `HMap.difference` HMap.fromList (map (,()) toDel)\n+        let addInfo = zipWith (\\s a -> (curTime,s,a)) sockets adapters\n+        modifyTVar (ztPeers ^. pivConnecting) $! \\p ->\n+            p `HMap.union` HMap.fromList (toAdd `zip` addInfo)\n+\n+        -- Remove them from the heartbeating worker.\n         modifyTVar ztHeartbeatInfo $\n-            foldr (.) id (map (\\nId -> at nId .~ Nothing) (Set.toList toDel)) .\n-            foldr (.) id (map (\\nId -> at nId .~ Just initHbs) (Set.toList toAdd))\n+            foldr (.) id (map (\\nId -> at nId .~ Nothing) toDel)\n+\n+        -- Initialise related heartbeating context\n         pure (toAdd,toDel)\n+\n     forM_ toDisconnect $ \\z -> do\n-        ztLog ztCliLogging Info $ \"changePeers: disconnecting \" <> show z\n         Z.disconnect ztCliBack $ ztNodeIdRouter z\n         Z.disconnect ztCliSub $ ztNodeIdPub z\n-    forM_ toConnect $ \\z -> do\n-        ztLog ztCliLogging Info $ \"changePeers: connecting \" <> show z\n-        Z.connect ztCliBack $ ztNodeIdRouter z\n-        Z.connect ztCliSub $ ztNodeIdPub z\n-\n+    unless (null toDisconnect) $\n+        ztLog ztCliLogging Info $ \"changePeers: disconnected \" <> show toDisconnect\n+    unless (null toConnect) $ do\n+        -- We connect all dealer sockets and send a connection request\n+        -- message.\n+        forM_ (toConnect `zip` sockets) $ \\(z,d) -> do\n+            Z.connect d $ ztNodeIdRouter z\n+            Z.sendMulti d $ NE.fromList [\"\",\"getid\"]","path":"code/network/lib/Loot/Network/ZMQ/Client.hs","position":null,"original_position":365,"commit_id":"5d026a1e139f0b62a549abcc827ebd51154df726","original_commit_id":"bfd02fdf62bc134d4a8a95b76a7e09941b6409ef","user":{"login":"Martoon-00","id":5394217,"node_id":"MDQ6VXNlcjUzOTQyMTc=","avatar_url":"https://avatars3.githubusercontent.com/u/5394217?v=4","gravatar_id":"","url":"https://api.github.com/users/Martoon-00","html_url":"https://github.com/Martoon-00","followers_url":"https://api.github.com/users/Martoon-00/followers","following_url":"https://api.github.com/users/Martoon-00/following{/other_user}","gists_url":"https://api.github.com/users/Martoon-00/gists{/gist_id}","starred_url":"https://api.github.com/users/Martoon-00/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Martoon-00/subscriptions","organizations_url":"https://api.github.com/users/Martoon-00/orgs","repos_url":"https://api.github.com/users/Martoon-00/repos","events_url":"https://api.github.com/users/Martoon-00/events{/privacy}","received_events_url":"https://api.github.com/users/Martoon-00/received_events","type":"User","site_admin":false},"body":"@volhovm I'd like you to respond on this (ack or nack), then I approve.\r\n\r\n> Update: I have done it straightforwardly without pattern synonyms.\r\nI'm actually more concerned about overall message format being duplicated, not only tags.","created_at":"2018-11-04T12:53:06Z","updated_at":"2018-11-04T12:53:06Z","html_url":"https://github.com/serokell/lootbox/pull/33#discussion_r230587599","pull_request_url":"https://api.github.com/repos/serokell/lootbox/pulls/33","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/serokell/lootbox/pulls/comments/230587599"},"html":{"href":"https://github.com/serokell/lootbox/pull/33#discussion_r230587599"},"pull_request":{"href":"https://api.github.com/repos/serokell/lootbox/pulls/33"}},"in_reply_to_id":230385622},"pull_request":{"url":"https://api.github.com/repos/serokell/lootbox/pulls/33","id":220958106,"node_id":"MDExOlB1bGxSZXF1ZXN0MjIwOTU4MTA2","html_url":"https://github.com/serokell/lootbox/pull/33","diff_url":"https://github.com/serokell/lootbox/pull/33.diff","patch_url":"https://github.com/serokell/lootbox/pull/33.patch","issue_url":"https://api.github.com/repos/serokell/lootbox/issues/33","number":33,"state":"open","locked":false,"title":"[DSCP-281] Getting rid of implicit network identities","user":{"login":"volhovm","id":5604643,"node_id":"MDQ6VXNlcjU2MDQ2NDM=","avatar_url":"https://avatars0.githubusercontent.com/u/5604643?v=4","gravatar_id":"","url":"https://api.github.com/users/volhovm","html_url":"https://github.com/volhovm","followers_url":"https://api.github.com/users/volhovm/followers","following_url":"https://api.github.com/users/volhovm/following{/other_user}","gists_url":"https://api.github.com/users/volhovm/gists{/gist_id}","starred_url":"https://api.github.com/users/volhovm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/volhovm/subscriptions","organizations_url":"https://api.github.com/users/volhovm/orgs","repos_url":"https://api.github.com/users/volhovm/repos","events_url":"https://api.github.com/users/volhovm/events{/privacy}","received_events_url":"https://api.github.com/users/volhovm/received_events","type":"User","site_admin":false},"body":"My goal is to get rid of predefined public-ip-based identities, replacing them with random identities, which are supposed to be communicated when the connection is initiated.\r\n\r\nI'll squash everything later.","created_at":"2018-10-07T16:26:46Z","updated_at":"2018-11-04T12:53:06Z","closed_at":null,"merged_at":null,"merge_commit_sha":"1a267fc88ed5963b9047cd23e0b847ccc259ee35","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":1082418562,"node_id":"MDU6TGFiZWwxMDgyNDE4NTYy","url":"https://api.github.com/repos/serokell/lootbox/labels/in%20progress","name":"in progress","color":"6cd845","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/serokell/lootbox/pulls/33/commits","review_comments_url":"https://api.github.com/repos/serokell/lootbox/pulls/33/comments","review_comment_url":"https://api.github.com/repos/serokell/lootbox/pulls/comments{/number}","comments_url":"https://api.github.com/repos/serokell/lootbox/issues/33/comments","statuses_url":"https://api.github.com/repos/serokell/lootbox/statuses/5d026a1e139f0b62a549abcc827ebd51154df726","head":{"label":"serokell:volhovm/dscp281","ref":"volhovm/dscp281","sha":"5d026a1e139f0b62a549abcc827ebd51154df726","user":{"login":"serokell","id":13840520,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEzODQwNTIw","avatar_url":"https://avatars2.githubusercontent.com/u/13840520?v=4","gravatar_id":"","url":"https://api.github.com/users/serokell","html_url":"https://github.com/serokell","followers_url":"https://api.github.com/users/serokell/followers","following_url":"https://api.github.com/users/serokell/following{/other_user}","gists_url":"https://api.github.com/users/serokell/gists{/gist_id}","starred_url":"https://api.github.com/users/serokell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/serokell/subscriptions","organizations_url":"https://api.github.com/users/serokell/orgs","repos_url":"https://api.github.com/users/serokell/repos","events_url":"https://api.github.com/users/serokell/events{/privacy}","received_events_url":"https://api.github.com/users/serokell/received_events","type":"Organization","site_admin":false},"repo":{"id":123646264,"node_id":"MDEwOlJlcG9zaXRvcnkxMjM2NDYyNjQ=","name":"lootbox","full_name":"serokell/lootbox","private":false,"owner":{"login":"serokell","id":13840520,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEzODQwNTIw","avatar_url":"https://avatars2.githubusercontent.com/u/13840520?v=4","gravatar_id":"","url":"https://api.github.com/users/serokell","html_url":"https://github.com/serokell","followers_url":"https://api.github.com/users/serokell/followers","following_url":"https://api.github.com/users/serokell/following{/other_user}","gists_url":"https://api.github.com/users/serokell/gists{/gist_id}","starred_url":"https://api.github.com/users/serokell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/serokell/subscriptions","organizations_url":"https://api.github.com/users/serokell/orgs","repos_url":"https://api.github.com/users/serokell/repos","events_url":"https://api.github.com/users/serokell/events{/privacy}","received_events_url":"https://api.github.com/users/serokell/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/serokell/lootbox","description":"Toolbox for your cool project","fork":false,"url":"https://api.github.com/repos/serokell/lootbox","forks_url":"https://api.github.com/repos/serokell/lootbox/forks","keys_url":"https://api.github.com/repos/serokell/lootbox/keys{/key_id}","collaborators_url":"https://api.github.com/repos/serokell/lootbox/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/serokell/lootbox/teams","hooks_url":"https://api.github.com/repos/serokell/lootbox/hooks","issue_events_url":"https://api.github.com/repos/serokell/lootbox/issues/events{/number}","events_url":"https://api.github.com/repos/serokell/lootbox/events","assignees_url":"https://api.github.com/repos/serokell/lootbox/assignees{/user}","branches_url":"https://api.github.com/repos/serokell/lootbox/branches{/branch}","tags_url":"https://api.github.com/repos/serokell/lootbox/tags","blobs_url":"https://api.github.com/repos/serokell/lootbox/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/serokell/lootbox/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/serokell/lootbox/git/refs{/sha}","trees_url":"https://api.github.com/repos/serokell/lootbox/git/trees{/sha}","statuses_url":"https://api.github.com/repos/serokell/lootbox/statuses/{sha}","languages_url":"https://api.github.com/repos/serokell/lootbox/languages","stargazers_url":"https://api.github.com/repos/serokell/lootbox/stargazers","contributors_url":"https://api.github.com/repos/serokell/lootbox/contributors","subscribers_url":"https://api.github.com/repos/serokell/lootbox/subscribers","subscription_url":"https://api.github.com/repos/serokell/lootbox/subscription","commits_url":"https://api.github.com/repos/serokell/lootbox/commits{/sha}","git_commits_url":"https://api.github.com/repos/serokell/lootbox/git/commits{/sha}","comments_url":"https://api.github.com/repos/serokell/lootbox/comments{/number}","issue_comment_url":"https://api.github.com/repos/serokell/lootbox/issues/comments{/number}","contents_url":"https://api.github.com/repos/serokell/lootbox/contents/{+path}","compare_url":"https://api.github.com/repos/serokell/lootbox/compare/{base}...{head}","merges_url":"https://api.github.com/repos/serokell/lootbox/merges","archive_url":"https://api.github.com/repos/serokell/lootbox/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/serokell/lootbox/downloads","issues_url":"https://api.github.com/repos/serokell/lootbox/issues{/number}","pulls_url":"https://api.github.com/repos/serokell/lootbox/pulls{/number}","milestones_url":"https://api.github.com/repos/serokell/lootbox/milestones{/number}","notifications_url":"https://api.github.com/repos/serokell/lootbox/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/serokell/lootbox/labels{/name}","releases_url":"https://api.github.com/repos/serokell/lootbox/releases{/id}","deployments_url":"https://api.github.com/repos/serokell/lootbox/deployments","created_at":"2018-03-03T00:49:54Z","updated_at":"2018-10-29T15:02:10Z","pushed_at":"2018-11-04T11:57:46Z","git_url":"git://github.com/serokell/lootbox.git","ssh_url":"git@github.com:serokell/lootbox.git","clone_url":"https://github.com/serokell/lootbox.git","svn_url":"https://github.com/serokell/lootbox","homepage":"","size":338,"stargazers_count":2,"watchers_count":2,"language":"Haskell","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":9,"license":null,"forks":0,"open_issues":9,"watchers":2,"default_branch":"master"}},"base":{"label":"serokell:master","ref":"master","sha":"58fbcddb5dacafa7d4c9717fd171e8546442f7a2","user":{"login":"serokell","id":13840520,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEzODQwNTIw","avatar_url":"https://avatars2.githubusercontent.com/u/13840520?v=4","gravatar_id":"","url":"https://api.github.com/users/serokell","html_url":"https://github.com/serokell","followers_url":"https://api.github.com/users/serokell/followers","following_url":"https://api.github.com/users/serokell/following{/other_user}","gists_url":"https://api.github.com/users/serokell/gists{/gist_id}","starred_url":"https://api.github.com/users/serokell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/serokell/subscriptions","organizations_url":"https://api.github.com/users/serokell/orgs","repos_url":"https://api.github.com/users/serokell/repos","events_url":"https://api.github.com/users/serokell/events{/privacy}","received_events_url":"https://api.github.com/users/serokell/received_events","type":"Organization","site_admin":false},"repo":{"id":123646264,"node_id":"MDEwOlJlcG9zaXRvcnkxMjM2NDYyNjQ=","name":"lootbox","full_name":"serokell/lootbox","private":false,"owner":{"login":"serokell","id":13840520,"node_id":"MDEyOk9yZ2FuaXphdGlvbjEzODQwNTIw","avatar_url":"https://avatars2.githubusercontent.com/u/13840520?v=4","gravatar_id":"","url":"https://api.github.com/users/serokell","html_url":"https://github.com/serokell","followers_url":"https://api.github.com/users/serokell/followers","following_url":"https://api.github.com/users/serokell/following{/other_user}","gists_url":"https://api.github.com/users/serokell/gists{/gist_id}","starred_url":"https://api.github.com/users/serokell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/serokell/subscriptions","organizations_url":"https://api.github.com/users/serokell/orgs","repos_url":"https://api.github.com/users/serokell/repos","events_url":"https://api.github.com/users/serokell/events{/privacy}","received_events_url":"https://api.github.com/users/serokell/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/serokell/lootbox","description":"Toolbox for your cool project","fork":false,"url":"https://api.github.com/repos/serokell/lootbox","forks_url":"https://api.github.com/repos/serokell/lootbox/forks","keys_url":"https://api.github.com/repos/serokell/lootbox/keys{/key_id}","collaborators_url":"https://api.github.com/repos/serokell/lootbox/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/serokell/lootbox/teams","hooks_url":"https://api.github.com/repos/serokell/lootbox/hooks","issue_events_url":"https://api.github.com/repos/serokell/lootbox/issues/events{/number}","events_url":"https://api.github.com/repos/serokell/lootbox/events","assignees_url":"https://api.github.com/repos/serokell/lootbox/assignees{/user}","branches_url":"https://api.github.com/repos/serokell/lootbox/branches{/branch}","tags_url":"https://api.github.com/repos/serokell/lootbox/tags","blobs_url":"https://api.github.com/repos/serokell/lootbox/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/serokell/lootbox/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/serokell/lootbox/git/refs{/sha}","trees_url":"https://api.github.com/repos/serokell/lootbox/git/trees{/sha}","statuses_url":"https://api.github.com/repos/serokell/lootbox/statuses/{sha}","languages_url":"https://api.github.com/repos/serokell/lootbox/languages","stargazers_url":"https://api.github.com/repos/serokell/lootbox/stargazers","contributors_url":"https://api.github.com/repos/serokell/lootbox/contributors","subscribers_url":"https://api.github.com/repos/serokell/lootbox/subscribers","subscription_url":"https://api.github.com/repos/serokell/lootbox/subscription","commits_url":"https://api.github.com/repos/serokell/lootbox/commits{/sha}","git_commits_url":"https://api.github.com/repos/serokell/lootbox/git/commits{/sha}","comments_url":"https://api.github.com/repos/serokell/lootbox/comments{/number}","issue_comment_url":"https://api.github.com/repos/serokell/lootbox/issues/comments{/number}","contents_url":"https://api.github.com/repos/serokell/lootbox/contents/{+path}","compare_url":"https://api.github.com/repos/serokell/lootbox/compare/{base}...{head}","merges_url":"https://api.github.com/repos/serokell/lootbox/merges","archive_url":"https://api.github.com/repos/serokell/lootbox/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/serokell/lootbox/downloads","issues_url":"https://api.github.com/repos/serokell/lootbox/issues{/number}","pulls_url":"https://api.github.com/repos/serokell/lootbox/pulls{/number}","milestones_url":"https://api.github.com/repos/serokell/lootbox/milestones{/number}","notifications_url":"https://api.github.com/repos/serokell/lootbox/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/serokell/lootbox/labels{/name}","releases_url":"https://api.github.com/repos/serokell/lootbox/releases{/id}","deployments_url":"https://api.github.com/repos/serokell/lootbox/deployments","created_at":"2018-03-03T00:49:54Z","updated_at":"2018-10-29T15:02:10Z","pushed_at":"2018-11-04T11:57:46Z","git_url":"git://github.com/serokell/lootbox.git","ssh_url":"git@github.com:serokell/lootbox.git","clone_url":"https://github.com/serokell/lootbox.git","svn_url":"https://github.com/serokell/lootbox","homepage":"","size":338,"stargazers_count":2,"watchers_count":2,"language":"Haskell","has_issues":true,"has_projects":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":9,"license":null,"forks":0,"open_issues":9,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/serokell/lootbox/pulls/33"},"html":{"href":"https://github.com/serokell/lootbox/pull/33"},"issue":{"href":"https://api.github.com/repos/serokell/lootbox/issues/33"},"comments":{"href":"https://api.github.com/repos/serokell/lootbox/issues/33/comments"},"review_comments":{"href":"https://api.github.com/repos/serokell/lootbox/pulls/33/comments"},"review_comment":{"href":"https://api.github.com/repos/serokell/lootbox/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/serokell/lootbox/pulls/33/commits"},"statuses":{"href":"https://api.github.com/repos/serokell/lootbox/statuses/5d026a1e139f0b62a549abcc827ebd51154df726"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"Martoon-00"}}