Commit ee4bc565 authored by Mickaël Turnel's avatar Mickaël Turnel

Fix network state montoring usage

parent 58815c2c
......@@ -138,7 +138,6 @@ static ortp_mutex_t liblinphone_log_collection_mutex;
static FILE * liblinphone_log_collection_file = NULL;
static size_t liblinphone_log_collection_file_size = 0;
static bool_t liblinphone_serialize_logs = FALSE;
static void set_network_reachable(LinphoneCore* lc,bool_t isReachable, time_t curtime);
static void set_sip_network_reachable(LinphoneCore* lc,bool_t isReachable, time_t curtime);
static void set_media_network_reachable(LinphoneCore* lc,bool_t isReachable);
static void linphone_core_run_hooks(LinphoneCore *lc);
......@@ -2083,8 +2082,6 @@ void linphone_configuring_terminated(LinphoneCore *lc, LinphoneConfiguringState
lc->provisioning_http_listener = NULL;
}
getPlatformHelpers(lc)->onLinphoneCoreReady(!!lc->auto_net_state_mon);
linphone_core_set_state(lc,LinphoneGlobalOn,"Ready");
}
......@@ -2363,6 +2360,11 @@ static void linphone_core_init(LinphoneCore * lc, LinphoneCoreCbs *cbs, LpConfig
#endif
lc->network_last_status = FALSE;
lc->sip_network_state.global_state = FALSE;
lc->sip_network_state.user_state = TRUE;
lc->media_network_state.global_state = FALSE;
lc->media_network_state.user_state = TRUE;
/* Create the http provider in dual stack mode (ipv4 and ipv6.
* If this creates problem, we may need to implement parallel ipv6/ ipv4 http requests in belle-sip.
......@@ -2419,6 +2421,8 @@ void linphone_core_start (LinphoneCore *lc) {
belle_http_provider_set_tls_crypto_config(lc->http_provider, lc->http_crypto_config);
}
getPlatformHelpers(lc)->onLinphoneCoreStart(!!lc->auto_net_state_mon);
linphone_core_set_state(lc, LinphoneGlobalConfiguring, "Configuring");
const char *remote_provisioning_uri = linphone_core_get_provisioning_uri(lc);
......@@ -3238,8 +3242,8 @@ static void notify_network_reachable_change (LinphoneCore *lc) {
return;
lc->network_reachable_to_be_notified = FALSE;
linphone_core_notify_network_reachable(lc, lc->sip_network_reachable);
if (lc->sip_network_reachable)
linphone_core_notify_network_reachable(lc, lc->sip_network_state.global_state);
if (lc->sip_network_state.global_state)
linphone_core_resolve_stun_server(lc);
}
......@@ -3407,7 +3411,7 @@ void linphone_core_iterate(LinphoneCore *lc){
linphone_core_run_hooks(lc);
linphone_core_do_plugin_tasks(lc);
if (lc->sip_network_reachable && lc->netup_time!=0 && (current_real_time-lc->netup_time)>=2){
if (lc->sip_network_state.global_state && lc->netup_time!=0 && (current_real_time-lc->netup_time)>=2){
/*not do that immediately, take your time.*/
linphone_core_send_initial_subscribes(lc);
}
......@@ -5960,7 +5964,7 @@ void sip_config_uninit(LinphoneCore *lc)
lp_config_set_int(lc->config,"sip","register_only_when_network_is_up",config->register_only_when_network_is_up);
lp_config_set_int(lc->config,"sip","register_only_when_upnp_is_ok",config->register_only_when_upnp_is_ok);
if (lc->sip_network_reachable) {
if (lc->sip_network_state.global_state) {
for(elem=config->proxies;elem!=NULL;elem=bctbx_list_next(elem)){
LinphoneProxyConfig *cfg=(LinphoneProxyConfig*)(elem->data);
_linphone_proxy_config_unpublish(cfg); /* to unpublish without changing the stored flag enable_publish */
......@@ -6291,7 +6295,7 @@ static void set_sip_network_reachable(LinphoneCore* lc,bool_t is_sip_reachable,
// second get the list of available proxies
const bctbx_list_t *elem = NULL;
if (lc->sip_network_reachable==is_sip_reachable) return; // no change, ignore.
if (lc->sip_network_state.global_state==is_sip_reachable) return; // no change, ignore.
lc->network_reachable_to_be_notified=TRUE;
if (is_sip_reachable){
......@@ -6310,36 +6314,31 @@ static void set_sip_network_reachable(LinphoneCore* lc,bool_t is_sip_reachable,
}
lc->netup_time=curtime;
lc->sip_network_reachable=is_sip_reachable;
lc->sip_network_state.global_state=is_sip_reachable;
if (!lc->sip_network_reachable){
if (!lc->sip_network_state.global_state){
linphone_core_invalidate_friend_subscriptions(lc);
lc->sal->resetTransports();
}
}
static void set_media_network_reachable(LinphoneCore* lc, bool_t is_media_reachable){
if (lc->media_network_reachable==is_media_reachable) return; // no change, ignore.
if (lc->media_network_state.global_state==is_media_reachable) return; // no change, ignore.
lc->network_reachable_to_be_notified=TRUE;
ms_message("Media network reachability state is now [%s]",is_media_reachable?"UP":"DOWN");
lc->media_network_reachable=is_media_reachable;
lc->media_network_state.global_state=is_media_reachable;
if (lc->media_network_reachable){
if (lc->media_network_state.global_state){
if (lc->bw_controller){
ms_bandwidth_controller_reset_state(lc->bw_controller);
}
}
}
static void set_network_reachable(LinphoneCore *lc, bool_t is_network_reachable, time_t curtime){
set_sip_network_reachable(lc, is_network_reachable, curtime);
set_media_network_reachable(lc, is_network_reachable);
}
void linphone_core_refresh_registers(LinphoneCore* lc) {
const bctbx_list_t *elem;
if (!lc->sip_network_reachable) {
if (!lc->sip_network_state.global_state) {
ms_warning("Refresh register operation not available (network unreachable)");
return;
}
......@@ -6354,7 +6353,8 @@ void linphone_core_refresh_registers(LinphoneCore* lc) {
void linphone_core_set_network_reachable_internal(LinphoneCore *lc, bool_t is_reachable) {
if (lc->auto_net_state_mon) {
set_network_reachable(lc, lc->network_reachable && is_reachable, ms_time(NULL));
set_sip_network_reachable(lc, lc->sip_network_state.user_state && is_reachable, ms_time(NULL));
set_media_network_reachable(lc, lc->media_network_state.user_state && is_reachable);
notify_network_reachable_change(lc);
}
}
......@@ -6362,25 +6362,40 @@ void linphone_core_set_network_reachable_internal(LinphoneCore *lc, bool_t is_re
void linphone_core_set_network_reachable(LinphoneCore *lc, bool_t is_reachable) {
bool_t reachable = is_reachable;
lc->sip_network_state.user_state = is_reachable;
lc->media_network_state.user_state = is_reachable;
if (lc->auto_net_state_mon) reachable = reachable && getPlatformHelpers(lc)->isNetworkReachable();
lc->network_reachable = is_reachable;
set_network_reachable(lc, reachable, ms_time(NULL));
set_sip_network_reachable(lc, reachable, ms_time(NULL));
set_media_network_reachable(lc, reachable);
notify_network_reachable_change(lc);
}
void linphone_core_set_media_network_reachable(LinphoneCore *lc, bool_t is_reachable){
set_media_network_reachable(lc, is_reachable);
bool_t reachable = is_reachable;
lc->media_network_state.user_state = is_reachable;
if (lc->auto_net_state_mon) reachable = reachable && getPlatformHelpers(lc)->isNetworkReachable();
set_media_network_reachable(lc, reachable);
notify_network_reachable_change(lc);
}
void linphone_core_set_sip_network_reachable(LinphoneCore *lc, bool_t is_reachable){
set_sip_network_reachable(lc, is_reachable, ms_time(NULL));
bool_t reachable = is_reachable;
lc->sip_network_state.user_state = is_reachable;
if (lc->auto_net_state_mon) reachable = reachable && getPlatformHelpers(lc)->isNetworkReachable();
set_sip_network_reachable(lc, reachable, ms_time(NULL));
notify_network_reachable_change(lc);
}
bool_t linphone_core_is_network_reachable(LinphoneCore* lc) {
return lc->sip_network_reachable;
return lc->sip_network_state.global_state;
}
ortp_socket_t linphone_core_get_sip_socket(LinphoneCore *lc){
......
......@@ -189,8 +189,6 @@ int parse_hostname_to_addr(const char *server, struct sockaddr_storage *ss, sock
bool_t host_has_ipv6_network(void);
bool_t lp_spawn_command_line_sync(const char *command, char **result,int *command_ret);
void linphone_core_set_network_reachable_internal(LinphoneCore *lc, bool_t is_reachable);
static MS2_INLINE void set_string(char **dest, const char *src, bool_t lowercase){
if (*dest){
ms_free(*dest);
......
......@@ -290,6 +290,12 @@ struct net_config
bool_t nat_sdp_only;
};
struct net_state
{
bool_t global_state;
bool_t user_state;
};
struct sound_config
{
struct _MSSndCard * ring_sndcard; /* the playback sndcard currently used */
......@@ -777,9 +783,8 @@ namespace LinphonePrivate {
bool_t bl_refresh; \
bool_t preview_finished; \
bool_t auto_net_state_mon; \
bool_t network_reachable; \
bool_t sip_network_reachable; \
bool_t media_network_reachable; \
net_state_t sip_network_state; \
net_state_t media_network_state; \
bool_t network_reachable_to_be_notified; \
bool_t use_preview_window; \
bool_t network_last_status; \
......
......@@ -37,6 +37,8 @@ typedef struct rtp_config rtp_config_t;
typedef struct net_config net_config_t;
typedef struct net_state net_state_t;
typedef struct sound_config sound_config_t;
typedef struct codecs_config codecs_config_t;
......
......@@ -1312,7 +1312,7 @@ SipSetup *linphone_proxy_config_get_sip_setup(LinphoneProxyConfig *cfg){
static bool_t can_register(LinphoneProxyConfig *cfg){
LinphoneCore *lc=cfg->lc;
if (lc->sip_conf.register_only_when_network_is_up){
return lc->sip_network_reachable;
return lc->sip_network_state.global_state;
}
return TRUE;
}
......
......@@ -125,6 +125,7 @@ LINPHONE_PUBLIC int linphone_friend_list_get_revision(const LinphoneFriendList *
LINPHONE_PUBLIC int linphone_remote_provisioning_load_file( LinphoneCore* lc, const char* file_path);
LINPHONE_PUBLIC void linphone_core_set_network_reachable_internal(LinphoneCore *lc, bool_t is_reachable);
#ifndef __cplusplus
LINPHONE_PUBLIC Sal *linphone_core_get_sal(const LinphoneCore *lc);
......
......@@ -244,7 +244,7 @@ void linphone_core_notify_configuring_status(LinphoneCore *lc, LinphoneConfiguri
}
void linphone_core_notify_network_reachable(LinphoneCore *lc, bool_t reachable) {
L_GET_PRIVATE_FROM_C_OBJECT(lc)->notifyNetworkReachable(!!lc->sip_network_reachable, !!lc->media_network_reachable);
L_GET_PRIVATE_FROM_C_OBJECT(lc)->notifyNetworkReachable(!!lc->sip_network_state.global_state, !!lc->media_network_state.global_state);
NOTIFY_IF_EXIST(network_reachable, lc,reachable);
cleanup_dead_vtable_refs(lc);
}
......
......@@ -816,7 +816,7 @@ void CallSessionPrivate::repairIfBroken () {
L_Q();
LinphoneCore *lc = q->getCore()->getCCore();
LinphoneConfig *config = linphone_core_get_config(lc);
if (!lp_config_get_int(config, "sip", "repair_broken_calls", 1) || !lc->media_network_reachable || !broken)
if (!lp_config_get_int(config, "sip", "repair_broken_calls", 1) || !lc->media_network_state.global_state || !broken)
return;
// If we are registered and this session has been broken due to a past network disconnection,
......
......@@ -60,7 +60,7 @@ public:
void setNetworkReachable (bool reachable) override;
void setHttpProxy (string host, int port) override;
void onLinphoneCoreReady (bool monitoringEnabled) override;
void onLinphoneCoreStart (bool monitoringEnabled) override;
void _setPreviewVideoWindow(jobject window);
void _setVideoWindow(jobject window);
......@@ -85,7 +85,7 @@ private:
jmethodID mSetNativeVideoWindowId;
jmethodID mSetNativePreviewVideoWindowId;
jmethodID mUpdateNetworkReachabilityId;
jmethodID mOnLinphoneCoreReadyId;
jmethodID mOnLinphoneCoreStartId;
jmethodID mOnWifiOnlyEnabledId;
jobject mPreviewVideoWindow;
jobject mVideoWindow;
......@@ -137,7 +137,7 @@ AndroidPlatformHelpers::AndroidPlatformHelpers (LinphoneCore *lc, void *systemCo
mSetNativeVideoWindowId = getMethodId(env, klass, "setVideoRenderingView", "(Ljava/lang/Object;)V");
mSetNativePreviewVideoWindowId = getMethodId(env, klass, "setVideoPreviewView", "(Ljava/lang/Object;)V");
mUpdateNetworkReachabilityId = getMethodId(env, klass, "updateNetworkReachability", "()V");
mOnLinphoneCoreReadyId = getMethodId(env, klass, "onLinphoneCoreReady", "(Z)V");
mOnLinphoneCoreStartId = getMethodId(env, klass, "onLinphoneCoreStart", "(Z)V");
mOnWifiOnlyEnabledId = getMethodId(env, klass, "onWifiOnlyEnabled", "(Z)V");
jobject pm = env->CallObjectMethod(mJavaHelper, mGetPowerManagerId);
......@@ -321,10 +321,10 @@ void AndroidPlatformHelpers::setNetworkReachable(bool reachable) {
// -----------------------------------------------------------------------------
void AndroidPlatformHelpers::onLinphoneCoreReady(bool monitoringEnabled) {
void AndroidPlatformHelpers::onLinphoneCoreStart(bool monitoringEnabled) {
JNIEnv *env = ms_get_jni_env();
if (env && mJavaHelper) {
env->CallVoidMethod(mJavaHelper, mOnLinphoneCoreReadyId, (jboolean)monitoringEnabled);
env->CallVoidMethod(mJavaHelper, mOnLinphoneCoreStartId, (jboolean)monitoringEnabled);
}
}
......
......@@ -69,7 +69,7 @@ public:
void setHttpProxy (string host, int port) override {}
void setNetworkReachable (bool reachable) override {}
void onLinphoneCoreReady (bool monitoringEnabled) override {}
void onLinphoneCoreStart (bool monitoringEnabled) override {}
private:
void bgTaskTimeout ();
......
......@@ -111,7 +111,7 @@ void GenericPlatformHelpers::setNetworkReachable (bool reachable) {
}
void GenericPlatformHelpers::onLinphoneCoreReady (bool monitoringEnabled) {
void GenericPlatformHelpers::onLinphoneCoreStart (bool monitoringEnabled) {
if (!monitoringEnabled) return;
if (!mMonitorTimer) {
......@@ -124,8 +124,9 @@ void GenericPlatformHelpers::onLinphoneCoreReady (bool monitoringEnabled) {
} else {
belle_sip_source_set_timeout(mMonitorTimer, DefaultMonitorTimeout * 1000);
}
//get ip right now to avoid waiting for 5s
monitorTimerExpired(this,0);
// Get ip right now to avoid waiting for 5s
monitorTimerExpired(this, 0);
}
......
......@@ -67,7 +67,7 @@ public:
virtual void setHttpProxy (std::string host, int port) = 0;
virtual void setNetworkReachable (bool reachable) = 0;
virtual void onLinphoneCoreReady (bool monitoringEnabled) = 0;
virtual void onLinphoneCoreStart (bool monitoringEnabled) = 0;
protected:
inline explicit PlatformHelpers (LinphoneCore *lc) : mCore(lc) {}
......@@ -109,7 +109,7 @@ public:
void setHttpProxy (std::string host, int port) override;
void setNetworkReachable (bool reachable) override;
void onLinphoneCoreReady (bool monitoringEnabled) override;
void onLinphoneCoreStart (bool monitoringEnabled) override;
private:
static int monitorTimerExpired (void *data, unsigned int revents);
......
......@@ -169,6 +169,8 @@ void account_create_on_server(Account *account, const LinphoneProxyConfig *refcf
linphone_address_unref(server_addr);
linphone_proxy_config_set_expires(cfg,3*3600); //accounts are valid 3 hours
linphone_core_set_network_reachable_internal(lc, TRUE);
linphone_core_add_proxy_config(lc,cfg);
/*wait 25 seconds, since the DNS SRV resolution may take a while - and
especially if router does NOT support DNS SRV and we have to wait its timeout*/
......
......@@ -174,7 +174,7 @@ static void subscriber_no_longer_reachable(void){
/*make sure marie subscribe is not reset by accident because of code below located in linphone_core_iterate
if (lc->sip_network_reachable && lc->netup_time!=0 && (current_real_time-lc->netup_time)>3){
if (lc->sip_network_state.global_state && lc->netup_time!=0 && (current_real_time-lc->netup_time)>3){
linphone_core_send_initial_subscribes(lc);
}
......
......@@ -140,7 +140,7 @@ public class AndroidPlatformHelper {
}
}
public void onLinphoneCoreReady(boolean monitoringEnabled) {
public void onLinphoneCoreStart(boolean monitoringEnabled) {
if (!monitoringEnabled) return;
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment