Esempio 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)
                    {
                    }
                }
            }
        }
Esempio 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)
                    {
                    }
                }
            }
        }
Esempio 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",
                        //   });
                    }
                }
            }
        }
Esempio n. 4
0
        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);
                    }
                }
            }
        }
Esempio n. 5
0
        /// <summary>
        /// Starts WCF service
        /// </summary>
        /// <exception cref="AddressAlreadyInUseException"></exception>
        private void StartWcfService()
        {
            _localService = new P2PService(this, _name);
            _host         = new ServiceHost(_localService, new Uri(_serviceUrl));

            NetTcpBinding binding = new NetTcpBinding();

            binding.Security.Mode = SecurityMode.None;

            _host.AddServiceEndpoint(typeof(IP2PService), binding, _serviceUrl);

            _host.Open();
        }
        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
                        }
                            );
                    }
                }
            });
        }
Esempio 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);
            }
        }
Esempio n. 8
0
        private void StartService()
        {
            try
            {
                host = new ServiceHost(this);
                host.Open();
                channelFactory = new ChannelFactory <IP2PService>("ChatEndpoint");
                _channel       = channelFactory.CreateChannel();

                // Information to send to the channel
                _channel.DisplayMessage(new CompositeType("Event", _myUserName + " has entered the conversation."));

                // Information to display locally
                _displayMessageDelegate(new CompositeType("Info", "To change your name, type setname: NEW_NAME"));
            }
            catch (Exception x)
            {
                Console.WriteLine(x);
            }
        }
        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
                        });
                    }
                }
            }
        }
Esempio n. 10
0
        private void OnPeerResolverFound(object sender, ResolveProgressChangedEventArgs e)
        {
            var peer = e.PeerNameRecord;

            foreach (var ep in peer.EndPointCollection)
            {
                if (ep.AddressFamily == AddressFamily.InterNetwork)
                {
                    var remoteUrl = string.Format("net.tcp://{0}:{1}/P2PService", ep.Address, ep.Port);
                    var binding   = new NetTcpBinding();
                    binding.Security.Mode = SecurityMode.None;

                    try
                    {
                        var peerContext = AvailablePeers.FirstOrDefault(x => x.PeerEntry.Address == remoteUrl);
                        if (peerContext == null)
                        {
                            IP2PService remoteService = ChannelFactory <IP2PService> .CreateChannel(
                                binding, new EndpointAddress(remoteUrl));

                            var peerEntry = new PeerEntry(remoteService, remoteUrl);
                            _foundPeers.Add(peerEntry);

                            _logger.Debug($"New peer found: {peerEntry}");
                        }
                        else
                        {
                            _foundPeers.Add(peerContext.PeerEntry);
                        }
                    }
                    catch (Exception ex) when(ex is InvalidOperationException || ex is CommunicationException)
                    {
                        _logger.Error(ex, "Cannot process new peer: {0}", ex.Message);
                    }
                }
            }
        }
Esempio n. 11
0
        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);
                        }
                    }
                }
            }
        }
Esempio n. 12
0
        private void StartService()
        {
            try
            {
                host = new ServiceHost(this);
                host.Open();
                channelFactory = new ChannelFactory<IP2PService>("ChatEndpoint");
                _channel = channelFactory.CreateChannel();

                // Information to send to the channel
                _channel.DisplayMessage(new CompositeType("Event", _myUserName + " has entered the conversation."));

                // Information to display locally
                _displayMessageDelegate(new CompositeType("Info", "To change your name, type setname: NEW_NAME"));
            }
            catch (Exception x)
            {
                Console.WriteLine(x);
            }
        }
Esempio n. 13
0
 /// <summary>
 /// </summary>
 /// <exception cref="CommunicationException"></exception>
 /// <param name="serviceProxy"></param>
 public PeerEntry(IP2PService serviceProxy, string address)
 {
     ServiceProxy  = serviceProxy;
     DisplayedName = serviceProxy.GetUserName();
     Address       = address;
 }