示例#1
0
        /// <summary>
        /// Creates a PeerName and registers it along with the metadata specified as command line arguments
        /// </summary>
        private static void CreateAndPublishPeerName()
        {
            try{
                // Creates a the PeerName to register using the classifier and type provided on the command line
                PeerName peerName = new PeerName(peerNameClassifier, peerNameType);

                // Create a registration object which represents the registration of the PeerName in a Cloud
                PeerNameRegistration peerNameRegistration = new PeerNameRegistration();
                peerNameRegistration.PeerName = peerName;
                peerNameRegistration.Port     = portNumber;
                peerNameRegistration.Comment  = comment;
                peerNameRegistration.Cloud    = cloudName;
                // Since the peerNameRegistration.EndPointCollection is not specified, all (IPv4&IPv6)
                // addresses assigned to the local host will automatically be assocaited with the
                // peerNameRegistration instance.  This behavior can be control via peerNameRegistration.UseAutoEndPointSelection

                //Note: Additional information may be specified on the PeerNameRegistration object, which is not shown in this example.

                //Starting the registration means the name is published for other peers to resolve
                peerNameRegistration.Start();
                Console.WriteLine("Registration of Peer Name: {0} complete.", peerName.ToString(), cloudName);
                Console.WriteLine();

                Console.WriteLine("Press any key to stop the registration and close the program");
                Console.ReadKey();

                // Stopping the registration means the name is no longer published
                peerNameRegistration.Stop();
            } catch (Exception e) {
                Console.WriteLine("Error creating and registering the PeerName: {0} \n", e.Message);
                Console.WriteLine(e.StackTrace);
            }
        }
示例#2
0
        public void Start(string peerClassifier, int port)
        {
            PeerName peerName = new PeerName(peerClassifier, PeerNameType.Unsecured);

            _peerNameRegistration = new PeerNameRegistration(peerName, port, Cloud.Global);
            _peerNameRegistration.Start();
        }
示例#3
0
        public void registerPeerName(string classifier)
        {
            PeerName peerName = new PeerName(classifier, PeerNameType.Unsecured);

            using (PeerNameRegistration registration = new PeerNameRegistration(peerName, 8080))
            {
                string timestamp = string.Format("Peer Created at: {0}", DateTime.Now.ToShortTimeString());

                registration.Comment = timestamp;

                UnicodeEncoding encoder = new UnicodeEncoding();
                byte[]          data    = encoder.GetBytes(timestamp);
                registration.Data = data;
                try
                {
                    registration.Start();
                    mRegistration = registration;
                    _stopFlag.WaitOne();
                }
                catch (PeerToPeerException ex)
                {
                    Console.WriteLine("PeerToPeer Exception: {0}", ex.Message);
                }
            }
        }
示例#4
0
        private static void Main(string[] args)
        {
            // Creates a secure (not spoofable) PeerName
            var peerName = new PeerName("MikesWebServer", PeerNameType.Secured);
            var pnReg    = new PeerNameRegistration {
                PeerName = peerName,
                Port     = 80,
                //OPTIONAL
                //The properties set below are optional.  You can register a PeerName without setting these properties
                Comment = "up to 39 unicode char comment",
                Data    = Encoding.UTF8.GetBytes("A data blob associated with the name")
            };

            /*
             * OPTIONAL
             * The properties below are also optional, but will not be set (ie. are commented out) for this example
             * pnReg.IPEndPointCollection = // a list of all {IPv4/v6 address, port} pairs to associate with the peername
             * pnReg.Cloud = //the scope in which the name should be registered (local subnet, internet, etc)
             */

            //Starting the registration means the name is published for others to resolve
            pnReg.Start();
            Console.WriteLine("Registration of Peer Name: {0} complete.", peerName);
            Console.WriteLine();
            Console.WriteLine("Press any key to stop the registration and close the program");
            Console.ReadKey();

            pnReg.Stop();
        }
示例#5
0
        private void btn_RegisterPeer_Click(object sender, RoutedEventArgs e)
        {
            PeerName peerName = new PeerName(txt_PeerName.Text, PeerNameType.Unsecured);

            using (PeerNameRegistration registration = new PeerNameRegistration(peerName, Int32.Parse(txt_Port.Text)))
            {
                registration.Comment = "My Comment";
                string          time    = string.Format("Peer Created at: {0}", DateTime.Now.ToString());
                UnicodeEncoding encoder = new UnicodeEncoding();
                byte[]          data    = encoder.GetBytes(time);

                try
                {
                    foreach (Cloud c in Cloud.GetAvailableClouds())
                    {
                        Console.WriteLine($"Cloud {c.Name}");
                    }
                    registration.Start();
                    Console.WriteLine("Registered");
                    Console.ReadLine();
                    //registration.Stop();
                }
                catch (PeerToPeerException ex)
                {
                    // There are other possible statndard exceptions to catch
                    // See documentation on for details
                }
            }
        }
示例#6
0
        public PeerNameRegistration CreateRegistration(PeerName peerName, int port)
        {
            if (peerName == null)              // in most cases, have a null peername does not make a lot of sense
            {
                throw new ArgumentException("Cannot have null or empty peerName");
            }

            Cloud regCloud;

            switch (_currerntScope)
            {
            case PnrpScope.Global:
                regCloud = Cloud.Global;
                break;

            case PnrpScope.LinkLocal:
                regCloud = Cloud.AllLinkLocal;
                break;

            default:
                regCloud = Cloud.Available;
                break;
            }

            PeerNameRegistration registration = new PeerNameRegistration(peerName, port, regCloud);

            registration.Comment = "Comment for " + peerName.Classifier;

            registration.Start();
            _registrations.Add(registration);
            SetScopedRegistrations(this.CurrentScope);
            ProcessRegistrations(this.CurrentScope);
            return(registration);
        }
示例#7
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            // Получение конфигурационной информации из app.config
            string port        = ConfigurationManager.AppSettings["port"];
            string username    = ConfigurationManager.AppSettings["username"];
            string machineName = Environment.MachineName;
            string serviceUrl  = null;

            // Установка заголовка окна
            this.Title = string.Format("P2P приложение - {0}", username);

            //  Получение URL-адреса службы с использованием адресаIPv4
            //  и порта из конфигурационного файла
            foreach (IPAddress address in Dns.GetHostAddresses(Dns.GetHostName()))
            {
                if (address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                {
                    serviceUrl = string.Format("net.tcp://{0}:{1}/P2PService", address, port);
                    break;
                }
            }

            // Выполнение проверки, не является ли адрес null
            if (serviceUrl == null)
            {
                // Отображение ошибки и завершение работы приложения
                MessageBox.Show(this, "Не удается определить адрес конечной точки WCF.", "Networking Error",
                                MessageBoxButton.OK, MessageBoxImage.Stop);
                Application.Current.Shutdown();
            }

            // Регистрация и запуск службы WCF
            localService = new P2PService(this, username);
            host         = new ServiceHost(localService, new Uri(serviceUrl));
            NetTcpBinding binding = new NetTcpBinding();

            binding.Security.Mode = SecurityMode.None;
            host.AddServiceEndpoint(typeof(IP2PService), binding, serviceUrl);
            try
            {
                host.Open();
            }
            catch (AddressAlreadyInUseException)
            {
                // Отображение ошибки и завершение работы приложения
                MessageBox.Show(this, "Не удается начать прослушивание, порт занят.", "WCF Error",
                                MessageBoxButton.OK, MessageBoxImage.Stop);
                Application.Current.Shutdown();
            }

            // Создание имени равноправного участника (пира)
            peerName = new PeerName("P2P Sample", PeerNameType.Unsecured);

            // Подготовка процесса регистрации имени равноправного участника в локальном облаке
            peerNameRegistration       = new PeerNameRegistration(peerName, int.Parse(port));
            peerNameRegistration.Cloud = Cloud.AllLinkLocal;

            // Запуск процесса регистрации
            peerNameRegistration.Start();
        }
示例#8
0
        public bool DeleteRegistration(PeerNameRegistration registration)
        {
            _registrations.Remove(registration);
            ProcessRegistrations(this.CurrentScope);

            return(false);
        }
示例#9
0
 /// <summary>
 /// 将PNRP Name 注册到Cloud中
 /// </summary>
 public static bool registerPeer(String strMyPeerName)
 {
     try
     {
         PeerName peerName = new PeerName(strMyPeerName, PeerNameType.Unsecured);
         // 以PeerName创建PeerNameRegistration实例
         peerNameRegistration = new PeerNameRegistration(peerName, port);
         //    peerNameRegistration.PeerName = peerName;
         //IPEndPointCollection ipEndPoints = new IPEndPointCollection();
         peerNameRegistration.UseAutoEndPointSelection = true;
         // 设定PNRP Peer Name的其他描述信息
         peerNameRegistration.Comment = "PNRP Peer Name的其他描述信息";
         // 设定用PeerNameRegistration的Data描述信息
         peerNameRegistration.Data = System.Text.Encoding.UTF8.GetBytes(String.Format("描述信息,注册时间{0}", DateTime.Now.ToString()));
         // 设定用户端或Peer端点目前参与的所有连接本机的PNRP群
         // peerNameRegistration.Cloud = Cloud.AllLinkLocal;
         // 将PNRP Peer Name注册至PNRP Cloud中
         //  strAllMyPeerName = peerName.ToString();
         peerNameRegistration.Start();
         return(true);
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.ToString());
         return(false);
     }
 }
示例#10
0
        internal void Init()
        {
            // Creates a secure (not spoofable) PeerName
            //peerName = new PeerName(Application.ProductName, PeerNameType.Secured);
            peerName       = new PeerName(Application.ProductName + "." + Application.CompanyName, PeerNameType.Secured);
            pnReg          = new PeerNameRegistration();
            pnReg.PeerName = peerName;

            pnReg.Port = (int)Config.Port;

            // OPTIONAL

            // The properties set below are optional.
            // You can register a PeerName without setting these properties
            // but this properties can help identify PC
            pnReg.Comment = "up to 39 unicode char comment";
            pnReg.Data    = Encoding.UTF8.GetBytes("A data blob associated with the name"); // @TODO Add binary data for Peer2Peer Netwwork

            // OPTIONAL
            // The properties below are also optional, but will not be set (ie. are commented out) for this example

            //pnReg.IPEndPointCollection = // a list of all {IPv4/v6 address, port} pairs to associate with the peername
            //pnReg.Cloud = //the scope in which the name should be registered (local subnet, internet, etc)
            //pnReg.Cloud = Cloud.Global; // resolve in Global Network -
            pnReg.Cloud = Cloud.Global; // resolve in Global Network -
        }
示例#11
0
        public PeerNameRegistration RegisterPeer(PeerName peerName, int port)
        {
            var peerNameRegistration = new PeerNameRegistration(peerName, port);

            peerNameRegistration.Start();
            return(peerNameRegistration);
        }
示例#12
0
        private void btnRegister_Click(object sender, RoutedEventArgs e)
        {
            if (txtPeerName.Text.Length > 0 && txtPort.Text.Length > 0)
            {
                // 建立PeerName物件
                // 設定PNRP Peer Name為未受保護的名稱
                PeerName peerName = new PeerName(txtPeerName.Text, PeerNameType.Unsecured);

                // 以PNRP Peer Name與通訊埠建立PeerNameRegistration物件
                peerNameRegistration = new PeerNameRegistration(peerName, Int32.Parse(txtPort.Text));

                // 設定PNRP Peer Name的其他資訊
                peerNameRegistration.Comment = "PNRP Peer Name的其他資訊";
                // 設定PeerNameRegistration物件之二進位資料
                peerNameRegistration.Data = System.Text.Encoding.UTF8.GetBytes("二進位資料");

                // 設定用戶端或Peer端點目前參與的所有連結本機之PNRP Cloud
                peerNameRegistration.Cloud = Cloud.AllLinkLocal;
                // 設定是否自動選取IP位址和通訊埠
                peerNameRegistration.UseAutoEndPointSelection = true;
                // 將PNRP Peer Name註冊至PNRP Cloud中
                peerNameRegistration.Start();
            }
            else
            {
                MessageBox.Show("Please enter Peer Name and Port.", "P2P", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
示例#13
0
        private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
        {
            // Получение конфигурационной информации из App.config
            string port        = ConfigurationManager.AppSettings["port"];
            string username    = ConfigurationManager.AppSettings["username"];
            string machineName = Environment.MachineName;

            // Установка заголовка окна
            Title = string.Format("{0}: P2P example - {1}", machineName, username);

            // Получение URL-адреса службы с использованием адреса IPv4 и порта из конфигурационного файла
            string serviceUrl = Dns.GetHostAddresses(Dns.GetHostName())
                                .Where(address => address.AddressFamily == AddressFamily.InterNetwork)
                                .Select(address => string.Format("net.tcp://{0}:{1}/PeerToPeerService", address, port))
                                .FirstOrDefault();

            // Выполнение проверки, не является ли адрес нулевым
            if (serviceUrl == null)
            {
                // Отображение ошибки и завершение работы приложения
                MessageBox.Show(this, "Unable to determine WCF endpoint.", "Networking Error", MessageBoxButton.OK,
                                MessageBoxImage.Stop);
                Application.Current.Shutdown();
                return;
            }

            // Регистрация и запуск службы WCF
            _localService = new PeerToPeerService(this, username);
            _host         = new ServiceHost(_localService, new Uri(serviceUrl));
            var binding = new NetTcpBinding {
                Security = { Mode = SecurityMode.None }
            };

            _host.AddServiceEndpoint(typeof(IPeerToPeerService), binding, serviceUrl);

            try
            {
                _host.Open();
            }
            catch (AddressAlreadyInUseException)
            {
                // Отображение ошибки и завершение работы приложения
                MessageBox.Show(this, "Cannot start listening, port in use", "WCF Error", MessageBoxButton.OK,
                                MessageBoxImage.Stop);
                Application.Current.Shutdown();
            }

            // Создание имени равноправного участника
            _peerName = new PeerName("P2P Sample", PeerNameType.Unsecured);

            // Подготовка регистрации имени равноправного участника в облаке локального соединения
            _peerNameRegistration = new PeerNameRegistration(_peerName, int.Parse(port))
            {
                Cloud = Cloud.AllLinkLocal
            };

            // Начало регистрации
            _peerNameRegistration.Start();
        }
示例#14
0
 public void Stop()
 {
     if (_peerNameRegistration != null)
     {
         _peerNameRegistration.Stop();
     }
     _peerNameRegistration = null;
 }
示例#15
0
        public static void RegisterNodeInPNRP(Cloud cloud = null)
        {
            PeerName name = new PeerName(DeNSo.Configuration.NodeIdentity.ToString(), PeerNameType.Secured);

            _peerNameRegistration       = new PeerNameRegistration(name, DeNSo.Configuration.Extensions.P2P().NetworkPort);
            _peerNameRegistration.Cloud = cloud ?? Cloud.Available;
            _peerNameRegistration.Start();
        }
示例#16
0
 public void StopPeerRegistration()
 {
     if (_peerNameRegistration != null)
     {
         _peerNameRegistration?.Stop();
         _peerNameRegistration = null;
     }
 }
示例#17
0
 public void Dispose()
 {
     if (peerNameRegistration != null)
     {
         peerNameRegistration.Stop();
         peerNameRegistration = null;
     }
 }
示例#18
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                var port     = ConfigurationManager.AppSettings["port"];
                var username = ConfigurationManager.AppSettings["username"];

                Title = $"P2P приложение - {username}";

                var dns = Dns.GetHostAddresses(Dns.GetHostName());

                var url = (from address in dns
                           where address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork
                           select $"net.tcp://{address}:{port}/P2PService").FirstOrDefault();

                MessageBox.Show(url);

                if (url == null)
                {
                    MessageBox.Show(this, "Не удается определить адрес конечной точки WCF.", "Networking Error",
                                    MessageBoxButton.OK, MessageBoxImage.Stop);
                    Application.Current.Shutdown();
                }

                _service = new P2PService(this, username);
                _host    = new ServiceHost(_service, new Uri(url));
                var binding = new NetTcpBinding {
                    Security = { Mode = SecurityMode.None }
                };
                _host.AddServiceEndpoint(typeof(IP2PService), binding, url);

                try
                {
                    _host.Open();
                }
                catch (AddressAlreadyInUseException)
                {
                    MessageBox.Show(this, "Не удается начать прослушивание, порт занят.", "WCF Error",
                                    MessageBoxButton.OK, MessageBoxImage.Stop);
                    Application.Current.Shutdown();
                }

                _pn  = new PeerName("0.P2P Sample");
                _pnr = new PeerNameRegistration(_pn, int.Parse(port))
                {
                    Cloud   = Cloud.Available,
                    Comment = "Simple p2p app untitled"
                };

                _pnr.Start();
                MessageBox.Show("Started!");
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
                MessageBox.Show(exception.StackTrace);
            }
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //get config from app.config
            string port       = ConfigurationManager.AppSettings["port"];
            string username   = ConfigurationManager.AppSettings["username"];
            string serviceUrl = null;

            // set form title
            this.Title = string.Format($"P2P node - {username}");

            //get url-address of service using Ipv4 and port from app config
            foreach (IPAddress address in Dns.GetHostAddresses(Dns.GetHostName()))
            {
                if (address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                {
                    serviceUrl = string.Format($"net.tcp://{address}:{port}/P2PService");
                    break;
                }
            }

            // check if address is not null
            if (serviceUrl == null)
            {
                MessageBox.Show(this, "Can not define service address WCF.", "Networking Error",
                                MessageBoxButton.OK, MessageBoxImage.Stop);
                Application.Current.Shutdown();
            }

            // registration and run WCF
            _localService = new P2PService(this, username);
            _host         = new ServiceHost(_localService, new Uri(serviceUrl ?? throw new InvalidOperationException()));
            NetTcpBinding binding = new NetTcpBinding();

            binding.Security.Mode = SecurityMode.None;
            _host.AddServiceEndpoint(typeof(IP2PService), binding, serviceUrl);
            try
            {
                _host.Open();
            }
            catch (AddressAlreadyInUseException)
            {
                MessageBox.Show(this, "Can not listen, the port is busy", "WCF Error",
                                MessageBoxButton.OK, MessageBoxImage.Stop);
                Application.Current.Shutdown();
            }

            // Create peer name
            peerName = new PeerName("P2P Sample", PeerNameType.Unsecured);

            // get ready to register participant in the local cloud
            _peerNameRegistration = new PeerNameRegistration(peerName, int.Parse(port))
            {
                Cloud = Cloud.AllLinkLocal
            };
            // run registration
            _peerNameRegistration.Start();
        }
示例#20
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            // Get configuration from app.config
            string port        = ConfigurationManager.AppSettings["port"];
            string username    = ConfigurationManager.AppSettings["username"];
            string machineName = Environment.MachineName;
            string serviceUrl  = null;

            // Set window title
            this.Title = string.Format("P2P example - {0}", username);

            // Get service url using IPv4 address and port from config file
            foreach (IPAddress address in Dns.GetHostAddresses(Dns.GetHostName()))
            {
                if (address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                {
                    serviceUrl = string.Format("net.tcp://{0}:{1}/P2PService", address, port);
                    break;
                }
            }

            // Check for null address
            if (serviceUrl == null)
            {
                // Display error and shutdown
                MessageBox.Show(this, "Unable to determine WCF endpoint.", "Networking Error", MessageBoxButton.OK, MessageBoxImage.Stop);
                Application.Current.Shutdown();
            }

            // Register and start WCF service.
            localService = new P2PService(this, username);
            host         = new ServiceHost(localService, new Uri(serviceUrl));
            NetTcpBinding binding = new NetTcpBinding();

            binding.Security.Mode = SecurityMode.None;
            host.AddServiceEndpoint(typeof(IP2PService), binding, serviceUrl);
            try
            {
                host.Open();
            }
            catch (AddressAlreadyInUseException)
            {
                // Display error and shutdown
                MessageBox.Show(this, "Cannot start listening, port in use.", "WCF Error", MessageBoxButton.OK, MessageBoxImage.Stop);
                Application.Current.Shutdown();
            }

            // Create peer name
            peerName = new PeerName("P2P Sample", PeerNameType.Unsecured);

            // Prepare peer name registration in link local clouds
            peerNameRegistration       = new PeerNameRegistration(peerName, int.Parse(port));
            peerNameRegistration.Cloud = Cloud.AllLinkLocal;

            // Start registration
            peerNameRegistration.Start();
        }
示例#21
0
        private void CreatePeer()
        {
            _peerName           = new PeerName(PEER_CLASSIFIER, PeerNameType.Unsecured);
            _registration       = new PeerNameRegistration(_peerName, _port);
            _registration.Cloud = Cloud.AllLinkLocal;

            // connect to peer cloud
            _registration.Start();
        }
示例#22
0
        //private readonly TcpClient _client;
        //private readonly TcpListener _listener;

        public LocalPeer(string name, int port, Cloud cloud)
        {
            var peerName = new PeerName(name, PeerNameType.Secured);

            // _client = new TcpClient();
            //_listener = new TcpListener();

            _peerRegist = new PeerNameRegistration(peerName, port, cloud);
            _peerRegist.Start();
        }
示例#23
0
        public PeerNameRegistration RegisterPeerGlobal(PeerName peerName, int port)
        {
            var peerNameRegistration = new PeerNameRegistration(peerName, port)
            {
                Cloud = Cloud.Global
            };

            peerNameRegistration.Start();
            return(peerNameRegistration);
        }
示例#24
0
        public void Init()
        {
            ips  = Dns.GetHostAddresses("");
            port = new Random().Next(48000, 50000);
            this.resourceNameReg = new PeerNameRegistration();
            register();
            // 将资源名注册到云中
            // 具体资源名的结构在博客有介绍

            resourceNameReg.Start();
        }
示例#25
0
        public void register()
        {
            PeerName resourceName = new PeerName(textBox_Name.Text, PeerNameType.Unsecured);

            // 用指定的名称和端口号初始化PeerNameRegistration类的实例
            resourceNameReg = new PeerNameRegistration(resourceName, this.port);
            // 设置在云中注册的对等名对象的其他信息的注释
            resourceNameReg.Comment = DateTime.Now.ToShortTimeString() + ":" + DateTime.Now.Second.ToString();
            // 设置PeerNameRegistration对象的应用程序定义的二进制数据
            resourceNameReg.Data = Encoding.UTF8.GetBytes(textBox_talk.Text.Length == 0 ? " " : textBox_talk.Text);
            // 在云中注册PeerName(对等名)
        }
示例#26
0
        public PNRPManager(string classifierName, int port)
        {
            this.ClassifierName = classifierName;
            this.Port           = port;

            PeerName peer = new PeerName(classifierName, PeerNameType.Unsecured);

            registration = new PeerNameRegistration(peer, port, Cloud.AllLinkLocal)
            {
                UseAutoEndPointSelection = true
            };
        }
示例#27
0
        public PeerToPeerImplementation()
        {
            peerList = new List <PeerEntry>();

            userName = userNames[random.Next(0, 4)];
            string port        = random.Next(1000, 10000).ToString();
            string machineName = Environment.MachineName;
            string serviceUri  = null;

            Console.Title = string.Format($"P2P app {userName}");

            var hostName  = Dns.GetHostName();//get host name from config file
            var addresses = Dns.GetHostAddresses(hostName);

            foreach (IPAddress address in addresses)
            {
                if (address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                {
                    serviceUri = string.Format($"net.tcp://{address}:{port}/P2PService");
                    break;
                }
            }

            if (serviceUri == null)
            {
                Console.WriteLine("Not able to determine endpoint for wcf");
            }
            else
            {
                localService = new P2PService(userName);
                host         = new ServiceHost(localService, new Uri(serviceUri));
                NetTcpBinding binding = new NetTcpBinding();
                binding.Security.Mode = SecurityMode.None;
                host.AddServiceEndpoint(typeof(IP2PService), binding, serviceUri);
                try
                {
                    host.Open();
                }
                catch (AddressAlreadyInUseException e)
                {
                    Console.WriteLine(e);
                }
            }
            //creating equal peer member
            peerName = new PeerName("P2P Sample", PeerNameType.Unsecured);

            //prepare peer member registration in local cloud
            peerNameRegistration       = new PeerNameRegistration(peerName, int.Parse(port));
            peerNameRegistration.Cloud = Cloud.AllLinkLocal;
            //start registration process
            peerNameRegistration.Start();
        }
示例#28
0
        public Messager()
        {
            peerList = new List <PeerEntry>();

            // Получение конфигурационной информации из app.config
            string port        = ConfigurationManager.AppSettings["port"];
            string username    = ConfigurationManager.AppSettings["username"];
            string machineName = Environment.MachineName;
            string serviceUrl  = null;

            //  Получение URL-адреса службы с использованием адресаIPv4
            //  и порта из конфигурационного файла
            foreach (IPAddress address in Dns.GetHostAddresses(Dns.GetHostName()))
            {
                if (address.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork)
                {
                    serviceUrl = string.Format("net.tcp://{0}:{1}/P2PService", address, port);
                    break;
                }
            }

            // Выполнение проверки, не является ли адрес null
            if (serviceUrl == null)
            {
                // Отображение ошибки и завершение работы приложения
                throw new Exception("Networking Error - Не удается определить адрес конечной точки WCF");
            }

            // Регистрация и запуск службы WCF
            localService = new P2PService(this, username);
            host         = new ServiceHost(localService, new Uri(serviceUrl));
            NetTcpBinding binding = new NetTcpBinding();

            binding.Security.Mode = SecurityMode.None;
            host.AddServiceEndpoint(typeof(IP2PService), binding, serviceUrl);
            host.Open();
            Console.WriteLine("Service {0} is opened", serviceUrl);

            // Создание имени равноправного участника (пира)
            string name = "P2P " + ConfigurationManager.AppSettings["username"];

            peerName = new PeerName(name, PeerNameType.Unsecured);

            // Подготовка процесса регистрации имени равноправного участника в локальном облаке
            peerNameRegistration       = new PeerNameRegistration(peerName, int.Parse(port));
            peerNameRegistration.Cloud = Cloud.AllLinkLocal;

            // Запуск процесса регистрации
            peerNameRegistration.Start();
            Console.WriteLine("Registration process is started");
        }
示例#29
0
        private static void Publish <I>(int port)
        {
            Console.Write("publishing " + typeof(I) + " via PNRP...");
            var name = new PeerName(typeof(I).FullName, PeerNameType.Unsecured);

            registration = new PeerNameRegistration(name, port);
            try {
                registration.Start();
                Console.WriteLine("published {0}:{1}", name, port);
            } catch (Exception e) {
                Console.WriteLine("FAILED");
                Console.Error.WriteLine(e.Message);
            }
        }
示例#30
0
        void Init()
        {
            PeerName myPeer = new PeerName("MyUnsecurePeer", PeerNameType.Unsecured);
            //PeerName mySecurePeer = new PeerName("MySecurePeer",PeerNameType.Secured);

            //Publishing o register the peer and associate it with a cloud
            PeerNameRegistration registeration = new PeerNameRegistration(myPeer, 3030);

            registeration.UseAutoEndPointSelection = true;
            registeration.Start();


            //Resolving :The PeerNameResolver can resolve a peer to either a PeerRecord or a cloud,
        }