RvSIP接收注册应答流程

//在StackConstructTransportModule模块构造时,根据本地UDP列表生成了一个SOCKET对
//象,同时放入FD对象中,并加入到了select引擎中,其中处理回调函数为
// TransportUdpEventCallback,之后select引擎由应用层一特定线程调用,当收到网络侧数
//据包,select引擎触发,最终调用TransportUdpEventCallback回调来处理UDP数据报。
//中间的过程就不再描述了
// StackConstructTransportModule
//	SipTransportConstruct
//		TransportMgrInitialize
//			OpenLocalAddresses
//				OpenLocalAddressesFromList
//					LocalAddressOpen
//						TransportUDPOpen

TransportUdpEventCallback
	//从FD对象中获取之前创建的UDP SOCKET对象
	pSock = RvFdGetSocket(fd);
	
	recvFromAddress.eTransport = RVSIP_TRANSPORT_UDP;
	
	switch (selectEvent)
	case RvSelectRead:
		//分配一个事件资源
		// ev ->type = MESSAGE_RCVD_EVENT;
		// ev ->typeSpecific.msgReceived.bytesRecv       = 0;
		// ev ->typeSpecific.msgReceived.receivedBuffer   = (RvUint8*)memBuff;
		// ev ->typeSpecific.msgReceived.pTransportMgr   = pMgr;
		// ev ->typeSpecific.msgReceived.hConn          = NULL;
		// ev ->typeSpecific.msgReceived.hInjectedMsg    = NULL;
		TransportProcessingQueueAllocateEvent((RvSipTransportMgrHandle)pMgr, NULL,
		MESSAGE_RCVD_EVENT ,RV_TRUE, &ev);
		
		recvBuffer = ev->typeSpecific.msgReceived.receivedBuffer;

//使用系统API接收网络报文,该报方最终存在
// ev ->typeSpecific.msgReceived.receivedBuffer中			 RvSocketReceiveBuffer(pSock,recvBuffer,pMgr->maxBufSize,pMgr->pLogMgr,
&bytesRecv,&recvFromAddress.addr);

recvBuffer[bytesRecv] = '\0';
recvFromAddress.eTransport = RVSIP_TRANSPORT_UDP;

//填充事件其它数据
ev->typeSpecific.msgReceived.hLocalAddr     =pLocalAddr;
ev->typeSpecific.msgReceived.bytesRecv      = (RvInt32)bytesRecv;
ev->typeSpecific.msgReceived.rcvFromAddr    = recvFromAddress;
ev->typeSpecific.msgReceived.eConnTransport = RVSIP_TRANSPORT_UDP;

//将此事件放入事件层处理队列
TransportProcessingQueueTailEvent((RvSipTransportMgrHandle)pMgr,ev);
	PQUEUE_TailEvent(pTransportMgr->hProcessingQueue, (HQEVENT)ev);
		//从事件队列池中分配资源
		RLIST_InsertTail(processing_queue->hEventQueuePool,
processing_queue->hEventQueue,&listItem);

//将要发送的事件写入事件池中
pEv = (HQEVENT*)listItem;
*pEv = ev;

//触发select引擎线程,告知事件队列里已经有待处理的事件
//该流程不详细描述,preemptionDispatchEvents句柄事件处理的回调函
//数为 TransportPreemptionSelectPreemptionDispatchEventsEvHandler
//,该回调在StackConstructTransportModule中设置。
// StackConstructTransportModule
//	SipTransportConstruct
//		TransportMgrInitialize
//			TransportPreemptionConstruct
RvSelectStopWaiting(processing_queue->pSelect, 
processing_queue->preemptionDispatchEvents,
processing_queue->pLogMgr);

-------------------------------------------------------------------------------------------------------------------------------
TransportPreemptionSelectPreemptionDispatchEventsEvHandler
	TransportProcessingQueueDispatchEvents(pMgr);
		//从队列中取出待处理的事件
		PQUEUE_PopEvent(pTransportMgr->hProcessingQueue,(HQEVENT*)&ev);
		
		switch (ev->type)
		case MESSAGE_RCVD_EVENT:
			//处理消息接收事件
			ProcessMsgReceivedEvent(ev);
				//触发应用层消息接收回调,当前VTP在ssmu_conn_setup_cbs函数中注
				//册对应回应用于打印收发包信息
				TransportCallbackBufferReceived(pTransportMgr,
				hLocalAddr, &recvFromAddr, pConn, buff, totalMsgSize, &bDiscardBuffer);
				
				//如果上面回调中,应用层设置此标记,则表示不需要协议栈在继
				//续处理此消息。
				if (RV_TRUE == bDiscardBuffer)
					……
					return
				
				switch (eConnTransport)
				case RVSIP_TRANSPORT_UDP:
					//解析消息
					TransportMsgBuilderParseUdpMsg(pTransportMgr, buff,
					totalMsgSize, hInjectedMsg, hLocalAddr, &recvFromAddr);
						//没有细看这个函数实现,大体就是解析收到的SIP消息,转换
						//RV使用的消息对象
						SipTransportMsgBuilderUdpMakeMsg(pTransportMgr,pBuffer,
totalMsgSize, RV_TRUE, NULL, pRecvFromAddr->eTransport,
&hMsg, pSigCompMsgInfo, &pPlainMsgBuf);
						
						//释放临时BUF
						TransportMgrFreeRcvBuffer(pTransportMgr, pPlainMsgBuf);
						
						//通知上层消息解析错误
						eBSAction = RVSIP_TRANSPORT_BS_ACTION_CONTINUE_PROCESS;
						InformBadSyntax(pTransportMgr, hMsg, &eBSAction);
						
						rcvdMsgDetails.eBSAction    = eBSAction;
						rcvdMsgDetails.hLocalAddr   = hLocalAddr;
						
						//获取接收的是否是信令压缩消息
						GetMsgCompressionType(pSigCompMsgInfo, 
						&rcvdMsgDetails.eCompression);
						
						//转换接收地址
						TransportMgrSipAddrGetDetails(pRecvFromAddr, 
						&rcvdMsgDetails.recvFromAddr);
						
						bProcessMsg = RV_TRUE;
						
						//通知上层处理消息接收,调用应用层设置消息处理回调
						TransportCallbackMsgReceivedExtEv(pTransportMgr, hMsg,
						&rcvdMsgDetails, pRecvFromAddr, 
						((TransportMgrLocalAddr*)hLocalAddr)->pSecOwner,
						&bProcessMsg);
						
						//如果应用层没有修改bProcessMsg标记,则继续由协议栈来处
						//理此消息
						if (RV_TRUE == bProcessMsg)
							//调用事务管理对象消息接收处理回调,该回调函数为
							// SipTransactionMgrMessageReceivedEv
							TransportCallbackMsgRcvdEv(pTransportMgr, hMsg, NULL,
							hLocalAddr, pRecvFromAddr, eBSAction, pSigCompMsgInfo);
				
				//消息BUG释放
				TransportMgrFreeRcvBuffer(pTransportMgr, buff);
		
		//释放队列资源
		PQUEUE_FreeEvent(pTransportMgr->hProcessingQueue,(HQEVENT)ev);

---------------------------------------------------------------------------------------------------------------------------
SipTransactionMgrMessageReceivedEv
	//当前为注册应答,所以消息类型为 RVSIP_MSG_RESPONSE ,走应答的处理流程
	eType = RvSipMsgGetMsgType(hReceivedMsg);
	if (RVSIP_MSG_RESPONSE == eType)
		ResponseMessageReceived(pTranscMgr, hReceivedMsg, hConn, hLocalAddr,
		pRecvFromAddr, eBSAction, pSigCompMsgInfo);
			HandleIncomingResponseMsg(pTranscMgr, hReceivedMsg, hConn, hLocalAddr,
			pRecvFromAddr, pSigCompMsgInfo);
				//从消息中获取事务信息,构造事务的HASH Key
				SipTransactionMgrGetKeyFromMessage((RvSipTranscMgrHandle)pTranscMgr, 
				hReceivedMsg, &key);
				
				//从事务管理对象中查找是否有之前的请求事务
				SipTransactionMgrFindTransaction(pTranscMgr, hReceivedMsg, &key, 
				RV_TRUE,&pTransc);
				
				// 检测是否是INVITE请求对应的1xx/2xx应答,并且含有to tag
				bIsRespOnInvite = Is1xx2xxRespWithToTagOnInviteMsg(hReceivedMsg);
				
				//检查事务是否有效
				CheckFoundTranscValidity(pTransc,hReceivedMsg, bIsRespOnInvite,
&bTranscValid);

// pTransc->receivedFrom = *pRecvFrom
TransactionSaveReceivedFromAddr(pTransc,pRecvFrom);

//TCP相关暂不关心
UpdateTranscConnection(pTransc, hConn,RV_FALSE);

//信令压缩暂不关心
TransactionHandleIncomingSigCompMsgIfNeeded(……)

// pTransc->hReceivedMsg = hReceivedMsg;
TransactionSetReceivedMsg(pTransc, hReceivedMsg);

//事务接收消息处理
TransactionMsgReceived(pTransc, hReceivedMsg);
	//注册应答
	bMsgType = RvSipMsgGetMsgType(hMsg);
	if (RVSIP_MSG_RESPONSE == bMsgType)
		//假设收到200 OK
		responseCode = RvSipMsgGetStatusCode(hMsg);
		if ((200 <= responseCode) && (700 > responseCode))
			//应答完成处理
			HandleFinalResponse(pTransc, hMsg);
				//应答码设置到pTransc->responseCode
				responseCode = RvSipMsgGetStatusCode(hMsg);
				TransactionSetResponseCode(pTransc, responseCode);
				
				switch (pTransc->eState)
			    case RVSIP_TRANSC_STATE_CLIENT_GEN_REQUEST_SENT
					//通用应答完成处理
					HandleGeneralFinalResponse(pTransc, hMsg, 
					responseCode);
						//调用事务客户端管理对象的消息接收回调
						//处理,该回调函数为
							// TranscClientTranscEvMsgReceived
						TransactionMsgReceivedNotifyOthers(pTransc,
hMsg);

TransactionStateUacGeneralFinalResponseRcvd(
FinalResponseReason(responseCode), pTransc);
	//停止之前事务请求的定时器
	TransactionTimerReleaseAllTimers(pTransc
							
							//事务状态切换,并且调用事务客户端对
							//象的状态改变回调处理,该回调函数为
							// TranscClientTranscEvStateChanged
							TransactionChangeState(pTransc,
RVSIP_TRANSC_STATE_CLIENT_GEN_FINAL_RESPONSE_RCVD,
							eReason);
							
							//当非INVITE事务收到正确应答后,启动
							//T4定时器,待T4定时器超时后才删除
							//此事务。
							switch (pTransc->eTranspType)
							case RVSIP_TRANSPORT_UDP:
								timerInterval = 
								(pTransc->pTimers->T4Timeout);
							
							TransactionTimerMainTimerStart(pTransc, 
							timerInterval,
"TransactionStateUacFinalResponseRcvd");

// pTransc->hReceivedMsg = NULL
TransactionSetReceivedMsg(pTransc, NULL);

-----------------------------------------------------------------------------------------------------------------------------
TranscClientTranscEvMsgReceived
	//调用注册客户端的消息接收回调函数,该回调函数为
	// RegClientTranscClientEvMsgReceived,该函数基本就是通知应用层处理消息接收回调
	TranscClientCallbackMsgReceivedEv ((SipTranscClientHandle)pTranscClient, hMsgReceived);
	
	//鉴权处理,暂不关心
	responseCode = RvSipMsgGetStatusCode(hMsgReceived);
	if(401 == responseCode || 407 == responseCode)
		……
	
	//消息重定向处理
	if ((300 <= responseCode) && (400 > responseCode))
		……

------------------------------------------------------------------------------------------------------------------------------
TranscClientTranscEvStateChanged
	//将消息句柄设置到pTranscClient->hReceivedMsg中
	UpdateReceivedMsg(pTranscClient, hTransaction, eNewState, eReason);
	
	switch (eNewState)
	case RVSIP_TRANSC_STATE_CLIENT_GEN_FINAL_RESPONSE_RCVD:
		TranscClientTransactionGenFinalResponseRcvd(pTranscClient, hTransaction);
			RvSipTransactionGetResponseCode(hTransaction,&responseCode);
			if((responseCode >= 200) && (responseCode < 300))
				// pTranscClient->eState =  SIP_TRANSC_CLIENT_STATE_ACTIVATED;
				// pTranscClient->bWasActivated = RV_TRUE;
				//调用注册客户端的状态改变回调函数,该回调函数为
				// RegClientTranscClientEvStateChanged,就是给上层通知注册状态
				TranscClientChangeState(SIP_TRANSC_CLIENT_STATE_ACTIVATED,
				SIP_TRANSC_CLIENT_REASON_RESPONSE_SUCCESSFUL_RECVD,
				pTranscClient, responseCode);
	
	//复位消息句柄
	ResetReceivedMsg(pTranscClient, eNewState);

RvSIP接收注册应答流程
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值