protected ConnectionState SetConState(ConnectionState new_cs, out bool success) {
ConnectionState old_state;
success = false;
lock( _sync ) {
old_state = _con_state;
if( old_state == new_cs ) {
//This is not a state change
return old_state;
}
if( new_cs == Node.ConnectionState.Joining ) {
success = (old_state == Node.ConnectionState.Offline);
}
else if( new_cs == Node.ConnectionState.Connected ) {
success = (old_state == Node.ConnectionState.Joining) ||
(old_state == Node.ConnectionState.SeekingConnections);
}
else if( new_cs == Node.ConnectionState.SeekingConnections ) {
success = (old_state == Node.ConnectionState.Connected);
}
else if( new_cs == Node.ConnectionState.Leaving ) {
success = (old_state != Node.ConnectionState.Disconnected);
}
else if( new_cs == Node.ConnectionState.Disconnected ) {
success = (old_state == Node.ConnectionState.Leaving );
}
else if( new_cs == Node.ConnectionState.Offline ) {
// We can never move into the Offline state.
success = false;
}
/*
* Now let's update _con_state
*/
if( success ) {
_con_state = new_cs;
}
}
return old_state;
}