예제 #1
0
        public void Init()
        {
            if (!File.Exists(DataPath))
            {
                Tox = new Tox(ToxOptions.Default);

                Tox.GetData().Save(DataPath);
            }
            else
            {
                Tox = new Tox(ToxOptions.Default, ToxData.FromDisk(DataPath));
            }

            foreach (var node in Nodes)
            {
                Tox.Bootstrap(node);
            }

            BindEvents();
            PopulateList();

            Tox.Start();

            Tox.StatusMessage = "Toxing on Detox";
        }
예제 #2
0
        public Basic()
        {
            ToxOptions options = new ToxOptions(true, false);

            tox = new Tox(options);
            tox.OnFriendRequest += tox_OnFriendRequest;
            tox.OnFriendMessage += tox_OnFriendMessage;

            foreach (ToxNode node in Nodes)
            {
                tox.BootstrapFromNode(node);
            }

            tox.Name          = "SharpTox";
            tox.StatusMessage = "Testing SharpTox";

            tox.Start();

            string id = tox.Id.ToString();

            Console.WriteLine("ID: {0}", id);

            Console.ReadKey();
            tox.Dispose();
        }
예제 #3
0
 public ReceiveFile()
 {
     _tox = new Tox(new ToxOptions(true, false));
     _tox.OnFileControl     += tox_OnFileControl;
     _tox.OnFileData        += tox_OnFileData;
     _tox.OnFileSendRequest += tox_OnFileSendRequest;
     _tox.Start();
 }
예제 #4
0
        public SendFile()
        {
            _tox = new Tox(new ToxOptions(true, false));
            _tox.OnFileControl += tox_OnFileControl;
            _tox.Start();

            int fileNumber = _tox.NewFileSender(0, 1337, "file.dat");
        }
예제 #5
0
        public Skynet()
        {
            // init tox client
            ToxOptions options = new ToxOptions(true, true);

            tox = new Tox(options);
            tox.OnFriendRequestReceived         += tox_OnFriendRequestReceived;
            tox.OnFriendMessageReceived         += tox_OnFriendMessageReceived;
            tox.OnFriendConnectionStatusChanged += tox_OnFriendConnectionStatusChanged;

            foreach (ToxNode node in Nodes)
            {
                tox.Bootstrap(node);
            }

            tox.Name          = "Skynet";
            tox.StatusMessage = "Running Skynet";
            tox.Start();

            string id = tox.Id.ToString();

            Console.WriteLine("ID: {0}", id);

            // Log tox online status
            Task.Run(() => {
                while (true)
                {
                    Thread.Sleep(200);
                    if (tox.IsConnected)
                    {
                        Console.WriteLine("From Server " + httpPort + ":" + "tox is connected.");
                        break;
                    }
                }
            });

            // start http server
            httpPort = Utils.Utils.FreeTcpPort();
            string baseUrl = "http://localhost:" + httpPort + "/";

            WebApp.Start <StartUp>(url: baseUrl);
            Console.WriteLine("Server listening on " + httpPort);

            allInstance.Add(this);
        }
예제 #6
0
        public void TestToxBootstrapAndConnectTcp()
        {
            var tox   = new Tox(new ToxOptions(true, false));
            var error = ToxErrorBootstrap.Ok;

            foreach (var node in Globals.TcpRelays)
            {
                bool result = tox.AddTcpRelay(node, out error);
                if (!result || error != ToxErrorBootstrap.Ok)
                {
                    Assert.Fail("Failed to bootstrap error: {0}, result: {1}", error, result);
                }
            }

            tox.Start();
            while (!tox.IsConnected)
            {
                Thread.Sleep(10);
            }

            Console.WriteLine("Tox connected!");
            tox.Dispose();
        }
예제 #7
0
        public void TestToxProxySocks5()
        {
            var options = new ToxOptions(true, ToxProxyType.Socks5, "127.0.0.1", 9050);
            var tox     = new Tox(options);
            var error   = ToxErrorBootstrap.Ok;

            foreach (var node in Globals.TcpRelays)
            {
                bool result = tox.AddTcpRelay(node, out error);
                if (!result || error != ToxErrorBootstrap.Ok)
                {
                    Assert.Fail("Failed to bootstrap, error: {0}, result: {1}", error, result);
                }
            }

            tox.Start();
            while (!tox.IsConnected)
            {
                Thread.Sleep(10);
            }

            Console.WriteLine("Tox connected!");
            tox.Dispose();
        }
예제 #8
0
        public Skynet(string filename = "")
        {
            // init tox client
            ToxOptions options = new ToxOptions(true, true);

            if (filename != "")
            {
                tox = new Tox(options, ToxData.FromDisk(filename));
            }
            else
            {
                tox = new Tox(options);
            }

            tox.OnFriendRequestReceived         += tox_OnFriendRequestReceived;
            tox.OnFriendLosslessPacketReceived  += tox_OnFriendLosslessPacketReceived;
            tox.OnFriendConnectionStatusChanged += tox_OnFriendConnectionStatusChanged;

            foreach (ToxNode node in Nodes)
            {
                tox.Bootstrap(node);
            }

            tox.Name          = "Skynet";
            tox.StatusMessage = "Running Skynet";
            tox.Start();

            string id = tox.Id.ToString();

            Console.WriteLine("ID: {0}", id);
            Utils.Utils.Log("ID: " + id, true);

            // Log tox online status
            Task.Factory.StartNew(async() =>
            {
                var offLineCount = 0;
                while (true)
                {
                    Thread.Sleep(2000);
                    if (tox.IsConnected)
                    {
                        Console.WriteLine("From Server " + httpPort + ":" + "tox is connected.");
                        Utils.Utils.Log("From Server " + httpPort + ":" + "tox is connected.", true);
                        Utils.Utils.WriteNodeInfo(tox.Id.ToString(), true);
                        offLineCount = 0;
                        break;
                    }
                    else
                    {
                        Utils.Utils.Log("Event: tox is offline", true);
                        offLineCount++;
                    }
                    if (offLineCount > 10)
                    {
                        // start a new tox node
                        offLineCount = 0;
                        tox.Stop();
                        options = new ToxOptions(true, true);
                        if (filename != "")
                        {
                            tox = new Tox(options, ToxData.FromDisk(filename));
                        }
                        else
                        {
                            tox = new Tox(options);
                        }

                        tox.OnFriendRequestReceived         += tox_OnFriendRequestReceived;
                        tox.OnFriendLosslessPacketReceived  += tox_OnFriendLosslessPacketReceived;
                        tox.OnFriendConnectionStatusChanged += tox_OnFriendConnectionStatusChanged;

                        foreach (ToxNode node in Nodes)
                        {
                            tox.Bootstrap(node);
                        }

                        tox.Name          = "Skynet";
                        tox.StatusMessage = "Running Skynet";
                        tox.Start();

                        id = tox.Id.ToString();
                        Console.WriteLine("ID: {0}", id);
                        Console.WriteLine("Start a new Tox node");
                        Utils.Utils.Log("ID: " + id, true);
                    }
                }

                bool onlineStatus = true;
                while (true)
                {
                    // start queue process
                    while (tox.IsConnected)
                    {
                        if (!onlineStatus)
                        {
                            onlineStatus = true;
                            Utils.Utils.Log("Event: tox is online");
                        }
                        processFriendMessage();
                    }
                    Utils.Utils.Log("Event: tox is offline", true);
                    onlineStatus = false;
                    Thread.Sleep(1000);
                }
            }, TaskCreationOptions.LongRunning).ForgetOrThrow();

            // start http server
            httpPort = Utils.Utils.FreeTcpPort();
            string baseUrl = "http://localhost:" + httpPort + "/";

            //WebApp.Start<StartUp> (url: baseUrl);
            Console.WriteLine("Server listening on " + httpPort);
            Utils.Utils.Log("Server listening on " + httpPort, true);
            allInstance.Add(this);
        }
예제 #9
0
        public void SwitchTo(ProfileInfo profile)
        {
            var options = ToxOptions.Default;

            options.Ipv6Enabled = Config.Instance.EnableIpv6;

            if (Config.Instance.ProxyType != ToxProxyType.None)
            {
                options.UdpEnabled = false;
                options.ProxyType  = Config.Instance.ProxyType;
                options.ProxyHost  = Config.Instance.ProxyAddress;
                options.ProxyPort  = Config.Instance.ProxyPort;
            }
            else
            {
                options.UdpEnabled = Config.Instance.EnableUdp;
            }

            Tox newTox;

            if (profile != null)
            {
                var data = ToxData.FromDisk(profile.Path);
                if (data == null)
                {
                    throw new Exception("Could not load profile.");
                }

                if (data.IsEncrypted)
                {
                    throw new Exception("Data is encrypted, Toxy does not support encrypted profiles yet.");
                }

                newTox = new Tox(options, data);
            }
            else
            {
                newTox = new Tox(options);
            }

            var newToxAv = new ToxAv(newTox);

            InitManagers(newTox, newToxAv);

            if (Tox != null)
            {
                Tox.Dispose();
            }

            if (ToxAv != null)
            {
                ToxAv.Dispose();
            }

            Tox   = newTox;
            ToxAv = newToxAv;

            AvatarManager.Rehash();
            ConnectionManager.DoBootstrap();

            //TODO: move this someplace else and make it configurable
            if (string.IsNullOrEmpty(Tox.Name))
            {
                Tox.Name = "Tox User";
            }
            if (string.IsNullOrEmpty(Tox.StatusMessage))
            {
                Tox.StatusMessage = "Toxing on Toxy";
            }

            Tox.Start();
            ToxAv.Start();

            CurrentProfile = profile;
            MainWindow.Instance.Reload();
        }
예제 #10
0
        public Skynet(string filename = "")
        {
            // init tox client
            ToxOptions options = new ToxOptions(true, true);

            if (filename != "")
            {
                tox = new Tox(options, ToxData.FromDisk(filename));
            }
            else
            {
                tox = new Tox(options);
            }



            tox.OnFriendRequestReceived         += tox_OnFriendRequestReceived;
            tox.OnFriendLosslessPacketReceived  += tox_OnFriendLosslessPacketReceived;
            tox.OnFriendConnectionStatusChanged += tox_OnFriendConnectionStatusChanged;

            foreach (ToxNode node in Nodes)
            {
                tox.Bootstrap(node);
            }

            tox.Name          = "Skynet";
            tox.StatusMessage = "Running Skynet";
            tox.Start();

            string id = tox.Id.ToString();

            Console.WriteLine("ID: {0}", id);
            Utils.Utils.LogUtils("ID: " + id);

            // Log tox online status
            Task.Factory.StartNew(async() => {
                var offLineCount = 0;
                while (true)
                {
                    Thread.Sleep(2000);
                    if (tox.IsConnected)
                    {
                        Console.WriteLine("From Server " + httpPort + ":" + "tox is connected.");
                        Utils.Utils.LogUtils("From Server " + httpPort + ":" + "tox is connected.");
                        offLineCount = 0;
                        // send a online message to server
                        using (var client = new HttpClient()){
                            await client.PostAsJsonAsync("http://xiaoqiang.bwbot.org/online", tox.Id.ToString());
                        }
                        break;
                    }
                    else
                    {
                        Utils.Utils.LogUtils("Event: tox is offline");
                        offLineCount++;
                    }
                    if (offLineCount > 10)
                    {
                        // start a new tox node
                        offLineCount = 0;
                        tox.Dispose();
                        options = new ToxOptions(true, true);
                        if (filename != "")
                        {
                            tox = new Tox(options, ToxData.FromDisk(filename));
                        }
                        else
                        {
                            tox = new Tox(options);
                        }

                        tox.OnFriendRequestReceived         += tox_OnFriendRequestReceived;
                        tox.OnFriendLosslessPacketReceived  += tox_OnFriendLosslessPacketReceived;
                        tox.OnFriendConnectionStatusChanged += tox_OnFriendConnectionStatusChanged;

                        foreach (ToxNode node in Nodes)
                        {
                            tox.Bootstrap(node);
                        }

                        tox.Name          = "Skynet";
                        tox.StatusMessage = "Running Skynet";
                        tox.Start();

                        id = tox.Id.ToString();
                        Console.WriteLine("ID: {0}", id);
                        Utils.Utils.LogUtils("ID: " + id);
                    }
                }

                while (true)
                {
                    // start queue process
                    while (tox.IsConnected)
                    {
                        Package processPack = null;
                        lock (reqQueueLock) {
                            if (reqQueue.Count > 0)
                            {
                                processPack = reqQueue.Dequeue();
                            }
                        }
                        if (processPack != null)
                        {
                            newReqReceived(processPack);
                        }
                        else
                        {
                            Thread.Sleep(1);
                        }
                    }
                    Utils.Utils.LogUtils("Event: tox is offline");
                    Thread.Sleep(1000);
                }
            }, TaskCreationOptions.LongRunning).ForgetOrThrow();



            // start http server
            httpPort = Utils.Utils.FreeTcpPort();
            string baseUrl = "http://localhost:" + httpPort + "/";

            WebApp.Start <StartUp> (url: baseUrl);
            Console.WriteLine("Server listening on " + httpPort);
            Utils.Utils.LogUtils("Server listening on " + httpPort);
            allInstance.Add(this);
        }