Commit e3edcea8 authored by Simon Morlat's avatar Simon Morlat

add new test to verify SRV/IP failover mechanism of channels

parent cb977e6a
...@@ -66,6 +66,8 @@ BELLESIP_EXPORT int belle_sip_client_transaction_send_request(belle_sip_client_t ...@@ -66,6 +66,8 @@ BELLESIP_EXPORT int belle_sip_client_transaction_send_request(belle_sip_client_t
* */ * */
BELLESIP_EXPORT int belle_sip_client_transaction_send_request_to(belle_sip_client_transaction_t *t,belle_sip_uri_t* outbound_proxy); BELLESIP_EXPORT int belle_sip_client_transaction_send_request_to(belle_sip_client_transaction_t *t,belle_sip_uri_t* outbound_proxy);
BELLESIP_EXPORT belle_sip_uri_t *belle_sip_client_transaction_get_route(belle_sip_client_transaction_t *t);
/** /**
* Creates an a sip refresher for transaction like REGISTER/SUBSCRIBE or INVITE which could be refreshed. * Creates an a sip refresher for transaction like REGISTER/SUBSCRIBE or INVITE which could be refreshed.
* Transaction must in be in stated BELLE_SIP_TRANSACTION_COMPLETED. Refresher is created and started. A ref is taken on object transaction * Transaction must in be in stated BELLE_SIP_TRANSACTION_COMPLETED. Refresher is created and started. A ref is taken on object transaction
......
...@@ -280,6 +280,7 @@ void belle_sip_main_loop_add_source(belle_sip_main_loop_t *ml, belle_sip_source_ ...@@ -280,6 +280,7 @@ void belle_sip_main_loop_add_source(belle_sip_main_loop_t *ml, belle_sip_source_
if (source->timeout>=0){ if (source->timeout>=0){
source->expire_ms=belle_sip_time_ms()+source->timeout; source->expire_ms=belle_sip_time_ms()+source->timeout;
} }
source->cancelled=FALSE;
ml->sources=belle_sip_list_append_link(ml->sources,&source->node); ml->sources=belle_sip_list_append_link(ml->sources,&source->node);
ml->nsources++; ml->nsources++;
} }
......
...@@ -667,6 +667,11 @@ static void channel_invoke_state_listener_defered(belle_sip_channel_t *obj){ ...@@ -667,6 +667,11 @@ static void channel_invoke_state_listener_defered(belle_sip_channel_t *obj){
belle_sip_object_unref(obj); belle_sip_object_unref(obj);
} }
static void channel_connect_next(belle_sip_channel_t *obj){
belle_sip_channel_connect(obj);
belle_sip_object_unref(obj);
}
static void belle_sip_channel_handle_error(belle_sip_channel_t *obj){ static void belle_sip_channel_handle_error(belle_sip_channel_t *obj){
if (obj->state!=BELLE_SIP_CHANNEL_READY){ if (obj->state!=BELLE_SIP_CHANNEL_READY){
/* Previous connection attempts were failed (channel could not get ready).*/ /* Previous connection attempts were failed (channel could not get ready).*/
...@@ -675,7 +680,7 @@ static void belle_sip_channel_handle_error(belle_sip_channel_t *obj){ ...@@ -675,7 +680,7 @@ static void belle_sip_channel_handle_error(belle_sip_channel_t *obj){
obj->current_peer=obj->current_peer->ai_next; obj->current_peer=obj->current_peer->ai_next;
channel_set_state(obj,BELLE_SIP_CHANNEL_RETRY); channel_set_state(obj,BELLE_SIP_CHANNEL_RETRY);
belle_sip_channel_close(obj); belle_sip_channel_close(obj);
belle_sip_channel_connect(obj); belle_sip_main_loop_do_later(obj->stack->ml,(belle_sip_callback_t)channel_connect_next,belle_sip_object_ref(obj));
return; return;
}/*else we have already tried all the ip addresses, so give up and notify the error*/ }/*else we have already tried all the ip addresses, so give up and notify the error*/
}/*else the channel was previously working good with the current ip address but now fails, so let's notify the error*/ }/*else the channel was previously working good with the current ip address but now fails, so let's notify the error*/
...@@ -685,8 +690,7 @@ static void belle_sip_channel_handle_error(belle_sip_channel_t *obj){ ...@@ -685,8 +690,7 @@ static void belle_sip_channel_handle_error(belle_sip_channel_t *obj){
* it is safer to invoke the listener outside the current call stack. * it is safer to invoke the listener outside the current call stack.
* Indeed the channel encounters network errors while being called for transmiting by a transaction. * Indeed the channel encounters network errors while being called for transmiting by a transaction.
*/ */
belle_sip_object_ref(obj); belle_sip_main_loop_do_later(obj->stack->ml,(belle_sip_callback_t)channel_invoke_state_listener_defered,belle_sip_object_ref(obj));
belle_sip_main_loop_do_later(obj->stack->ml,(belle_sip_callback_t)channel_invoke_state_listener_defered,obj);
} }
int belle_sip_channel_notify_timeout(belle_sip_channel_t *obj){ int belle_sip_channel_notify_timeout(belle_sip_channel_t *obj){
......
...@@ -456,6 +456,10 @@ void belle_sip_client_transaction_add_response(belle_sip_client_transaction_t *t ...@@ -456,6 +456,10 @@ void belle_sip_client_transaction_add_response(belle_sip_client_transaction_t *t
BELLE_SIP_OBJECT_VPTR(t,belle_sip_client_transaction_t)->on_response(t,resp); BELLE_SIP_OBJECT_VPTR(t,belle_sip_client_transaction_t)->on_response(t,resp);
} }
belle_sip_uri_t *belle_sip_client_transaction_get_route(belle_sip_client_transaction_t *t){
return t->preset_route;
}
static void client_transaction_destroy(belle_sip_client_transaction_t *t ){ static void client_transaction_destroy(belle_sip_client_transaction_t *t ){
if (t->preset_route) belle_sip_object_unref(t->preset_route); if (t->preset_route) belle_sip_object_unref(t->preset_route);
if (t->next_hop) belle_sip_object_unref(t->next_hop); if (t->next_hop) belle_sip_object_unref(t->next_hop);
......
...@@ -170,15 +170,11 @@ int finalize_stream_connection(belle_sip_stream_channel_t *obj, unsigned int rev ...@@ -170,15 +170,11 @@ int finalize_stream_connection(belle_sip_stream_channel_t *obj, unsigned int rev
socklen_t optlen=sizeof(errnum); socklen_t optlen=sizeof(errnum);
belle_sip_socket_t sock=belle_sip_source_get_socket((belle_sip_source_t*)obj); belle_sip_socket_t sock=belle_sip_source_get_socket((belle_sip_source_t*)obj);
if (revents & BELLE_SIP_EVENT_READ){
belle_sip_warning("channel [%p]: getting read event while connecting",obj);
return -1;
}
if (revents==BELLE_SIP_EVENT_TIMEOUT){ if (revents==BELLE_SIP_EVENT_TIMEOUT){
belle_sip_warning("channel [%p]: user-defined transport timeout.",obj); belle_sip_warning("channel [%p]: user-defined transport timeout.",obj);
return -1; return -1;
} }
if (!(revents & BELLE_SIP_EVENT_WRITE)){ if (!(revents & BELLE_SIP_EVENT_WRITE) && !(revents & BELLE_SIP_EVENT_READ)){
belle_sip_warning("channel [%p]: getting unexpected event while connecting",obj); belle_sip_warning("channel [%p]: getting unexpected event while connecting",obj);
return -1; return -1;
} }
...@@ -215,7 +211,7 @@ static int stream_channel_process_data(belle_sip_stream_channel_t *obj,unsigned ...@@ -215,7 +211,7 @@ static int stream_channel_process_data(belle_sip_stream_channel_t *obj,unsigned
belle_sip_channel_state_t state=belle_sip_channel_get_state((belle_sip_channel_t*)obj); belle_sip_channel_state_t state=belle_sip_channel_get_state((belle_sip_channel_t*)obj);
belle_sip_channel_t *base=(belle_sip_channel_t*)obj; belle_sip_channel_t *base=(belle_sip_channel_t*)obj;
belle_sip_message("TCP channel process_data"); /*belle_sip_message("TCP channel process_data");*/
if (state == BELLE_SIP_CHANNEL_CONNECTING ) { if (state == BELLE_SIP_CHANNEL_CONNECTING ) {
if (finalize_stream_connection(obj,revents,(struct sockaddr*)&ss,&addrlen)) { if (finalize_stream_connection(obj,revents,(struct sockaddr*)&ss,&addrlen)) {
......
...@@ -78,14 +78,17 @@ static void process_response_event(void *user_ctx, const belle_sip_response_even ...@@ -78,14 +78,17 @@ static void process_response_event(void *user_ctx, const belle_sip_response_even
if (status==401) { if (status==401) {
belle_sip_header_cseq_t* cseq; belle_sip_header_cseq_t* cseq;
belle_sip_client_transaction_t *t; belle_sip_client_transaction_t *t;
belle_sip_uri_t *dest;
CU_ASSERT_NOT_EQUAL_FATAL(number_of_challenge,2); CU_ASSERT_NOT_EQUAL_FATAL(number_of_challenge,2);
CU_ASSERT_PTR_NOT_NULL_FATAL(belle_sip_response_event_get_client_transaction(event)); /*require transaction mode*/ CU_ASSERT_PTR_NOT_NULL_FATAL(belle_sip_response_event_get_client_transaction(event)); /*require transaction mode*/
dest=belle_sip_client_transaction_get_route(belle_sip_response_event_get_client_transaction(event));
request=belle_sip_transaction_get_request(BELLE_SIP_TRANSACTION(belle_sip_response_event_get_client_transaction(event))); request=belle_sip_transaction_get_request(BELLE_SIP_TRANSACTION(belle_sip_response_event_get_client_transaction(event)));
cseq=(belle_sip_header_cseq_t*)belle_sip_message_get_header(BELLE_SIP_MESSAGE(request),BELLE_SIP_CSEQ); cseq=(belle_sip_header_cseq_t*)belle_sip_message_get_header(BELLE_SIP_MESSAGE(request),BELLE_SIP_CSEQ);
belle_sip_header_cseq_set_seq_number(cseq,belle_sip_header_cseq_get_seq_number(cseq)+1); belle_sip_header_cseq_set_seq_number(cseq,belle_sip_header_cseq_get_seq_number(cseq)+1);
CU_ASSERT_TRUE_FATAL(belle_sip_provider_add_authorization(prov,request,belle_sip_response_event_get_response(event),NULL)); CU_ASSERT_TRUE_FATAL(belle_sip_provider_add_authorization(prov,request,belle_sip_response_event_get_response(event),NULL));
t=belle_sip_provider_create_client_transaction(prov,request); t=belle_sip_provider_create_client_transaction(prov,request);
belle_sip_client_transaction_send_request(t); belle_sip_client_transaction_send_request_to(t,dest);
number_of_challenge++; number_of_challenge++;
authorized_request=request; authorized_request=request;
belle_sip_object_ref(authorized_request); belle_sip_object_ref(authorized_request);
...@@ -517,6 +520,14 @@ static void test_tls_to_tcp(void){ ...@@ -517,6 +520,14 @@ static void test_tls_to_tcp(void){
belle_sip_stack_set_transport_timeout(stack,orig); belle_sip_stack_set_transport_timeout(stack,orig);
} }
static void register_dns_srv(void){
belle_sip_request_t *req;
io_error_count=0;
req=try_register_user_at_domain(stack, prov, "TCP",1,"tester",client_auth_domain,"sip:linphone.net;transport=tcp",1);
CU_ASSERT_TRUE(io_error_count==0);
if (req) belle_sip_object_unref(req);
}
test_t register_tests[] = { test_t register_tests[] = {
{ "Stateful UDP", stateful_register_udp }, { "Stateful UDP", stateful_register_udp },
{ "Stateful UDP with keep-alive", stateful_register_udp_with_keep_alive }, { "Stateful UDP with keep-alive", stateful_register_udp_with_keep_alive },
...@@ -534,7 +545,8 @@ test_t register_tests[] = { ...@@ -534,7 +545,8 @@ test_t register_tests[] = {
{ "Channel inactive", test_register_channel_inactive }, { "Channel inactive", test_register_channel_inactive },
{ "TCP connection failure", test_connection_failure }, { "TCP connection failure", test_connection_failure },
{ "TCP connection too long", test_connection_too_long }, { "TCP connection too long", test_connection_too_long },
{ "TLS connection to TCP server", test_tls_to_tcp } { "TLS connection to TCP server", test_tls_to_tcp },
{ "Register with DNS SRV failover", register_dns_srv }
}; };
test_suite_t register_test_suite = { test_suite_t register_test_suite = {
......
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