private JObject CreateRelayTreeNode(HostTreeNode node)
{
var res = new JObject();
var host = node.Host;
var endpoint = (host.GlobalEndPoint!=null && host.GlobalEndPoint.Port!=0) ? host.GlobalEndPoint : host.LocalEndPoint;
res["sessionId"] = host.SessionID.ToString("N").ToUpper();
res["address"] = endpoint.Address.ToString();
res["port"] = endpoint.Port;
res["isFirewalled"] = host.IsFirewalled;
res["localRelays"] = host.RelayCount;
res["localDirects"] = host.DirectCount;
res["isTracker"] = host.IsTracker;
res["isRelayFull"] = host.IsRelayFull;
res["isDirectFull"] = host.IsDirectFull;
res["isReceiving"] = host.IsReceiving;
res["isControlFull"]= host.IsControlFull;
res["version"] = host.Extra.GetHostVersion();
res["versionVP"] = host.Extra.GetHostVersionVP();
var ex = host.Extra.GetHostVersionEXPrefix();
var exnum = host.Extra.GetHostVersionEXNumber();
if (ex!=null && exnum.HasValue) {
try {
res["versionEX"] = System.Text.Encoding.UTF8.GetString(ex) + exnum.ToString();
}
catch (ArgumentException) {
//ignore
}
}
res["children"] = new JArray(node.Children.Select(c => CreateRelayTreeNode(c)));
return res;
}