{"action":"closed","issue":{"url":"https://api.github.com/repos/mike820324/microProxy/issues/147","repository_url":"https://api.github.com/repos/mike820324/microProxy","labels_url":"https://api.github.com/repos/mike820324/microProxy/issues/147/labels{/name}","comments_url":"https://api.github.com/repos/mike820324/microProxy/issues/147/comments","events_url":"https://api.github.com/repos/mike820324/microProxy/issues/147/events","html_url":"https://github.com/mike820324/microProxy/issues/147","id":174046603,"number":147,"title":"[Proposal]: Adding server state related API and ServerContext","user":{"login":"mike820324","id":1079601,"avatar_url":"https://avatars.githubusercontent.com/u/1079601?v=3","gravatar_id":"","url":"https://api.github.com/users/mike820324","html_url":"https://github.com/mike820324","followers_url":"https://api.github.com/users/mike820324/followers","following_url":"https://api.github.com/users/mike820324/following{/other_user}","gists_url":"https://api.github.com/users/mike820324/gists{/gist_id}","starred_url":"https://api.github.com/users/mike820324/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mike820324/subscriptions","organizations_url":"https://api.github.com/users/mike820324/orgs","repos_url":"https://api.github.com/users/mike820324/repos","events_url":"https://api.github.com/users/mike820324/events{/privacy}","received_events_url":"https://api.github.com/users/mike820324/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/mike820324/microProxy/labels/enhancement","name":"enhancement","color":"84b6eb"},{"url":"https://api.github.com/repos/mike820324/microProxy/labels/review","name":"review","color":"33CCFF"}],"state":"closed","locked":false,"assignee":{"login":"mike820324","id":1079601,"avatar_url":"https://avatars.githubusercontent.com/u/1079601?v=3","gravatar_id":"","url":"https://api.github.com/users/mike820324","html_url":"https://github.com/mike820324","followers_url":"https://api.github.com/users/mike820324/followers","following_url":"https://api.github.com/users/mike820324/following{/other_user}","gists_url":"https://api.github.com/users/mike820324/gists{/gist_id}","starred_url":"https://api.github.com/users/mike820324/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mike820324/subscriptions","organizations_url":"https://api.github.com/users/mike820324/orgs","repos_url":"https://api.github.com/users/mike820324/repos","events_url":"https://api.github.com/users/mike820324/events{/privacy}","received_events_url":"https://api.github.com/users/mike820324/received_events","type":"User","site_admin":false},"assignees":[{"login":"mike820324","id":1079601,"avatar_url":"https://avatars.githubusercontent.com/u/1079601?v=3","gravatar_id":"","url":"https://api.github.com/users/mike820324","html_url":"https://github.com/mike820324","followers_url":"https://api.github.com/users/mike820324/followers","following_url":"https://api.github.com/users/mike820324/following{/other_user}","gists_url":"https://api.github.com/users/mike820324/gists{/gist_id}","starred_url":"https://api.github.com/users/mike820324/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mike820324/subscriptions","organizations_url":"https://api.github.com/users/mike820324/orgs","repos_url":"https://api.github.com/users/mike820324/repos","events_url":"https://api.github.com/users/mike820324/events{/privacy}","received_events_url":"https://api.github.com/users/mike820324/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/mike820324/microProxy/milestones/4","html_url":"https://github.com/mike820324/microProxy/milestones/0.4.0","labels_url":"https://api.github.com/repos/mike820324/microProxy/milestones/4/labels","id":1914018,"number":4,"title":"0.4.0","description":"","creator":{"login":"mike820324","id":1079601,"avatar_url":"https://avatars.githubusercontent.com/u/1079601?v=3","gravatar_id":"","url":"https://api.github.com/users/mike820324","html_url":"https://github.com/mike820324","followers_url":"https://api.github.com/users/mike820324/followers","following_url":"https://api.github.com/users/mike820324/following{/other_user}","gists_url":"https://api.github.com/users/mike820324/gists{/gist_id}","starred_url":"https://api.github.com/users/mike820324/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mike820324/subscriptions","organizations_url":"https://api.github.com/users/mike820324/orgs","repos_url":"https://api.github.com/users/mike820324/repos","events_url":"https://api.github.com/users/mike820324/events{/privacy}","received_events_url":"https://api.github.com/users/mike820324/received_events","type":"User","site_admin":false},"open_issues":3,"closed_issues":32,"state":"open","created_at":"2016-07-31T14:28:53Z","updated_at":"2016-09-21T08:16:49Z","due_on":"2016-09-30T00:00:00Z","closed_at":null},"comments":0,"created_at":"2016-08-30T15:12:56Z","updated_at":"2016-09-21T08:16:49Z","closed_at":"2016-09-21T08:16:49Z","body":"## Global ServerState:\r\n\r\n### API List\r\n  - ```init_server_state(config)````: initialize server state. ex cert_store and interceptor\r\n  - ```get_server_state()```: get ServerContext.\r\n\r\n### ServerContext: \r\n- **config**: user pass in and should not be modifed.\r\n- **interceptor**: there should only be one interceptor instance in the proxy server. And the interceptor is immutable after it is created.\r\n- **cert_store**: should be one cert_store. But the cert_store will mutate.\r\n- (optional) **io_loop**: there will be only one io_loop instance. Currently we use curr_loop() to get the io_loop.\r\n\r\nex. \r\n```python\r\n# server init\r\ndef proxy_main():\r\n  config = parse_config(args)\r\n  init_server_state(config)\r\n  start_events_server()\r\n  start_proxy_server()\r\n```\r\n\r\n\r\n```python\r\n# get server state\r\ndef __init__(self):\r\n   self.config = get_server_state().config\r\n   self.interceptor = get_server_state().interceptor\r\n   self.cert_store = get_server_state().cert_store\r\n```\r\n\r\n## Layer Refinement:\r\n\r\nThe following are the reason that I decide to refine the LayerManger and LayerContext.\r\n\r\nWhen we create the initial layer context, we already know which kind of layer mode we want this layer to start. In proxy.py, config is the indicator; meanwhile, in replay.py, the class itself is the indicator. \r\n\r\nSo the actual problem becomes that application/http1.py and application/http2.py will need to know which mode the current layer is. In this case, I think putting a mode field in LayerContext would be a better way. \r\n\r\n\r\n### LayerManager:\r\n\r\nThe functions of ```layer_manager``` should be slightly modified.\r\n\r\n### LayerContext:\r\nBased on the ServerState changed, the LayerContext will have to slightly modified.\r\n\r\n- remove ```config``` and ```interceptor``` field.\r\n- add mode to indicate which entry point we want to get in. \r\n  - \"replay\r\n  - \"socks\"\r\n  - \"transparent\"\r\n"}}
{"actor":{"display_login":"mike820324"}}