From 2ef718fe314ff550937721457fdde61385409935 Mon Sep 17 00:00:00 2001 From: Ben Bangert Date: Fri, 8 Sep 2017 09:27:58 -0700 Subject: [PATCH] feat: use config hostname for Rust websocket binding Closes #1004 --- autopush/tests/test_webpush_server.py | 1 + autopush_rs/__init__.py | 3 +++ autopush_rs/src/server.rs | 5 ++++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/autopush/tests/test_webpush_server.py b/autopush/tests/test_webpush_server.py index 1f5f5720..b3e0cab0 100644 --- a/autopush/tests/test_webpush_server.py +++ b/autopush/tests/test_webpush_server.py @@ -156,6 +156,7 @@ class BaseSetup(unittest.TestCase): def setUp(self): self.conf = AutopushConfig( hostname="localhost", + resolve_hostname=True, port=8080, statsd_host=None, env="test", diff --git a/autopush_rs/__init__.py b/autopush_rs/__init__.py index 42aa9a29..8888f7af 100644 --- a/autopush_rs/__init__.py +++ b/autopush_rs/__init__.py @@ -27,6 +27,9 @@ def __init__(self, conf, queue): cfg.close_handshake_timeout = conf.close_handshake_timeout cfg.max_connections = conf.max_connections cfg.open_handshake_timeout = 5 + if not conf._resolve_hostname: + raise Exception("Must set resolve_hostname to True") + cfg.host_ip = ffi_from_buffer(conf.hostname) cfg.port = conf.port cfg.ssl_cert = ffi_from_buffer(conf.ssl.cert) cfg.ssl_dh_param = ffi_from_buffer(conf.ssl.dh_param) diff --git a/autopush_rs/src/server.rs b/autopush_rs/src/server.rs index 3b046f31..749092e7 100644 --- a/autopush_rs/src/server.rs +++ b/autopush_rs/src/server.rs @@ -43,6 +43,7 @@ struct AutopushServerInner { #[repr(C)] pub struct AutopushServerOptions { pub debug: i32, + pub host_ip: *const c_char, pub port: u16, pub url: *const c_char, pub ssl_key: *const c_char, @@ -66,6 +67,7 @@ pub struct Server { pub struct ServerOptions { pub debug: bool, + pub host_ip: String, pub port: u16, pub url: String, pub ssl_key: Option, @@ -119,6 +121,7 @@ pub extern "C" fn autopush_server_new(opts: *const AutopushServerOptions, let opts = ServerOptions { debug: opts.debug != 0, + host_ip: to_s(opts.host_ip).expect("hostname must be specified").to_string(), port: opts.port, url: to_s(opts.url).expect("url must be specified").to_string(), ssl_key: to_s(opts.ssl_key).map(PathBuf::from), @@ -265,7 +268,7 @@ impl Server { handle: core.handle(), tx: tx, }); - let addr = format!("127.0.0.1:{}", srv.opts.port); + let addr = format!("{}:{}", srv.opts.host_ip, srv.opts.port); let ws_listener = TcpListener::bind(&addr.parse().unwrap(), &srv.handle)?; assert!(srv.opts.ssl_key.is_none(), "ssl not supported yet");