Beispiel #1
0
        public async Task <NodeResponse> Get(string id)
        {
            Skynet curHost = Skynet.allInstance.Where(x => x.httpPort == Request.RequestUri.Port).FirstOrDefault();

            if (!ToxId.IsValid(id))
            {
                return(new NodeResponse
                {
                    statusCode = NodeResponseCode.InvalidRequest,
                    description = "your tox id is invalid",
                });
            }

            // check if target tox client is local client
            if (curHost.tox.Id.ToString() == id)
            {
                // list all nodes on target tox client
                return(new NodeResponse
                {
                    statusCode = NodeResponseCode.OK,
                    description = "success",
                    value = JsonConvert.SerializeObject(new ToxClient
                    {
                        Id = id,
                        nodes = Node.AllLocalNodes.Select(x => x.getInfo()).ToList()
                    })
                });
            }
            // if not, send tox req to target tox client
            bool        reqStatus    = false;
            ToxResponse nodeResponse = await curHost.sendRequest(new ToxId(id), RequestProxy.toNodeRequest(Request), out reqStatus);

            if (nodeResponse != null)
            {
                return(JsonConvert.DeserializeObject <NodeResponse>(Encoding.UTF8.GetString(nodeResponse.content)));
            }
            else
            {
                return new NodeResponse
                       {
                           statusCode  = NodeResponseCode.NotFound,
                           description = "target does not exist or target is current offline",
                       }
            };
        }