Simplify G-line code somewhat. Generate better output for ?gtrace print.
authorMichael Poole <mdpoole@troilus.org>
Thu, 18 Mar 2010 02:53:30 +0000 (22:53 -0400)
committerMichael Poole <mdpoole@troilus.org>
Thu, 18 Mar 2010 02:53:30 +0000 (22:53 -0400)
A hub with a negative clock skew will cause adverse results (like the
issued or lastmod times being in the network's future).  That will be
fixed in ircu.

src/gline.c (gline_for_p): Rewrite to just compare the G-line pointer.
  (gline_add): Use that instead.  Move "issued" back in time if the
    lastmod time is earlier than we know the G-line was issued.
src/opserv.c (OSMSG_GTRACE_FOREVER): New format string.
  (OSMSG_GTRACE_EXPIRED): Likewise.
  (gtrace_print_func): Use the appropriate OSMSG_GTRACE_* string.

src/gline.c
src/opserv.c

index 0b2ed9bb36f25d4ea6e1c5ef137f0aee7a8beb6a..a1cb2504ea81e790e2e5c509dc54ab38d349207c 100644 (file)
@@ -72,10 +72,9 @@ free_gline(struct gline *ent)
 }
 
 static int
-gline_for_p(UNUSED_ARG(void *key), void *data, void *extra)
+gline_equal_p(UNUSED_ARG(void *key), void *data, void *extra)
 {
-    struct gline *ge = data;
-    return !irccasecmp(ge->target, extra);
+    return data == extra;
 }
 
 static void
@@ -125,13 +124,15 @@ gline_add(const char *issuer, const char *target, unsigned long duration, const
         lifetime = expires;
     ent = dict_find(gline_dict, target, NULL);
     if (ent) {
-        heap_remove_pred(gline_heap, gline_for_p, (char*)target);
+        heap_remove_pred(gline_heap, gline_equal_p, ent);
+        if (ent->issued > lastmod)
+            ent->issued = lastmod;
+        if (ent->lastmod < lastmod)
+            ent->lastmod = lastmod;
         if (ent->expires != expires)
             ent->expires = expires;
         if (ent->lifetime < lifetime)
             ent->lifetime = lifetime;
-        if (ent->lastmod < lastmod)
-            ent->lastmod = lastmod;
         if (strcmp(ent->issuer, issuer)) {
             free(ent->issuer);
             ent->issuer = strdup(issuer);
index 4bc6be2791ba476c1bc0991a0d0b81460598e2ee..ec4b57fc58b6589286f6e654390708f52dacc2e2 100644 (file)
@@ -202,6 +202,8 @@ static const struct message_entry msgtab[] = {
     { "OSMSG_LOG_SEARCH_RESULTS", "The following log entries were found:" },
     { "OSMSG_GSYNC_RUNNING", "Synchronizing glines from %s." },
     { "OSMSG_GTRACE_FORMAT", "%1$s (issued %2$s ago by %3$s, lastmod %4$s ago, expires %5$s, lifetime %7$s): %6$s" },
+    { "OSMSG_GTRACE_FOREVER", "%1$s (issued %2$s ago by %3$s, lastmod %4$s ago, never expires, lifetime %7$s): %6$s" },
+    { "OSMSG_GTRACE_EXPIRED", "%1$s (issued %2$s ago by %3$s, lastmod %4$s ago, expired %5$s ago, lifetime %7$s): %6$s" },
     { "OSMSG_GAG_APPLIED", "Gagged $b%s$b, affecting %d users." },
     { "OSMSG_GAG_ADDED", "Gagged $b%s$b." },
     { "OSMSG_REDUNDANT_GAG", "Gag $b%s$b is redundant." },
@@ -3808,12 +3810,17 @@ gtrace_print_func(struct gline *gline, void *extra)
         intervalString(lastmod, now - gline->lastmod, xtra->user->handle_info);
     else
         strcpy(lastmod, "<unknown>");
-    if (gline->expires)
-        intervalString(expires, gline->expires - now, xtra->user->handle_info);
-    else
-        strcpy(expires, "never");
     intervalString(lifetime, gline->lifetime - now, xtra->user->handle_info);
-    send_message(xtra->user, opserv, "OSMSG_GTRACE_FORMAT", gline->target, issued, gline->issuer, lastmod, expires, gline->reason, lifetime);
+    if (gline->expires < now) {
+        intervalString(expires, now - gline->expires, xtra->user->handle_info);
+        send_message(xtra->user, opserv, "OSMSG_GTRACE_EXPIRED", gline->target, issued, gline->issuer, lastmod, expires, gline->reason, lifetime);
+    } else if (gline->expires) {
+        intervalString(expires, gline->expires - now, xtra->user->handle_info);
+        send_message(xtra->user, opserv, "OSMSG_GTRACE_FORMAT", gline->target, issued, gline->issuer, lastmod, expires, gline->reason, lifetime);
+    } else {
+        send_message(xtra->user, opserv, "OSMSG_GTRACE_FOREVER", gline->target, issued, gline->issuer, lastmod, NULL, gline->reason, lifetime);
+
+    }
 }
 
 static MODCMD_FUNC(cmd_stats_glines) {