Esempio n. 1
0
        protected override void ReadPlainTextFrom(BinaryReader bR)
        {
            if (Encoding.ASCII.GetString(bR.ReadBytes(2)) != "BP")
            {
                throw new BitChatException("Invalid BitChatProfile data format.");
            }

            byte version = bR.ReadByte();

            switch (version)
            {
            case 1:
                #region version 1

                //tracker client id
                TrackerClientID localClientID = new TrackerClientID(bR);

                //local cert store
                if (bR.ReadByte() == 1)
                {
                    _localCertStore = new CertificateStore(bR);
                }

                //bitchat local service end point
                _localEP = new IPEndPoint(new IPAddress(bR.ReadBytes(bR.ReadByte())), bR.ReadInt32());

                //default tracker urls
                _trackerURIs = DefaultTrackerURIs;

                break;

                #endregion

            case 2:
            case 3:
                #region version 2 & 3

                //local cert store
                if (bR.ReadByte() == 1)
                {
                    _localCertStore = new CertificateStore(bR);
                }

                //bitchat local service end point
                _localEP = new IPEndPoint(new IPAddress(bR.ReadBytes(bR.ReadByte())), bR.ReadInt32());

                //download folder
                _downloadFolder = Encoding.UTF8.GetString(bR.ReadBytes(bR.ReadUInt16()));
                if (_downloadFolder == null)
                {
                    _downloadFolder = @"C:\";
                }

                //load tracker urls
                _trackerURIs = new Uri[bR.ReadByte()];
                for (int i = 0; i < _trackerURIs.Length; i++)
                {
                    _trackerURIs[i] = new Uri(Encoding.UTF8.GetString(bR.ReadBytes(bR.ReadByte())));
                }

                //load bitchat info
                _bitChatInfoList = new BitChatInfo[bR.ReadByte()];
                for (int i = 0; i < _bitChatInfoList.Length; i++)
                {
                    _bitChatInfoList[i] = new BitChatInfo(bR);
                }

                if (version > 2)
                {
                    //check CertificateRevocationList
                    _checkCertificateRevocationList = bR.ReadBoolean();
                }
                else
                {
                    _checkCertificateRevocationList = true;
                }

                //generic client data
                int dataCount = bR.ReadInt32();
                if (dataCount > 0)
                {
                    _clientData = bR.ReadBytes(dataCount);
                }

                break;

                #endregion

            default:
                throw new BitChatException("BitChatProfile data version not supported.");
            }
        }
Esempio n. 2
0
        protected override void ReadPlainTextFrom(BinaryReader bR)
        {
            if (Encoding.ASCII.GetString(bR.ReadBytes(2)) != "BP")
                throw new BitChatException("Invalid BitChatProfile data format.");

            byte version = bR.ReadByte();

            switch (version)
            {
                case 1:
                    #region version 1

                    //tracker client id
                    TrackerClientID localClientID = new TrackerClientID(bR);

                    //local cert store
                    if (bR.ReadByte() == 1)
                        _localCertStore = new CertificateStore(bR);

                    //bitchat local service end point
                    _localEP = new IPEndPoint(new IPAddress(bR.ReadBytes(bR.ReadByte())), bR.ReadInt32());

                    //default tracker urls
                    _trackerURIs = DefaultTrackerURIs;

                    break;

                    #endregion

                case 2:
                case 3:
                    #region version 2 & 3

                    //local cert store
                    if (bR.ReadByte() == 1)
                        _localCertStore = new CertificateStore(bR);

                    //bitchat local service end point
                    _localEP = new IPEndPoint(new IPAddress(bR.ReadBytes(bR.ReadByte())), bR.ReadInt32());

                    //download folder
                    _downloadFolder = Encoding.UTF8.GetString(bR.ReadBytes(bR.ReadUInt16()));
                    if (_downloadFolder == null)
                        _downloadFolder = @"C:\";

                    //load tracker urls
                    _trackerURIs = new Uri[bR.ReadByte()];
                    for (int i = 0; i < _trackerURIs.Length; i++)
                        _trackerURIs[i] = new Uri(Encoding.UTF8.GetString(bR.ReadBytes(bR.ReadByte())));

                    //load bitchat info
                    _bitChatInfoList = new BitChatInfo[bR.ReadByte()];
                    for (int i = 0; i < _bitChatInfoList.Length; i++)
                        _bitChatInfoList[i] = new BitChatInfo(bR);

                    if (version > 2)
                    {
                        //check CertificateRevocationList
                        _checkCertificateRevocationList = bR.ReadBoolean();
                    }
                    else
                    {
                        _checkCertificateRevocationList = true;
                    }

                    //generic client data
                    int dataCount = bR.ReadInt32();
                    if (dataCount > 0)
                        _clientData = bR.ReadBytes(dataCount);

                    break;

                    #endregion

                default:
                    throw new BitChatException("BitChatProfile data version not supported.");
            }
        }
Esempio n. 3
0
        protected override void ReadPlainTextFrom(Stream s)
        {
            BincodingDecoder decoder = new BincodingDecoder(s, "BP");

            if (decoder.Version != 7)
            {
                throw new BitChatException("BitChatProfile data version not supported.");
            }

            NetProxyType proxyType    = NetProxyType.None;
            string       proxyAddress = "127.0.0.1";
            int          proxyPort    = 0;
            string       username     = null;
            string       password     = "";

            while (true)
            {
                Bincoding value = decoder.DecodeNext();

                if (value.Type == BincodingType.NULL)
                {
                    break;
                }

                KeyValuePair <string, Bincoding> item = value.GetKeyValuePair();

                switch (item.Key)
                {
                case "local_port":
                    _localPort = item.Value.GetIntegerValue();
                    break;

                case "check_cert_revocation":
                    _checkCertificateRevocationList = item.Value.GetBooleanValue();
                    break;

                case "enable_upnp":
                    _enableUPnP = item.Value.GetBooleanValue();
                    break;

                case "allow_inbound_invitations":
                    _allowInboundInvitations = item.Value.GetBooleanValue();
                    break;

                case "allow_only_local_inbound_invitations":
                    _allowOnlyLocalInboundInvitations = item.Value.GetBooleanValue();
                    break;

                case "download_folder":
                    _downloadFolder = item.Value.GetStringValue();
                    break;

                case "local_cert_store":
                    _localCertStore = new CertificateStore(item.Value.GetValueStream());
                    break;

                case "profile_image_date_modified":
                    _profileImageDateModified = item.Value.GetLongValue();
                    break;

                case "profile_image":
                case "profile_image_large":
                    _profileImage = item.Value.Value;
                    break;

                case "tracker_list":
                {
                    List <Bincoding> trackerList = item.Value.GetList();

                    _trackerURIs = new Uri[trackerList.Count];
                    int i = 0;

                    foreach (Bincoding trackerItem in trackerList)
                    {
                        _trackerURIs[i++] = new Uri(trackerItem.GetStringValue());
                    }
                }
                break;

                case "bitchat_info":
                {
                    List <Bincoding> bitChatInfoList = item.Value.GetList();

                    _bitChatInfoList = new BitChatInfo[bitChatInfoList.Count];
                    int i = 0;

                    foreach (Bincoding infoItem in bitChatInfoList)
                    {
                        _bitChatInfoList[i++] = new BitChatInfo(infoItem.GetValueStream());
                    }
                }
                break;

                case "dht_nodes":
                {
                    try
                    {
                        List <Bincoding> dhtNodeList = item.Value.GetList();

                        _bootstrapDhtNodes = new IPEndPoint[dhtNodeList.Count];
                        int i = 0;

                        foreach (Bincoding dhtItem in dhtNodeList)
                        {
                            _bootstrapDhtNodes[i++] = IPEndPointParser.Parse(dhtItem.GetValueStream());
                        }
                    }
                    catch (NotSupportedException)
                    {
                        _bootstrapDhtNodes = new IPEndPoint[] { };
                    }
                }
                break;

                case "proxy_type":
                    proxyType = (NetProxyType)item.Value.GetByteValue();
                    break;

                case "proxy_address":
                    proxyAddress = item.Value.GetStringValue();
                    break;

                case "proxy_port":
                    proxyPort = item.Value.GetIntegerValue();
                    break;

                case "proxy_user":
                    username = item.Value.GetStringValue();
                    break;

                case "proxy_pass":
                    password = item.Value.GetStringValue();
                    break;

                case "client_data":
                    if (item.Value.Type == BincodingType.BINARY)
                    {
                        _clientData = item.Value.Value;
                    }

                    break;
                }
            }

            if (string.IsNullOrEmpty(_downloadFolder))
            {
                _downloadFolder = Path.Combine(_profileFolder, "Downloads");

                if (!Directory.Exists(_downloadFolder))
                {
                    try
                    {
                        Directory.CreateDirectory(_downloadFolder);
                    }
                    catch
                    { }
                }
            }

            //apply proxy settings
            NetworkCredential proxyCredentials = null;

            if (username != null)
            {
                proxyCredentials = new NetworkCredential(username, password);
            }

            ConfigureProxy(proxyType, proxyAddress, proxyPort, proxyCredentials);
        }
Esempio n. 4
0
 public void UpdateBitChatInfo(BitChatInfo[] bitChatInfoList)
 {
     _bitChatInfoList = bitChatInfoList;
 }