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

Commit

Permalink
fix: resolve hostnames and send pings out
Browse files Browse the repository at this point in the history
Closes #1011
  • Loading branch information
bbangert committed Sep 11, 2017
1 parent 0a33d2c commit e57932c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
2 changes: 0 additions & 2 deletions autopush_rs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ 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.router_ip = ffi_from_buffer(conf.router_hostname)
cfg.router_port = conf.router_port
Expand Down
15 changes: 12 additions & 3 deletions autopush_rs/src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use std::collections::HashMap;
use std::ffi::CStr;
use std::io;
use std::mem;
use std::net::{IpAddr, ToSocketAddrs};
use std::panic;
use std::path::PathBuf;
use std::rc::Rc;
Expand Down Expand Up @@ -91,6 +92,10 @@ pub struct ServerOptions {
pub close_handshake_timeout: Option<Duration>,
}

fn resolve(host: &str) -> IpAddr {
(host, 0).to_socket_addrs().unwrap().next().unwrap().ip()
}

#[no_mangle]
pub extern "C" fn autopush_server_new(opts: *const AutopushServerOptions,
err: &mut AutopushError)
Expand Down Expand Up @@ -246,7 +251,8 @@ impl Server {
use hyper::server::Http;

let handle = core.handle();
let addr = format!("{}:{}", srv.opts.router_ip, srv.opts.router_port).parse().unwrap();
let router_ip = resolve(&srv.opts.router_ip);
let addr = format!("{}:{}", 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 Expand Up @@ -281,7 +287,8 @@ impl Server {
handle: core.handle(),
tx: tx,
});
let addr = format!("{}:{}", srv.opts.host_ip, srv.opts.port);
let host_ip = resolve(&srv.opts.host_ip);
let addr = format!("{}:{}", 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 Expand Up @@ -497,6 +504,9 @@ impl Future for PingManager {
}
}

// Ensure the scheduled ping is actually flushed out
self.socket.borrow_mut().poll_complete()?;

// At this point looks our state of ping management A-OK, so try to
// make progress on our client, and when done with that execute the
// closing handshake.
Expand Down Expand Up @@ -590,7 +600,6 @@ impl<T> Stream for WebpushSocket<T>
Pong::None => {}
Pong::Received => {}
Pong::Waiting(task) => {
self.pong = Pong::None;
task.notify();
}
}
Expand Down

0 comments on commit e57932c

Please sign in to comment.