Ejemplo n.º 1
0
        void resolver_ResolveProgressChanged(object sender, ResolveProgressChangedEventArgs e)
        {
            PeerNameRecord peer = e.PeerNameRecord;

            foreach (IPEndPoint ep in peer.EndPointCollection)
            {
                if (ep.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                {
                    try
                    {
                        string        endpointUrl = string.Format("net.tcp://{0}:{1}/P2PService", ep.Address, ep.Port);
                        NetTcpBinding binding     = new NetTcpBinding();
                        binding.Security.Mode = SecurityMode.None;
                        IP2PService serviceProxy = ChannelFactory <IP2PService> .CreateChannel(
                            binding, new EndpointAddress(endpointUrl));

                        PeerList.Add(
                            new PeerEntry
                        {
                            PeerName      = peer.PeerName,
                            ServiceProxy  = serviceProxy,
                            DisplayString = serviceProxy.GetName(),
                            State         = PeerState.User,
                            Player        = serviceProxy.GetPlayer(),
                            PlayerId      = serviceProxy.GetPlayerId()
                        });
                        ResolveProgressChanged();
                    }
                    catch (EndpointNotFoundException)
                    {
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void resolver_ResolverProgressChanged(object sender, ResolveProgressChangedEventArgs e)
        {
            PeerNameRecord peer = e.PeerNameRecord;//taking link for record with peer name that was detected

            var endPointCollection = peer.EndPointCollection;

            foreach (IPEndPoint endPoint in endPointCollection)
            {
                if (endPoint.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                {
                    try
                    {
                        string        endPointUrl = string.Format($"net.tcp://{endPoint.Address}:{endPoint.Port}/P2PService");
                        NetTcpBinding binding     = new NetTcpBinding();
                        binding.Security.Mode = SecurityMode.None;

                        IP2PService serviceProxy =
                            ChannelFactory <IP2PService> .CreateChannel(binding, new EndpointAddress(endPointUrl));

                        peerList.Add(new PeerEntry
                        {
                            PeerName      = peer.PeerName,
                            ServiceProxy  = serviceProxy,
                            DisplayString = serviceProxy.GetName()
                        });
                    }
                    catch (Exception exception)
                    {
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void resolver_ResolveProgressChanged(object sender, ResolveProgressChangedEventArgs e)
        {
            PeerNameRecord peer = e.PeerNameRecord;

            foreach (IPEndPoint ep in peer.EndPointCollection)
            {
                //if (ep.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                if (ep.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6)
                {
                    try
                    {
                        string        endpointUrl = string.Format(endpointuriformat, ep.Address, ep.Port);
                        NetTcpBinding binding     = new NetTcpBinding();
                        //binding.Security.Mode = SecurityMode.None;
                        binding.Security.Mode = SecurityMode.None;

                        /////
                        /////
                        // Stream add
                        ////
                        ////
                        binding.TransferMode           = TransferMode.Streamed;
                        binding.MaxReceivedMessageSize = 20134217728; // 20 GB
                        binding.MaxBufferPoolSize      = 1024 * 1024; // 1 MB
                        ////
                        ////
                        ////
                        ////

                        IP2PService serviceProxy = ChannelFactory <IP2PService> .CreateChannel(
                            binding, new EndpointAddress(endpointUrl));

                        PeerEntry entry = new PeerEntry
                        {
                            PeerName      = peer.PeerName,
                            ServiceProxy  = serviceProxy,
                            DisplayString = serviceProxy.GetName(),
                        };

                        //Vault.Peers.Add(peer);
                        Logger.Log.Info(endpointUrl);
                        Logger.Log.Info(entry.PeerName);
                        Logger.Log.Info(entry.Comment);
                        Logger.Log.Info("\t Endpoint:{0}", ep);

                        Vault.Peers.Add(entry);
                    }
                    catch (EndpointNotFoundException)
                    {
                        //Vault.Peers.Add(
                        //   new PeerEntry
                        //   {
                        //       PeerName = peer.PeerName,
                        //       DisplayString = "Unknown Peer",
                        //   });
                    }
                }
            }
        }
Ejemplo n.º 4
0
        // 自訂非同步解析作業正在執行中,所呼叫的方法
        private void ResolveProgressChangedCallback(object sender, ResolveProgressChangedEventArgs e)
        {
            // 取得非同步作業的進度百分比
            // 並藉此改變ProgressBar物件的顯示進度
            progressBar.Value = e.ProgressPercentage;

            // 取得PNRP Peer Name記錄物件
            PeerNameRecord pnr = e.PeerNameRecord;

            foreach (IPEndPoint endpoint in pnr.EndPointCollection)
            {
                lstPeerNameRecord.Items.Add(endpoint);
            }
        }
        void resolver_ResolveProgressChanged(object sender, ResolveProgressChangedEventArgs e)
        {
            // Get peer record from event args
            PeerNameRecord peer = e.PeerNameRecord;

            // Examine endpoints for peer
            peer.EndPointCollection.Where(ep => ep.Address.AddressFamily == AddressFamily.InterNetwork)
            .AsParallel().ForAll(ep =>
            {
                try
                {
                    // Get service reference
                    string endpointUrl       = string.Format("net.tcp://{0}:{1}/P2PService", ep.Address, ep.Port);
                    var binding              = new NetTcpBinding();
                    binding.Security.Mode    = SecurityMode.None;
                    IP2PService serviceProxy = ChannelFactory <IP2PService> .CreateChannel(binding, new EndpointAddress(endpointUrl));

                    lock (peersLock)
                    {
                        peerList.Add(
                            new PeerEntry
                        {
                            PeerName       = peer.PeerName,
                            ServiceProxy   = serviceProxy,
                            DisplayString  = serviceProxy.GetName(),
                            ButtonsEnabled = true
                        }
                            );
                    }
                }
                catch (EndpointNotFoundException)
                {
                    // Add client but not extra info.
                    lock (peersLock)
                    {
                        peerList.Add(
                            new PeerEntry
                        {
                            PeerName       = peer.PeerName,
                            DisplayString  = "Unknown peer",
                            ButtonsEnabled = false
                        }
                            );
                    }
                }
            });
        }
Ejemplo n.º 6
0
        private void Resolver_ResolveProgressChanged(object sender, ResolveProgressChangedEventArgs e)
        {
            PeerNameRecord peer = e.PeerNameRecord;

            peer.EndPointCollection.Where(point => point.Address.AddressFamily == AddressFamily.InterNetwork)
            .AsParallel()
            .ForAll(
                point =>
            {
                try
                {
                    string endpointUrl = string.Format("net.tcp://{0}:{1}/PeerToPeerService", point.Address, point.Port);
                    var binding        = new NetTcpBinding {
                        Security = { Mode = SecurityMode.None }
                    };
                    IPeerToPeerService serviceProxy = ChannelFactory <IPeerToPeerService> .CreateChannel(binding,
                                                                                                         new EndpointAddress(endpointUrl));

                    lock (_peersLock)
                    {
                        _peerList.Add(new PeerEntry
                        {
                            PeerName       = peer.PeerName,
                            ServiceProxy   = serviceProxy,
                            DisplayString  = serviceProxy.GetName(),
                            ButtonsEnabled = true
                        });
                    }
                }
                catch (EndpointNotFoundException)
                {
                    lock (_peersLock)
                    {
                        _peerList.Add(new PeerEntry
                        {
                            PeerName       = peer.PeerName,
                            DisplayString  = "Unknown peer",
                            ButtonsEnabled = false
                        });
                    }
                }
            });
        }
Ejemplo n.º 7
0
        void resolver_ResolveProgressChanged(object sender, ResolveProgressChangedEventArgs e)
        {
            PeerNameRecord peer = e.PeerNameRecord;

            foreach (IPEndPoint ep in peer.EndPointCollection)
            {
                if (ep.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                {
                    try
                    {
                        string        endpointUrl = string.Format("net.tcp://{0}:{1}/P2PService", ep.Address, ep.Port);
                        NetTcpBinding binding     = new NetTcpBinding();
                        binding.Security.Mode = SecurityMode.None;
                        IP2PService serviceProxy = ChannelFactory <IP2PService> .CreateChannel(
                            binding, new EndpointAddress(endpointUrl));

                        peerList.Add(
                            new PeerEntry
                        {
                            PeerName      = peer.PeerName,
                            ServiceProxy  = serviceProxy,
                            DisplayString = serviceProxy.GetName()
                        });
                        Console.WriteLine("Peer {0} is found", peer.PeerName);
                    }
                    catch (EndpointNotFoundException)
                    {
                        //peerList.Add(
                        //   new PeerEntry
                        //   {
                        //       PeerName = peer.PeerName,
                        //       DisplayString = "Unknown type"
                        //   });
                        Console.WriteLine("Peer {0} of unknown type is found", peer.PeerName);
                    }
                }
            }

            if (peerList.Count > 0)
            {
                PeersAreFound?.Invoke(this, EventArgs.Empty);
            }
        }
        void resolver_ResolveProgressChanged(object sender, ResolveProgressChangedEventArgs e)
        {
            PeerNameRecord peer = e.PeerNameRecord;

            foreach (IPEndPoint ep in peer.EndPointCollection)
            {
                if (ep.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                {
                    try
                    {
                        string        endpointUrl = string.Format($"net.tcp://{ep.Address}:{ep.Port}/P2PService");
                        NetTcpBinding binding     = new NetTcpBinding {
                            Security = { Mode = SecurityMode.None }
                        };
                        IP2PService serviceProxy = ChannelFactory <IP2PService> .CreateChannel(
                            binding, new EndpointAddress(endpointUrl));

                        PeerList.Items.Add(
                            new PeerEntry
                        {
                            PeerName       = peer.PeerName,
                            ServiceProxy   = serviceProxy,
                            DisplayString  = serviceProxy.GetName(),
                            ButtonsEnabled = true
                        });
                    }
                    catch (EndpointNotFoundException)
                    {
                        PeerList.Items.Add(
                            new PeerEntry
                        {
                            PeerName       = peer.PeerName,
                            DisplayString  = "Unknown peer",
                            ButtonsEnabled = false
                        });
                    }
                }
            }
        }
Ejemplo n.º 9
0
        private void Search()
        {
            if (textBox_Name2.Text == "")
            {
                return;
            }

            // 初始化要搜索的资源名
            PeerName searchSeed = new PeerName("0." + textBox_Name2.Text);
            // PeerNameResolver类是将节点名解析为PeerNameRecord的值(即将通过资源名来查找资源名所在的地址,包括IP地址和端口号)
            // PeerNameRecord用来定于云中的各个节点
            PeerNameResolver myresolver = new PeerNameResolver();

            // PeerNameRecordCollection表示PeerNameRecord元素的容器
            // Resolve方法是同步的完成解析
            // 使用同步方法可能会出现界面“假死”现象
            // 解决界面假死现象可以采用多线程或异步的方式
            // 关于多线程的知识可以参考本人博客中多线程系列我前面UDP编程中有所使用
            // 在这里就不列出多线程的使用了,朋友可以自己实现,如果有问题可以留言给我一起讨论
            PeerNameRecordCollection recordCollection = myresolver.Resolve(searchSeed);

            if (recordCollection.Count == 0)
            {
                return;
            }
            PeerNameRecord record = recordCollection[0];
            ListViewItem   item   = new ListViewItem();
            string         t      = record.Comment.ToString();

            if (this.lastInfoTime != t)
            {
                this.lastInfoTime = t;
                item.SubItems.Add(record.Comment.ToString());
                item.SubItems.Add(record.PeerName.ToString().Substring(2));
                item.SubItems.Add(Encoding.UTF8.GetString(record.Data));
                listView1.Items.Add(item);
            }
        }
Ejemplo n.º 10
0
 public PeerNodeData(PeerNameRecord peerNameRecord)
 {
     this.peerNameRecord = peerNameRecord;
     Data = Serializer.Deserialize<T>(peerNameRecord.Data);
 }