コード例 #1
0
        public MainWindow(int port)
        {
            InitializeComponent();

            dictionary = new P2PDictionary("Peer Dictionary", P2PDictionary.GetFreePort(port), "SimpleChat", P2PDictionaryServerMode.AutoRegister, P2PDictionaryClientMode.AutoConnect);
            dictionary.AddSubscription("*");
            dictionary.Notification += new EventHandler<NotificationEventArgs>(dictionary_Notification);

            this.Title = "Simple Chat (" + (dictionary.LocalEndPoint as System.Net.IPEndPoint).Port + ")";
        }
コード例 #2
0
        public MainWindow(int port)
        {
            InitializeComponent();

            dictionary = new P2PDictionary("Peer Dictionary", port, "shared_photos", P2PDictionaryServerMode.AutoRegister, P2PDictionaryClientMode.AutoConnect);
            dictionary.AddSubscription("*");
            dictionary.Notification += new EventHandler<NotificationEventArgs>(dictionary_Notification);

            dictionary[dictionary.LocalID + "/" + counter] = ConsoleColor.Blue;
        }
コード例 #3
0
        public MainWindow(int port)
        {
            InitializeComponent();

            dictionary = new P2PDictionary("Peer Dictionary",
                                           P2PDictionary.GetFreePort(port),
                                           "SimpleChat",
                                           P2PDictionaryServerMode.AutoRegister,
                                           P2PDictionaryClientMode.AutoConnect,
                                           peerDiscovery: new ZeroconfDiscovery());
            dictionary.AddSubscription("*");
            dictionary.Notification += new EventHandler <NotificationEventArgs>(dictionary_Notification);

            this.Title = "Simple Chat (" + (dictionary.LocalEndPoint as System.Net.IPEndPoint).Port + ")";
        }
コード例 #4
0
        public MainWindow(string ns, int portHint)
        {
            InitializeComponent();

            mDictionary = new P2PDictionary("Dictionary Inspector", P2PDictionary.GetFreePort(portHint),
                ns, P2PDictionaryServerMode.AutoRegister, P2PDictionaryClientMode.AutoConnect);
            mDictionary.DebugBuffer = System.Console.Out;
            mDictionary.AddSubscription("*");

            mMetadata = new P2PNetworkMetadata(mDictionary);

            mTimer = new DispatcherTimer();
            mTimer.Interval = new TimeSpan(0, 0, 0, 1);
            mTimer.Tick += new EventHandler(mTimer_Tick);
            mTimer.Start();

            this.Title = "Dictionary Inspector (ns: " + ns + ") port " + ((System.Net.IPEndPoint)mDictionary.LocalEndPoint).Port;

            dataGrid.ItemsSource = GetDictionary(mDictionary);
        }
コード例 #5
0
        public MainWindow(string ns, int portHint)
        {
            InitializeComponent();

            mDictionary = new P2PDictionary("Dictionary Inspector", P2PDictionary.GetFreePort(portHint),
                                            ns, P2PDictionaryServerMode.AutoRegister, P2PDictionaryClientMode.AutoConnect,
                                            peerDiscovery: new ZeroconfDiscovery());
            mDictionary.DebugBuffer = System.Console.Out;
            mDictionary.AddSubscription("*");

            mMetadata = new P2PNetworkMetadata(mDictionary);

            mTimer          = new DispatcherTimer();
            mTimer.Interval = new TimeSpan(0, 0, 0, 1);
            mTimer.Tick    += new EventHandler(mTimer_Tick);
            mTimer.Start();

            this.Title = "Dictionary Inspector (ns: " + ns + ") port " + ((System.Net.IPEndPoint)mDictionary.LocalEndPoint).Port;

            dataGrid.ItemsSource = GetDictionary(mDictionary);
        }
コード例 #6
0
        static void Main(string[] args)
        {
            // FileStream fs = new FileStream("setup-jammanhci-2.3.exe", FileMode.Open);
            //byte[] buffer = new byte[fs.Length];
            //fs.Read(buffer, 0, (int)fs.Length);
            P2PDictionary port80 = new P2PDictionary("port 80", base_port + 80, "test", P2PDictionaryServerMode.Hidden, P2PDictionaryClientMode.ManualConnect);

            port80.SetDebugBuffer(new StreamWriter("output-80.txt"), 0, true);

            //port80.AddSubscription("*");
            port80["hidden"] = "Server at 80";
            port80["junk"]   = "junk junk junk";

            P2PDictionary port81 = new P2PDictionary("port 81", base_port + 81, "test", P2PDictionaryServerMode.Hidden, P2PDictionaryClientMode.ManualConnect);

            //client.StartClient("127.0.0.1", 80);
            port81.DebugBuffer = new StreamWriter("output-81.txt");
            port81["hidden"]   = "Server at 81";
            port81["number"]   = 1;
            port81["text"]     = "Hello world!";

            P2PDictionary port82 = new P2PDictionary("port 82", base_port + 82, "test", P2PDictionaryServerMode.Hidden, P2PDictionaryClientMode.ManualConnect);

            port82.DebugBuffer = new StreamWriter("output-82.txt");
            port81["hidden"]   = "Server at 82";
            port82["ohayo"]    = "o-ha-yo go-za-i-ma-su";
            port82["binary"]   = new byte[] { 88, 88, 77, 77, 88, 88 };
            port82["bool"]     = true;

            P2PDictionary port83 = new P2PDictionary("port 83", base_port + 83, "test", P2PDictionaryServerMode.Hidden, P2PDictionaryClientMode.ManualConnect);

            port83.DebugBuffer = new StreamWriter("output-83.txt");
            port83["hidden"]   = "Server at 83";

            //server3.AddSubscription("*");


            P2PDictionary port92 = new P2PDictionary("port 92", base_port + 92, "test", P2PDictionaryServerMode.Hidden, P2PDictionaryClientMode.ManualConnect);

            port92.DebugBuffer = new StreamWriter("output-92.txt");
            // stuck.AddSubscription("*");
            port92.AddSubscription("number");

            Console.WriteLine("Press space bar to quit");

            port81.OpenClient(System.Net.IPAddress.Loopback, base_port + 80);
            port82.OpenClient(System.Net.IPAddress.Loopback, base_port + 81);
            port83.OpenClient(System.Net.IPAddress.Loopback, base_port + 82);
            port92.OpenClient(System.Net.IPAddress.Loopback, base_port + 83);
            port92.OpenClient(System.Net.IPAddress.Loopback, 3333);

            Console.WriteLine($"debug peers {base_port + 80}-{base_port + 83}, {base_port + 92} using a web browser and request /data");
            Console.WriteLine($"press space bar to quit or any other key for write/delete on port {base_port + 82}");
            ConsoleKeyInfo k;

            do
            {
                k = Console.ReadKey();

                port82["junk"] = "new junk";
                port82.Remove("junk");
            }while (k.KeyChar != ' ');

            var stuff = port80.GetEnumerator();

            // break connection and modify keys
            Console.WriteLine($"wrote hidden key in peer {base_port + 80}, press any key to quit");
            port83.Close();
            port80["hidden"] = $"won't make it to {base_port + 92}";
            Console.ReadKey();

            Console.WriteLine("Stopping...");
            port82.Close();
            port83.Close();
            port81.Close();
            port80.Close();
            port92.Close();

            port80.DebugBuffer.Flush();
            port81.DebugBuffer.Flush();
            port82.DebugBuffer.Flush();
            port83.DebugBuffer.Flush();
            port92.DebugBuffer.Flush();
        }
コード例 #7
0
        static void Main(string[] args)
        {
            // FileStream fs = new FileStream("setup-jammanhci-2.3.exe", FileMode.Open);
            //byte[] buffer = new byte[fs.Length];
            //fs.Read(buffer, 0, (int)fs.Length);
            com.rhfung.P2PDictionary.P2PDictionary port80 = new P2PDictionary("port 80", 80, "test", P2PDictionaryServerMode.Hidden, P2PDictionaryClientMode.ManualConnect);
            port80.SetDebugBuffer(new StreamWriter("output-80.txt"), 0, true);

            //port80.AddSubscription("*");
            port80["hidden"] = "Server at 80";
            port80["junk"] = "junk junk junk";

            com.rhfung.P2PDictionary.P2PDictionary port81 = new P2PDictionary("port 81", 81, "test", P2PDictionaryServerMode.Hidden, P2PDictionaryClientMode.ManualConnect);
            //client.StartClient("127.0.0.1", 80);
            port81.DebugBuffer = new StreamWriter("output-81.txt");
            port81["hidden"] = "Server at 81";
            port81["number"] = 1;
            port81["text"] = "Hello world!";

            com.rhfung.P2PDictionary.P2PDictionary port82 = new P2PDictionary("port 82", 82, "test", P2PDictionaryServerMode.Hidden, P2PDictionaryClientMode.ManualConnect);
            port82.DebugBuffer = new StreamWriter("output-82.txt");
            port81["hidden"] = "Server at 82";
            port82["ohayo"] = "o-ha-yo go-za-i-ma-su";
            port82["binary"] = new byte[] { 88, 88, 77, 77, 88, 88 };
            port82["bool"] = true;

            com.rhfung.P2PDictionary.P2PDictionary port83 = new P2PDictionary("port 83", 83, "test", P2PDictionaryServerMode.Hidden, P2PDictionaryClientMode.ManualConnect);
            port83.DebugBuffer = new StreamWriter("output-83.txt");
            port83["hidden"] = "Server at 83";

            //server3.AddSubscription("*");

            P2PDictionary port92 = new P2PDictionary("port 92", 92, "test", P2PDictionaryServerMode.Hidden, P2PDictionaryClientMode.ManualConnect);
            port92.DebugBuffer = new StreamWriter("output-92.txt");
            // stuck.AddSubscription("*");
            port92.AddSubscription("number");

            /*
            FormPeerOverview form1 = new FormPeerOverview();
            form1.Show();
            form1.SetServer(server);

            FormPeerOverview form2 = new FormPeerOverview();
            form2.Show();
            form2.SetServer(client);

            FormPeerOverview form3 = new FormPeerOverview();
            form3.Show();
            form3.SetServer(client2);

            FormPeerOverview form4 = new FormPeerOverview();
            form4.Show();
            form4.SetServer(server3);

            FormPeerOverview form5 = new FormPeerOverview();
            form5.Show();
            form5.SetServer(stuck);

            System.Console.WriteLine("Press space bar to quit");

            System.Windows.Forms.Application.Run(form1);
             */

            port81.OpenClient(System.Net.IPAddress.Loopback, 80);
            port82.OpenClient(System.Net.IPAddress.Loopback, 81);
            port83.OpenClient(System.Net.IPAddress.Loopback, 82);
            port92.OpenClient(System.Net.IPAddress.Loopback, 83);
            port92.OpenClient(System.Net.IPAddress.Loopback, 3333);

            Console.WriteLine("debug peers 80-83, 92 using a web browser and request /data");
            Console.WriteLine("press space bar to quit or any other key for write/delete on port 82");
            ConsoleKeyInfo k;
            do
            {
                 k = System.Console.ReadKey();

                 port82["junk"] = "new junk";
                 port82.Remove("junk");
            }
            while (k.KeyChar != ' ');

            var stuff = port80.GetEnumerator();

            // break connection and modify keys
            Console.WriteLine("wrote hidden key in peer 80, press any key to quit");
            port83.Close();
            port80["hidden"] = "won't make it to 92";
            System.Console.ReadKey();

            System.Console.WriteLine("Stopping...");
            port82.Close();
            port83.Close();
            port81.Close();
            port80.Close();
            port92.Close();

            port80.DebugBuffer.Flush();
            port81.DebugBuffer.Flush();
            port82.DebugBuffer.Flush();
            port83.DebugBuffer.Flush();
            port92.DebugBuffer.Flush();
        }
コード例 #8
0
        static void RunOptionsAndExit(Options opts)
        {
            var discoveryModules = new Dictionary <string, Func <IPeerInterface> >();

            discoveryModules.Add("none", () => new NoDiscovery());
#if !NETCOREAPP2_0
            discoveryModules.Add("bonjour", () => new ZeroconfDiscovery());
            discoveryModules.Add("win-bonjour", () => new ZeroconfDiscovery());
#endif

            if (!discoveryModules.ContainsKey(opts.Discovery))
            {
                Console.Error.WriteLine($"Discovery module not supported: {opts.Discovery}");
                return;
            }

            P2PDictionary dict = new P2PDictionary(
                opts.Description,
                opts.Port,
                opts.Namespace,
                searchForClients: opts.Timespan,
                peerDiscovery: discoveryModules[opts.Discovery]());

            if (opts.FullDebug)
            {
                dict.SetDebugBuffer(Console.Out, 0, true);
            }
            else if (opts.Debug)
            {
                dict.SetDebugBuffer(Console.Out, 1, true);
            }

            if (!opts.NoPattern)
            {
                bool hasAddedPattern = false;
                foreach (var pattern in opts.Pattern)
                {
                    hasAddedPattern = true;
                    dict.AddSubscription(pattern);
                }

                if (!hasAddedPattern)
                {
                    dict.AddSubscription("*");
                }
            }

            foreach (var node in opts.Node)
            {
                var splitStr = node.Split(':');
                var address  = IPAddress.Parse(splitStr[0]);
                dict.OpenClient(address, Int32.Parse(splitStr[1]));
            }

            bool cancelled = false;

            Console.Out.WriteLine("Server started");
            Console.CancelKeyPress += (object sender, ConsoleCancelEventArgs e) => {
                Console.Out.WriteLine("Cancel pressed");
                cancelled = true;
                e.Cancel  = true;
            };

            while (!cancelled)
            {
                try
                {
                    Thread.Sleep(1000);
                }
                catch (ThreadInterruptedException)
                {
                    break;
                }
            }

            dict.Close();

            Console.Out.WriteLine("Server finished");
        }