Ejemplo n.º 1
0
        public ProfileWindow(ProfileItem profileItem, OutoposManager outoposManager, BufferManager bufferManager)
        {
            _profileItem = profileItem;
            _outoposManager = outoposManager;
            _bufferManager = bufferManager;

            var digitalSignatureCollection = new List<object>();
            digitalSignatureCollection.Add(new ComboBoxItem() { Content = "" });
            digitalSignatureCollection.AddRange(Settings.Instance.Global_DigitalSignatureCollection.Select(n => new DigitalSignatureComboBoxItem(n)).ToArray());

            InitializeComponent();

            _wikiTextBox.MaxLength = Wiki.MaxNameLength;
            _chatTextBox.MaxLength = Chat.MaxNameLength;

            lock (_profileItem.ThisLock)
            {
                _uploadSignature = _profileItem.UploadSignature;
                _signatureCollection.AddRange(_profileItem.TrustSignatures);
                _wikiCollection.AddRange(_profileItem.Wikis);
                _chatCollection.AddRange(_profileItem.Chats);
            }

            _signatureListView.ItemsSource = _signatureCollection;
            _wikiListView.ItemsSource = _wikiCollection;
            _chatListView.ItemsSource = _chatCollection;

            _signatureComboBox.ItemsSource = digitalSignatureCollection;

            this.Sort();
        }
        public OverlayNetworkManager(OutoposManager outoposManager, BufferManager bufferManager)
        {
            _outoposManager = outoposManager;
            _bufferManager = bufferManager;

            _settings = new Settings(this.ThisLock);

            _outoposManager.CreateCapEvent = this.CreateCap;
            _outoposManager.AcceptCapEvent = this.AcceptCap;
        }
Ejemplo n.º 3
0
        public ChatListWindow(IEnumerable<Chat> chats, OutoposManager outoposManager)
        {
            _outoposManager = outoposManager;

            InitializeComponent();

            {
                var icon = new BitmapImage();

                icon.BeginInit();
                icon.StreamSource = new FileStream(Path.Combine(App.DirectoryPaths["Icons"], "Outopos.ico"), FileMode.Open, FileAccess.Read, FileShare.Read);
                icon.EndInit();
                if (icon.CanFreeze) icon.Freeze();

                this.Icon = icon;
            }

            _chatCollection = new ObservableCollectionEx<Chat>(chats);
            _listView.ItemsSource = _chatCollection;

            CollectionViewSource.GetDefaultView(_listView.ItemsSource).Filter = (object o) =>
            {
                string searchText = _searchTextBox.Text;
                if (string.IsNullOrWhiteSpace(searchText)) return true;

                var item = o as Chat;
                if (item == null) return false;

                var words = searchText.ToLower().Split(new string[] { " ", " " }, StringSplitOptions.RemoveEmptyEntries);
                var text = (item.Name ?? "").ToLower();

                foreach (var word in words)
                {
                    if (!text.Contains(word))
                    {
                        return false;
                    }
                }

                return true;
            };

            this.Sort();
        }
        public AutoBaseNodeSettingManager(OutoposManager outoposManager)
        {
            _outoposManager = outoposManager;

            _settings = new Settings(this.ThisLock);
        }
        public TransfarLimitManager(OutoposManager outoposManager)
        {
            _outoposManager = outoposManager;

            _settings = new Settings(this.ThisLock);
        }
Ejemplo n.º 6
0
        public OptionsWindow(OutoposManager outoposManager, AutoBaseNodeSettingManager autoBaseNodeSettingManager, OverlayNetworkManager overlayNetworkManager, BufferManager bufferManager)
        {
            _outoposManager = outoposManager;
            _autoBaseNodeSettingManager = autoBaseNodeSettingManager;
            _overlayNetworkManager = overlayNetworkManager;
            _bufferManager = bufferManager;

            InitializeComponent();

            _baseNodeTextBox.MaxLength = UriCollection.MaxUriLength;

            {
                var icon = new BitmapImage();

                icon.BeginInit();
                icon.StreamSource = new FileStream(Path.Combine(App.DirectoryPaths["Icons"], "Outopos.ico"), FileMode.Open, FileAccess.Read, FileShare.Read);
                icon.EndInit();
                if (icon.CanFreeze) icon.Freeze();

                this.Icon = icon;
            }

            foreach (var item in Enum.GetValues(typeof(ConnectionType)).Cast<ConnectionType>())
            {
                _clientFiltersConnectionTypeComboBox.Items.Add(item);
            }

            foreach (var u in new string[] { "Byte", "KB", "MB", "GB", "TB" })
            {
                _dataCacheSizeComboBox.Items.Add(u);
            }

            _dataCacheSizeComboBox.SelectedItem = Settings.Instance.OptionsWindow_DataCacheSize_Unit;

            foreach (var u in new string[] { "Byte", "KB", "MB", "GB", })
            {
                _bandwidthLimitComboBox.Items.Add(u);
            }

            _bandwidthLimitComboBox.SelectedItem = Settings.Instance.OptionsWindow_BandwidthLimit_Unit;

            lock (_outoposManager.ThisLock)
            {
                var baseNode = _outoposManager.BaseNode;

                _baseNode_Id = baseNode.Id;
                _baseNode_Uris = new ObservableCollectionEx<string>(baseNode.Uris);
                _otherNodes = new ObservableCollectionEx<Node>(_outoposManager.OtherNodes);
                _clientFilters = new ObservableCollectionEx<ConnectionFilter>(_outoposManager.Filters.Select(n => n.Clone()));
                _serverListenUris = new ObservableCollectionEx<string>(_outoposManager.ListenUris);

                try
                {
                    _dataCacheSizeTextBox.Text = NetworkConverter.ToSizeString(_outoposManager.Size, Settings.Instance.OptionsWindow_DataCacheSize_Unit);
                }
                catch (Exception)
                {
                    _dataCacheSizeTextBox.Text = "";
                }

                _bandwidthConnectionCountTextBox.Text = _outoposManager.ConnectionCountLimit.ToString();

                try
                {
                    _bandwidthLimitTextBox.Text = NetworkConverter.ToSizeString(_outoposManager.BandwidthLimit, Settings.Instance.OptionsWindow_BandwidthLimit_Unit);
                }
                catch (Exception)
                {
                    _bandwidthLimitTextBox.Text = "";
                }
            }

            _baseNodeUrisListView.ItemsSource = _baseNode_Uris;
            _otherNodesListView.ItemsSource = _otherNodes;
            _clientFiltersListView.ItemsSource = _clientFilters;
            _serverListenUrisListView.ItemsSource = _serverListenUris;

            _baseNodeUpdate();
            _otherNodesUpdate();
            _clientFiltersListViewUpdate();
            _serverListenUrisUpdate();

            _eventOpenPortAndGetIpAddressCheckBox.IsChecked = Settings.Instance.Global_AutoBaseNodeSetting_IsEnabled;
            _eventUseI2pCheckBox.IsChecked = Settings.Instance.Global_I2p_SamBridge_IsEnabled;

            lock (_overlayNetworkManager.ThisLock)
            {
                _eventSamBridgeUriTextBox.Text = _overlayNetworkManager.SamBridgeUri;
            }

            _updateUrlTextBox.Text = Settings.Instance.Global_Update_Url;
            _updateProxyUriTextBox.Text = Settings.Instance.Global_Update_ProxyUri;
            _updateSignatureTextBox.Text = Settings.Instance.Global_Update_Signature;

            if (Settings.Instance.Global_Update_Option == UpdateOption.None)
            {
                _updateOptionNoneRadioButton.IsChecked = true;
            }
            else if (Settings.Instance.Global_Update_Option == UpdateOption.AutoCheck)
            {
                _updateOptionAutoCheckRadioButton.IsChecked = true;
            }
            else if (Settings.Instance.Global_Update_Option == UpdateOption.AutoUpdate)
            {
                _updateOptionAutoUpdateRadioButton.IsChecked = true;
            }

            _languageComboBoxItemCollection = new ObservableCollectionEx<LanguageComboBoxItem>(LanguagesManager.Instance.Languages.Select(n => new LanguageComboBoxItem(n)));
            _languageComboBox.ItemsSource = _languageComboBoxItemCollection;
            _languagesComboBoxUpdate();

            _signatureListViewItemCollection = new ObservableCollectionEx<SignatureListViewItem>(Settings.Instance.Global_DigitalSignatureCollection.Select(n => new SignatureListViewItem(n)));
            _signatureListView.ItemsSource = _signatureListViewItemCollection;
            _signatureListViewUpdate();

            _fontMessageFontFamilyComboBoxItemCollection.AddRange(Fonts.SystemFontFamilies.Select(n => n.ToString()));
            _fontMessageFontFamilyComboBox.ItemsSource = _fontMessageFontFamilyComboBoxItemCollection;
            _fontMessageFontFamilyComboBox.SelectedItem = Settings.Instance.Global_Fonts_MessageFontFamily;

            _fontMessageFontSizeTextBox.Text = Settings.Instance.Global_Fonts_MessageFontSize.ToString();

            _amoebaPathTextBox.Text = Settings.Instance.Global_Amoeba_Path;
        }
Ejemplo n.º 7
0
        private void Setting_Init()
        {
            NativeMethods.SetThreadExecutionState(ExecutionState.SystemRequired | ExecutionState.Continuous);

            {
                bool initFlag = false;

                _outoposManager = new OutoposManager(Path.Combine(App.DirectoryPaths["Configuration"], "Cache.bitmap"), App.Cache.Path, _bufferManager);
                _outoposManager.Load(_configrationDirectoryPaths["OutoposManager"]);

                if (!File.Exists(Path.Combine(App.DirectoryPaths["Configuration"], "Outopos.version")))
                {
                    initFlag = true;

                    // デフォルトのTrustSignaturesの設定。
                    {
                        Settings.Instance.Global_TrustSignatures.Add("Lyrise@OTAhpWvmegu50LT-p5dZ16og7U6bdpO4z5TInZxGsCs");
                    }

                    // デフォルトのChatタグを設定。
                    {
                        var amoebaTag = OutoposConverter.FromChatString("Chat:AAAAAAAGQW1vZWJhAQAAACCrzcPHuDlkIdAKPyrMvdoRizFo3IOOSlWhQhPTKBIOiWRXEcU");
                        var outoposTag = OutoposConverter.FromChatString("Chat:AAAAAAAHT3V0b3BvcwEAAAAgr9B65c-3yJS95GHleeXi3TekYOtScR4VzJRpz7AoQ294gS26");
                        var testTag = OutoposConverter.FromChatString("Chat:AAAAAAAEVGVzdAEAAAAgye1mG24NVcdu5Vb2UZXwrnT_kwhXUNWONT0W0m5IAyplJHYb");

                        Settings.Instance.ChatControl_ChatCategorizeTreeItem.ChatTreeItems.Add(new ChatTreeItem(amoebaTag));
                        Settings.Instance.ChatControl_ChatCategorizeTreeItem.ChatTreeItems.Add(new ChatTreeItem(outoposTag));
                        Settings.Instance.ChatControl_ChatCategorizeTreeItem.ChatTreeItems.Add(new ChatTreeItem(testTag));
                    }

                    {
                        byte[] buffer = new byte[32];

                        using (var random = RandomNumberGenerator.Create())
                        {
                            random.GetBytes(buffer);
                        }

                        _outoposManager.SetBaseNode(new Node(buffer, null));
                    }

                    _outoposManager.ListenUris.Clear();
                    _outoposManager.ListenUris.Add(string.Format("tcp:{0}:{1}", IPAddress.Any.ToString(), _random.Next(1024, ushort.MaxValue + 1)));
                    _outoposManager.ListenUris.Add(string.Format("tcp:[{0}]:{1}", IPAddress.IPv6Any.ToString(), _random.Next(1024, ushort.MaxValue + 1)));

                    var ipv4ConnectionFilter = new ConnectionFilter()
                    {
                        ConnectionType = ConnectionType.Tcp,
                        UriCondition = new UriCondition()
                        {
                            Value = @"tcp:([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3}).*",
                        },
                    };

                    var ipv6ConnectionFilter = new ConnectionFilter()
                    {
                        ConnectionType = ConnectionType.Tcp,
                        UriCondition = new UriCondition()
                        {
                            Value = @"tcp:\[(\d|:)*\].*",
                        },
                    };

                    var tcpConnectionFilter = new ConnectionFilter()
                    {
                        ConnectionType = ConnectionType.Tcp,
                        UriCondition = new UriCondition()
                        {
                            Value = @"tcp:.*",
                        },
                    };

                    var torConnectionFilter = new ConnectionFilter()
                    {
                        ConnectionType = ConnectionType.Socks5Proxy,
                        ProxyUri = "tcp:127.0.0.1:29050",
                        UriCondition = new UriCondition()
                        {
                            Value = @"tor:.*",
                        },
                    };

                    var i2pConnectionFilter = new ConnectionFilter()
                    {
                        ConnectionType = ConnectionType.None,
                        UriCondition = new UriCondition()
                        {
                            Value = @"i2p:.*",
                        },
                    };

                    _outoposManager.Filters.Clear();
                    _outoposManager.Filters.Add(ipv4ConnectionFilter);
                    _outoposManager.Filters.Add(ipv6ConnectionFilter);
                    _outoposManager.Filters.Add(tcpConnectionFilter);
                    _outoposManager.Filters.Add(torConnectionFilter);
                    _outoposManager.Filters.Add(i2pConnectionFilter);

                    if (CultureInfo.CurrentUICulture.Name == "ja-JP")
                    {
                        Settings.Instance.Global_UseLanguage = "Japanese";
                    }
                    else
                    {
                        Settings.Instance.Global_UseLanguage = "English";
                    }

                    // ProfileItem
                    {
                        var digitalSignature = new DigitalSignature("Anonymous", DigitalSignatureAlgorithm.Rsa2048_Sha256);
                        Settings.Instance.Global_DigitalSignatureCollection.Add(digitalSignature);

                        var profileItem = new ProfileItem();
                        Settings.Instance.Global_ProfileItem = profileItem;

                        {
                            profileItem.UploadSignature = digitalSignature.ToString();
                            profileItem.Exchange = new Exchange(ExchangeAlgorithm.Rsa2048);

                            // Upload
                            {
                                _outoposManager.UploadProfile(profileItem.Cost,
                                    profileItem.Exchange.GetExchangePublicKey(),
                                    profileItem.TrustSignatures,
                                    profileItem.DeleteSignatures,
                                    profileItem.Wikis,
                                    profileItem.Chats,
                                    digitalSignature);
                            }
                        }
                    }

                    // Nodes.txtにあるノード情報を追加する。
                    if (File.Exists(Path.Combine(App.DirectoryPaths["Settings"], "Nodes.txt")))
                    {
                        var list = new List<Node>();

                        using (StreamReader reader = new StreamReader(Path.Combine(App.DirectoryPaths["Settings"], "Nodes.txt"), new UTF8Encoding(false)))
                        {
                            string line;

                            while ((line = reader.ReadLine()) != null)
                            {
                                list.Add(OutoposConverter.FromNodeString(line));
                            }
                        }

                        _outoposManager.SetOtherNodes(list);
                    }
                }
                else
                {
                    Version version;

                    using (StreamReader reader = new StreamReader(Path.Combine(App.DirectoryPaths["Configuration"], "Outopos.version"), new UTF8Encoding(false)))
                    {
                        version = new Version(reader.ReadLine());
                    }

                    if (version <= new Version(1, 0, 0))
                    {
                        // デフォルトのTrustSignaturesの設定。
                        {
                            Settings.Instance.Global_TrustSignatures.Add("Lyrise@OTAhpWvmegu50LT-p5dZ16og7U6bdpO4z5TInZxGsCs");
                        }
                    }
                }

                using (StreamWriter writer = new StreamWriter(Path.Combine(App.DirectoryPaths["Configuration"], "Outopos.version"), false, new UTF8Encoding(false)))
                {
                    writer.WriteLine(App.OutoposVersion.ToString());
                }

                _autoBaseNodeSettingManager = new AutoBaseNodeSettingManager(_outoposManager);
                _autoBaseNodeSettingManager.Load(_configrationDirectoryPaths["AutoBaseNodeSettingManager"]);

                _overlayNetworkManager = new OverlayNetworkManager(_outoposManager, _bufferManager);
                _overlayNetworkManager.Load(_configrationDirectoryPaths["OverlayNetworkManager"]);

                _catharsisManager = new CatharsisManager(_outoposManager, _bufferManager);
                _catharsisManager.Load(_configrationDirectoryPaths["CatharsisManager"]);

                if (initFlag)
                {
                    _catharsisManager.Save(_configrationDirectoryPaths["CatharsisManager"]);
                    _overlayNetworkManager.Save(_configrationDirectoryPaths["OverlayNetworkManager"]);
                    _autoBaseNodeSettingManager.Save(_configrationDirectoryPaths["AutoBaseNodeSettingManager"]);
                    _outoposManager.Save(_configrationDirectoryPaths["OutoposManager"]);
                    Settings.Instance.Save(_configrationDirectoryPaths["MainWindow"]);
                }

                {
                    var outoposPath = Path.Combine(App.DirectoryPaths["Configuration"], "Outopos");
                    var libraryPath = Path.Combine(App.DirectoryPaths["Configuration"], "Library");

                    try
                    {
                        if (Directory.Exists(outoposPath))
                        {
                            if (Directory.Exists(outoposPath + ".old"))
                                Directory.Delete(outoposPath + ".old", true);

                            MainWindow.CopyDirectory(outoposPath, outoposPath + ".old");
                        }

                        if (Directory.Exists(libraryPath))
                        {
                            if (Directory.Exists(libraryPath + ".old"))
                                Directory.Delete(libraryPath + ".old", true);

                            MainWindow.CopyDirectory(libraryPath, libraryPath + ".old");
                        }
                    }
                    catch (Exception e2)
                    {
                        Log.Warning(e2);
                    }
                }
            }
        }