STUN 请求处理

flowchart TD

__wildcard_endpoint_map-->__assign_stream_fds
monologue_offer_answer-->__assign_stream_fds
monologue_publish-->__assign_stream_fds
monologue_subscribe_request1-->__assign_stream_fds
call_make_transform_media-->__assign_stream_fds

__wildcard_endpoint_map -->__get_endpoint_map
monologue_offer_answer -->__get_endpoint_map
monologue_publish -->__get_endpoint_map
monologue_subscribe_request1 -->__get_endpoint_map
call_make_transform_media -->__get_endpoint_map

__assign_stream_fds --> stream_fd_new
__get_endpoint_map --> stream_fd_new

stream_fd_new --> stream_fd_recv

stream_fd_new-->stream_fd_readable
stream_fd_readable-->__stream_fd_readable
stream_fd_recv-->
__stream_fd_readable-->
stream_packet-->
media_demux_protocols --> 
stun --> __stun_request --> ice_request

从SDP Offer之后,stream_fd_new 函数里做了几个事件订阅, 当对应的的媒体端口收到包之后,这个包可能是好几种协议,例如RTP, DTLS, STUN等。

在media_demux_protocols() 中决定了这个包是以上包的哪一种, 如果是STUN包,则进入stun()中处理。

STUN包也分为请求和响应,当消息是响应时,进入ice_request().

 1int ice_request(stream_fd *sfd, const endpoint_t *src,
 2		struct stun_attrs *attrs)
 3{
 4	struct packet_stream *ps = sfd->stream;
 5	struct call_media *media = ps->media;
 6	struct ice_agent *ag;
 7	const char *err;
 8	struct ice_candidate *cand;
 9	struct ice_candidate_pair *pair;
10	int ret;
11
12	ilogs(ice, LOG_DEBUG, "Received ICE/STUN request from %s on %s",
13			endpoint_print_buf(src),
14			endpoint_print_buf(&sfd->socket.local));
flowchart TD
ice_update-->__do_ice_checks
ice_agents_timer_run-->__do_ice_checks

__do_ice_checks --> __do_ice_check