changeset 291:30e6b272d5eb draft

testnet and keypoololdest added to RPC getinfo output. And RPC now sends proper HTTP Date headers. git-svn-id: https://bitcoin.svn.sourceforge.net/svnroot/bitcoin/trunk@172 1a98c847-1fd6-4fd8-948a-caf3550aa51b
author gavinandresen <gavinandresen@1a98c847-1fd6-4fd8-948a-caf3550aa51b>
date Fri, 22 Oct 2010 15:15:20 +0000
parents 3026ce829889
children 4bba9e8b9d42 e9032781dde2
files db.cpp db.h headers.h rpc.cpp serialize.h
diffstat 5 files changed, 31 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/db.cpp
+++ b/db.cpp
@@ -908,3 +908,12 @@
     KeepKey(nIndex);
     return keypool.vchPubKey;
 }
+
+int64 CWalletDB::GetOldestKeyPoolTime()
+{
+    int64 nIndex = 0;
+    CKeyPool keypool;
+    ReserveKeyFromKeyPool(nIndex, keypool);
+    ReturnKey(nIndex);
+    return keypool.nTime;
+}
--- a/db.h
+++ b/db.h
@@ -432,6 +432,7 @@
     friend class CReserveKey;
 public:
     vector<unsigned char> GetKeyFromKeyPool();
+    int64 GetOldestKeyPoolTime();
 };
 
 bool LoadWallet(bool& fFirstRunRet);
--- a/headers.h
+++ b/headers.h
@@ -43,6 +43,7 @@
 #include <db_cxx.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <time.h>
 #include <math.h>
 #include <limits.h>
 #include <float.h>
--- a/rpc.cpp
+++ b/rpc.cpp
@@ -261,6 +261,8 @@
     obj.push_back(Pair("genproclimit",  (int)(fLimitProcessors ? nLimitProcessors : -1)));
     obj.push_back(Pair("difficulty",    (double)GetDifficulty()));
     obj.push_back(Pair("hashespersec",  gethashespersec(params, false)));
+    obj.push_back(Pair("testnet",       fTestNet));
+    obj.push_back(Pair("keypoololdest", (boost::int64_t)CWalletDB().GetOldestKeyPoolTime()));
     obj.push_back(Pair("errors",        GetWarnings("statusbar")));
     return obj;
 }
@@ -767,12 +769,22 @@
     return s.str();
 }
 
+string rfc1123Time()
+{
+    char buffer[32];
+    time_t now;
+    time(&now);
+    struct tm* now_gmt = gmtime(&now);
+    strftime(buffer, sizeof(buffer), "%a, %d %b %Y %H:%M:%S %Z", now_gmt);
+    return string(buffer);
+}
+
 string HTTPReply(int nStatus, const string& strMsg)
 {
     if (nStatus == 401)
-        return "HTTP/1.0 401 Authorization Required\r\n"
-            "Server: HTTPd/1.0\r\n"
-            "Date: Sat, 08 Jul 2006 12:04:08 GMT\r\n"
+        return strprintf("HTTP/1.0 401 Authorization Required\r\n"
+            "Date: %s\r\n"
+            "Server: bitcoin-json-rpc\r\n"
             "WWW-Authenticate: Basic realm=\"jsonrpc\"\r\n"
             "Content-Type: text/html\r\n"
             "Content-Length: 311\r\n"
@@ -785,7 +797,7 @@
             "<META HTTP-EQUIV='Content-Type' CONTENT='text/html; charset=ISO-8859-1'>\r\n"
             "</HEAD>\r\n"
             "<BODY><H1>401 Unauthorized.</H1></BODY>\r\n"
-            "</HTML>\r\n";
+            "</HTML>\r\n", rfc1123Time().c_str());
     string strStatus;
          if (nStatus == 200) strStatus = "OK";
     else if (nStatus == 400) strStatus = "Bad Request";
@@ -793,15 +805,16 @@
     else if (nStatus == 500) strStatus = "Internal Server Error";
     return strprintf(
             "HTTP/1.1 %d %s\r\n"
+            "Date: %s\r\n"
             "Connection: close\r\n"
             "Content-Length: %d\r\n"
             "Content-Type: application/json\r\n"
-            "Date: Sat, 08 Jul 2006 12:04:08 GMT\r\n"
-            "Server: json-rpc/1.0\r\n"
+            "Server: bitcoin-json-rpc/1.0\r\n"
             "\r\n"
             "%s",
         nStatus,
         strStatus.c_str(),
+        rfc1123Time().c_str(),
         strMsg.size(),
         strMsg.c_str());
 }
--- a/serialize.h
+++ b/serialize.h
@@ -22,7 +22,7 @@
 class CAutoFile;
 static const unsigned int MAX_SIZE = 0x02000000;
 
-static const int VERSION = 31400;
+static const int VERSION = 31401;
 static const char* pszSubVer = "";