Hi,
appended is a patch for GTKG that adds HSEP support to the GTK1 GUI.
Change log:
- added a "Horizon stats" frame to the GTK1 Gnet stats panel, which
displays the reachable nodes, files and bytes within 1 to 10 hops
(updated as often as the other stats on the stats panel)
- changed API documentation in hsep.c
- added missing '\n's in printf() calls in hsep.c
- renamed hsep_get_table() to hsep_get_global_table() in hsep.c
Missing:
- the column sizes of the horizon stats clist are not persistent yet
Note that I did not include the patch for the generated sourcecode
file of the GUI. It needs to be rebuilt from the included glade file.
Please have a look whether what I did is OK or not. If it is OK,
please commit the changes. I will then also add a similar frame to the
GTK2 GUI. As always, any comments are welcome.
Greetings,
Thomas.
Index: gtk-gnutella.glade
===================================================================
RCS file: /cvsroot/gtk-gnutella/gtk-gnutella-current/gtk-gnutella.glade,v
retrieving revision 1.208
diff -u -r1.208 gtk-gnutella.glade
--- gtk-gnutella.glade 23 May 2004 09:37:23 -0000 1.208
+++ gtk-gnutella.glade 2 Jun 2004 07:31:14 -0000
@@ -17343,6 +17343,103 @@
</widget>
</widget>
</widget>
+
+ <widget>
+ <class>GtkFrame</class>
+ <name>frame125</name>
+ <label>Horizon stats</label>
+ <label_xalign>0</label_xalign>
+ <shadow_type>GTK_SHADOW_ETCHED_IN</shadow_type>
+ <child>
+ <padding>0</padding>
+ <expand>True</expand>
+ <fill>True</fill>
+ </child>
+
+ <widget>
+ <class>GtkVBox</class>
+ <name>vbox125</name>
+ <homogeneous>False</homogeneous>
+ <spacing>0</spacing>
+
+ <widget>
+ <class>GtkScrolledWindow</class>
+ <name>scrolledwindow45</name>
+ <hscrollbar_policy>GTK_POLICY_AUTOMATIC</hscrollbar_policy>
+ <vscrollbar_policy>GTK_POLICY_AUTOMATIC</vscrollbar_policy>
+ <hupdate_policy>GTK_UPDATE_CONTINUOUS</hupdate_policy>
+ <vupdate_policy>GTK_UPDATE_CONTINUOUS</vupdate_policy>
+ <child>
+ <padding>0</padding>
+ <expand>True</expand>
+ <fill>True</fill>
+ </child>
+
+ <widget>
+ <class>GtkCList</class>
+ <name>clist_gnet_stats_horizon</name>
+ <can_focus>True</can_focus>
+ <columns>4</columns>
+ <column_widths>36,50,78,80</column_widths>
+ <selection_mode>GTK_SELECTION_SINGLE</selection_mode>
+ <show_titles>True</show_titles>
+ <shadow_type>GTK_SHADOW_IN</shadow_type>
+
+ <widget>
+ <class>GtkLabel</class>
+ <child_name>CList:title</child_name>
+ <name>label663</name>
+ <label>Hops</label>
+ <justify>GTK_JUSTIFY_CENTER</justify>
+ <wrap>False</wrap>
+ <xalign>7.45058e-09</xalign>
+ <yalign>0.5</yalign>
+ <xpad>0</xpad>
+ <ypad>0</ypad>
+ </widget>
+
+ <widget>
+ <class>GtkLabel</class>
+ <child_name>CList:title</child_name>
+ <name>label664</name>
+ <label>Nodes</label>
+ <justify>GTK_JUSTIFY_CENTER</justify>
+ <wrap>False</wrap>
+ <xalign>0.5</xalign>
+ <yalign>0.5</yalign>
+ <xpad>0</xpad>
+ <ypad>0</ypad>
+ </widget>
+
+ <widget>
+ <class>GtkLabel</class>
+ <child_name>CList:title</child_name>
+ <name>label665</name>
+ <label>Files</label>
+ <justify>GTK_JUSTIFY_CENTER</justify>
+ <wrap>False</wrap>
+ <xalign>0.5</xalign>
+ <yalign>0.5</yalign>
+ <xpad>0</xpad>
+ <ypad>0</ypad>
+ </widget>
+
+ <widget>
+ <class>GtkLabel</class>
+ <child_name>CList:title</child_name>
+ <name>label666</name>
+ <label>Size</label>
+ <justify>GTK_JUSTIFY_CENTER</justify>
+ <wrap>False</wrap>
+ <xalign>0.5</xalign>
+ <yalign>0.5</yalign>
+ <xpad>0</xpad>
+ <ypad>0</ypad>
+ </widget>
+ </widget>
+ </widget>
+ </widget>
+ </widget>
</widget>
<widget>
Index: src/hsep.c
===================================================================
RCS file: /cvsroot/gtk-gnutella/gtk-gnutella-current/src/hsep.c,v
retrieving revision 1.11
diff -u -r1.11 hsep.c
--- src/hsep.c 17 Apr 2004 01:44:18 -0000 1.11
+++ src/hsep.c 2 Jun 2004 07:31:14 -0000
@@ -40,15 +40,21 @@
* - hsep_process_msg(node) should be called whenever a HSEP message
* is received from a HSEP-capable node
* - hsep_reset() can be used to reset all HSEP data (not for normal use)
- *
- * To display horizon size information, use the global array hsep_global_table
- * or the per-connection array node->hsep_table. The usable array indexes are
- * between 1 (for 1 hop) and HSEP_N_MAX (for n_max hops). Note that the arrays
- * only consider other nodes (i.e. exclude what we share ourselves), so the
- * array index 0 always contains zeros. Note also that each triple represents
- * the reachable resources *within* the number of hops, not at *exactly* the
- * number of hops. To get the values for exactly the number of hops, simply
- * subtract the preceeding triple from the desired triple.
+ * - hsep_get_global_table(dest,triples) can be used to get the global
+ * HSEP table
+ * - hsep_get_connection_table(conn,dest,triples) can be used to get the
+ * per-connection HSEP table
+ *
+ * To display horizon size information, use the global HSEP table or the
+ * per-connection HSEP table, using hsep_get_global_table(...) or
+ * hsep_get_connection_table (...), respectively (never access the internal
+ * arrays directly). The usable array indexes are between 1 (for 1 hop) and
+ * HSEP_N_MAX (for n_max hops). Note that the arrays only consider other
+ * nodes (i.e. exclude what we share ourselves), so the array index 0 always
+ * contains zeros. Note also that each triple represents the reachable
+ * resources *within* the number of hops, not at *exactly* the number of hops.
+ * To get the values for exactly the number of hops, simply subtract the
+ * preceeding triple from the desired triple.
*/
/*
@@ -58,11 +64,10 @@
*/
/*
- * TODO: check if semaphores are required for access to global or per-node
- * HSEP tables (e.g. in multithreaded applications). If semaphores are
- * required, a semaphore-based get()-function for the global and
- * per-connection table should be implemented instead of using these arrays
- * directly and locking/unlocking has to be used to enable thread-safety
+ * TODO: If GTKG becomes multi-threaded, locking mechanisms should be used
+ * to avoid race conditions with read/write or write/write accesses to the
+ * HSEP tables. If the API is used as described, only this file needs to be
+ * adapted.
*/
#include "common.h"
@@ -271,7 +276,7 @@
* hsep_process_msg
*
* Processes a received HSEP message by updating the
- * connection's HSEP data and the global HSEP table.
+ * connection's HSEP table and the global HSEP table.
*/
void hsep_process_msg(struct gnutella_node *n)
@@ -331,17 +336,17 @@
messaget++;
}
- messaget = (guint64 *) n->data; /* Back to front */
+ messaget = (guint64 *) n->data; /* back to front */
/* sanity check */
if (*messaget != 1) { /* number of nodes for 1 hop must be 1 */
- printf("HSEP: Node %p's message's #nodes for 1 hop is not 1", n);
+ printf("HSEP: Node %p's message's #nodes for 1 hop is not 1\n", n);
return;
}
if (!hsep_check_monotony((hsep_triple *) messaget, max)) {
- printf("HSEP: Node %p's message's monotony check failed", n);
+ printf("HSEP: Node %p's message's monotony check failed\n", n);
return;
}
@@ -732,7 +737,7 @@
}
/**
- * hsep_get_table
+ * hsep_get_global_table
*
* Copies the first maxtriples triples from the global HSEP table into
* the specified buffer. If maxtriples is larger than the number of
@@ -741,7 +746,7 @@
* The number of copied triples is returned.
*/
-unsigned int hsep_get_table(hsep_triple *buffer, unsigned int maxtriples)
+unsigned int hsep_get_global_table(hsep_triple *buffer, unsigned int maxtriples)
{
unsigned int i;
guint64 *src = (guint64 *) hsep_global_table;
Index: src/hsep.h
===================================================================
RCS file: /cvsroot/gtk-gnutella/gtk-gnutella-current/src/hsep.h,v
retrieving revision 1.4
diff -u -r1.4 hsep.h
--- src/hsep.h 17 Apr 2004 01:44:18 -0000 1.4
+++ src/hsep.h 2 Jun 2004 07:31:14 -0000
@@ -64,7 +64,7 @@
gboolean hsep_check_monotony(hsep_triple *table, unsigned int triples);
unsigned int hsep_triples_to_send(const hsep_triple *table,
unsigned int triples);
-unsigned int hsep_get_table(hsep_triple *buffer, unsigned int maxtriples);
+unsigned int hsep_get_global_table(hsep_triple *buffer, unsigned int maxtriples);
unsigned int hsep_get_connection_table(struct gnutella_node *n,
hsep_triple *buffer, unsigned int maxtriples);
Index: src/gnet_stats_gui.c
===================================================================
RCS file: /cvsroot/gtk-gnutella/gtk-gnutella-current/src/gnet_stats_gui.c,v
retrieving revision 1.37
diff -u -r1.37 gnet_stats_gui.c
--- src/gnet_stats_gui.c 28 May 2004 07:24:03 -0000 1.37
+++ src/gnet_stats_gui.c 2 Jun 2004 07:31:16 -0000
@@ -24,6 +24,8 @@
*/
#include "config.h"
+#include "common.h"
+#include "hsep.h"
#ifdef USE_GTK1
@@ -194,6 +196,24 @@
}
}
+gchar *horizon_stat_str(hsep_triple *table, gint row, gint column)
+{
+ static gchar strbuf[21];
+
+ switch(column)
+ {
+ case 0: gm_snprintf(strbuf, sizeof(strbuf), "%u", row);
+ return strbuf;
+ case 1: gm_snprintf(strbuf, sizeof(strbuf), "%llu", table[row][HSEP_IDX_NODES]);
+ return strbuf;
+ case 2: gm_snprintf(strbuf, sizeof(strbuf), "%llu", table[row][HSEP_IDX_FILES]);
+ return strbuf;
+ case 3: return(short_kb_size64(table[row][HSEP_IDX_KIB]));
+ }
+
+ return NULL;
+}
+
gchar *flowc_stat_str_pkg(guint64 *val_tbl, gint type)
{
static gchar strbuf[21];
@@ -239,6 +259,7 @@
GtkCList *clist_stats_fc_hops;
GtkCList *clist_general;
GtkCList *clist_reason;
+ GtkCList *clist_horizon;
GtkCombo *combo_types;
gchar *titles[10];
guint n;
@@ -256,6 +277,8 @@
lookup_widget(main_window, "clist_gnet_stats_drop_reasons"));
clist_general = GTK_CLIST(
lookup_widget(main_window, "clist_gnet_stats_general"));
+ clist_horizon = GTK_CLIST(
+ lookup_widget(main_window, "clist_gnet_stats_horizon"));
combo_types = GTK_COMBO(
lookup_widget(main_window, "combo_gnet_stats_type"));
@@ -267,6 +290,11 @@
gtk_clist_set_column_justification(
clist_reason, 1, GTK_JUSTIFY_RIGHT);
+ for (n = 0; n < 4; n ++) {
+ gtk_clist_set_column_justification(
+ clist_horizon, n, GTK_JUSTIFY_RIGHT);
+ }
+
for (n = 1; n < 6; n ++) {
gtk_clist_set_column_justification(
clist_stats_msg, n, GTK_JUSTIFY_RIGHT);
@@ -288,6 +316,7 @@
gtk_clist_column_titles_passive(clist_stats_fc_hops);
gtk_clist_column_titles_passive(clist_reason);
gtk_clist_column_titles_passive(clist_general);
+ gtk_clist_column_titles_passive(clist_horizon);
/*
* Initialize stats tables.
@@ -336,6 +365,13 @@
row = gtk_clist_append(clist_general, titles);
gtk_clist_set_selectable(clist_general, row, FALSE);
}
+
+ for (n = 0; n < HSEP_N_MAX; n ++) {
+ gint row;
+ titles[0] = (gchar *) horizon_stat_str(NULL, n + 1, 0);
+ row = gtk_clist_append(clist_horizon, titles);
+ gtk_clist_set_selectable(clist_horizon, row, FALSE);
+ }
}
void gnet_stats_gui_shutdown(void)
@@ -349,10 +385,12 @@
GtkCList *clist_stats_msg;
GtkCList *clist_reason;
GtkCList *clist_general;
+ GtkCList *clist_horizon;
GtkCList *clist_stats_fc_ttl;
GtkCList *clist_stats_fc_hops;
gint n;
gnet_stats_t stats;
+ hsep_triple hsep_table[HSEP_N_MAX + 1];
gint current_page;
@@ -373,6 +411,8 @@
lookup_widget(main_window, "clist_gnet_stats_drop_reasons"));
clist_general = GTK_CLIST(
lookup_widget(main_window, "clist_gnet_stats_general"));
+ clist_horizon = GTK_CLIST(
+ lookup_widget(main_window, "clist_gnet_stats_horizon"));
clist_stats_fc_ttl = GTK_CLIST(
lookup_widget(main_window, "clist_gnet_stats_fc_ttl"));
clist_stats_fc_hops = GTK_CLIST(
@@ -380,6 +420,7 @@
gtk_clist_freeze(clist_reason);
gtk_clist_freeze(clist_general);
+ gtk_clist_freeze(clist_horizon);
gtk_clist_freeze(clist_stats_msg);
gtk_clist_freeze(clist_stats_fc_ttl);
gtk_clist_freeze(clist_stats_fc_hops);
@@ -427,8 +468,18 @@
for (n = 0; n < GNR_TYPE_COUNT; n ++)
gtk_clist_set_text(clist_general, n, 1, general_stat_str(&stats, n));
+ hsep_get_global_table(hsep_table, HSEP_N_MAX + 1);
+
+ for (n = 0; n < HSEP_N_MAX; n ++) {
+ // note that we output hsep_table[1..HSEP_N_MAX]
+ gtk_clist_set_text(clist_horizon, n, 1, horizon_stat_str(hsep_table, n + 1,
1));
+ gtk_clist_set_text(clist_horizon, n, 2, horizon_stat_str(hsep_table, n + 1,
2));
+ gtk_clist_set_text(clist_horizon, n, 3, horizon_stat_str(hsep_table, n + 1
,3));
+ }
+
gtk_clist_thaw(clist_reason);
gtk_clist_thaw(clist_general);
+ gtk_clist_thaw(clist_horizon);
gtk_clist_thaw(clist_stats_msg);
gtk_clist_thaw(clist_stats_fc_ttl);
gtk_clist_thaw(clist_stats_fc_hops);
Index: src/shell.c
===================================================================
RCS file: /cvsroot/gtk-gnutella/gtk-gnutella-current/src/shell.c,v
retrieving revision 1.29
diff -u -r1.29 shell.c
--- src/shell.c 28 May 2004 09:01:23 -0000 1.29
+++ src/shell.c 2 Jun 2004 07:31:16 -0000
@@ -613,7 +613,7 @@
return REPLY_READY;
}
- hsep_get_table(globaltable, HSEP_N_MAX + 1);
+ hsep_get_global_table(globaltable, HSEP_N_MAX + 1);
globalt = (gint64 *) &globaltable[1];
/*