DNS seeding
authorJeff Garzik <jeff@garzik.org>
Wed, 9 Mar 2011 03:40:50 +0000 (22:40 -0500)
committerJeff Garzik <jgarzik@pobox.com>
Wed, 9 Mar 2011 03:40:50 +0000 (22:40 -0500)
init.cpp
net.cpp
net.h

index 9c84dca..f74a143 100644 (file)
--- a/init.cpp
+++ b/init.cpp
@@ -416,6 +416,9 @@ bool AppInit2(int argc, char* argv[])
         }
     }
 
+    if (mapArgs.count("-dnsseed"))
+        DNSAddressSeed();
+
     if (mapArgs.count("-paytxfee"))
     {
         if (!ParseMoney(mapArgs["-paytxfee"], nTransactionFee))
diff --git a/net.cpp b/net.cpp
index d18b63e..798c7e5 100644 (file)
--- a/net.cpp
+++ b/net.cpp
@@ -857,7 +857,34 @@ void ThreadSocketHandler2(void* parg)
 
 
 
+static const char *strDNSSeed[] = {
+    "bitseed.xf2.org",
+};
 
+void DNSAddressSeed()
+{
+    int found = 0;
+
+    printf("Loading addresses from DNS seeds (could take a while)\n");
+
+    for (int seed_idx = 0; seed_idx < ARRAYLEN(strDNSSeed); seed_idx++) {
+        struct hostent* phostent = gethostbyname(strDNSSeed[seed_idx]);
+        if (!phostent)
+            continue;
+
+        for (int host = 0; phostent->h_addr_list[host] != NULL; host++) {
+            CAddress addr(*(unsigned int*)phostent->h_addr_list[host],
+                          GetDefaultPort(), NODE_NETWORK);
+            addr.nTime = 0;
+            if (addr.IsValid() && addr.GetByte(3) != 127) {
+                AddAddress(addr);
+                found++;
+            }
+        }
+    }
+
+    printf("%d addresses found from DNS seeds\n");
+}
 
 
 
diff --git a/net.h b/net.h
index f070816..05ef5e0 100644 (file)
--- a/net.h
+++ b/net.h
@@ -30,6 +30,7 @@ CNode* FindNode(unsigned int ip);
 CNode* ConnectNode(CAddress addrConnect, int64 nTimeout=0);
 void AbandonRequests(void (*fn)(void*, CDataStream&), void* param1);
 bool AnySubscribed(unsigned int nChannel);
+void DNSAddressSeed();
 bool BindListenPort(string& strError=REF(string()));
 void StartNode(void* parg);
 bool StopNode();