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) { } } } }
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) { } } } }
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", // }); } } } }
internal void Resolve2() { Logger.Log.Info("Start P2P resolver..."); // create a resolver object to resolve a peername resolver = new PeerNameResolver(); string endpointUrl = null; // resolve the PeerName - this is a network operation and will block until the resolve completes //PeerNameRecordCollection results = resolver.Resolve(peerName, 100); // Max 100 records PeerNameRecordCollection results = resolver.Resolve(peerName, Cloud.Available, 100); // Max 100 records foreach (PeerNameRecord record in results) { foreach (IPEndPoint ep in record.EndPointCollection) { if (ep.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) { endpointUrl = string.Format(endpointuriformat4, ep.Address, ep.Port); } else if (ep.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6) //if ((ep.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6) && !ep.Address.IsIPv6LinkLocal) { endpointUrl = string.Format(endpointuriformat6, ep.Address, ep.Port); } try { NetTcpBinding binding = Helper.GetStreamBinding(); IP2PService serviceProxy = ChannelFactory <IP2PService> .CreateChannel( binding, new EndpointAddress(endpointUrl)); PeerEntry peer = new PeerEntry(); peer.PeerName = record.PeerName; peer.ServiceProxy = serviceProxy; peer.DisplayString = serviceProxy.GetName(); if (record.Comment != null) { peer.Comment = record.Comment; } if (record.Data != null) { peer.Data = System.Text.Encoding.ASCII.GetString(record.Data); } Logger.Log.Info(string.Format("SUCCESS Connect:{0} \t\t {1} ", endpointUrl, peer.Comment)); Vault.Peers.Add(peer); } catch (EndpointNotFoundException e) { Logger.Log.Debug(e.Message); } } } }
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 } ); } } }); }
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 }); } } } }
internal void Resolve2_old() { Logger.Log.Info("Start P2P resolver..."); // create a resolver object to resolve a peername resolver = new PeerNameResolver(); // resolve the PeerName - this is a network operation and will block until the resolve completes PeerNameRecordCollection results = resolver.Resolve(peerName, 100); // Max 100 records foreach (PeerNameRecord record in results) { foreach (IPEndPoint ep in record.EndPointCollection) { //if (ep.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork) if (ep.Address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6 && !ep.Address.IsIPv6LinkLocal) { try { string endpointUrl = string.Format(endpointuriformat, ep.Address, ep.Port); NetTcpBinding binding = Helper.GetStreamBinding(); //NetTcpBinding binding = new NetTcpBinding(); ////binding.Security.Mode = SecurityMode.None; //binding.Security.Mode = SecurityMode.None; ////EndpointAddress epa = new EndpointAddress() /////// /////// //// 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)); //IP2PService serviceProxy = ChannelFactory<IP2PService>.CreateChannel( // binding, new EndpointAddress(ep.Address.ToString() + ":" + Port.ToString())); //PeerEntry entry = new PeerEntry //{ // PeerName = record.PeerName, // ServiceProxy = serviceProxy, // DisplayString = serviceProxy.GetName(), //}; PeerEntry peer = new PeerEntry(); peer.PeerName = record.PeerName; peer.ServiceProxy = serviceProxy; peer.DisplayString = serviceProxy.GetName(); if (record.Comment != null) { peer.Comment = record.Comment; } if (record.Data != null) { peer.Data = System.Text.Encoding.ASCII.GetString(record.Data); } //Vault.Peers.Add(peer); Logger.Log.Info(endpointUrl); Logger.Log.Info(peer.PeerName); Logger.Log.Info(peer.Comment); Logger.Log.Info("\t Endpoint:{0}", ep); Vault.Peers.Add(peer); } catch (EndpointNotFoundException e) { //Vault.Peers.Add( // new PeerEntry // { // PeerName = peer.PeerName, // DisplayString = "Unknown Peer", // }); Logger.Log.Info(e.Message); } } } } }