{"action":"created","comment":{"url":"https://api.github.com/repos/Metaswitch/cpp-common/pulls/comments/41152260","id":41152260,"diff_hunk":"@@ -343,60 +356,36 @@ void Stack::fd_peer_hook_cb(enum fd_hook_type type,\n   {\n     TRC_DEBUG(\"Callback (type %d) from freeDiameter: %s\", type, peer->info.pi_diamid);\n \n-    DiamId_t host = peer->info.pi_diamid;\n-    DiamId_t realm = peer->info.runtime.pir_realm;\n-    pthread_mutex_lock(&_peers_lock);\n-    std::vector<Peer*>::iterator ii;\n-    bool peer_found = false;\n-    for (ii = _peers.begin();\n-         ii != _peers.end();\n-         ii++)\n-    {\n-      if ((*ii)->host().compare(host) == 0)\n-      {\n-        peer_found = true;\n-        if ((*ii)->listener())\n-        {\n-          if (type == HOOK_PEER_CONNECT_SUCCESS)\n-          {\n-            if ((*ii)->realm().empty() || ((*ii)->realm().compare(realm) == 0))\n-            {\n-              TRC_DEBUG(\"Successfully connected to %s in realm %s\", host, realm);\n-              (*ii)->listener()->connection_succeeded(*ii);\n-              (*ii)->set_connected();\n-            }\n-            else\n-            {\n-              TRC_WARNING(\"Connected to %s in wrong realm (expected %s, got %s), disconnect\", host,\n-                                                                                              (*ii)->realm().c_str(),\n-                                                                                              realm);\n-              Diameter::Peer* stack_peer = *ii;\n-              remove_int(stack_peer);\n-              stack_peer->listener()->connection_failed(stack_peer);\n-            }\n-          }\n-          else if (type == HOOK_PEER_CONNECT_FAILED)\n-          {\n-            CL_DIAMETER_CONN_ERR.log(host);\n-            TRC_WARNING(\"Failed to connect to %s\", host);\n-            Diameter::Peer* stack_peer = *ii;\n-            _peers.erase(ii);\n-            stack_peer->listener()->connection_failed(stack_peer);\n-          }\n-        }\n-        break;\n-      }\n-    }\n+    std::string host = peer->info.pi_diamid;\n+    std::string realm = peer->info.runtime.pir_realm;\n \n-    if (!peer_found)\n+    for (std::map<std::string, PeerConnectionCB>::const_iterator cb = _peer_connection_cbs.begin();","path":"src/diameterstack.cpp","position":195,"original_position":195,"commit_id":"ceffb48a056bd6c1c12c95968a1c37da5df527f9","original_commit_id":"ceffb48a056bd6c1c12c95968a1c37da5df527f9","user":{"login":"graemerobertson","id":5907876,"avatar_url":"https://avatars.githubusercontent.com/u/5907876?v=3","gravatar_id":"","url":"https://api.github.com/users/graemerobertson","html_url":"https://github.com/graemerobertson","followers_url":"https://api.github.com/users/graemerobertson/followers","following_url":"https://api.github.com/users/graemerobertson/following{/other_user}","gists_url":"https://api.github.com/users/graemerobertson/gists{/gist_id}","starred_url":"https://api.github.com/users/graemerobertson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/graemerobertson/subscriptions","organizations_url":"https://api.github.com/users/graemerobertson/orgs","repos_url":"https://api.github.com/users/graemerobertson/repos","events_url":"https://api.github.com/users/graemerobertson/events{/privacy}","received_events_url":"https://api.github.com/users/graemerobertson/received_events","type":"User","site_admin":false},"body":"Say what?","created_at":"2015-10-05T14:48:33Z","updated_at":"2015-10-05T14:48:33Z","html_url":"https://github.com/Metaswitch/cpp-common/pull/385#discussion_r41152260","pull_request_url":"https://api.github.com/repos/Metaswitch/cpp-common/pulls/385","_links":{"self":{"href":"https://api.github.com/repos/Metaswitch/cpp-common/pulls/comments/41152260"},"html":{"href":"https://github.com/Metaswitch/cpp-common/pull/385#discussion_r41152260"},"pull_request":{"href":"https://api.github.com/repos/Metaswitch/cpp-common/pulls/385"}}},"pull_request":{"url":"https://api.github.com/repos/Metaswitch/cpp-common/pulls/385","id":46767535,"html_url":"https://github.com/Metaswitch/cpp-common/pull/385","diff_url":"https://github.com/Metaswitch/cpp-common/pull/385.diff","patch_url":"https://github.com/Metaswitch/cpp-common/pull/385.patch","issue_url":"https://api.github.com/repos/Metaswitch/cpp-common/issues/385","number":385,"state":"open","locked":false,"title":"Reviewer AMC: SRV priority and Diameter routing","user":{"login":"graemerobertson","id":5907876,"avatar_url":"https://avatars.githubusercontent.com/u/5907876?v=3","gravatar_id":"","url":"https://api.github.com/users/graemerobertson","html_url":"https://github.com/graemerobertson","followers_url":"https://api.github.com/users/graemerobertson/followers","following_url":"https://api.github.com/users/graemerobertson/following{/other_user}","gists_url":"https://api.github.com/users/graemerobertson/gists{/gist_id}","starred_url":"https://api.github.com/users/graemerobertson/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/graemerobertson/subscriptions","organizations_url":"https://api.github.com/users/graemerobertson/orgs","repos_url":"https://api.github.com/users/graemerobertson/repos","events_url":"https://api.github.com/users/graemerobertson/events{/privacy}","received_events_url":"https://api.github.com/users/graemerobertson/received_events","type":"User","site_admin":false},"body":"Hi Andy,\r\n\r\nPlease can you review these cpp-common changes to allow us to take into account SRV priority when routing Diameter messages?\r\n\r\nThe bulk of the work here is to refactor the existing code to make it more usable. Specifically, I've made RealmManager the sole manager of Diameter peers (removing the Diameter Stack's list of them), and I've tried to keep freeDiameter out of the RealmManager (instead using the Diameter Stack as the interface to freeDiameter), and I've made RealmManager an application of the Diameter Stack, so that the Stack doesn't know anything about RealmManager.\r\n\r\nIn addition to this, RealmManager now keeps track of the peers as a map rather than a vector, so that we can easily look up the Peer object when we get a call back. This is important because we now need to do this on the call path (i.e. when taking into account the SRV priority on message routing).\r\n\r\nThere is an accompanying Homestead PR (https://github.com/Metaswitch/homestead/pull/261) because the RealmManager is UTed in Homestead. I've still got complete code coverage on the RealmManager. I've also verified that existing function still works live, and I'm intending to run through the rest of the test plan later in the week.\r\n\r\nLet me know if you've got any questions. It would be great if you could review by **end of Wednesday**, but let me know if that's going to be a problem.\r\n\r\nThanks,\r\nGraeme","created_at":"2015-10-05T11:02:15Z","updated_at":"2015-10-05T14:48:33Z","closed_at":null,"merged_at":null,"merge_commit_sha":"cbe86f70ac2ffa6d0913de4362d94e7b04b43837","assignee":{"login":"bossmc","id":1073983,"avatar_url":"https://avatars.githubusercontent.com/u/1073983?v=3","gravatar_id":"","url":"https://api.github.com/users/bossmc","html_url":"https://github.com/bossmc","followers_url":"https://api.github.com/users/bossmc/followers","following_url":"https://api.github.com/users/bossmc/following{/other_user}","gists_url":"https://api.github.com/users/bossmc/gists{/gist_id}","starred_url":"https://api.github.com/users/bossmc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bossmc/subscriptions","organizations_url":"https://api.github.com/users/bossmc/orgs","repos_url":"https://api.github.com/users/bossmc/repos","events_url":"https://api.github.com/users/bossmc/events{/privacy}","received_events_url":"https://api.github.com/users/bossmc/received_events","type":"User","site_admin":false},"milestone":null,"commits_url":"https://api.github.com/repos/Metaswitch/cpp-common/pulls/385/commits","review_comments_url":"https://api.github.com/repos/Metaswitch/cpp-common/pulls/385/comments","review_comment_url":"https://api.github.com/repos/Metaswitch/cpp-common/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Metaswitch/cpp-common/issues/385/comments","statuses_url":"https://api.github.com/repos/Metaswitch/cpp-common/statuses/ceffb48a056bd6c1c12c95968a1c37da5df527f9","head":{"label":"Metaswitch:srv_priority","ref":"srv_priority","sha":"ceffb48a056bd6c1c12c95968a1c37da5df527f9","user":{"login":"Metaswitch","id":453759,"avatar_url":"https://avatars.githubusercontent.com/u/453759?v=3","gravatar_id":"","url":"https://api.github.com/users/Metaswitch","html_url":"https://github.com/Metaswitch","followers_url":"https://api.github.com/users/Metaswitch/followers","following_url":"https://api.github.com/users/Metaswitch/following{/other_user}","gists_url":"https://api.github.com/users/Metaswitch/gists{/gist_id}","starred_url":"https://api.github.com/users/Metaswitch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Metaswitch/subscriptions","organizations_url":"https://api.github.com/users/Metaswitch/orgs","repos_url":"https://api.github.com/users/Metaswitch/repos","events_url":"https://api.github.com/users/Metaswitch/events{/privacy}","received_events_url":"https://api.github.com/users/Metaswitch/received_events","type":"Organization","site_admin":false},"repo":{"id":15284898,"name":"cpp-common","full_name":"Metaswitch/cpp-common","owner":{"login":"Metaswitch","id":453759,"avatar_url":"https://avatars.githubusercontent.com/u/453759?v=3","gravatar_id":"","url":"https://api.github.com/users/Metaswitch","html_url":"https://github.com/Metaswitch","followers_url":"https://api.github.com/users/Metaswitch/followers","following_url":"https://api.github.com/users/Metaswitch/following{/other_user}","gists_url":"https://api.github.com/users/Metaswitch/gists{/gist_id}","starred_url":"https://api.github.com/users/Metaswitch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Metaswitch/subscriptions","organizations_url":"https://api.github.com/users/Metaswitch/orgs","repos_url":"https://api.github.com/users/Metaswitch/repos","events_url":"https://api.github.com/users/Metaswitch/events{/privacy}","received_events_url":"https://api.github.com/users/Metaswitch/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Metaswitch/cpp-common","description":"Common C/C++ modules for Clearwater components","fork":false,"url":"https://api.github.com/repos/Metaswitch/cpp-common","forks_url":"https://api.github.com/repos/Metaswitch/cpp-common/forks","keys_url":"https://api.github.com/repos/Metaswitch/cpp-common/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Metaswitch/cpp-common/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Metaswitch/cpp-common/teams","hooks_url":"https://api.github.com/repos/Metaswitch/cpp-common/hooks","issue_events_url":"https://api.github.com/repos/Metaswitch/cpp-common/issues/events{/number}","events_url":"https://api.github.com/repos/Metaswitch/cpp-common/events","assignees_url":"https://api.github.com/repos/Metaswitch/cpp-common/assignees{/user}","branches_url":"https://api.github.com/repos/Metaswitch/cpp-common/branches{/branch}","tags_url":"https://api.github.com/repos/Metaswitch/cpp-common/tags","blobs_url":"https://api.github.com/repos/Metaswitch/cpp-common/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Metaswitch/cpp-common/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Metaswitch/cpp-common/git/refs{/sha}","trees_url":"https://api.github.com/repos/Metaswitch/cpp-common/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Metaswitch/cpp-common/statuses/{sha}","languages_url":"https://api.github.com/repos/Metaswitch/cpp-common/languages","stargazers_url":"https://api.github.com/repos/Metaswitch/cpp-common/stargazers","contributors_url":"https://api.github.com/repos/Metaswitch/cpp-common/contributors","subscribers_url":"https://api.github.com/repos/Metaswitch/cpp-common/subscribers","subscription_url":"https://api.github.com/repos/Metaswitch/cpp-common/subscription","commits_url":"https://api.github.com/repos/Metaswitch/cpp-common/commits{/sha}","git_commits_url":"https://api.github.com/repos/Metaswitch/cpp-common/git/commits{/sha}","comments_url":"https://api.github.com/repos/Metaswitch/cpp-common/comments{/number}","issue_comment_url":"https://api.github.com/repos/Metaswitch/cpp-common/issues/comments{/number}","contents_url":"https://api.github.com/repos/Metaswitch/cpp-common/contents/{+path}","compare_url":"https://api.github.com/repos/Metaswitch/cpp-common/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Metaswitch/cpp-common/merges","archive_url":"https://api.github.com/repos/Metaswitch/cpp-common/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Metaswitch/cpp-common/downloads","issues_url":"https://api.github.com/repos/Metaswitch/cpp-common/issues{/number}","pulls_url":"https://api.github.com/repos/Metaswitch/cpp-common/pulls{/number}","milestones_url":"https://api.github.com/repos/Metaswitch/cpp-common/milestones{/number}","notifications_url":"https://api.github.com/repos/Metaswitch/cpp-common/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Metaswitch/cpp-common/labels{/name}","releases_url":"https://api.github.com/repos/Metaswitch/cpp-common/releases{/id}","created_at":"2013-12-18T14:11:57Z","updated_at":"2015-08-31T09:54:09Z","pushed_at":"2015-10-05T11:02:16Z","git_url":"git://github.com/Metaswitch/cpp-common.git","ssh_url":"git@github.com:Metaswitch/cpp-common.git","clone_url":"https://github.com/Metaswitch/cpp-common.git","svn_url":"https://github.com/Metaswitch/cpp-common","homepage":null,"size":4618,"stargazers_count":1,"watchers_count":1,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":15,"forks":5,"open_issues":15,"watchers":1,"default_branch":"master"}},"base":{"label":"Metaswitch:master","ref":"master","sha":"09eac370e3cc80b024af81a0ddd2f0b8b92b6e40","user":{"login":"Metaswitch","id":453759,"avatar_url":"https://avatars.githubusercontent.com/u/453759?v=3","gravatar_id":"","url":"https://api.github.com/users/Metaswitch","html_url":"https://github.com/Metaswitch","followers_url":"https://api.github.com/users/Metaswitch/followers","following_url":"https://api.github.com/users/Metaswitch/following{/other_user}","gists_url":"https://api.github.com/users/Metaswitch/gists{/gist_id}","starred_url":"https://api.github.com/users/Metaswitch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Metaswitch/subscriptions","organizations_url":"https://api.github.com/users/Metaswitch/orgs","repos_url":"https://api.github.com/users/Metaswitch/repos","events_url":"https://api.github.com/users/Metaswitch/events{/privacy}","received_events_url":"https://api.github.com/users/Metaswitch/received_events","type":"Organization","site_admin":false},"repo":{"id":15284898,"name":"cpp-common","full_name":"Metaswitch/cpp-common","owner":{"login":"Metaswitch","id":453759,"avatar_url":"https://avatars.githubusercontent.com/u/453759?v=3","gravatar_id":"","url":"https://api.github.com/users/Metaswitch","html_url":"https://github.com/Metaswitch","followers_url":"https://api.github.com/users/Metaswitch/followers","following_url":"https://api.github.com/users/Metaswitch/following{/other_user}","gists_url":"https://api.github.com/users/Metaswitch/gists{/gist_id}","starred_url":"https://api.github.com/users/Metaswitch/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Metaswitch/subscriptions","organizations_url":"https://api.github.com/users/Metaswitch/orgs","repos_url":"https://api.github.com/users/Metaswitch/repos","events_url":"https://api.github.com/users/Metaswitch/events{/privacy}","received_events_url":"https://api.github.com/users/Metaswitch/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Metaswitch/cpp-common","description":"Common C/C++ modules for Clearwater components","fork":false,"url":"https://api.github.com/repos/Metaswitch/cpp-common","forks_url":"https://api.github.com/repos/Metaswitch/cpp-common/forks","keys_url":"https://api.github.com/repos/Metaswitch/cpp-common/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Metaswitch/cpp-common/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Metaswitch/cpp-common/teams","hooks_url":"https://api.github.com/repos/Metaswitch/cpp-common/hooks","issue_events_url":"https://api.github.com/repos/Metaswitch/cpp-common/issues/events{/number}","events_url":"https://api.github.com/repos/Metaswitch/cpp-common/events","assignees_url":"https://api.github.com/repos/Metaswitch/cpp-common/assignees{/user}","branches_url":"https://api.github.com/repos/Metaswitch/cpp-common/branches{/branch}","tags_url":"https://api.github.com/repos/Metaswitch/cpp-common/tags","blobs_url":"https://api.github.com/repos/Metaswitch/cpp-common/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Metaswitch/cpp-common/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Metaswitch/cpp-common/git/refs{/sha}","trees_url":"https://api.github.com/repos/Metaswitch/cpp-common/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Metaswitch/cpp-common/statuses/{sha}","languages_url":"https://api.github.com/repos/Metaswitch/cpp-common/languages","stargazers_url":"https://api.github.com/repos/Metaswitch/cpp-common/stargazers","contributors_url":"https://api.github.com/repos/Metaswitch/cpp-common/contributors","subscribers_url":"https://api.github.com/repos/Metaswitch/cpp-common/subscribers","subscription_url":"https://api.github.com/repos/Metaswitch/cpp-common/subscription","commits_url":"https://api.github.com/repos/Metaswitch/cpp-common/commits{/sha}","git_commits_url":"https://api.github.com/repos/Metaswitch/cpp-common/git/commits{/sha}","comments_url":"https://api.github.com/repos/Metaswitch/cpp-common/comments{/number}","issue_comment_url":"https://api.github.com/repos/Metaswitch/cpp-common/issues/comments{/number}","contents_url":"https://api.github.com/repos/Metaswitch/cpp-common/contents/{+path}","compare_url":"https://api.github.com/repos/Metaswitch/cpp-common/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Metaswitch/cpp-common/merges","archive_url":"https://api.github.com/repos/Metaswitch/cpp-common/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Metaswitch/cpp-common/downloads","issues_url":"https://api.github.com/repos/Metaswitch/cpp-common/issues{/number}","pulls_url":"https://api.github.com/repos/Metaswitch/cpp-common/pulls{/number}","milestones_url":"https://api.github.com/repos/Metaswitch/cpp-common/milestones{/number}","notifications_url":"https://api.github.com/repos/Metaswitch/cpp-common/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Metaswitch/cpp-common/labels{/name}","releases_url":"https://api.github.com/repos/Metaswitch/cpp-common/releases{/id}","created_at":"2013-12-18T14:11:57Z","updated_at":"2015-08-31T09:54:09Z","pushed_at":"2015-10-05T11:02:16Z","git_url":"git://github.com/Metaswitch/cpp-common.git","ssh_url":"git@github.com:Metaswitch/cpp-common.git","clone_url":"https://github.com/Metaswitch/cpp-common.git","svn_url":"https://github.com/Metaswitch/cpp-common","homepage":null,"size":4618,"stargazers_count":1,"watchers_count":1,"language":"C++","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":15,"forks":5,"open_issues":15,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Metaswitch/cpp-common/pulls/385"},"html":{"href":"https://github.com/Metaswitch/cpp-common/pull/385"},"issue":{"href":"https://api.github.com/repos/Metaswitch/cpp-common/issues/385"},"comments":{"href":"https://api.github.com/repos/Metaswitch/cpp-common/issues/385/comments"},"review_comments":{"href":"https://api.github.com/repos/Metaswitch/cpp-common/pulls/385/comments"},"review_comment":{"href":"https://api.github.com/repos/Metaswitch/cpp-common/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Metaswitch/cpp-common/pulls/385/commits"},"statuses":{"href":"https://api.github.com/repos/Metaswitch/cpp-common/statuses/ceffb48a056bd6c1c12c95968a1c37da5df527f9"}}}}