Ejemplo n.º 1
0
            public SharedFileInfo(Stream s)
            {
                BincodingDecoder decoder = new BincodingDecoder(s, "FI");

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

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

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

                    switch (pair.Key)
                    {
                    case "file_path":
                        _filePath = pair.Value.GetStringValue();
                        break;

                    case "file_metadata":
                        _fileMetaData = new SharedFileMetaData(pair.Value.GetValueStream());
                        break;

                    case "state":
                        _state = (SharedFileState)pair.Value.GetByteValue();
                        break;

                    case "block_available":
                        _blockAvailable = pair.Value.Value;
                        break;
                    }
                }
            }
Ejemplo n.º 2
0
            public BitChatInfo(Stream s)
            {
                BincodingDecoder decoder = new BincodingDecoder(s, "BI");

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

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

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

                    switch (pair.Key)
                    {
                    case "type":
                        _type = (BitChatNetworkType)pair.Value.GetByteValue();
                        break;

                    case "network_name":
                        _networkNameOrPeerEmailAddress = pair.Value.GetStringValue();
                        break;

                    case "shared_secret":
                        _sharedSecret = pair.Value.GetStringValue();
                        break;

                    case "enable_tracking":
                        _enableTracking = pair.Value.GetBooleanValue();
                        break;

                    case "send_invitation":
                        _sendInvitation = pair.Value.GetBooleanValue();
                        break;

                    case "invitation_sender":
                        _invitationSender = pair.Value.GetStringValue();
                        break;

                    case "invitation_message":
                        _invitationMessage = pair.Value.GetStringValue();
                        break;

                    case "network_status":
                        _networkStatus = (BitChatNetworkStatus)pair.Value.GetByteValue();
                        break;

                    case "hashed_peer_email_address":
                        _hashedPeerEmailAddress = new BinaryNumber(pair.Value.Value);
                        break;

                    case "network_id":
                        _networkID = new BinaryNumber(pair.Value.Value);
                        break;

                    case "network_secret":
                        _networkSecret = new BinaryNumber(pair.Value.Value);
                        break;

                    case "message_store_id":
                        _messageStoreID = pair.Value.GetStringValue();
                        break;

                    case "message_store_key":
                        _messageStoreKey = pair.Value.Value;
                        break;

                    case "group_image_date_modified":
                        _groupImageDateModified = pair.Value.GetLongValue();
                        break;

                    case "group_image":
                        _groupImage = pair.Value.Value;
                        break;

                    case "mute":
                        _mute = pair.Value.GetBooleanValue();
                        break;

                    case "peer_certs":
                    {
                        List <Bincoding> peerCerts = pair.Value.GetList();

                        _peerCerts = new Certificate[peerCerts.Count];
                        int i = 0;

                        foreach (Bincoding item in peerCerts)
                        {
                            _peerCerts[i++] = new Certificate(item.GetValueStream());
                        }
                    }
                    break;

                    case "shared_files":
                    {
                        List <Bincoding> sharedFiles = pair.Value.GetList();

                        _sharedFiles = new SharedFileInfo[sharedFiles.Count];
                        int i = 0;

                        foreach (Bincoding item in sharedFiles)
                        {
                            _sharedFiles[i++] = new SharedFileInfo(item.GetValueStream());
                        }
                    }
                    break;

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

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

                        foreach (Bincoding item in trackerList)
                        {
                            _trackerURIs[i++] = new Uri(item.GetStringValue());
                        }
                    }
                    break;
                    }
                }
            }
Ejemplo 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);
        }