aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Corallo <matt@bluematt.me>2012-01-31 17:36:25 -0500
committerMatt Corallo <matt@bluematt.me>2012-01-31 17:42:15 -0500
commit177dbcaace432f46b191add5c26226dbaac2c81c (patch)
tree86cb53e2cae8cbe5443608fd3920a0351e4468a1
parentc52296a73e5222628bf6a03eaf727622594bf464 (diff)
Fix UPnP by reannouncing every 20 minutes.
-rw-r--r--src/net.cpp24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/net.cpp b/src/net.cpp
index a0e093dcf0..66c9218cd0 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -967,11 +967,11 @@ void ThreadMapPort2(void* parg)
{
string strDesc = "Bitcoin " + FormatFullVersion();
#ifndef UPNPDISCOVER_SUCCESS
- /* miniupnpc 1.5 */
+ /* miniupnpc 1.5 */
r = UPNP_AddPortMapping(urls.controlURL, data.first.servicetype,
port, port, lanaddr, strDesc.c_str(), "TCP", 0);
#else
- /* miniupnpc 1.6 */
+ /* miniupnpc 1.6 */
r = UPNP_AddPortMapping(urls.controlURL, data.first.servicetype,
port, port, lanaddr, strDesc.c_str(), "TCP", 0, "0");
#endif
@@ -981,6 +981,7 @@ void ThreadMapPort2(void* parg)
port, port, lanaddr, r, strupnperror(r));
else
printf("UPnP Port Mapping successful.\n");
+ int i = 1;
loop {
if (fShutdown || !fUseUPnP)
{
@@ -990,7 +991,26 @@ void ThreadMapPort2(void* parg)
FreeUPNPUrls(&urls);
return;
}
+ if (i % 600 == 0) // Refresh every 20 minutes
+ {
+#ifndef UPNPDISCOVER_SUCCESS
+ /* miniupnpc 1.5 */
+ r = UPNP_AddPortMapping(urls.controlURL, data.first.servicetype,
+ port, port, lanaddr, strDesc.c_str(), "TCP", 0);
+#else
+ /* miniupnpc 1.6 */
+ r = UPNP_AddPortMapping(urls.controlURL, data.first.servicetype,
+ port, port, lanaddr, strDesc.c_str(), "TCP", 0, "0");
+#endif
+
+ if(r!=UPNPCOMMAND_SUCCESS)
+ printf("AddPortMapping(%s, %s, %s) failed with code %d (%s)\n",
+ port, port, lanaddr, r, strupnperror(r));
+ else
+ printf("UPnP Port Mapping successful.\n");;
+ }
Sleep(2000);
+ i++;
}
} else {
printf("No valid UPnP IGDs found\n");