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 void WriteTo(Stream s)
            {
                BincodingEncoder encoder = new BincodingEncoder(s, "BI", 7);

                encoder.Encode("type", (byte)_type);

                if (_networkNameOrPeerEmailAddress != null)
                {
                    encoder.Encode("network_name", _networkNameOrPeerEmailAddress);
                }

                if (_sharedSecret != null)
                {
                    encoder.Encode("shared_secret", _sharedSecret);
                }

                encoder.Encode("enable_tracking", _enableTracking);
                encoder.Encode("send_invitation", _sendInvitation);

                if (_invitationSender != null)
                {
                    encoder.Encode("invitation_sender", _invitationSender);
                }

                if (_invitationMessage != null)
                {
                    encoder.Encode("invitation_message", _invitationMessage);
                }

                encoder.Encode("network_status", (byte)_networkStatus);

                if (_hashedPeerEmailAddress != null)
                {
                    encoder.Encode("hashed_peer_email_address", _hashedPeerEmailAddress.Number);
                }

                if (_networkID != null)
                {
                    encoder.Encode("network_id", _networkID.Number);
                }

                if (_networkSecret != null)
                {
                    encoder.Encode("network_secret", _networkSecret.Number);
                }

                encoder.Encode("message_store_id", _messageStoreID);
                encoder.Encode("message_store_key", _messageStoreKey);

                encoder.Encode("group_image_date_modified", _groupImageDateModified);
                if (_groupImage != null)
                {
                    encoder.Encode("group_image", _groupImage);
                }

                encoder.Encode("mute", _mute);

                encoder.Encode("peer_certs", _peerCerts);
                encoder.Encode("shared_files", _sharedFiles);

                {
                    List <Bincoding> trackerList = new List <Bincoding>(_sharedFiles.Length);

                    foreach (Uri trackerURI in _trackerURIs)
                    {
                        trackerList.Add(Bincoding.GetValue(trackerURI.AbsoluteUri));
                    }

                    encoder.Encode("tracker_list", trackerList);
                }

                //signal end of settings
                encoder.EncodeNull();
            }
Ejemplo n.º 3
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.º 4
0
        protected override void WritePlainTextTo(Stream s)
        {
            BincodingEncoder encoder = new BincodingEncoder(s, "BP", 7);

            //main settings

            //bitchat local port
            encoder.Encode("local_port", _localPort);

            //check CertificateRevocationList
            encoder.Encode("check_cert_revocation", _checkCertificateRevocationList);

            //upnp enabled
            encoder.Encode("enable_upnp", _enableUPnP);

            //enable invitation
            encoder.Encode("allow_inbound_invitations", _allowInboundInvitations);
            encoder.Encode("allow_only_local_inbound_invitations", _allowOnlyLocalInboundInvitations);

            //download folder
            if (_downloadFolder != null)
            {
                encoder.Encode("download_folder", _downloadFolder);
            }

            //local cert store
            if (_localCertStore != null)
            {
                encoder.Encode("local_cert_store", _localCertStore);
            }

            //profile image
            encoder.Encode("profile_image_date_modified", _profileImageDateModified);

            if (_profileImage != null)
            {
                encoder.Encode("profile_image", _profileImage);
            }

            //tracker urls
            {
                List <Bincoding> trackerList = new List <Bincoding>(_trackerURIs.Length);

                foreach (Uri trackerURI in _trackerURIs)
                {
                    trackerList.Add(Bincoding.GetValue(trackerURI.AbsoluteUri));
                }

                encoder.Encode("tracker_list", trackerList);
            }

            //bitchat info
            {
                List <Bincoding> bitChatInfoList = new List <Bincoding>(_bitChatInfoList.Length);

                foreach (BitChatInfo info in _bitChatInfoList)
                {
                    bitChatInfoList.Add(Bincoding.GetValue(info));
                }

                encoder.Encode("bitchat_info", bitChatInfoList);
            }

            //bootstrap dht nodes
            {
                List <Bincoding> dhtNodeList = new List <Bincoding>(_bootstrapDhtNodes.Length);

                using (MemoryStream mS = new MemoryStream())
                {
                    foreach (IPEndPoint nodeEP in _bootstrapDhtNodes)
                    {
                        mS.SetLength(0);
                        IPEndPointParser.WriteTo(nodeEP, mS);

                        dhtNodeList.Add(Bincoding.GetValue(mS.ToArray()));
                    }
                }

                encoder.Encode("dht_nodes", dhtNodeList);
            }

            //proxy settings

            //proxy type
            if (_proxy != null)
            {
                encoder.Encode("proxy_type", (byte)_proxy.Type);
            }

            //proxy address
            if (_proxyAddress != null)
            {
                encoder.Encode("proxy_address", _proxyAddress);
            }

            //proxy port
            encoder.Encode("proxy_port", _proxyPort);

            //proxy credentials
            if (_proxyCredentials != null)
            {
                encoder.Encode("proxy_user", _proxyCredentials.UserName);
                encoder.Encode("proxy_pass", _proxyCredentials.Password);
            }

            //generic client data
            if ((_clientData != null) && (_clientData.Length > 0))
            {
                encoder.Encode("client_data", _clientData);
            }

            //signal end of settings
            encoder.EncodeNull();
        }
Ejemplo n.º 5
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);
        }