Hi,

the attached patch adds two new features to GTKG:

- HSEP will announce shared files and KiB in HSEP msgs
  (but only if max_uploads is > 0)
- the horizon size information is available in the
  remote shell using the HORIZON command

It would be good if this could be applied to CVS.

If possible, please also bump the GTKG date to a more recent one. ;)

Thanks!


Greetings,
Thomas.
Index: hsep.c
===================================================================
RCS file: /cvsroot/gtk-gnutella/gtk-gnutella-current/src/hsep.c,v
retrieving revision 1.3
diff -u -r1.3 hsep.c
--- hsep.c      26 Feb 2004 22:25:40 -0000      1.3
+++ hsep.c      27 Feb 2004 22:16:35 -0000
@@ -715,6 +715,72 @@
        return triples;
 }
 
+/**
+ * hsep_get_table
+ *
+ * Copies the first maxtriples triples from the global HSEP table into
+ * the specified buffer. If maxtriples is larger than the number of
+ * triples in the table, it is truncated appropriately.
+ *
+ * The number of copied triples is returned.
+ */
+
+unsigned int hsep_get_table(hsep_triple *buffer, unsigned int maxtriples)
+{
+       unsigned int i;
+       guint64 *src = (guint64 *) hsep_global_table;
+       guint64 *dest = (guint64 *) buffer;
+
+       g_assert(buffer);
+
+       if(maxtriples > HSEP_N_MAX + 1)
+               maxtriples = HSEP_N_MAX + 1;
+
+       for (i = 0; i < maxtriples; i++)
+       {
+               *dest++ = *src++;
+               *dest++ = *src++;
+               *dest++ = *src++;
+       }
+
+       return maxtriples;
+}
+
+/**
+ * hsep_get_connection_table
+ *
+ * Copies the first maxtriples triples from the connection's HSEP table into
+ * the specified buffer. If maxtriples is larger than the number of
+ * triples in the table, it is truncated appropriately.
+ *
+ * The number of copied triples is returned.
+ */
+
+unsigned int hsep_get_connection_table(struct gnutella_node *n,
+    hsep_triple *buffer, unsigned int maxtriples)
+{
+       unsigned int i;
+       guint64 *src;
+       guint64 *dest = (guint64 *) buffer;
+       
+       g_assert(n);
+       g_assert(buffer);
+
+       src = (guint64 *) n->hsep_table;
+
+       if(maxtriples > HSEP_N_MAX + 1)
+               maxtriples = HSEP_N_MAX + 1;
+
+       for (i = 0; i < maxtriples; i++)
+       {
+               *dest++ = *src++;
+               *dest++ = *src++;
+               *dest++ = *src++;
+       }
+
+       return maxtriples;
+}
+
 /*
  * hsep_close
  *
Index: hsep.h
===================================================================
RCS file: /cvsroot/gtk-gnutella/gtk-gnutella-current/src/hsep.h,v
retrieving revision 1.2
diff -u -r1.2 hsep.h
--- hsep.h      26 Feb 2004 22:25:40 -0000      1.2
+++ hsep.h      27 Feb 2004 22:16:35 -0000
@@ -50,8 +50,6 @@
        HSEP_IDX_KIB = 2
 };
 
-extern hsep_triple hsep_global_table[HSEP_N_MAX+1];
-
 void hsep_init(void);
 void hsep_reset(void);
 void hsep_close(void);
@@ -65,5 +63,9 @@
 void hsep_sanity_check(void);
 gboolean hsep_check_monotony(hsep_triple *table, unsigned int triples);
 unsigned int hsep_triples_to_send(hsep_triple *table, unsigned int triples);
+unsigned int hsep_get_table(hsep_triple *buffer, unsigned int maxtriples);
+unsigned int hsep_get_connection_table(struct gnutella_node *n,
+    hsep_triple *buffer, unsigned int maxtriples);
+
 
 #endif
Index: share.c
===================================================================
RCS file: /cvsroot/gtk-gnutella/gtk-gnutella-current/src/share.c,v
retrieving revision 1.132
diff -u -r1.132 share.c
--- share.c     14 Jan 2004 21:33:34 -0000      1.132
+++ share.c     27 Feb 2004 22:17:10 -0000
@@ -1148,6 +1148,22 @@
 
        in_share_scan = FALSE;
        gnet_prop_set_boolean_val(PROP_LIBRARY_REBUILDING, FALSE);
+
+       /*
+        * Tell HSEP about our shared resources.
+        *
+        * Note that currently HSEP only (re-)learns about resources when
+        * files are scanned, not when the number of upload slots is
+        * changed from 0 or to 0 in the GUI. We'd have to listen for
+        * that event and would have to call the same code as specified
+        * below. As shared files are scanned every 1000 seconds, this should
+        * be ok.
+        */
+
+       if (max_uploads > 0)
+               hsep_notify_shared(files_scanned, kbytes_scanned);
+       else
+               hsep_notify_shared(0, 0);
 }
 
 void share_close(void)
Index: shell.c
===================================================================
RCS file: /cvsroot/gtk-gnutella/gtk-gnutella-current/src/shell.c,v
retrieving revision 1.26
diff -u -r1.26 shell.c
--- shell.c     25 Jan 2004 20:20:46 -0000      1.26
+++ shell.c     27 Feb 2004 22:17:49 -0000
@@ -35,6 +35,8 @@
 #include "sockets.h"
 #include "settings.h"
 #include "gnet_property_priv.h"
+#include "nodes.h"
+#include "hsep.h"
 
 #include "search_gui.h" /* FIXME: remove this dependency */
 #include "override.h"          /* Must be the last header included */
@@ -78,7 +80,8 @@
        CMD_HELP,
        CMD_PRINT,
        CMD_SET,
-       CMD_WHATIS
+       CMD_WHATIS,
+       CMD_HORIZON
 };
 
 static struct {
@@ -92,7 +95,8 @@
        {CMD_HELP,   "HELP"},
        {CMD_PRINT,  "PRINT"},
        {CMD_SET,    "SET"},
-       {CMD_WHATIS, "WHATIS"}
+       {CMD_WHATIS, "WHATIS"},
+       {CMD_HORIZON, "HORIZON"}
 };
 
 
@@ -568,6 +572,94 @@
        return REPLY_ERROR;
 }
 
+/*
+ * shell_exec_horizon
+ *
+ * Displays horizon size information.
+ */
+static guint shell_exec_horizon(gnutella_shell_t *sh, const gchar *cmd) 
+{
+       guint i;
+       gchar buf[200];
+       guint maxlen[3];
+       hsep_triple globaltable[HSEP_N_MAX + 1];
+       guint64 *globalt;
+       guint nodes = 0;
+       guint hsep_nodes = 0;
+       GSList *sl;
+       
+       g_assert(sh);
+       g_assert(cmd);
+       g_assert(!IS_PROCESSING(sh));
+
+       sh->msg = "";
+
+       for (sl = (GSList *) node_all_nodes() ; sl; sl = g_slist_next(sl)) {
+               struct gnutella_node *n = (struct gnutella_node *) sl->data;
+
+               nodes++;
+               
+               if (!(n->attrs & NODE_A_CAN_HSEP))
+                       continue;
+
+               hsep_nodes ++;
+       }
+
+       gm_snprintf(buf, sizeof(buf) - 1,
+               "Horizon size (%d/%d nodes support HSEP):\n\n", hsep_nodes,nodes);
+
+       shell_write(sh, buf);
+
+       if (hsep_nodes == 0)
+       {
+               shell_write(sh, "No horizon information available.\n");
+               return REPLY_READY;
+       }
+       
+       hsep_get_table(globaltable, HSEP_N_MAX + 1);    
+       globalt = (gint64 *)&globaltable[1];
+
+       /*
+        * Determine maximum width of each column.
+        */
+       
+       maxlen[0] = 5;   /* length of Hosts */
+       maxlen[1] = 5;   /* length of Files */
+       maxlen[2] = 3;   /* length of KiB */
+
+       for (i=0; i < HSEP_N_MAX * 3; i++)
+       {
+               int n = gm_snprintf(buf, sizeof(buf) - 1, "%llu", *globalt++);         
 
+
+               if(n > maxlen[i % 3])
+                       maxlen[i % 3] = n;
+       }
+
+       gm_snprintf(buf, sizeof(buf) - 1, "Hops  %*s  %*s  %*s\n----------",
+               maxlen[0], "Hosts", maxlen[1], "Files", maxlen[2], "KiB");
+
+       shell_write(sh, buf);
+
+       for (i = maxlen[0] + maxlen[1] + maxlen[2];i > 0;i--)
+               shell_write(sh, "-");
+
+       shell_write(sh, "\n");
+
+       globalt = (gint64 *)&globaltable[1];
+       
+       for (i = 0; i < HSEP_N_MAX; i++)
+       {
+               gm_snprintf(buf, sizeof(buf) - 1, "%4d  %*llu  %*llu  %*llu\n", i+1,
+                       maxlen[0], globalt[HSEP_IDX_HOSTS],
+                       maxlen[1], globalt[HSEP_IDX_FILES],
+                       maxlen[2], globalt[HSEP_IDX_KIB]);
+
+               shell_write(sh, buf);
+               globalt += 3;
+       }               
+       
+       return REPLY_READY; 
+}
 
 /*
  * shell_exec:
@@ -597,6 +689,7 @@
                        "100-PRINT <property>\n"
                        "100-SET <property> <value>\n"
                        "100-WHATIS <property>\n"
+                       "100-HORIZON\n"
                        "100-QUIT\n"
                        "100-HELP\n");
                reply_code = REPLY_READY;
@@ -620,6 +713,9 @@
                break;
        case CMD_WHATIS:
                reply_code = shell_exec_whatis(sh, cmd+pos);
+               break;
+       case CMD_HORIZON:
+               reply_code = shell_exec_horizon(sh, cmd+pos);
                break;
        default:
                goto error;

Reply via email to