public async Task <string> GetNodeVersion(string endpoint) { var result = await RpcCaller.MakeRPCCall <RPCResponseBody <RPCResponseVersion> >(endpoint, "getversion"); return(result == null ? string.Empty : result.Result.Useragent); }
private void HandleNewAddress(RPCPeer address, StateOfNeoContext db) { var newNode = default(Node); string successUrl = null; var ports = this.netSettings.GetPorts(); foreach (var portWithType in ports) { var url = portWithType.GetFullUrl(address.Address.ToMatchedIp()); try { var rpcResult = RpcCaller.MakeRPCCall <RPCResponseBody <int> >(url, "getblockcount") .GetAwaiter() .GetResult(); if (rpcResult?.Result > 0) { successUrl = url; newNode = this.CreateNodeOfAddress(address.Address, portWithType.Type, successUrl, NodeAddressType.RPC); break; } } catch (Exception e) { Log.Error($"Get blockcount parse error {e.Message}", e); break; } } if (newNode == default(Node)) { var httpTypes = new string[] { "https", "http" }; foreach (var httpType in httpTypes) { var url = $"{httpType}://{address.Address.ToMatchedIp()}"; var heightResponse = HttpRequester.MakeRestCall <HeightResponseObject>($@"{url}/api/main_net/v1/get_height", HttpMethod.Get) .GetAwaiter() .GetResult(); if (heightResponse != null) { successUrl = url; newNode = this.CreateNodeOfAddress(address.Address, httpType, successUrl, NodeAddressType.REST, NodeCallsConstants.NeoScan); break; } var versionResponse = HttpRequester.MakeRestCall <NeoNotificationVersionResponse>($@"{url}/v1/version", HttpMethod.Get) .GetAwaiter() .GetResult(); if (versionResponse != null) { successUrl = url; newNode = this.CreateNodeOfAddress(address.Address, httpType, successUrl, NodeAddressType.REST, NodeCallsConstants.NeoNotification); break; } } } if (newNode != null) { var newNodeAddress = new NodeAddress { Ip = address.Address.ToMatchedIp(), Node = newNode }; var peer = db.Peers.FirstOrDefault(x => x.Ip == address.Address.ToMatchedIp()); var result = LocationCaller.UpdateNode(newNode, newNodeAddress.Ip).GetAwaiter().GetResult(); newNode.NodeAddresses.Add(newNodeAddress); db.NodeAddresses.Add(newNodeAddress); db.Nodes.Add(newNode); peer.Node = newNode; db.SaveChanges(); } }