{"action":"created","comment":{"url":"https://api.github.com/repos/micro/go-micro/pulls/comments/298715866","pull_request_review_id":255930948,"id":298715866,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDI5ODcxNTg2Ng==","diff_hunk":"@@ -69,43 +72,110 @@ func (r *router) Network() string {\n \treturn r.opts.Network\n }\n \n-// Advertise advertises the routes to the network. It is a blocking function.\n+// Advertise advertises the routes to the network.\n // It returns error if any of the launched goroutines fail with error.\n-func (r *router) Advertise() error {\n-\t// add local service routes into the routing table\n-\tif err := r.addServiceRoutes(r.opts.Registry, \"local\", DefaultLocalMetric); err != nil {\n-\t\treturn fmt.Errorf(\"failed adding routes: %v\", err)\n-\t}\n+func (r *router) Advertise() (<-chan *Update, error) {\n+\tr.Lock()\n+\tdefer r.Unlock()\n+\n+\tif r.status.Code != Running {\n+\t\t// add local service routes into the routing table\n+\t\tif err := r.addServiceRoutes(r.opts.Registry, \"local\", DefaultLocalMetric); err != nil {\n+\t\t\treturn nil, fmt.Errorf(\"failed adding routes: %v\", err)\n+\t\t}\n \n-\tlocalWatcher, err := r.opts.Registry.Watch()\n-\tif err != nil {\n-\t\treturn fmt.Errorf(\"failed to create registry watcher: %v\", err)\n+\t\t// add default gateway into routing table\n+\t\tif r.opts.Gateway != \"\" {\n+\t\t\t// note, the only non-default value is the gateway\n+\t\t\troute := Route{\n+\t\t\t\tDestination: \"*\",\n+\t\t\t\tGateway:     r.opts.Gateway,\n+\t\t\t\tRouter:      \"*\",\n+\t\t\t\tNetwork:     \"*\",\n+\t\t\t\tMetric:      DefaultLocalMetric,\n+\t\t\t}\n+\t\t\tif err := r.opts.Table.Add(route); err != nil {\n+\t\t\t\treturn nil, fmt.Errorf(\"error to add default gateway route: %s\", err)\n+\t\t\t}\n+\t\t}\n+\n+\t\t// routing table watcher which watches all routes i.e. to every destination\n+\t\ttableWatcher, err := r.opts.Table.Watch(WatchDestination(\"*\"))\n+\t\tif err != nil {\n+\t\t\treturn nil, fmt.Errorf(\"failed to create routing table watcher: %v\", err)\n+\t\t}\n+\n+\t\t// registry watcher\n+\t\tregWatcher, err := r.opts.Registry.Watch()\n+\t\tif err != nil {\n+\t\t\treturn nil, fmt.Errorf(\"failed to create registry watcher: %v\", err)\n+\t\t}\n+\n+\t\t// error channel collecting goroutine errors\n+\t\terrChan := make(chan error, 2)\n+\n+\t\tr.wg.Add(1)\n+\t\tgo func() {\n+\t\t\tdefer r.wg.Done()\n+\t\t\t// watch local registry and register routes in routine table\n+\t\t\terrChan <- r.manageServiceRoutes(regWatcher, DefaultLocalMetric)\n+\t\t}()\n+\n+\t\tr.wg.Add(1)\n+\t\tgo func() {\n+\t\t\tdefer r.wg.Done()\n+\t\t\t// watch local registry and register routes in routing table\n+\t\t\terrChan <- r.watchTable(tableWatcher)\n+\t\t}()\n+\n+\t\tr.wg.Add(1)\n+\t\tgo func() {\n+\t\t\tdefer r.wg.Done()\n+\t\t\tselect {\n+\t\t\t// wait for exit chan\n+\t\t\tcase <-r.exit:\n+\t\t\t\tr.status.Code = Stopped\n+\t\t\tcase err := <-errChan:\n+\t\t\t\tr.status.Code = Error\n+\t\t\t\tr.status.Error = err\n+\t\t\t}\n+\t\t\t// close the advertise channel\n+\t\t\tclose(r.advertChan)","path":"network/router/default_router.go","position":127,"original_position":127,"commit_id":"21c1c6bbf713323f12bc6b1c9ee94a0cda989e36","original_commit_id":"21c1c6bbf713323f12bc6b1c9ee94a0cda989e36","user":{"login":"asim","id":17530,"node_id":"MDQ6VXNlcjE3NTMw","avatar_url":"https://avatars1.githubusercontent.com/u/17530?v=4","gravatar_id":"","url":"https://api.github.com/users/asim","html_url":"https://github.com/asim","followers_url":"https://api.github.com/users/asim/followers","following_url":"https://api.github.com/users/asim/following{/other_user}","gists_url":"https://api.github.com/users/asim/gists{/gist_id}","starred_url":"https://api.github.com/users/asim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/asim/subscriptions","organizations_url":"https://api.github.com/users/asim/orgs","repos_url":"https://api.github.com/users/asim/repos","events_url":"https://api.github.com/users/asim/events{/privacy}","received_events_url":"https://api.github.com/users/asim/received_events","type":"User","site_admin":false},"body":"If you close this here, if I call Advertise again is it creating a new advertChan?","created_at":"2019-06-28T19:06:35Z","updated_at":"2019-06-28T19:06:35Z","html_url":"https://github.com/micro/go-micro/pull/553#discussion_r298715866","pull_request_url":"https://api.github.com/repos/micro/go-micro/pulls/553","author_association":"MEMBER","_links":{"self":{"href":"https://api.github.com/repos/micro/go-micro/pulls/comments/298715866"},"html":{"href":"https://github.com/micro/go-micro/pull/553#discussion_r298715866"},"pull_request":{"href":"https://api.github.com/repos/micro/go-micro/pulls/553"}}},"pull_request":{"url":"https://api.github.com/repos/micro/go-micro/pulls/553","id":292618964,"node_id":"MDExOlB1bGxSZXF1ZXN0MjkyNjE4OTY0","html_url":"https://github.com/micro/go-micro/pull/553","diff_url":"https://github.com/micro/go-micro/pull/553.diff","patch_url":"https://github.com/micro/go-micro/pull/553.patch","issue_url":"https://api.github.com/repos/micro/go-micro/issues/553","number":553,"state":"open","locked":false,"title":"Changed router interface. Added table watcher. Advertise routes","user":{"login":"milosgajdos83","id":1392526,"node_id":"MDQ6VXNlcjEzOTI1MjY=","avatar_url":"https://avatars2.githubusercontent.com/u/1392526?v=4","gravatar_id":"","url":"https://api.github.com/users/milosgajdos83","html_url":"https://github.com/milosgajdos83","followers_url":"https://api.github.com/users/milosgajdos83/followers","following_url":"https://api.github.com/users/milosgajdos83/following{/other_user}","gists_url":"https://api.github.com/users/milosgajdos83/gists{/gist_id}","starred_url":"https://api.github.com/users/milosgajdos83/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/milosgajdos83/subscriptions","organizations_url":"https://api.github.com/users/milosgajdos83/orgs","repos_url":"https://api.github.com/users/milosgajdos83/repos","events_url":"https://api.github.com/users/milosgajdos83/events{/privacy}","received_events_url":"https://api.github.com/users/milosgajdos83/received_events","type":"User","site_admin":false},"body":"**DO NOT MERGE IN YET**\r\n\r\n* Changed router interface to return Advertisement channel\r\n* Added default gateway route to the routing table if supplied\r\n* Watch table for updates and advertise to the network\r\n* We hash the routes on 3-tuple (Destination, Gateway, Network)","created_at":"2019-06-27T22:00:47Z","updated_at":"2019-06-28T19:06:35Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5c7e779aae0fc4c0581bed02589d28a90464e999","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[{"id":1426427139,"node_id":"MDU6TGFiZWwxNDI2NDI3MTM5","url":"https://api.github.com/repos/micro/go-micro/labels/WIP","name":"WIP","color":"d15045","default":false}],"milestone":null,"commits_url":"https://api.github.com/repos/micro/go-micro/pulls/553/commits","review_comments_url":"https://api.github.com/repos/micro/go-micro/pulls/553/comments","review_comment_url":"https://api.github.com/repos/micro/go-micro/pulls/comments{/number}","comments_url":"https://api.github.com/repos/micro/go-micro/issues/553/comments","statuses_url":"https://api.github.com/repos/micro/go-micro/statuses/21c1c6bbf713323f12bc6b1c9ee94a0cda989e36","head":{"label":"milosgajdos83:router-network","ref":"router-network","sha":"21c1c6bbf713323f12bc6b1c9ee94a0cda989e36","user":{"login":"milosgajdos83","id":1392526,"node_id":"MDQ6VXNlcjEzOTI1MjY=","avatar_url":"https://avatars2.githubusercontent.com/u/1392526?v=4","gravatar_id":"","url":"https://api.github.com/users/milosgajdos83","html_url":"https://github.com/milosgajdos83","followers_url":"https://api.github.com/users/milosgajdos83/followers","following_url":"https://api.github.com/users/milosgajdos83/following{/other_user}","gists_url":"https://api.github.com/users/milosgajdos83/gists{/gist_id}","starred_url":"https://api.github.com/users/milosgajdos83/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/milosgajdos83/subscriptions","organizations_url":"https://api.github.com/users/milosgajdos83/orgs","repos_url":"https://api.github.com/users/milosgajdos83/repos","events_url":"https://api.github.com/users/milosgajdos83/events{/privacy}","received_events_url":"https://api.github.com/users/milosgajdos83/received_events","type":"User","site_admin":false},"repo":{"id":191018731,"node_id":"MDEwOlJlcG9zaXRvcnkxOTEwMTg3MzE=","name":"go-micro","full_name":"milosgajdos83/go-micro","private":false,"owner":{"login":"milosgajdos83","id":1392526,"node_id":"MDQ6VXNlcjEzOTI1MjY=","avatar_url":"https://avatars2.githubusercontent.com/u/1392526?v=4","gravatar_id":"","url":"https://api.github.com/users/milosgajdos83","html_url":"https://github.com/milosgajdos83","followers_url":"https://api.github.com/users/milosgajdos83/followers","following_url":"https://api.github.com/users/milosgajdos83/following{/other_user}","gists_url":"https://api.github.com/users/milosgajdos83/gists{/gist_id}","starred_url":"https://api.github.com/users/milosgajdos83/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/milosgajdos83/subscriptions","organizations_url":"https://api.github.com/users/milosgajdos83/orgs","repos_url":"https://api.github.com/users/milosgajdos83/repos","events_url":"https://api.github.com/users/milosgajdos83/events{/privacy}","received_events_url":"https://api.github.com/users/milosgajdos83/received_events","type":"User","site_admin":false},"html_url":"https://github.com/milosgajdos83/go-micro","description":"A microservice development framework","fork":true,"url":"https://api.github.com/repos/milosgajdos83/go-micro","forks_url":"https://api.github.com/repos/milosgajdos83/go-micro/forks","keys_url":"https://api.github.com/repos/milosgajdos83/go-micro/keys{/key_id}","collaborators_url":"https://api.github.com/repos/milosgajdos83/go-micro/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/milosgajdos83/go-micro/teams","hooks_url":"https://api.github.com/repos/milosgajdos83/go-micro/hooks","issue_events_url":"https://api.github.com/repos/milosgajdos83/go-micro/issues/events{/number}","events_url":"https://api.github.com/repos/milosgajdos83/go-micro/events","assignees_url":"https://api.github.com/repos/milosgajdos83/go-micro/assignees{/user}","branches_url":"https://api.github.com/repos/milosgajdos83/go-micro/branches{/branch}","tags_url":"https://api.github.com/repos/milosgajdos83/go-micro/tags","blobs_url":"https://api.github.com/repos/milosgajdos83/go-micro/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/milosgajdos83/go-micro/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/milosgajdos83/go-micro/git/refs{/sha}","trees_url":"https://api.github.com/repos/milosgajdos83/go-micro/git/trees{/sha}","statuses_url":"https://api.github.com/repos/milosgajdos83/go-micro/statuses/{sha}","languages_url":"https://api.github.com/repos/milosgajdos83/go-micro/languages","stargazers_url":"https://api.github.com/repos/milosgajdos83/go-micro/stargazers","contributors_url":"https://api.github.com/repos/milosgajdos83/go-micro/contributors","subscribers_url":"https://api.github.com/repos/milosgajdos83/go-micro/subscribers","subscription_url":"https://api.github.com/repos/milosgajdos83/go-micro/subscription","commits_url":"https://api.github.com/repos/milosgajdos83/go-micro/commits{/sha}","git_commits_url":"https://api.github.com/repos/milosgajdos83/go-micro/git/commits{/sha}","comments_url":"https://api.github.com/repos/milosgajdos83/go-micro/comments{/number}","issue_comment_url":"https://api.github.com/repos/milosgajdos83/go-micro/issues/comments{/number}","contents_url":"https://api.github.com/repos/milosgajdos83/go-micro/contents/{+path}","compare_url":"https://api.github.com/repos/milosgajdos83/go-micro/compare/{base}...{head}","merges_url":"https://api.github.com/repos/milosgajdos83/go-micro/merges","archive_url":"https://api.github.com/repos/milosgajdos83/go-micro/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/milosgajdos83/go-micro/downloads","issues_url":"https://api.github.com/repos/milosgajdos83/go-micro/issues{/number}","pulls_url":"https://api.github.com/repos/milosgajdos83/go-micro/pulls{/number}","milestones_url":"https://api.github.com/repos/milosgajdos83/go-micro/milestones{/number}","notifications_url":"https://api.github.com/repos/milosgajdos83/go-micro/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/milosgajdos83/go-micro/labels{/name}","releases_url":"https://api.github.com/repos/milosgajdos83/go-micro/releases{/id}","deployments_url":"https://api.github.com/repos/milosgajdos83/go-micro/deployments","created_at":"2019-06-09T14:49:07Z","updated_at":"2019-06-09T14:49:09Z","pushed_at":"2019-06-28T17:36:28Z","git_url":"git://github.com/milosgajdos83/go-micro.git","ssh_url":"git@github.com:milosgajdos83/go-micro.git","clone_url":"https://github.com/milosgajdos83/go-micro.git","svn_url":"https://github.com/milosgajdos83/go-micro","homepage":"","size":1975,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":0,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"micro:master","ref":"master","sha":"d8e998ad85feac9288dd34dfb2dd75ce66bde6f4","user":{"login":"micro","id":5161210,"node_id":"MDEyOk9yZ2FuaXphdGlvbjUxNjEyMTA=","avatar_url":"https://avatars3.githubusercontent.com/u/5161210?v=4","gravatar_id":"","url":"https://api.github.com/users/micro","html_url":"https://github.com/micro","followers_url":"https://api.github.com/users/micro/followers","following_url":"https://api.github.com/users/micro/following{/other_user}","gists_url":"https://api.github.com/users/micro/gists{/gist_id}","starred_url":"https://api.github.com/users/micro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/micro/subscriptions","organizations_url":"https://api.github.com/users/micro/orgs","repos_url":"https://api.github.com/users/micro/repos","events_url":"https://api.github.com/users/micro/events{/privacy}","received_events_url":"https://api.github.com/users/micro/received_events","type":"Organization","site_admin":false},"repo":{"id":29217054,"node_id":"MDEwOlJlcG9zaXRvcnkyOTIxNzA1NA==","name":"go-micro","full_name":"micro/go-micro","private":false,"owner":{"login":"micro","id":5161210,"node_id":"MDEyOk9yZ2FuaXphdGlvbjUxNjEyMTA=","avatar_url":"https://avatars3.githubusercontent.com/u/5161210?v=4","gravatar_id":"","url":"https://api.github.com/users/micro","html_url":"https://github.com/micro","followers_url":"https://api.github.com/users/micro/followers","following_url":"https://api.github.com/users/micro/following{/other_user}","gists_url":"https://api.github.com/users/micro/gists{/gist_id}","starred_url":"https://api.github.com/users/micro/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/micro/subscriptions","organizations_url":"https://api.github.com/users/micro/orgs","repos_url":"https://api.github.com/users/micro/repos","events_url":"https://api.github.com/users/micro/events{/privacy}","received_events_url":"https://api.github.com/users/micro/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/micro/go-micro","description":"A microservice development framework","fork":false,"url":"https://api.github.com/repos/micro/go-micro","forks_url":"https://api.github.com/repos/micro/go-micro/forks","keys_url":"https://api.github.com/repos/micro/go-micro/keys{/key_id}","collaborators_url":"https://api.github.com/repos/micro/go-micro/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/micro/go-micro/teams","hooks_url":"https://api.github.com/repos/micro/go-micro/hooks","issue_events_url":"https://api.github.com/repos/micro/go-micro/issues/events{/number}","events_url":"https://api.github.com/repos/micro/go-micro/events","assignees_url":"https://api.github.com/repos/micro/go-micro/assignees{/user}","branches_url":"https://api.github.com/repos/micro/go-micro/branches{/branch}","tags_url":"https://api.github.com/repos/micro/go-micro/tags","blobs_url":"https://api.github.com/repos/micro/go-micro/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/micro/go-micro/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/micro/go-micro/git/refs{/sha}","trees_url":"https://api.github.com/repos/micro/go-micro/git/trees{/sha}","statuses_url":"https://api.github.com/repos/micro/go-micro/statuses/{sha}","languages_url":"https://api.github.com/repos/micro/go-micro/languages","stargazers_url":"https://api.github.com/repos/micro/go-micro/stargazers","contributors_url":"https://api.github.com/repos/micro/go-micro/contributors","subscribers_url":"https://api.github.com/repos/micro/go-micro/subscribers","subscription_url":"https://api.github.com/repos/micro/go-micro/subscription","commits_url":"https://api.github.com/repos/micro/go-micro/commits{/sha}","git_commits_url":"https://api.github.com/repos/micro/go-micro/git/commits{/sha}","comments_url":"https://api.github.com/repos/micro/go-micro/comments{/number}","issue_comment_url":"https://api.github.com/repos/micro/go-micro/issues/comments{/number}","contents_url":"https://api.github.com/repos/micro/go-micro/contents/{+path}","compare_url":"https://api.github.com/repos/micro/go-micro/compare/{base}...{head}","merges_url":"https://api.github.com/repos/micro/go-micro/merges","archive_url":"https://api.github.com/repos/micro/go-micro/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/micro/go-micro/downloads","issues_url":"https://api.github.com/repos/micro/go-micro/issues{/number}","pulls_url":"https://api.github.com/repos/micro/go-micro/pulls{/number}","milestones_url":"https://api.github.com/repos/micro/go-micro/milestones{/number}","notifications_url":"https://api.github.com/repos/micro/go-micro/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/micro/go-micro/labels{/name}","releases_url":"https://api.github.com/repos/micro/go-micro/releases{/id}","deployments_url":"https://api.github.com/repos/micro/go-micro/deployments","created_at":"2015-01-13T23:30:18Z","updated_at":"2019-06-28T17:54:37Z","pushed_at":"2019-06-28T17:36:30Z","git_url":"git://github.com/micro/go-micro.git","ssh_url":"git@github.com:micro/go-micro.git","clone_url":"https://github.com/micro/go-micro.git","svn_url":"https://github.com/micro/go-micro","homepage":"","size":1989,"stargazers_count":7728,"watchers_count":7728,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":783,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":11,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":783,"open_issues":11,"watchers":7728,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/micro/go-micro/pulls/553"},"html":{"href":"https://github.com/micro/go-micro/pull/553"},"issue":{"href":"https://api.github.com/repos/micro/go-micro/issues/553"},"comments":{"href":"https://api.github.com/repos/micro/go-micro/issues/553/comments"},"review_comments":{"href":"https://api.github.com/repos/micro/go-micro/pulls/553/comments"},"review_comment":{"href":"https://api.github.com/repos/micro/go-micro/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/micro/go-micro/pulls/553/commits"},"statuses":{"href":"https://api.github.com/repos/micro/go-micro/statuses/21c1c6bbf713323f12bc6b1c9ee94a0cda989e36"}},"author_association":"MEMBER"}}
{"actor":{"display_login":"asim"}}