Ejemplo n.º 1
0
        public void ReadResponse(byte[] datas, long offset, long size, out byte[] rcvData)
        {
            serializer.SetBuffer(datas, offset, size);

            methodId      = (ushort)((uint)serializer.ReadUShort() & 0x3FFF); //0x3F (0011 1111) sets left most 2 bits to 00
            methodLength  = serializer.ReadUShort();
            transactionID = serializer.ReadBytes(16);

            if (!Enum.IsDefined(typeof(STUNMethod), (STUNMethod)methodId) || methodLength != serializer.byteLength - serializer.bytePos)
            {
                serializer.SetStartPos();
                isIndicateData = IsSTUNMessage = false;
                serializer.ReverserBuffer((int)offset, 4);
                ushort appSize = serializer.ReadUShort();
                responseChannelNumber = serializer.ReadUShort();
                rcvData = new byte[appSize];
                Array.Copy(datas, 4, rcvData, 0, appSize);
                return;
            }


            method         = (STUNMethod)methodId;
            isIndicateData = method == STUNMethod.DataIndication;
            IsSTUNMessage  = !isIndicateData;
            ReadAttribute(out rcvData);
        }
Ejemplo n.º 2
0
        private List <byte[]> DecryptPackage(byte[] data)
        {
            serializer.SetBuffer(data, 0, data.Length);
            List <byte[]> packages = new List <byte[]>();

            while (!serializer.IsEnd())
            {
                int pkgLength = serializer.ReadInt();
                packages.Add(serializer.ReadBytes(pkgLength));
            }
            return(packages);
        }
Ejemplo n.º 3
0
        public void ReadAttribute()
        {
            while (serializer.bytePos < serializer.byteLength)
            {
                NATPAttribute attrType = (NATPAttribute)serializer.ReadByte();
                attributeTypes.Add(attrType);

                switch (attrType)
                {
                case NATPAttribute.RoomAddress:
                case NATPAttribute.PeerAddress:
                    response.Add(attrType, ReadPeerAddress());
                    break;

                case NATPAttribute.User:
                case NATPAttribute.Passowrd:
                case NATPAttribute.RoomName:
                case NATPAttribute.RoomDescription:
                case NATPAttribute.RoomTag:
                    response.Add(attrType, ReadString());
                    break;

                /*case NATPAttribute.Room:
                 *  response.Add(attrType, ReadRoom());
                 *  break;*/
                default:
                    ushort attrLen = serializer.ReadUShort();
                    byte[] bytes   = serializer.ReadBytes(attrLen);
                    response.Add(attrType, bytes);
                    while (((attrLen++) % 4) != 0)
                    {
                        serializer.ReadByte();
                    }
                    break;
                }
            }
        }
Ejemplo n.º 4
0
        public void ReadAttribute()
        {
            List <IPEndPoint> roomAddressList     = new List <IPEndPoint>();
            List <string>     roomNameList        = new List <string>();
            List <string>     roomDescriptionList = new List <string>();
            List <Room>       roomList            = new List <Room>();
            string            name    = "";
            string            des     = "";
            IPEndPoint        address = null;
            int roomFieldCount        = 0;

            while (serializer.bytePos < serializer.byteLength)
            {
                SignalingAttribute attrType = (SignalingAttribute)serializer.ReadByte();
                attributeTypes.Add(attrType);

                switch (attrType)
                {
                case SignalingAttribute.PeerAddress:
                    response.Add(attrType, ReadPeerAddress());
                    break;

                case SignalingAttribute.RoomAddress:
                    //roomAddressList.Add(ReadPeerAddress());
                    roomFieldCount++;
                    address = ReadPeerAddress();
                    break;

                case SignalingAttribute.RoomName:
                    //roomNameList.Add(serializer.ReadString());
                    name = ReadString();
                    roomFieldCount++;
                    break;

                case SignalingAttribute.RoomDescription:
                    //roomDescriptionList.Add(serializer.ReadString());
                    des = ReadString();
                    roomFieldCount++;
                    break;

                case SignalingAttribute.Failed:
                    response.Add(attrType, false);
                    break;

                case SignalingAttribute.Success:
                    response.Add(attrType, true);
                    break;

                default:
                    ushort attrLen = serializer.ReadUShort();
                    byte[] bytes   = serializer.ReadBytes(attrLen);
                    response.Add(attrType, bytes);
                    while (((attrLen++) % 4) != 0)
                    {
                        serializer.ReadByte();
                    }
                    break;
                }
                if (roomFieldCount == 3)
                {
                    roomList.Add(new Room("", address, des, name));
                    roomFieldCount = 0;
                }
            }
            if (roomList.Count > 0)
            {
                response.Add(SignalingAttribute.Room, roomList);
            }
        }