Add rhizome fetch status html page

This commit is contained in:
Jeremy Lakeman 2013-07-11 12:32:06 +09:30
parent ac734b3161
commit a1ac7febe2
4 changed files with 69 additions and 17 deletions

View File

@ -658,6 +658,7 @@ enum rhizome_start_fetch_result rhizome_fetch_request_manifest_by_prefix(const s
int rhizome_any_fetch_active();
int rhizome_any_fetch_queued();
int rhizome_fetch_queue_bytes();
int rhizome_fetch_status_html(struct strbuf *b);
int rhizome_fetch_has_queue_space(unsigned char log2_size);
struct http_response_parts {

View File

@ -163,6 +163,34 @@ int rhizome_fetch_queue_bytes(){
return bytes;
}
int rhizome_fetch_status_html(struct strbuf *b)
{
int i,j;
for(i=0;i<NQUEUES;i++){
struct rhizome_fetch_queue *q=&rhizome_fetch_queues[i];
strbuf_sprintf(b, "<p>Slot %d, ", i);
if (q->active.state!=RHIZOME_FETCH_FREE){
strbuf_sprintf(b, "%lld[+%d] of %lld",
q->active.write_state.file_offset,
q->active.write_state.data_size,
q->active.manifest->fileLength);
}else{
strbuf_puts(b, "inactive");
}
int candidates=0;
long long candidate_size=0;
for (j=0; j< q->candidate_queue_size;j++){
if (q->candidate_queue[j].manifest){
candidates++;
candidate_size += q->candidate_queue[j].manifest->fileLength;
}
}
if (candidates)
strbuf_sprintf(b, ", %d candidates [%lld bytes]", candidates, candidate_size);
}
return 0;
}
static struct sched_ent sched_activate = STRUCT_SCHED_ENT_UNUSED;
static struct profile_total fetch_stats;

View File

@ -529,20 +529,32 @@ int rhizome_server_parse_http_request(rhizome_http_request *r)
if (path) {
char *id = NULL;
INFOF("RHIZOME HTTP SERVER, GET %s", alloca_toprint(1024, path, pathlen));
if (strcmp(path, "/favicon.ico") == 0) {
if (strcmp(path, "/")==0) {
r->request_type = RHIZOME_HTTP_REQUEST_FROMBUFFER;
char temp[8192];
snprintf(temp,8192,
"<html><body>"
"<h1>Hello, I'm %s*</h1><br>"
"<a href=\"/rssi\">rssi</a><br>"
"<a href=\"/rhizome/status\">rhizome status</a><br>"
"<a href=\"/rhizome/files\">rhizome files</a><br>"
"<a href=\"/rhizome/bars\">rhizome bars</a><br>"
"</body></html>",
alloca_tohex(my_subscriber->sid, 8));
rhizome_server_simple_http_response(r, 200, temp);
} else if (strcmp(path, "/favicon.ico") == 0) {
r->request_type = RHIZOME_HTTP_REQUEST_FAVICON;
rhizome_server_http_response_header(r, 200, "image/vnd.microsoft.icon", favicon_len);
} else if (strcmp(path, "/rssi.csv") == 0) {
r->request_type = RHIZOME_HTTP_REQUEST_FROMBUFFER;
char temp[8192];
char *sidprefix=alloca_tohex_sid(my_subscriber->sid); sidprefix[8]=0;
snprintf(temp,8192,
";%lld;%d;%d;%d;%d;%s;%d;%d;%d;%d;%d\n",
gettime_ms(),
last_radio_rssi,last_radio_temperature,
(int)bundles_available,
rhizome_active_fetch_count(),
sidprefix,
alloca_tohex(my_subscriber->sid, 8),
rhizome_active_fetch_bytes_received(0),
rhizome_active_fetch_bytes_received(1),
rhizome_active_fetch_bytes_received(2),
@ -553,17 +565,16 @@ int rhizome_server_parse_http_request(rhizome_http_request *r)
} else if (strcmp(path, "/rssi") == 0) {
r->request_type = RHIZOME_HTTP_REQUEST_FROMBUFFER;
char temp[8192];
char *sidprefix=alloca_tohex_sid(my_subscriber->sid); sidprefix[8]=0;
snprintf(temp,8192,
"<head><meta http-equiv=\"refresh\" content=\"5\" >"
"</head><html><h1>Radio link margin = %+ddB<br>"
"<html><head><meta http-equiv=\"refresh\" content=\"5\" >"
"</head><body><h1>Radio link margin = %+ddB<br>"
"Radio temperature = %d&deg;C<br>"
"SID: %s*<br>"
"%d rhizome bundles in database<br>"
"%d rhizome transfers in progress<br>(%d,%d,%d,%d,%d bytes)<br>"
"</h1></html>\n",
"</h1></body></html>\n",
last_radio_rssi,last_radio_temperature,
sidprefix,
alloca_tohex(my_subscriber->sid, 8),
(int)bundles_available,
rhizome_active_fetch_count(),
rhizome_active_fetch_bytes_received(0),
@ -577,6 +588,14 @@ int rhizome_server_parse_http_request(rhizome_http_request *r)
if (strcmp(path, "/rhizome/groups") == 0) {
/* Return the list of known groups */
rhizome_server_sql_query_http_response(r, "id", "groups", "from groups", 32, 1);
} else if (strcmp(path, "/rhizome/status") == 0) {
char buf[32*1024];
struct strbuf b;
strbuf_init(&b, buf, sizeof buf);
strbuf_puts(&b, "<html><head><meta http-equiv=\"refresh\" content=\"5\" ></head><body>");
rhizome_fetch_status_html(&b);
strbuf_puts(&b, "</body></html>");
rhizome_server_simple_http_response(r, 200, buf);
} else if (strcmp(path, "/rhizome/files") == 0) {
/* Return the list of known files */
rhizome_server_sql_query_http_response(r, "id", "files", "from files", 32, 1);
@ -726,6 +745,7 @@ int rhizome_server_set_response(rhizome_http_request *r, const struct http_respo
int rhizome_server_simple_http_response(rhizome_http_request *r, int result, const char *response)
{
struct http_response hr;
bzero(&hr, sizeof hr);
hr.result_code = result;
hr.content_type = "text/html";
hr.content_length = strlen(response);
@ -741,6 +761,7 @@ int rhizome_server_simple_http_response(rhizome_http_request *r, int result, con
int rhizome_server_http_response_header(rhizome_http_request *r, int result, const char *mime_type, unsigned long long bytes)
{
struct http_response hr;
bzero(&hr, sizeof hr);
hr.result_code = result;
hr.content_type = mime_type;
hr.content_length = bytes;

View File

@ -46,10 +46,13 @@ struct rhizome_sync
uint64_t sync_end;
uint64_t highest_seen;
unsigned char sync_complete;
// a short list of BAR's we are interested in from the last parsed message
struct bar_entry bars[CACHE_BARS];
int bar_count;
time_ms_t next_request;
time_ms_t last_extended;
time_ms_t last_response;
time_ms_t last_new_bundle;
// a short list of BAR's we are interested in from the last parsed message
struct bar_entry bars[CACHE_BARS];
};
static void rhizome_sync_request(struct subscriber *subscriber, uint64_t token, unsigned char forwards)
@ -110,10 +113,6 @@ static void rhizome_sync_send_requests(struct subscriber *subscriber, struct rhi
mdp.out.src.port=MDP_PORT_RHIZOME_RESPONSE;
bcopy(subscriber->sid,mdp.out.dst.sid,SID_SIZE);
mdp.out.dst.port=MDP_PORT_RHIZOME_MANIFEST_REQUEST;
if (subscriber->reachable&REACHABLE_DIRECT)
mdp.out.ttl=1;
else
mdp.out.ttl=64;
mdp.packetTypeAndFlags=MDP_TX;
mdp.out.queue=OQ_OPPORTUNISTIC;
@ -198,10 +197,12 @@ static int sync_cache_bar(struct rhizome_sync *state, unsigned char *bar, uint64
}
if (state->sync_end < token){
state->sync_end = token;
state->last_extended = gettime_ms();
ret=1;
}
if (state->sync_start > token){
state->sync_start = token;
state->last_extended = gettime_ms();
ret=1;
}
return ret;
@ -217,6 +218,8 @@ static void sync_process_bar_list(struct subscriber *subscriber, struct rhizome_
int has_before=0, has_after=0;
int mid_point = -1;
state->last_response = gettime_ms();
while(ob_remaining(b)>0 && bar_count < BARS_PER_RESPONSE){
bar_tokens[bar_count]=ob_get_packed_ui64(b);
bars[bar_count]=ob_get_bytes_ptr(b, RHIZOME_BAR_BYTES);
@ -230,6 +233,7 @@ static void sync_process_bar_list(struct subscriber *subscriber, struct rhizome_
// track the highest BAR we've seen, even if we can't sync it yet, so we know what BARs to request.
if (state->highest_seen < bar_tokens[bar_count]){
state->highest_seen = bar_tokens[bar_count];
state->last_new_bundle = gettime_ms();
state->sync_complete = 0;
}
@ -321,10 +325,8 @@ static void sync_send_response(struct subscriber *dest, int forwards, uint64_t t
mdp.packetTypeAndFlags|=(MDP_NOCRYPT|MDP_NOSIGN);
}
if (!dest || dest->reachable&REACHABLE_DIRECT)
if (!dest)
mdp.out.ttl=1;
else
mdp.out.ttl=64;
struct overlay_buffer *b = ob_static(mdp.out.payload, sizeof(mdp.out.payload));
ob_append_byte(b, MSG_TYPE_BARS);