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

Commit

Permalink
fix: use router ip/port for proper binding in Rust PoC
Browse files Browse the repository at this point in the history
  • Loading branch information
bbangert committed Sep 8, 2017
1 parent 8f41f49 commit 56facd8
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions autopush/tests/test_webpush_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ def setUp(self):
hostname="localhost",
resolve_hostname=True,
port=8080,
router_port=8081,
statsd_host=None,
env="test",
auto_ping_interval=float(300),
Expand Down
2 changes: 2 additions & 0 deletions autopush_rs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ def __init__(self, conf, queue):
if not conf._resolve_hostname:
raise Exception("Must set resolve_hostname to True")
cfg.host_ip = ffi_from_buffer(conf.hostname)
cfg.router_ip = ffi_from_buffer(conf.router_hostname)
cfg.router_port = conf.router_port
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
8 changes: 7 additions & 1 deletion autopush_rs/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,9 @@ struct AutopushServerInner {
#[repr(C)]
pub struct AutopushServerOptions {
pub debug: i32,
pub router_ip: *const c_char,
pub host_ip: *const c_char,
pub router_port: u16,
pub port: u16,
pub url: *const c_char,
pub ssl_key: *const c_char,
Expand All @@ -68,6 +70,8 @@ pub struct Server {
pub struct ServerOptions {
pub debug: bool,
pub host_ip: String,
pub router_ip: String,
pub router_port: u16,
pub port: u16,
pub url: String,
pub ssl_key: Option<PathBuf>,
Expand Down Expand Up @@ -122,7 +126,9 @@ 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(),
router_ip: to_s(opts.router_ip).expect("router hostname must be specified").to_string(),
port: opts.port,
router_port: opts.router_port,
url: to_s(opts.url).expect("url must be specified").to_string(),
ssl_key: to_s(opts.ssl_key).map(PathBuf::from),
ssl_cert: to_s(opts.ssl_cert).map(PathBuf::from),
Expand Down Expand Up @@ -233,7 +239,7 @@ impl Server {
use hyper::server::Http;

let handle = core.handle();
let addr = "127.0.0.1:8081".parse().unwrap();
let addr = format!("{}:{}", srv.opts.router_ip, srv.opts.router_port).parse().unwrap();
let push_listener = TcpListener::bind(&addr, &handle).unwrap();
let proto = Http::new();
let push_srv = push_listener.incoming().for_each(move |(socket, addr)| {
Expand Down

0 comments on commit 56facd8

Please sign in to comment.