Ticket #25511: b25511-001.patch

File b25511-001.patch, 3.9 KB (added by neel, 15 months ago)

Patch (Revision 1)

  • src/common/util.c

    From 078cdeebf3da5478c6b18670fb5de5ddbd7d8386 Mon Sep 17 00:00:00 2001
    From: Neel Chauhan <neel@neelc.org>
    Date: Mon, 2 Apr 2018 20:57:50 -0400
    Subject: [PATCH 1/2] Add format_local_iso_time_nospace()
    
    ---
     src/common/util.c | 9 +++++++++
     src/common/util.h | 1 +
     2 files changed, 10 insertions(+)
    
    diff --git a/src/common/util.c b/src/common/util.c
    index f63b12167..9003480b6 100644
    a b format_iso_time(char *buf, time_t t) 
    18211821  strftime(buf, ISO_TIME_LEN+1, "%Y-%m-%d %H:%M:%S", tor_gmtime_r(&t, &tm));
    18221822}
    18231823
     1824/** As format_local_iso_time, but use the yyyy-mm-ddThh:mm:ss format to avoid
     1825 * embedding an internal space. */
     1826void
     1827format_local_iso_time_nospace(char *buf, time_t t)
     1828{
     1829  format_local_iso_time(buf, t);
     1830  buf[10] = 'T';
     1831}
     1832
    18241833/** As format_iso_time, but use the yyyy-mm-ddThh:mm:ss format to avoid
    18251834 * embedding an internal space. */
    18261835void
  • src/common/util.h

    diff --git a/src/common/util.h b/src/common/util.h
    index aeed8e823..7ec8e6728 100644
    a b int parse_rfc1123_time(const char *buf, time_t *t); 
    269269#define ISO_TIME_USEC_LEN (ISO_TIME_LEN+7)
    270270void format_local_iso_time(char *buf, time_t t);
    271271void format_iso_time(char *buf, time_t t);
     272void format_local_iso_time_nospace(char *buf, time_t t);
    272273void format_iso_time_nospace(char *buf, time_t t);
    273274void format_iso_time_nospace_usec(char *buf, const struct timeval *tv);
    274275int parse_iso_time_(const char *cp, time_t *t, int strict, int nospace);
  • new file changes/ticket25511

    -- 
    2.16.3
    
    
    From 64878021b706ee7a68d5c767794c179f7746b3bd Mon Sep 17 00:00:00 2001
    From: Neel Chauhan <neel@neelc.org>
    Date: Mon, 2 Apr 2018 20:59:34 -0400
    Subject: [PATCH 2/2] Add GETINFO current-time/{local,utc} command to
     ControlPort
    
    ---
     changes/ticket25511 |  5 +++++
     src/or/control.c    | 28 ++++++++++++++++++++++++++++
     2 files changed, 33 insertions(+)
     create mode 100644 changes/ticket25511
    
    diff --git a/changes/ticket25511 b/changes/ticket25511
    new file mode 100644
    index 000000000..0a24e265c
    - +  
     1  o Minor features (control port):
     2    - Introduce GETINFO "current-time/{local,utc}" to return the local
     3      and UTC times respectively in ISO format. This helps a controller
     4      like Tor Browser detect a time-related error. Closes ticket 25511.
     5      Patch by Neel Chauhan.
  • src/or/control.c

    diff --git a/src/or/control.c b/src/or/control.c
    index 5cac0e172..97f85e962 100644
    a b getinfo_helper_listeners(control_connection_t *control_conn, 
    19361936  return 0;
    19371937}
    19381938
     1939/** Implementation helper for GETINFO: answers requests for information about
     1940 * the current time in both local and UTF forms. */
     1941static int
     1942getinfo_helper_current_time(control_connection_t *control_conn,
     1943                         const char *question,
     1944                         char **answer, const char **errmsg)
     1945{
     1946  (void)control_conn;
     1947  (void)errmsg;
     1948
     1949  struct timeval now;
     1950  tor_gettimeofday(&now);
     1951  char timebuf[ISO_TIME_LEN+1];
     1952
     1953  if (!strcmp(question, "current-time/local"))
     1954    format_local_iso_time_nospace(timebuf, (time_t)now.tv_sec);
     1955  else if (!strcmp(question, "current-time/utc"))
     1956    format_iso_time_nospace(timebuf, (time_t)now.tv_sec);
     1957  else
     1958    return 0;
     1959
     1960  *answer = tor_strdup(timebuf);
     1961  return 0;
     1962}
     1963
    19391964/** Implementation helper for GETINFO: knows the answers for questions about
    19401965 * directory information. */
    19411966STATIC int
    static const getinfo_item_t getinfo_items[] = { 
    30783103  DOC("config/defaults",
    30793104      "List of default values for configuration options. "
    30803105      "See also config/names"),
     3106  PREFIX("current-time/", current_time, "Current time."),
     3107  DOC("current-time/local", "Current time on the local system."),
     3108  DOC("current-time/utc", "Current UTC time."),
    30813109  PREFIX("downloads/networkstatus/", downloads,
    30823110         "Download statuses for networkstatus objects"),
    30833111  DOC("downloads/networkstatus/ns",