Skip to content
This repository has been archived by the owner on Jul 13, 2023. It is now read-only.

fix: use websocket hostname for server binding #1005

Merged
merged 1 commit into from
Sep 8, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions autopush/tests/test_webpush_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 3 additions & 0 deletions autopush_rs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 4 additions & 1 deletion autopush_rs/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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<PathBuf>,
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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");
Expand Down