static size_t stats_return_busy_networks( char * reply, stats_network_node *tree, int amount, int limit ) { ot_ip6 networks[amount]; ot_ip6 node_value; size_t scores[amount]; int i; char * r = reply; memset( scores, 0, sizeof( scores ) ); memset( networks, 0, sizeof( networks ) ); memset( node_value, 0, sizeof( node_value ) ); stats_get_highscore_networks( tree, 0, node_value, scores, networks, amount, limit ); r += sprintf( r, "Networks, limit /%d:\n", limit+STATS_NETWORK_NODE_BITWIDTH ); for( i=amount-1; i>=0; --i) { if( scores[i] ) { r += sprintf( r, "%08zd: ", scores[i] ); #ifdef WANT_V6 r += fmt_ip6c( r, networks[i] ); #else r += fmt_ip4( r, networks[i]); #endif *r++ = '\n'; } } *r++ = '\n'; return r - reply; }
static void stats_return_fulllog( int *iovec_entries, struct iovec **iovector, char *r ) { ot_log *loglist = g_logchain_first, *llnext; char * re = r + OT_STATS_TMPSIZE; g_logchain_first = g_logchain_last = 0; while( loglist ) { if( r + ( loglist->size + 64 ) >= re ) { r = iovec_fix_increase_or_free( iovec_entries, iovector, r, 32 * OT_STATS_TMPSIZE ); if( !r ) return; re = r + 32 * OT_STATS_TMPSIZE; } r += sprintf( r, "%08ld: ", loglist->time ); r += fmt_ip6c( r, loglist->ip ); *r++ = '\n'; memcpy( r, loglist->data, loglist->size ); r += loglist->size; *r++ = '\n'; *r++ = '*'; *r++ = '\n'; *r++ = '\n'; llnext = loglist->next; free( loglist->data ); free( loglist ); loglist = llnext; } iovec_fixlast( iovec_entries, iovector, r ); }
int ip_vhost(struct http_data* h) { char* y; int i; /* construct artificial Host header from IP */ y=alloca(IP6_FMT+7); i=fmt_ip6c(y,h->myip); i+=fmt_str(y+i,":"); i+=fmt_ulong(y+i,h->myport); y[i]=0; #ifdef __MINGW32__ // printf("chdir(\"%s\") -> %d\n",origdir,chdir(origdir)); chdir(origdir); #else fchdir(origdir); #endif if (virtual_hosts>=0) { if (chdir(y)==-1) if (chdir("default")==-1) if (virtual_hosts==1) { h->hdrbuf="425 no such virtual host.\r\n"; return -1; } } return 0; }
void stats_issue_event( ot_status_event event, PROTO_FLAG proto, uintptr_t event_data ) { switch( event ) { case EVENT_ACCEPT: if( proto == FLAG_TCP ) ot_overall_tcp_connections++; else ot_overall_udp_connections++; #ifdef WANT_LOG_NETWORKS stat_increase_network_count( &stats_network_counters_root, 0, event_data ); #endif break; case EVENT_ANNOUNCE: if( proto == FLAG_TCP ) ot_overall_tcp_successfulannounces++; else ot_overall_udp_successfulannounces++; break; case EVENT_CONNECT: if( proto == FLAG_TCP ) ot_overall_tcp_connects++; else ot_overall_udp_connects++; break; case EVENT_COMPLETED: #ifdef WANT_SYSLOGS if( event_data) { struct ot_workstruct *ws = (struct ot_workstruct *)event_data; char timestring[64]; char hash_hex[42], peerid_hex[42], ip_readable[64]; struct tm time_now; time_t ttt; time( &ttt ); localtime_r( &ttt, &time_now ); strftime( timestring, sizeof( timestring ), "%FT%T%z", &time_now ); to_hex( hash_hex, *ws->hash ); if( ws->peer_id ) to_hex( peerid_hex, (uint8_t*)ws->peer_id ); else { *peerid_hex=0; } #ifdef WANT_V6 ip_readable[ fmt_ip6c( ip_readable, (char*)&ws->peer ) ] = 0; #else ip_readable[ fmt_ip4( ip_readable, (char*)&ws->peer ) ] = 0; #endif syslog( LOG_INFO, "time=%s event=completed info_hash=%s peer_id=%s ip=%s", timestring, hash_hex, peerid_hex, ip_readable ); } #endif ot_overall_completed++; break; case EVENT_SCRAPE: if( proto == FLAG_TCP ) ot_overall_tcp_successfulscrapes++; else ot_overall_udp_successfulscrapes++; case EVENT_FULLSCRAPE: ot_full_scrape_count++; ot_full_scrape_size += event_data; break; case EVENT_FULLSCRAPE_REQUEST: { ot_ip6 *ip = (ot_ip6*)event_data; /* ugly hack to transfer ip to stats */ char _debug[512]; int off = snprintf( _debug, sizeof(_debug), "[%08d] scrp: ", (unsigned int)(g_now_seconds - ot_start_time)/60 ); off += fmt_ip6c( _debug+off, *ip ); off += snprintf( _debug+off, sizeof(_debug)-off, " - FULL SCRAPE\n" ); write( 2, _debug, off ); ot_full_scrape_request_count++; } break; case EVENT_FULLSCRAPE_REQUEST_GZIP: { ot_ip6 *ip = (ot_ip6*)event_data; /* ugly hack to transfer ip to stats */ char _debug[512]; int off = snprintf( _debug, sizeof(_debug), "[%08d] scrp: ", (unsigned int)(g_now_seconds - ot_start_time)/60 ); off += fmt_ip6c(_debug+off, *ip ); off += snprintf( _debug+off, sizeof(_debug)-off, " - FULL SCRAPE\n" ); write( 2, _debug, off ); ot_full_scrape_request_count++; } break; case EVENT_FAILED: ot_failed_request_counts[event_data]++; break; case EVENT_RENEW: ot_renewed[event_data]++; break; case EVENT_SYNC: ot_overall_sync_count+=event_data; break; case EVENT_BUCKET_LOCKED: ot_overall_stall_count++; break; #ifdef WANT_SPOT_WOODPECKER case EVENT_WOODPECKER: pthread_mutex_lock( &g_woodpeckers_mutex ); stat_increase_network_count( &stats_woodpeckers_tree, 0, event_data ); pthread_mutex_unlock( &g_woodpeckers_mutex ); break; #endif case EVENT_CONNID_MISSMATCH: ++ot_overall_udp_connectionidmissmatches; default: break; } }