Skip to content

Commit

Permalink
Update using Arc::downgrade() for latest nightly
Browse files Browse the repository at this point in the history
Issues hsow now in igd though.
  • Loading branch information
dirvine committed Aug 22, 2015
1 parent cb54aee commit ba63e49
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions src/connection_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl ConnectionManager {
// For any protocol that doesn't have an entry, we should inject one (either random or 0).
// Currently, only TCP is supported.

let ws = self.state.downgrade();
let ws = Arc::downgrade(&self.state);

let mut listening_ports = Vec::new();
self.beacon_guid_and_port = match beacon::BroadcastAcceptor::new(self.config.beacon_port) {
Expand Down Expand Up @@ -290,14 +290,14 @@ impl ConnectionManager {
/// It will reiterate the list of all endpoints until it gets at least one connection.
pub fn bootstrap(&mut self, max_successful_bootstrap_connection: usize) {
// Disconnect existing connections
let mut ws = self.state.downgrade();
let mut ws = Arc::downgrade(&self.state);
let _ = lock_mut_state(&mut ws, |s: &mut State| {
let _ = s.connections.clear();
s.bs_count = (0, max_successful_bootstrap_connection.clone());
Ok(())
});

let ws = self.state.downgrade();
let ws = Arc::downgrade(&self.state);
let bs_file_lock = self.beacon_guid_and_port.is_some();
let config = self.config.clone();
let beacon_guid_and_port = self.beacon_guid_and_port.clone();
Expand Down Expand Up @@ -340,7 +340,7 @@ impl ConnectionManager {
self.beacon_guid_and_port = None;
}
let mut listening_ports = Vec::<Port>::new();
let weak_state = self.state.downgrade();
let weak_state = Arc::downgrade(&self.state);
{
let _ = lock_mut_state(&weak_state, |state: &mut State| {
for itr in &state.listening_ports {
Expand Down Expand Up @@ -376,7 +376,7 @@ impl ConnectionManager {
/// For details on handling of connect in different protocol refer
/// https://github.com/dirvine/crust/blob/master/docs/connect.md
pub fn connect(&self, endpoints: Vec<Endpoint>) {
let ws = self.state.downgrade();
let ws = Arc::downgrade(&self.state);
{
let result = lock_mut_state(&ws, |s: &mut State| {
for endpoint in &endpoints {
Expand Down Expand Up @@ -408,7 +408,7 @@ impl ConnectionManager {
/// mean that the data will be received. It is possible for the corresponding connection to hang
/// up immediately after this function returns Ok.
pub fn send(&self, endpoint: Endpoint, message: Bytes) -> io::Result<()> {
let ws = self.state.downgrade();
let ws = Arc::downgrade(&self.state);

let writer_channel = try!(lock_state(&ws, |s| {
match s.connections.get(&endpoint) {
Expand All @@ -424,7 +424,7 @@ impl ConnectionManager {

/// Closes connection with the specified endpoint.
pub fn drop_node(&self, endpoint: Endpoint) {
let mut ws = self.state.downgrade();
let mut ws = Arc::downgrade(&self.state);
let _ = lock_mut_state(&mut ws, |s: &mut State| {
let _ = s.connections.remove(&endpoint);
Ok(())
Expand Down Expand Up @@ -516,7 +516,7 @@ impl ConnectionManager {
let local_port = acceptor.local_port();
self.own_endpoints = map_external_port(&local_port);

let mut weak_state = self.state.downgrade();
let mut weak_state = Arc::downgrade(&self.state);

let _ = lock_mut_state(&mut weak_state, |s| Ok(s.listening_ports.insert(local_port)));

Expand Down Expand Up @@ -1142,8 +1142,8 @@ mod test {
stop_called: false,
bs_count: (0,1),
}));
assert!(bootstrap_off_list(state.downgrade(), vec![], false, 15).is_err());
assert!(bootstrap_off_list(state.downgrade(),
assert!(bootstrap_off_list(Arc::downgrade(&state), vec![], false, 15).is_err());
assert!(bootstrap_off_list(Arc::downgrade(&state),
vec![Contact{endpoint: ep.clone()}], false, 15)
.is_ok());
}
Expand Down Expand Up @@ -1191,8 +1191,8 @@ mod test {
stop_called: false,
bs_count: (0,max_count),
}));
assert!(bootstrap_off_list(state.downgrade(), vec![], false, 15).is_err());
assert!(bootstrap_off_list(state.downgrade(),
assert!(bootstrap_off_list(Arc::downgrade(&state), vec![], false, 15).is_err());
assert!(bootstrap_off_list(Arc::downgrade(&state),
contacts.clone(), false, max_count)
.is_ok());

Expand Down

0 comments on commit ba63e49

Please sign in to comment.