linphone用戶註冊與sip交互過程分析

linphone用戶註冊與sip交互過程分析

在linphone_core_init
在linphone_configuring_terminated
在linphone_core_start
在 sip_config_read
在linphone_core_set_sip_transports
在_linphone_core_apply_transports
在sal_listen_port
在sal_add_listen_port
在 belle_sip_stack_create_listening_point
在belle_sip_udp_listening_point_new
在belle_sip_udp_listening_point_init
在belle_sip_udp_listening_point_init_socket
在create_udp_socket
實現隨機端口原理是 將udp的端口號設爲-1,這樣處理的時候會隨機賦值,具體處理在create_udp_socket函數中 原理是,bind時使用端口號爲0,這樣會隨機綁定一個未佔用的端口,然後通過getsockname 獲取具體綁定的端口返回

linphone監聽端口是在linphone_core_init函數中就已經處理完成的,在這個函數中會先讀取文本配置,然後根據配置再進行處理

使用belle_sip_main_loop_add_source 將lp->source(攜帶了監聽的socket)加入到ml->fd_sources鏈表中,該結構最終在linphonecore.c文件 linphone_core_iterate函數下sal_iterate(lc->sal)中調用,跟代碼可以發現前面監聽的socket是在lc->sal->prov->lp 下,
sal_iterate最終執行代碼如下:
void belle_sip_main_loop_run(belle_sip_main_loop_t *ml){
if (ml->in_loop){
belle_sip_warning(“belle_sip_main_loop_run(): reentrancy detected, doing nothing”);
return;
}
ml->run = TRUE;
ml->in_loop = TRUE;
while(ml->run){
belle_sip_main_loop_iterate(ml);
}
ml->in_loop = FALSE;
}

其中belle_sip_main_loop_iterate(ml)中對於監聽的socket 採用了eventselect模型進行io處理
當有read write事件時,會調用s->notify 指針綁定的方法,udp的話就是udp_listeningpoint.c 文件下的 on_udp_data方法;

->on_udp_data
->belle_sip_channel_process_data (在 make_logbuf 會將接受的sip信息用char*然後輸出log)
->belle_sip_channel_recv
在這裏如果是udp端口對應處理結構是
BELLE_SIP_INSTANCIATE_CUSTOM_VPTR_BEGIN(belle_sip_udp_channel_t)
{
{
BELLE_SIP_VPTR_INIT(belle_sip_udp_channel_t,belle_sip_channel_t,FALSE),
(belle_sip_object_destroy_t)udp_channel_uninit,
NULL,
NULL,
BELLE_SIP_DEFAULT_BUFSIZE_HINT
},
“UDP”,
0, /is_reliable/
udp_channel_connect,
udp_channel_send,
udp_channel_recv,
NULL /no close method/
}

即udp_channel_recv

接收完數據後轉到
->belle_sip_channel_process_stream(obj,FALSE);
->belle_sip_channel_parse_stream 在其中會通過查\r\n\r\n的結尾符號 獲取整個sip文本部分

後面處理request
siplistener.c process_request_event
sal_impl.c process_request_event
sal_op_call.c process_request_event

關於監聽端口 跟蹤

關鍵函數:
sal_register

_sal_op_send_request_with_contact
方法中 next_hop_uri保存了sip服務器ip和端口
op->base.root->prov 保存了本地使用的ip和端口

belle_sip_client_transaction_send_request_to

關鍵結構
salop->base.root->prov 保存了端口相關信息

listeningpoint.c文件
int belle_sip_listening_point_get_well_known_port(const char *transport){
if (strcasecmp(transport,”UDP”)==0 || strcasecmp(transport,”TCP”)==0 ) return 5060;
if (strcasecmp(transport,”DTLS”)==0 || strcasecmp(transport,”TLS”)==0 ) return 5061;
belle_sip_error(“No well known port for transport %s”, transport);
return -1;
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章