/// <summary> /// Used only to create MyNode. Generate an RSA for the current node. /// </summary> /// <param name="myNode">Parameters for this node</param> internal Node(NodeInitializer myNode) { Address = myNode.Address; MachineName = myNode.VirtualDevice?.MachineName ?? Environment.MachineName; //Create RSA var rsa = new System.Security.Cryptography.RSACryptoServiceProvider(); rsa.ImportCspBlob(Convert.FromBase64String(myNode.PrivateKey)); PublicKey = Convert.ToBase64String(rsa.ExportCspBlob(false)); _rsa = rsa; }
/// <summary> /// This method initializes the network. /// You can join the network as a node, and contribute to decentralization, or hook yourself to the network as an /// external user. /// To create a node, set the MyAddress parameter with your web address.If MyAddress is not set then you are an external /// user. /// </summary> /// <param name="entryPoints">The list of permanent access points nodes, to access the network</param> /// <param name="networkName">The name of the infrastructure. For tests we recommend using "testnet"</param> /// <param name="myNode">Data related to your node. If you do not want to create the node, omit this parameter</param> public NetworkConnection(IEnumerable <Node> entryPoints, string networkName = "testnet", NodeInitializer myNode = null) : base(myNode?.VirtualDevice) { //if (VirtualDevice != null) //{ // //base = new Device() { VirtualDevice = VirtualDevice }; //} Networks.Add(this); Communication = new Communication(this); Protocol = new Protocol(this); PipelineManager = new PipelineManager(this); MappingNetwork = new MappingNetwork(this); var entry = new List <Node>(entryPoints as Node[] ?? entryPoints.ToArray()); NodeList = new NodeList(this); if (myNode != null) { MyNode = new Node(myNode); MyNode.Ip = VirtualDevice?.Ip ?? MyNode.DetectIp(); var count = entry.Count; entry.RemoveAll(x => x.Address == MyNode.Address || x.Ip == MyNode.Ip); _imEntryPoint = count != entry.Count; ThisNode = new InfoNode(MyNode); NodeList.Add(MyNode); } entry.ForEach(x => x.DetectIp()); NodeList.AddRange(entry); NetworkName = networkName; //Setup.NetworkConnection.MyAddress = MyAddress; //Setup.NetworkConnection.NetworkName = NetworkName; //if (EntryPoints != null) // Setup.NetworkConnection.EntryPoints = EntryPoints; #pragma warning disable CS0618 // 'NetworkConnection.OnReceivesHttpRequest' è obsoleto: 'We recommend using this method from the Device class because each device could handle multiple networks' OnReceivesHttpRequest = base.OnReceivesHttpRequest; //Is ok! Don't worry #pragma warning restore CS0618 // 'NetworkConnection.OnReceivesHttpRequest' è obsoleto: 'We recommend using this method from the Device class because each device could handle multiple networks' OnlineDetection.WaitForInternetConnection(); }