Esempio n. 1
0
        public void WriteEmpty(NATPAttribute attr)
        {
            serializer.SetBufferLength(0);

            serializer.Write((byte)attr);
            serializer.Write((ushort)0);

            attributeTypes.Add(attr);
            attributeBytes.Add(serializer.ToArray());
        }
Esempio n. 2
0
        public object Get(NATPAttribute attr)
        {
            if (!response.ContainsKey(attr))
            {
                return(null);
            }
            object value = response[attr];

            return(value);
        }
Esempio n. 3
0
        public void WriteUInt(NATPAttribute attr, uint value)
        {
            serializer.SetBufferLength(0);

            serializer.Write((byte)attr);
            serializer.Write((ushort)4);
            serializer.Write(value);

            attributeTypes.Add(attr);
            attributeBytes.Add(serializer.ToArray());
        }
Esempio n. 4
0
        public void WriteBytes(NATPAttribute attr, byte[] bytes)
        {
            serializer.SetBufferLength(0);
            serializer.Write((byte)attr);
            serializer.Write((ushort)bytes.Length);
            serializer.Write(bytes);

            //pad to multiple of 4
            PadTo32Bits(bytes.Length, serializer);

            attributeTypes.Add(attr);
            attributeBytes.Add(serializer.ToArray());
        }
Esempio n. 5
0
        public void WriteString(NATPAttribute attr, string text)
        {
            serializer.SetBufferLength(0);

            int len = Encoding.UTF8.GetByteCount(text);

            serializer.Write((byte)attr);
            serializer.Write(text, len);

            //pad to multiple of 4
            PadTo32Bits(len, serializer);

            attributeTypes.Add(attr);
            attributeBytes.Add(serializer.ToArray());
        }
Esempio n. 6
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;
                }
            }
        }