summaryrefslogtreecommitdiffstats
path: root/src/server/altservers.c
diff options
context:
space:
mode:
authorSimon Rettberg2017-11-08 16:14:32 +0100
committerSimon Rettberg2017-11-08 16:14:32 +0100
commit01a2ebb9a402dc4c3f9183d457565685885f6fb9 (patch)
treeb54fd8702865fcb02abf865536734987e1b52a01 /src/server/altservers.c
parent[SERVER] Add multiple config options for limiting stuff (diff)
downloaddnbd3-01a2ebb9a402dc4c3f9183d457565685885f6fb9.tar.gz
dnbd3-01a2ebb9a402dc4c3f9183d457565685885f6fb9.tar.xz
dnbd3-01a2ebb9a402dc4c3f9183d457565685885f6fb9.zip
[SERVER] rpc: Add q=logfile, q=altservers and q=config to /query
Diffstat (limited to 'src/server/altservers.c')
-rw-r--r--src/server/altservers.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/server/altservers.c b/src/server/altservers.c
index 5644625..d0bb206 100644
--- a/src/server/altservers.c
+++ b/src/server/altservers.c
@@ -8,6 +8,7 @@
#include "../serverconfig.h"
#include <assert.h>
#include <inttypes.h>
+#include <jansson.h>
static dnbd3_connection_t *pending[SERVER_MAX_PENDING_ALT_CHECKS];
static pthread_spinlock_t pendingLockWrite; // Lock for adding something to pending. (NULL -> nonNULL)
@@ -264,6 +265,35 @@ int altservers_getListForUplink(dnbd3_host_t *output, int size, int emergency)
return count;
}
+json_t* altservers_toJson()
+{
+ json_t *list = json_array();
+
+ spin_lock( &altServersLock );
+ char host[100];
+ const int count = numAltServers;
+ dnbd3_alt_server_t src[count];
+ memcpy( src, altServers, sizeof(src) );
+ spin_unlock( &altServersLock );
+ for (int i = 0; i < count; ++i) {
+ json_t *rtts = json_array();
+ for (int j = 0; j < SERVER_RTT_PROBES; ++j) {
+ json_array_append_new( rtts, json_integer( src[i].rtt[ (j + src[i].rttIndex + 1) % SERVER_RTT_PROBES ] ) );
+ }
+ sock_printHost( &src[i].host, host, sizeof(host) );
+ json_t *server = json_pack( "{ss,ss,so,sb,sb,si}",
+ "comment", src[i].comment,
+ "host", host,
+ "rtt", rtts,
+ "isPrivate", (int)src[i].isPrivate,
+ "isClientOnly", (int)src[i].isClientOnly,
+ "numFails", src[i].numFails
+ );
+ json_array_append_new( list, server );
+ }
+ return list;
+}
+
/**
* Update rtt history of given server - returns the new average for that server
*/