Exemplo n.º 1
0
 def HandleCheckAuth(self, sClientIPPort, dwCmdId, CmdIStr):
     # 处理客户端鉴权,返回格式为: (sClientIPPort,dwCmdId,CmdOStr)
     # PrintTimeMsg("HandleCheckAuth.dwCmdId=%d=" % dwCmdId)
     sP2PKind = CmdIStr[1]
     sHubId = CmdIStr[2]
     sAcctId = CmdIStr[3]
     sAcctPwd = CmdIStr[4]
     ynForceLogin = CmdIStr[5]
     sClientInfo = CmdIStr[6]
     if sP2PKind != P2PKIND_ACCTSHARE and sHubId != self.sHubId:
         CmdOStr = GenErrorTuple(CSTPError.CHECK_AUTH_HUBID,
                                 'CHubCallbackBase.HandleCheckAuth',
                                 sP2PKind=sP2PKind,
                                 sHubId=sHubId)
     else:
         oLink = self.dictObjLinkByCIP.get(sClientIPPort, None)
         if oLink:
             CmdOStr = self.DoHandleCheckAuth(oLink, dwCmdId, sHubId,
                                              sP2PKind, sAcctId, sAcctPwd,
                                              ynForceLogin, sClientInfo)
         else:
             CmdOStr = GenErrorTuple(CSTPError.CHECK_AUTH_NO_CIP,
                                     'CHubCallbackBase.HandleCheckAuth',
                                     sClientIPPort=sClientIPPort)
     return (sClientIPPort, GetCmdReplyFmRequest(dwCmdId), CmdOStr)
Exemplo n.º 2
0
 def SendP2PMsgToPeerByCIP(self, sClientIPPort, sSuffixFm, sListSuffixTo,
                           CmdIStr):
     # 发送P2P消息, 返回 CmdOStr
     sWhere = 'CHubCallbackP2PLayout.SendP2PMsgToPeerByCIP'
     sPairId = self.GetLinkAttrValue(sClientIPPort, 'sPairId', '')
     if not sPairId:
         return GenErrorTuple(CSTPError.P2P_SEND_MSG_CIP_NO_PAIRID,
                              sWhere,
                              sClientIPPort=sClientIPPort)
     if '@' in sListSuffixTo:
         return GenErrorTuple(CSTPError.P2P_SEND_MSG_NO_SUPPORT_0,
                              sWhere,
                              sListSuffixTo=sListSuffixTo)
     setSuffix = self.CalcMatchSuffixSetFromTo(sPairId, sListSuffixTo)
     return self.BroadcastP2PMsgToSuffixSet(sPairId, setSuffix, CmdIStr)
Exemplo n.º 3
0
 def CheckPairPwdStatus(self, sPairId, sSuffix, sAcctPwd):
     # 返回 CmdOStr #bPass, sMsg
     sWhereMsg = 'CHubCallbackP2PLayout.CheckPairPwdStatus'
     if sPairId not in self.lsPairIdAllow:
         return GenErrorTuple(CSTPError.CHECK_AUTH_P2P_PAIRID_1,
                              sWhereMsg,
                              sPairId=sPairId)
     dictPasswdBySuffix = self.dictP2PLayoutByPairId.get(sPairId, {})
     if dictPasswdBySuffix:
         if dictPasswdBySuffix.get(sSuffix, '') != sAcctPwd:
             return GenErrorTuple(CSTPError.CHECK_AUTH_P2P_SUFFIX_PWD,
                                  sWhereMsg,
                                  sSuffix=sSuffix)
         return GenOkMsgTuple(sWhereMsg)
     else:
         return GenErrorTuple(CSTPError.CHECK_AUTH_P2P_PAIRID_2,
                              sWhereMsg,
                              sPairId=sPairId)
Exemplo n.º 4
0
 def SendP2PMsgToPeerByPairId(self, sPairId, sSuffixTo, CmdIStr):
     # 依据sPairId发送P2P消息, 返回 CmdOStr #sErrno,sMsg 其中,sErrno='' 表示无错误
     sWhereMsg = 'CHubCallbackP2PLayout.SendP2PMsgToPeerByPairId'
     sPeerIdTo = self.GetPeerIdFmPairId(sPairId, sSuffixTo)
     sClientIPPortTo = self.dictCIPByPeerId.get(sPeerIdTo, '')
     if not sClientIPPortTo:
         return GenErrorTuple(CSTPError.P2P_SEND_MSG_CIP_NOT_FOUND,
                              sWhere,
                              sPairId=sPairId,
                              sPeerIdTo=sPeerIdTo)
     self.PutCmdStrToReturnQueue(
         [sClientIPPortTo, CMDID_NOTIFY_MSG, CmdIStr])
     return GenOkMsgTuple(sWhereMsg)
Exemplo n.º 5
0
 def DoP2PLayoutSendCmdToPeer(self, sClientIPPort, dwCmdId, CmdIStr):
     # 向同一sPairId中的其它Peer发命令请求
     # PrintTimeMsg('DoP2PLayoutSendCmdToPeer.CmdIStr=(%s)!' % (','.join(CmdIStr)))
     sSuffixFm = self.GetLinkAttrValue(sClientIPPort, 'sSuffix', '')
     if sSuffixFm == CmdIStr[1]:
         sListSuffixTo = CmdIStr[2]
         return self.SendP2PMsgToPeerByCIP(sClientIPPort, sSuffixFm,
                                           sListSuffixTo, CmdIStr)  #原样送达
     else:
         sWhere = 'CHubCallbackP2PLayout.DoP2PLayoutSendCmdToPeer'
         return GenErrorTuple(CSTPError.P2P_SEND_MSG_SUFFIX_FM_ERR,
                              sWhere,
                              sSuffixFm=sSuffixFm,
                              sSuffixFmHub=CmdIStr[1])
Exemplo n.º 6
0
 def DealSpecialCmdReply(self, oObj, dwCmdId, CmdOStr):
     # 处理特殊命令应答
     # PrintTimeMsg('DealSpecialCmdReply.CmdIStr=(%s)!' % str(CmdIStr))
     if CmdOStr[0] == CMD0_KICK_OFFLINE:  #被踢出
         sClientIPPortA = CmdOStr[1]
         sClientIPPortB = CmdOStr[2]
         sReasonDesc = CmdOStr[3]
         CmdOStr = GenErrorTuple(CSTPError.CHECK_AUTH_KICK_OFFLINE,
                                 'TCmdStringHub.DealSpecialCmdReply',
                                 sClientIPPortA=sClientIPPortA,
                                 sClientIPPortB=sClientIPPortB,
                                 sReasonDesc=sReasonDesc)
         oObj.WriteCmdStrToLink(dwCmdId, CmdOStr)
         oObj.SetCloseQuitFlag('DealSpecialCmdReply.CMD0_KICK_OFFLINE')
         self.oHubCallback.SetKickOffFlagTrue(sClientIPPortB)
         return True
     return False
Exemplo n.º 7
0
 def DealSpecialCmdRequest(self, oObj, dwCmdId, CmdIStr):
     # 处理特殊命令请求
     # PrintTimeMsg('DealSpecialCmdRequest.CmdIStr=(%s)!' % str(CmdIStr))
     if CmdIStr[0] == CMD0_CHECK_AUTH:  # .startswith('ABLOGIN.ChkPasswd'):
         if oObj.cLoginStatus != 'L':
             CmdOStr = GenErrorTuple(CSTPError.CHECK_AUTH_CMD_SEQ,
                                     'TCmdStringHub.DealSpecialCmdRequest',
                                     cmd0=CMD0_CHECK_AUTH)
             oObj.WriteCmdStrToLink(GetCmdReplyFmRequest(dwCmdId), CmdOStr)
             oObj.SetCloseQuitFlag('DealSpecialCmdRequest.CMD0_CHECK_AUTH')
         else:
             sClientIPPort = oObj.GetObjIPPort()
             (sClientIPPort, dwCmdId,
              CmdOStr) = self.oHubCallback.HandleCheckAuth(
                  sClientIPPort, dwCmdId, CmdIStr)
             oObj.WriteCmdStrToLink(dwCmdId, CmdOStr)
         return True
     return False
Exemplo n.º 8
0
 def DoHandleCheckAuth(self, oLink, dwCmdId, sHubId, sP2PKind, sAcctId,
                       sAcctPwd, ynForceLogin, sClientInfo):
     # 处理客户端鉴权,返回格式为: CmdOStr
     return GenErrorTuple(CSTPError.CHECK_AUTH_P2PKIND,
                          'CHubCallbackBase.DoHandleCheckAuth',
                          sP2PKind=sP2PKind)
Exemplo n.º 9
0
 def DoHandleCheckAuthLayout(self, oLink, dwCmdId, sHubId, sP2PKind,
                             sAcctId, sAcctPwd, ynForceLogin, sClientInfo):
     # 处理客户端P1A/P1B鉴权,返回格式为:CmdOStr
     sWhere = 'CHubCallbackP2PLayout.DoHandleCheckAuthLayout'
     CmdOStr = GenErrorTuple(CSTPError.CHECK_AUTH_DEFAULT, sWhere)
     (sPairId, cSep, sSuffix) = sAcctId.partition(CHAR_SEP_P2PLAYOUT)
     if cSep == '':
         CmdOStr = GenErrorTuple(CSTPError.CHECK_AUTH_P2P_ACCTID_FMT,
                                 sWhere,
                                 sAcctId=sAcctId)
     else:
         CmdOStr = self.CheckPairPwdStatus(sPairId, sSuffix, sAcctPwd)
         if CmdOStr[0] == 'OK':  #bPass:
             if self.bVerbosePrintCmdStr:
                 PrintTimeMsg(
                     'DoHandleCheckAuthP1.*******.dictCIPByPeerId=%s=' %
                     str(self.dictCIPByPeerId))
             sPeerId = self.GetPeerIdFmPairId(sPairId, sSuffix)
             sOldIPPort = self.dictCIPByPeerId.get(sPeerId, '')
             if sOldIPPort == '' or ynForceLogin in 'Yy':
                 if sOldIPPort:
                     sReasonDesc = 'sP2PKind=%s,sPairId=%s,ynForceLogin=%s' % (
                         sP2PKind, sPairId, ynForceLogin)
                     csKickOffline = [
                         CMD0_KICK_OFFLINE, oLink.sClientIPPort, sOldIPPort,
                         sReasonDesc
                     ]
                     self.PutCmdStrToReturnQueue(
                         [sOldIPPort, CMDID_NOTIFY_MSG, csKickOffline])
                 setSuffix = self.dictSuffixSetByPairId.get(
                     sPairId, set([]))
                 setSuffix.add(sSuffix)
                 self.dictSuffixSetByPairId[sPairId] = setSuffix
                 oLink.sPeerId = sPeerId  #链接对象保留 sPeerId 消息
                 oLink.sPairId = sPairId
                 oLink.sSuffix = sSuffix
                 self.dictCIPByPeerId[sPeerId] = oLink.sClientIPPort
                 if self.bVerbosePrintCmdStr:
                     PrintTimeMsg(
                         'DoHandleCheckAuthP1.dictCIPByPeerId=%s=' %
                         str(self.dictCIPByPeerId))
                 sOnlineList = ','.join(setSuffix)
                 #发送上线通知消息
                 CmdIStr = [
                     CMD0_P2PLAYOUT_SEND_SYSTEM_MSG,
                     'PeerOnline',  #Action
                     sPairId,  #Pair标识
                     sSuffix,  #Pair后缀
                     sOnlineList,  #在线 sSuffix 列表串
                     GetCurrentTime(),  #服务器时间
                 ]
                 self.BroadcastP2PMsgByPairId(sPairId, sSuffix, CmdIStr)
                 if not self.bVerbosePrintCmdStr:
                     PrintTimeMsg('PeerOnline(%s).sOnlineList=%s=' %
                                  (sSuffix, sOnlineList))
                 return (
                     'OK',
                     sP2PKind,
                     sHubId,
                     sAcctId,
                     GetCurrentTime(),
                     'sServerInfo@P2PLayout',
                 )
             else:
                 return GenErrorTuple(CSTPError.CHECK_AUTH_P2P_ALREADY_ON,
                                      sWhere,
                                      sPairId=sPairId,
                                      sSuffix=sSuffix,
                                      sOldIPPort=sOldIPPort)
     return CmdOStr