fix network_start regression (#1629)
* fix network_start regression * network io handler * move registration to the network start
This commit is contained in:
parent
78007cf80b
commit
7b5d39e0a1
@ -35,7 +35,7 @@ use util::rlp::{RlpStream, Rlp, UntrustedRlp};
|
|||||||
use util::journaldb;
|
use util::journaldb;
|
||||||
use util::journaldb::JournalDB;
|
use util::journaldb::JournalDB;
|
||||||
use util::kvdb::*;
|
use util::kvdb::*;
|
||||||
use util::{Stream, View, PerfTimer, Itertools, Colour};
|
use util::{Stream, View, PerfTimer, Itertools};
|
||||||
use util::{Mutex, RwLock};
|
use util::{Mutex, RwLock};
|
||||||
|
|
||||||
// other
|
// other
|
||||||
@ -608,18 +608,6 @@ impl Client {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Notify us that the network has been started.
|
|
||||||
pub fn network_started(&self, url: &str) {
|
|
||||||
let mut previous_enode = self.previous_enode.lock();
|
|
||||||
if let Some(ref u) = *previous_enode {
|
|
||||||
if u == url {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*previous_enode = Some(url.into());
|
|
||||||
info!(target: "mode", "Public node URL: {}", Colour::White.bold().paint(url));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Ipc)]
|
#[derive(Ipc)]
|
||||||
|
@ -21,10 +21,25 @@ use network::error::NetworkError;
|
|||||||
use network::host::{Host, NetworkContext, NetworkIoMessage, ProtocolId};
|
use network::host::{Host, NetworkContext, NetworkIoMessage, ProtocolId};
|
||||||
use network::stats::NetworkStats;
|
use network::stats::NetworkStats;
|
||||||
use io::*;
|
use io::*;
|
||||||
|
|
||||||
use std::sync::Arc;
|
|
||||||
|
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
|
use std::sync::Arc;
|
||||||
|
use ansi_term::Colour;
|
||||||
|
|
||||||
|
struct HostHandler {
|
||||||
|
public_url: RwLock<Option<String>>
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IoHandler<NetworkIoMessage> for HostHandler {
|
||||||
|
fn message(&self, _io: &IoContext<NetworkIoMessage>, message: &NetworkIoMessage) {
|
||||||
|
if let NetworkIoMessage::NetworkStarted(ref public_url) = *message {
|
||||||
|
let mut url = self.public_url.write();
|
||||||
|
if url.as_ref().map(|uref| uref != public_url).unwrap_or(true) {
|
||||||
|
info!(target: "network", "Public node URL: {}", Colour::White.bold().paint(public_url.as_ref()));
|
||||||
|
}
|
||||||
|
*url = Some(public_url.to_owned());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// IO Service with networking
|
/// IO Service with networking
|
||||||
/// `Message` defines a notification data type.
|
/// `Message` defines a notification data type.
|
||||||
@ -34,12 +49,14 @@ pub struct NetworkService {
|
|||||||
host: RwLock<Option<Arc<Host>>>,
|
host: RwLock<Option<Arc<Host>>>,
|
||||||
stats: Arc<NetworkStats>,
|
stats: Arc<NetworkStats>,
|
||||||
panic_handler: Arc<PanicHandler>,
|
panic_handler: Arc<PanicHandler>,
|
||||||
|
host_handler: Arc<HostHandler>,
|
||||||
config: NetworkConfiguration,
|
config: NetworkConfiguration,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl NetworkService {
|
impl NetworkService {
|
||||||
/// Starts IO event loop
|
/// Starts IO event loop
|
||||||
pub fn new(config: NetworkConfiguration) -> Result<NetworkService, UtilError> {
|
pub fn new(config: NetworkConfiguration) -> Result<NetworkService, UtilError> {
|
||||||
|
let host_handler = Arc::new(HostHandler { public_url: RwLock::new(None) });
|
||||||
let panic_handler = PanicHandler::new_in_arc();
|
let panic_handler = PanicHandler::new_in_arc();
|
||||||
let io_service = try!(IoService::<NetworkIoMessage>::start());
|
let io_service = try!(IoService::<NetworkIoMessage>::start());
|
||||||
panic_handler.forward_from(&io_service);
|
panic_handler.forward_from(&io_service);
|
||||||
@ -53,6 +70,7 @@ impl NetworkService {
|
|||||||
panic_handler: panic_handler,
|
panic_handler: panic_handler,
|
||||||
host: RwLock::new(None),
|
host: RwLock::new(None),
|
||||||
config: config,
|
config: config,
|
||||||
|
host_handler: host_handler,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,6 +124,11 @@ impl NetworkService {
|
|||||||
try!(self.io_service.register_handler(h.clone()));
|
try!(self.io_service.register_handler(h.clone()));
|
||||||
*host = Some(h);
|
*host = Some(h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if self.host_handler.public_url.read().is_none() {
|
||||||
|
try!(self.io_service.register_handler(self.host_handler.clone()));
|
||||||
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user