MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / ThreadMapPort

Function ThreadMapPort

src/net.cpp:1479–1558  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1477static CThreadInterrupt g_upnp_interrupt;
1478static std::thread g_upnp_thread;
1479static void ThreadMapPort()
1480{
1481 std::string port = strprintf("%u", GetListenPort());
1482 const char * multicastif = nullptr;
1483 const char * minissdpdpath = nullptr;
1484 struct UPNPDev * devlist = nullptr;
1485 char lanaddr[64];
1486
1487#ifndef UPNPDISCOVER_SUCCESS
1488 /* miniupnpc 1.5 */
1489 devlist = upnpDiscover(2000, multicastif, minissdpdpath, 0);
1490#elif MINIUPNPC_API_VERSION < 14
1491 /* miniupnpc 1.6 */
1492 int error = 0;
1493 devlist = upnpDiscover(2000, multicastif, minissdpdpath, 0, 0, &error);
1494#else
1495 /* miniupnpc 1.9.20150730 */
1496 int error = 0;
1497 devlist = upnpDiscover(2000, multicastif, minissdpdpath, 0, 0, 2, &error);
1498#endif
1499
1500 struct UPNPUrls urls;
1501 struct IGDdatas data;
1502 int r;
1503
1504 r = UPNP_GetValidIGD(devlist, &urls, &data, lanaddr, sizeof(lanaddr));
1505 if (r == 1)
1506 {
1507 if (fDiscover) {
1508 char externalIPAddress[40];
1509 r = UPNP_GetExternalIPAddress(urls.controlURL, data.first.servicetype, externalIPAddress);
1510 if(r != UPNPCOMMAND_SUCCESS)
1511 LogPrintf("UPnP: GetExternalIPAddress() returned %d\n", r);
1512 else
1513 {
1514 if(externalIPAddress[0])
1515 {
1516 CNetAddr resolved;
1517 if(LookupHost(externalIPAddress, resolved, false)) {
1518 LogPrintf("UPnP: ExternalIPAddress = %s\n", resolved.ToString().c_str());
1519 AddLocal(resolved, LOCAL_UPNP);
1520 }
1521 }
1522 else
1523 LogPrintf("UPnP: GetExternalIPAddress failed.\n");
1524 }
1525 }
1526
1527 std::string strDesc = "Bitcoin " + FormatFullVersion();
1528
1529 do {
1530#ifndef UPNPDISCOVER_SUCCESS
1531 /* miniupnpc 1.5 */
1532 r = UPNP_AddPortMapping(urls.controlURL, data.first.servicetype,
1533 port.c_str(), port.c_str(), lanaddr, strDesc.c_str(), "TCP", 0);
1534#else
1535 /* miniupnpc 1.6 */
1536 r = UPNP_AddPortMapping(urls.controlURL, data.first.servicetype,

Callers

nothing calls this directly

Calls 6

GetListenPortFunction · 0.85
LookupHostFunction · 0.85
AddLocalFunction · 0.85
FormatFullVersionFunction · 0.85
sleep_forMethod · 0.80
ToStringMethod · 0.45

Tested by

no test coverage detected