aboutsummaryrefslogtreecommitdiff
path: root/src/net.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/net.cpp')
-rw-r--r--src/net.cpp54
1 files changed, 26 insertions, 28 deletions
diff --git a/src/net.cpp b/src/net.cpp
index aaf7883e51..76e44a6cf8 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -233,8 +233,8 @@ bool AddLocal(const CService& addr, int nScore)
bool fAlready = mapLocalHost.count(addr) > 0;
LocalServiceInfo &info = mapLocalHost[addr];
if (!fAlready || nScore >= info.nScore) {
- info.nScore = nScore;
- info.nPort = addr.GetPort() + (fAlready ? 1 : 0);
+ info.nScore = nScore + (fAlready ? 1 : 0);
+ info.nPort = addr.GetPort();
}
SetReachable(addr.GetNetwork());
}
@@ -1020,9 +1020,7 @@ void ThreadMapPort2(void* parg)
{
printf("ThreadMapPort started\n");
- char port[6];
- sprintf(port, "%d", GetListenPort());
-
+ std::string port = strprintf("%d", GetListenPort());
const char * multicastif = 0;
const char * minissdpdpath = 0;
struct UPNPDev * devlist = 0;
@@ -1065,23 +1063,23 @@ void ThreadMapPort2(void* parg)
#ifndef UPNPDISCOVER_SUCCESS
/* miniupnpc 1.5 */
r = UPNP_AddPortMapping(urls.controlURL, data.first.servicetype,
- port, port, lanaddr, strDesc.c_str(), "TCP", 0);
+ port.c_str(), port.c_str(), 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");
+ port.c_str(), port.c_str(), 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));
+ port.c_str(), port.c_str(), lanaddr, r, strupnperror(r));
else
printf("UPnP Port Mapping successful.\n");
int i = 1;
loop {
if (fShutdown || !fUseUPnP)
{
- r = UPNP_DeletePortMapping(urls.controlURL, data.first.servicetype, port, "TCP", 0);
+ r = UPNP_DeletePortMapping(urls.controlURL, data.first.servicetype, port.c_str(), "TCP", 0);
printf("UPNP_DeletePortMapping() returned : %d\n", r);
freeUPNPDevlist(devlist); devlist = 0;
FreeUPNPUrls(&urls);
@@ -1092,16 +1090,16 @@ void ThreadMapPort2(void* parg)
#ifndef UPNPDISCOVER_SUCCESS
/* miniupnpc 1.5 */
r = UPNP_AddPortMapping(urls.controlURL, data.first.servicetype,
- port, port, lanaddr, strDesc.c_str(), "TCP", 0);
+ port.c_str(), port.c_str(), 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");
+ port.c_str(), port.c_str(), 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));
+ port.c_str(), port.c_str(), lanaddr, r, strupnperror(r));
else
printf("UPnP Port Mapping successful.\n");;
}
@@ -1125,7 +1123,7 @@ void MapPort()
{
if (fUseUPnP && vnThreadsRunning[THREAD_UPNP] < 1)
{
- if (!CreateThread(ThreadMapPort, NULL))
+ if (!NewThread(ThreadMapPort, NULL))
printf("Error: ThreadMapPort(ThreadMapPort) failed\n");
}
}
@@ -1887,7 +1885,7 @@ void static Discover()
// Don't use external IPv4 discovery, when -onlynet="IPv6"
if (!IsLimited(NET_IPV4))
- CreateThread(ThreadGetMyExternalIP, NULL);
+ NewThread(ThreadGetMyExternalIP, NULL);
}
void StartNode(void* parg)
@@ -1913,36 +1911,36 @@ void StartNode(void* parg)
if (!GetBoolArg("-dnsseed", true))
printf("DNS seeding disabled\n");
else
- if (!CreateThread(ThreadDNSAddressSeed, NULL))
- printf("Error: CreateThread(ThreadDNSAddressSeed) failed\n");
+ if (!NewThread(ThreadDNSAddressSeed, NULL))
+ printf("Error: NewThread(ThreadDNSAddressSeed) failed\n");
// Map ports with UPnP
if (fUseUPnP)
MapPort();
// Get addresses from IRC and advertise ours
- if (!CreateThread(ThreadIRCSeed, NULL))
- printf("Error: CreateThread(ThreadIRCSeed) failed\n");
+ if (!NewThread(ThreadIRCSeed, NULL))
+ printf("Error: NewThread(ThreadIRCSeed) failed\n");
// Send and receive from sockets, accept connections
- if (!CreateThread(ThreadSocketHandler, NULL))
- printf("Error: CreateThread(ThreadSocketHandler) failed\n");
+ if (!NewThread(ThreadSocketHandler, NULL))
+ printf("Error: NewThread(ThreadSocketHandler) failed\n");
// Initiate outbound connections from -addnode
- if (!CreateThread(ThreadOpenAddedConnections, NULL))
- printf("Error: CreateThread(ThreadOpenAddedConnections) failed\n");
+ if (!NewThread(ThreadOpenAddedConnections, NULL))
+ printf("Error: NewThread(ThreadOpenAddedConnections) failed\n");
// Initiate outbound connections
- if (!CreateThread(ThreadOpenConnections, NULL))
- printf("Error: CreateThread(ThreadOpenConnections) failed\n");
+ if (!NewThread(ThreadOpenConnections, NULL))
+ printf("Error: NewThread(ThreadOpenConnections) failed\n");
// Process messages
- if (!CreateThread(ThreadMessageHandler, NULL))
- printf("Error: CreateThread(ThreadMessageHandler) failed\n");
+ if (!NewThread(ThreadMessageHandler, NULL))
+ printf("Error: NewThread(ThreadMessageHandler) failed\n");
// Dump network addresses
- if (!CreateThread(ThreadDumpAddress, NULL))
- printf("Error; CreateThread(ThreadDumpAddress) failed\n");
+ if (!NewThread(ThreadDumpAddress, NULL))
+ printf("Error; NewThread(ThreadDumpAddress) failed\n");
// Generate coins in the background
GenerateBitcoins(GetBoolArg("-gen", false), pwalletMain);