예제 #1
0
파일: ICE.cs 프로젝트: quangfox/Voip
        public void TellRemoteEndToUseThisPair(RTPStream stream, string strUsername, string strPassword)
        {
            if (IsControlling == false)
            {
                throw new Exception("Only controlling endpoint can send a usecandidate attribute");
            }

            STUN2Message msgRequest = new STUN2Message();

            msgRequest.Method = StunMethod.Binding;
            msgRequest.Class  = StunClass.Request;

            PriorityAttribute pattr = new PriorityAttribute();

            pattr.Priority = (int)CalculatePriority(110, 30, this.LocalCandidate.component); ///Peer reflexive, not sure of the purpose of this yet  //this.Priority;
            msgRequest.AddAttribute(pattr);

            IceControllingAttribute cattr = new IceControllingAttribute();

            msgRequest.AddAttribute(cattr);

            UseCandidateAttribute uattr = new UseCandidateAttribute();

            msgRequest.AddAttribute(uattr);

            if (strUsername != null)
            {
                UserNameAttribute unameattr = new UserNameAttribute();
                unameattr.UserName = strUsername;
                msgRequest.AddAttribute(unameattr);
            }


            /// Add message integrity, computes over all the items currently added
            ///
            int nLengthWithoutMessageIntegrity = msgRequest.Bytes.Length;
            MessageIntegrityAttribute mac      = new MessageIntegrityAttribute();

            msgRequest.AddAttribute(mac);
            mac.ComputeHMACShortTermCredentials(msgRequest, nLengthWithoutMessageIntegrity, strPassword);

            /// Add fingerprint
            ///
            int nLengthWithoutFingerPrint = msgRequest.Bytes.Length;
            FingerPrintAttribute fattr    = new FingerPrintAttribute();

            msgRequest.AddAttribute(fattr);
            fattr.ComputeCRC(msgRequest, nLengthWithoutFingerPrint);

            foreach (int nNextTimeout in Timeouts)
            {
                STUNMessage ResponseMessage = stream.SendRecvSTUN(this.RemoteCandidate.IPEndPoint, msgRequest, nNextTimeout);
                if (ResponseMessage != null)
                {
                    break;
                }
            }
        }
예제 #2
0
파일: ICE.cs 프로젝트: Hitchhikrr/Voip
        public void TellRemoteEndToUseThisPair(RTPStream stream, string strUsername, string strPassword)
        {
            if (IsControlling == false)
                throw new Exception("Only controlling endpoint can send a usecandidate attribute");

            STUN2Message msgRequest = new STUN2Message();
            msgRequest.Method = StunMethod.Binding;
            msgRequest.Class = StunClass.Request;

            PriorityAttribute pattr = new PriorityAttribute();
            pattr.Priority = (int)CalculatePriority(110, 30, this.LocalCandidate.component); ///Peer reflexive, not sure of the purpose of this yet  //this.Priority;
            msgRequest.AddAttribute(pattr);

            IceControllingAttribute cattr = new IceControllingAttribute();
            msgRequest.AddAttribute(cattr);

            UseCandidateAttribute uattr = new UseCandidateAttribute();
            msgRequest.AddAttribute(uattr);

            if (strUsername != null)
            {
                UserNameAttribute unameattr = new UserNameAttribute();
                unameattr.UserName = strUsername;
                msgRequest.AddAttribute(unameattr);
            }

            /// Add message integrity, computes over all the items currently added
            ///
            int nLengthWithoutMessageIntegrity = msgRequest.Bytes.Length;
            MessageIntegrityAttribute mac = new MessageIntegrityAttribute();
            msgRequest.AddAttribute(mac);
            mac.ComputeHMACShortTermCredentials(msgRequest, nLengthWithoutMessageIntegrity, strPassword);

            /// Add fingerprint
            ///
            int nLengthWithoutFingerPrint = msgRequest.Bytes.Length;
            FingerPrintAttribute fattr = new FingerPrintAttribute();
            msgRequest.AddAttribute(fattr);
            fattr.ComputeCRC(msgRequest, nLengthWithoutFingerPrint);

            foreach (int nNextTimeout in Timeouts)
            {
                STUNMessage ResponseMessage = stream.SendRecvSTUN(this.RemoteCandidate.IPEndPoint, msgRequest, nNextTimeout);
                if (ResponseMessage != null)
                    break;
            }
        }