Exemplo n.º 1
0
        public void PerformRequest()
        {
            ResponseMessage = null;
            WaitHandle.Reset();
            EndPoint epStun = SocketServer.ConnectMgr.GetIPEndpoint(StunServer, StunPort);

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

            MappedAddressAttribute mattr = new MappedAddressAttribute();
            mattr.IPAddress = LocalEndpoint.Address;
            mattr.Port = (ushort) LocalEndpoint.Port;

            msgRequest.AddAttribute(mattr);

            SocketServer.UDPSocketClient client = new SocketServer.UDPSocketClient(LocalEndpoint);
            client.OnReceivePacket += new SocketServer.UDPSocketClient.DelegateReceivePacket(client_OnReceivePacket3);
            #if !WINDOWS_PHONE
            client.StartReceiving(true);
            #else
            client.StartReceiving();
            #endif

            byte [] bMessage = msgRequest.Bytes;
            client.SendUDP(bMessage, bMessage.Length, epStun);
        }
Exemplo n.º 2
0
        public void PerformRequest()
        {
            ResponseMessage = null;
            WaitHandle.Reset();
            EndPoint epStun = SocketServer.ConnectMgr.GetIPEndpoint(StunServer, StunPort);

            STUNMessage msgRequest = new STUNMessage();

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


            MappedAddressAttribute mattr = new MappedAddressAttribute();

            mattr.IPAddress = LocalEndpoint.Address;
            mattr.Port      = (ushort)LocalEndpoint.Port;


            msgRequest.AddAttribute(mattr);

            SocketServer.UDPSocketClient client = new SocketServer.UDPSocketClient(LocalEndpoint);
            client.OnReceivePacket += new SocketServer.UDPSocketClient.DelegateReceivePacket(client_OnReceivePacket3);
#if !WINDOWS_PHONE
            client.StartReceiving(true);
#else
            client.StartReceiving();
#endif

            byte [] bMessage = msgRequest.Bytes;
            client.SendUDP(bMessage, bMessage.Length, epStun);
        }
Exemplo n.º 3
0
        public string CreateAndSendSTUN(DnsEndPoint serverEp)
        {
            STUN2Message msgRequest = new STUN2Message();

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


            MappedAddressAttribute mattr = new MappedAddressAttribute();

            mattr.IPAddress = LocalEndpoint.Address;
            mattr.Port      = (ushort)LocalEndpoint.Port;

            msgRequest.AddAttribute(mattr);

            byte[] tosend = msgRequest.Bytes;

            return(RTPUDPClient.SendByteArray(tosend, serverEp));
        }
Exemplo n.º 4
0
        public IPEndPoint RecvSTUN(DnsEndPoint serverEp, int timeout)
        {
            byte[]      recv            = RTPUDPClient.ReceiveByteArray(serverEp.Port, timeout);
            STUNMessage ResponseMessage = new STUNMessage();

            ResponseMessage.Bytes = recv;
            IPEndPoint retep = LocalEndpoint;

            if (ResponseMessage != null)
            {
                foreach (STUNAttributeContainer cont in ResponseMessage.Attributes)
                {
                    if (cont.ParsedAttribute.Type == StunAttributeType.MappedAddress)
                    {
                        MappedAddressAttribute attrib = cont.ParsedAttribute as MappedAddressAttribute;
                        retep = new IPEndPoint(attrib.IPAddress, attrib.Port);
                    }
                }
            }
            return(retep);
        }
Exemplo n.º 5
0
Arquivo: ICE.cs Projeto: quangfox/Voip
        public void PerformOutgoingSTUNCheckGoogle(RTPStream stream, string strUsername, string strPassword)
        {
            STUN2Message msgRequest = new STUN2Message();

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


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

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

                ResponseEndpoint = null;
                if (ResponseMessage != null)
                {
                    foreach (STUNAttributeContainer cont in ResponseMessage.Attributes)
                    {
                        if (cont.ParsedAttribute.Type == StunAttributeType.MappedAddress)
                        {
                            MappedAddressAttribute attrib = cont.ParsedAttribute as MappedAddressAttribute;
                            ResponseEndpoint = new IPEndPoint(attrib.IPAddress, attrib.Port);
                        }
                    }
                    this.CandidatePairState = RTP.CandidatePairState.Succeeded;
                    break;
                }
                else
                {
                    this.CandidatePairState = RTP.CandidatePairState.Failed;
                }
            }
        }
Exemplo n.º 6
0
Arquivo: ICE.cs Projeto: quangfox/Voip
        public void PerformOutgoingSTUNCheck(RTPStream stream, string strUsername, string strPassword)
        {
            STUN2Message msgRequest = new STUN2Message();

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


            //MappedAddressAttribute mattr = new MappedAddressAttribute();
            //mattr.IPAddress = LocalCandidate.IPEndPoint.Address;
            //mattr.Port = (ushort)LocalCandidate.IPEndPoint.Port;

            //msgRequest.AddAttribute(mattr);

            PriorityAttribute pattr = new PriorityAttribute();

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

            if (IsControlling == true)
            {
                IceControllingAttribute cattr = new IceControllingAttribute();
                msgRequest.AddAttribute(cattr);
            }
            else
            {
                IceControlledAttribute cattr = new IceControlledAttribute();
                msgRequest.AddAttribute(cattr);
            }

            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);

                ResponseEndpoint = null;
                if (ResponseMessage != null)
                {
                    foreach (STUNAttributeContainer cont in ResponseMessage.Attributes)
                    {
                        if (cont.ParsedAttribute.Type == StunAttributeType.MappedAddress)
                        {
                            MappedAddressAttribute attrib = cont.ParsedAttribute as MappedAddressAttribute;
                            ResponseEndpoint = new IPEndPoint(attrib.IPAddress, attrib.Port);
                        }
                    }
                    System.Diagnostics.Debug.WriteLine("STUN check for remote candidate {0} succeeded", this.RemoteCandidate.IPEndPoint);
                    this.CandidatePairState = RTP.CandidatePairState.Succeeded;
                    break;
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine("STUN check for remote candidate {0} failed", this.RemoteCandidate.IPEndPoint);
                    this.CandidatePairState = RTP.CandidatePairState.Failed;
                }
            }
        }
Exemplo n.º 7
0
        public string CreateAndSendSTUN(DnsEndPoint serverEp)
        {
            STUN2Message msgRequest = new STUN2Message();
            msgRequest.Method = StunMethod.Binding;
            msgRequest.Class = StunClass.Request;

            MappedAddressAttribute mattr = new MappedAddressAttribute();
            mattr.IPAddress = LocalEndpoint.Address;
            mattr.Port = (ushort)LocalEndpoint.Port;

            msgRequest.AddAttribute(mattr);

            byte[] tosend = msgRequest.Bytes;

            return RTPUDPClient.SendByteArray(tosend, serverEp);
        }