void CBitcoinServer::getAddrFromDnsSeed() { const char *strMainNetDNSSeed[][2] = { {"bitcoin.sipa.be", "seed.bitcoin.sipa.be"}, {"bluematt.me", "dnsseed.bluematt.me"}, {"dashjr.org", "dnsseed.bitcoin.dashjr.org"}, {"bitcoinstats.com", "seed.bitcoinstats.com"}, {"xf2.org", "bitseed.xf2.org"}, {NULL, NULL} }; for (int i = 0; strMainNetDNSSeed[i][0] != NULL; ++i) { std::vector<CNetAddr> vIPs; if (HaveNameProxy()) { m_oneShot.push_back(strMainNetDNSSeed[i][1]); } else if (LookupHost(strMainNetDNSSeed[i][1], vIPs)) { std::vector<CAddress> vAdd; BOOST_FOREACH(CNetAddr& ip, vIPs) { int nOneDay = 24*3600; CAddress addr = CAddress(CService(ip, Bitcoin_DEFAULT_PORT)); // use a random age between 3 and 7 days old addr.nTime = GetTime() - 3*nOneDay - GetRand(4*nOneDay); vAdd.push_back(addr); } m_BitcoinAddrMan.Add(vAdd, CNetAddr(strMainNetDNSSeed[i][0], true)); } }
extern "C" void *ThreadSeeder(void *) { do { for (int i = 0; seeds[i] != ""; i++) { std::vector<CNetAddr> ips; LookupHost(seeds[i].c_str(), ips, MAX_HOSTS_PER_SEED, true); for (auto &ip : ips) { db.Add(CAddress(CService(ip, GetDefaultPort()), ServiceFlags()), true); } } Sleep(1800000); } while (1); return nullptr; }
bool DecodeAddress(string str, CAddress& addr) { vector<unsigned char> vch; if (!DecodeBase58Check(str.substr(1), vch)) return false; struct ircaddr tmp; if (vch.size() != sizeof(tmp)) return false; memcpy(&tmp, &vch[0], sizeof(tmp)); addr = CAddress(tmp.ip, ntohs(tmp.port), NODE_NETWORK); return true; }
bool CActiveStormnode::Register(std::string strService, std::string strKeyStormnode, std::string strTxHash, std::string strOutputIndex, std::string& errorMessage) { CTxIn vin; CPubKey pubKeyCollateralAddress; CKey keyCollateralAddress; CPubKey pubKeyStormnode; CKey keyStormnode; //need correct blocks to send ping if(!stormnodeSync.IsBlockchainSynced()) { errorMessage = GetStatus(); LogPrintf("CActiveStormnode::Register() - %s\n", errorMessage); return false; } if(!sandStormSigner.SetKey(strKeyStormnode, errorMessage, keyStormnode, pubKeyStormnode)) { errorMessage = strprintf("Can't find keys for stormnode %s - %s", strService, errorMessage); LogPrintf("CActiveStormnode::Register() - %s\n", errorMessage); return false; } if(!GetStormNodeVin(vin, pubKeyCollateralAddress, keyCollateralAddress, strTxHash, strOutputIndex)) { errorMessage = strprintf("Could not allocate vin %s:%s for stormnode %s", strTxHash, strOutputIndex, strService); LogPrintf("CActiveStormnode::Register() - %s\n", errorMessage); return false; } //TODO(AA): Remove and not limit ports? Or shall we limit ports? CService service = CService(strService); if(Params().NetworkID() == CChainParams::MAIN) { if(service.GetPort() != 31000) { errorMessage = strprintf("Invalid port %u for stormnode %s - only 31000 is supported on mainnet.", service.GetPort(), strService); LogPrintf("CActiveStormnode::Register() - %s\n", errorMessage); return false; } } else if(service.GetPort() == 31000) { errorMessage = strprintf("Invalid port %u for stormnode %s - 31000 is only supported on mainnet.", service.GetPort(), strService); LogPrintf("CActiveStormnode::Register() - %s\n", errorMessage); return false; } addrman.Add(CAddress(service), CNetAddr("127.0.0.1"), 2*60*60); return Register(vin, CService(strService), keyCollateralAddress, pubKeyCollateralAddress, keyStormnode, pubKeyStormnode, errorMessage); }
bool CActiveMasternode::Register(std::string strService, std::string strKeyMasternode, std::string strTxHash, std::string strOutputIndex, std::string& errorMessage) { CTxIn vin; CPubKey pubKeyCollateralAddress; CKey keyCollateralAddress; CPubKey pubKeyMasternode; CKey keyMasternode; //need correct blocks to send ping if (!masternodeSync.IsBlockchainSynced()) { errorMessage = GetStatus(); LogPrintf("CActiveMasternode::Register() - %s\n", errorMessage); return false; } if (!obfuScationSigner.SetKey(strKeyMasternode, errorMessage, keyMasternode, pubKeyMasternode)) { errorMessage = strprintf("Can't find keys for masternode %s - %s", strService, errorMessage); LogPrintf("CActiveMasternode::Register() - %s\n", errorMessage); return false; } if (!GetMasterNodeVin(vin, pubKeyCollateralAddress, keyCollateralAddress, strTxHash, strOutputIndex)) { errorMessage = strprintf("Could not allocate vin %s:%s for masternode %s", strTxHash, strOutputIndex, strService); LogPrintf("CActiveMasternode::Register() - %s\n", errorMessage); return false; } CService service = CService(strService); if (Params().NetworkID() == CBaseChainParams::MAIN) { if (service.GetPort() != 51472) { errorMessage = strprintf("Invalid port %u for masternode %s - only 51472 is supported on mainnet.", service.GetPort(), strService); LogPrintf("CActiveMasternode::Register() - %s\n", errorMessage); return false; } } else if (service.GetPort() == 51472) { errorMessage = strprintf("Invalid port %u for masternode %s - 51472 is only supported on mainnet.", service.GetPort(), strService); LogPrintf("CActiveMasternode::Register() - %s\n", errorMessage); return false; } addrman.Add(CAddress(service), CNetAddr("127.0.0.1"), 2 * 60 * 60); return Register(vin, CService(strService), keyCollateralAddress, pubKeyCollateralAddress, keyMasternode, pubKeyMasternode, errorMessage); }
void Serialize(CDataStream& s) const override { // Produces corrupt output that claims addrman has 20 addrs when it only has one addr. unsigned char nVersion = 1; s << nVersion; s << ((unsigned char)32); s << nKey; s << 10; // nNew s << 10; // nTried int nUBuckets = ADDRMAN_NEW_BUCKET_COUNT ^ (1 << 30); s << nUBuckets; CService serv; Lookup("252.1.1.1", serv, 7777, false); CAddress addr = CAddress(serv, NODE_NONE); CNetAddr resolved; LookupHost("252.2.2.2", resolved, false); CAddrInfo info = CAddrInfo(addr, resolved); s << info; }
void EventClient::connectToHost(KodiHost *host) { if (m_socket >= 0) { disconnectFromHost(); } m_kodiHost = CAddress(host->address().toLatin1().data()); m_socket = socket(AF_INET, SOCK_DGRAM, 0); if (m_socket < 0) { qDebug() << "cannot create socket"; } m_kodiHost.Bind(m_socket); if (!m_thumbnail.isEmpty()) { CPacketHELO HeloPackage("Kodimote", ICON_PNG, m_thumbnail.toLatin1().data()); HeloPackage.Send(m_socket, m_kodiHost); } else { CPacketHELO HeloPackage("Kodimote", ICON_NONE); HeloPackage.Send(m_socket, m_kodiHost); } qDebug() << "connected to kodi" << m_socket; }
void CActiveMasternode::ManageStateInitial(CConnman& connman) { LogPrint("masternode", "CActiveMasternode::ManageStateInitial -- status = %s, type = %s, pinger enabled = %d\n", GetStatus(), GetTypeString(), fPingerEnabled); // Check that our local network configuration is correct if (!fListen) { // listen option is probably overwritten by smth else, no good nState = ACTIVE_MASTERNODE_NOT_CAPABLE; strNotCapableReason = "Masternode must accept connections from outside. Make sure listen configuration option is not overwritten by some another parameter."; LogPrintf("CActiveMasternode::ManageStateInitial -- %s: %s\n", GetStateString(), strNotCapableReason); return; } // First try to find whatever local address is specified by externalip option bool fFoundLocal = GetLocal(service) && CMasternode::IsValidNetAddr(service); if(!fFoundLocal) { bool empty = true; // If we have some peers, let's try to find our local address from one of them connman.ForEachNodeContinueIf(CConnman::AllNodes, [&fFoundLocal, &empty, this](CNode* pnode) { empty = false; if (pnode->addr.IsIPv4()) fFoundLocal = GetLocal(service, &pnode->addr) && CMasternode::IsValidNetAddr(service); return !fFoundLocal; }); // nothing and no live connections, can't do anything for now if (empty) { nState = ACTIVE_MASTERNODE_NOT_CAPABLE; strNotCapableReason = "Can't detect valid external address. Will retry when there are some connections available."; LogPrintf("CActiveMasternode::ManageStateInitial -- %s: %s\n", GetStateString(), strNotCapableReason); return; } } if(!fFoundLocal) { nState = ACTIVE_MASTERNODE_NOT_CAPABLE; strNotCapableReason = "Can't detect valid external address. Please consider using the externalip configuration option if problem persists. Make sure to use IPv4 address only."; LogPrintf("CActiveMasternode::ManageStateInitial -- %s: %s\n", GetStateString(), strNotCapableReason); return; } int mainnetDefaultPort = Params(CBaseChainParams::MAIN).GetDefaultPort(); if(Params().NetworkIDString() == CBaseChainParams::MAIN) { if(service.GetPort() != mainnetDefaultPort) { nState = ACTIVE_MASTERNODE_NOT_CAPABLE; strNotCapableReason = strprintf("Invalid port: %u - only %d is supported on mainnet.", service.GetPort(), mainnetDefaultPort); LogPrintf("CActiveMasternode::ManageStateInitial -- %s: %s\n", GetStateString(), strNotCapableReason); return; } } else if(service.GetPort() == mainnetDefaultPort) { nState = ACTIVE_MASTERNODE_NOT_CAPABLE; strNotCapableReason = strprintf("Invalid port: %u - %d is only supported on mainnet.", service.GetPort(), mainnetDefaultPort); LogPrintf("CActiveMasternode::ManageStateInitial -- %s: %s\n", GetStateString(), strNotCapableReason); return; } LogPrintf("CActiveMasternode::ManageStateInitial -- Checking inbound connection to '%s'\n", service.ToString()); if(!connman.ConnectNode(CAddress(service, NODE_NETWORK), NULL, true)) { nState = ACTIVE_MASTERNODE_NOT_CAPABLE; strNotCapableReason = "Could not connect to " + service.ToString(); LogPrintf("CActiveMasternode::ManageStateInitial -- %s: %s\n", GetStateString(), strNotCapableReason); return; } // Default to REMOTE eType = MASTERNODE_REMOTE; // Check if wallet funds are available if(!pwalletMain) { LogPrintf("CActiveMasternode::ManageStateInitial -- %s: Wallet not available\n", GetStateString()); return; } if(pwalletMain->IsLocked()) { LogPrintf("CActiveMasternode::ManageStateInitial -- %s: Wallet is locked\n", GetStateString()); return; } if(pwalletMain->GetBalance() < 1000*COIN) { LogPrintf("CActiveMasternode::ManageStateInitial -- %s: Wallet balance is < 1000 TINCOIN\n", GetStateString()); return; } // Choose coins to use CPubKey pubKeyCollateral; CKey keyCollateral; // If collateral is found switch to LOCAL mode if(pwalletMain->GetMasternodeOutpointAndKeys(outpoint, pubKeyCollateral, keyCollateral)) { eType = MASTERNODE_LOCAL; } LogPrint("masternode", "CActiveMasternode::ManageStateInitial -- End status = %s, type = %s, pinger enabled = %d\n", GetStatus(), GetTypeString(), fPingerEnabled); }
void CMuleKad::Process(UINT Tick) { if(m_MyBuddy && IsFirewalled() && m_NextBuddyPing < GetCurTick()) { m_NextBuddyPing = GetCurTick() + MIN2MS(10); m_MyBuddy->SendBuddyPing(); } QVariantMap Request; Request["Firewalled"] = theCore->m_MuleManager->IsFirewalled(CAddress::IPv4, false, true); Request["PublicIP"] = theCore->m_MuleManager->GetAddress(CAddress::IPv4, true).ToQString(); if(theCore->m_MuleManager->IsFirewalled(CAddress::IPv4)) { if(m_MyBuddy) { Request["BuddyIP"] = m_MyBuddy->GetMule().IPv4.ToQString(); Request["BuddyPort"] = m_MyBuddy->GetKadPort(); } } // Note: we always advertize IPv6 addresses CAddress IPv6 = theCore->m_MuleManager->GetAddress(CAddress::IPv6, true); if(!IPv6.IsNull()) Request["IPv6"] = IPv6.ToQString(); if(Tick & EPerSec) { if(theCore->Cfg()->GetBool("Log/Merge")) SyncLog(); } QVariantMap Response = theCore->m_Interfaces->RemoteProcedureCall("MuleKad", "SyncState", Request).toMap(); m_KadID = Response["KadID"].toByteArray(); if(Response["Result"] == "Connected") { if(m_KadStatus != eConnected) { LogLine(LOG_SUCCESS, tr("MuleKad Connected, ID: %1").arg(QString(m_KadID.toHex()).toUpper())); m_KadStatus = eConnected; } } else if(Response["Result"] == "Connecting") m_KadStatus = eConnecting; else //if(Response["Result"] == "Disconnected") m_KadStatus = eDisconnected; if(m_KadStatus == eDisconnected) { if(GetCurTick() > m_NextConnectionAttempt) { LogLine(LOG_INFO, tr("Connecting emule kademlia")); m_NextConnectionAttempt = GetCurTick() + SEC2MS(theCore->Cfg()->GetInt("Ed2kMule/IdleTimeout")); StartKad(); } return; } m_Address = CAddress(Response["PublicIP"].toString()); m_KadPort = Response["KadPort"].toUInt(); // external kad port //m_UDPPort = Response["UDPPort"].toUInt(); // socket port m_Firewalled = Response["Firewalled"].toBool(); m_KadFirewalled = Response["KadFirewalled"].toBool(); if (m_KadFirewalled && m_uNextKadFirewallRecheck <= GetCurTick()) { m_uNextKadFirewallRecheck = GetCurTick() + SEC2MS(theCore->Cfg()->GetInt("Ed2kMule/CheckFWInterval")); CheckFWState(); } foreach(const QVariant& vQueuedFWCheck, Response["QueuedFWChecks"].toList()) { QVariantMap QueuedFWCheck = vQueuedFWCheck.toMap(); SMuleSource Mule; Mule.SetIP(CAddress(QueuedFWCheck["Address"].toString())); Mule.TCPPort = QueuedFWCheck["TCPPort"].toUInt(); Mule.ConOpts.Bits = QueuedFWCheck["ConOpts"].toUInt(); if(Mule.ConOpts.Fields.RequestsCryptLayer) // some cleints seam to mess this up Mule.ConOpts.Fields.SupportsCryptLayer = true; QByteArray UserHash = QueuedFWCheck["UserHash"].toByteArray(); if(!Mule.SelectIP() || !theCore->m_PeerWatch->CheckPeer(Mule.GetIP(), Mule.TCPPort)) continue; bool bAdded = false; CMuleClient* pClient = theCore->m_MuleManager->GetClient(Mule, &bAdded); if(!bAdded) { if(QueuedFWCheck["TestUDP"].toBool() == true) SetUDPFWCheckResult(pClient, true); continue; } if(QueuedFWCheck["TestUDP"].toBool() == true) { uint32 UDPKey; if(QueuedFWCheck.contains("UDPKey")) UDPKey = QueuedFWCheck["UDPKey"].toUInt(); else UDPKey = theCore->m_MuleManager->GetServer()->GetUDPKey(Mule.GetIP()); m_QueuedFWChecks.insert(pClient, SFWCheck(QueuedFWCheck["IntPort"].toUInt(), QueuedFWCheck["ExtPort"].toUInt(), UDPKey)); } else m_QueuedFWChecks.insert(pClient, SFWCheck()); connect(pClient, SIGNAL(HelloRecived()), this, SLOT(OnHelloRecived())); connect(pClient, SIGNAL(SocketClosed()), this, SLOT(OnSocketClosed())); pClient->SetUserHash(UserHash); pClient->Connect(); } QList<CAddress> PendingFWChecks; foreach(const QVariant& vPendingFWCheck, Response["PendingFWChecks"].toList()) { QVariantMap PendingFWCheck = vPendingFWCheck.toMap(); PendingFWChecks.append(CAddress(PendingFWCheck["Address"].toString())); } theCore->m_MuleManager->GetServer()->SetExpected(PendingFWChecks); foreach(const QVariant& vBufferedCallback, Response["BufferedCallbacks"].toList()) { QVariantMap BufferedCallback = vBufferedCallback.toMap(); CAddress Address = CAddress(BufferedCallback["Address"].toString()); uint16 uPort = BufferedCallback["TCPPort"].toUInt(); QByteArray BuddyID = BufferedCallback["BuddyID"].toByteArray(); QByteArray FileID = BufferedCallback["FileID"].toByteArray(); if(m_MyBuddy && m_MyBuddy->IsFirewalled(CAddress::IPv4)) { if(m_MyBuddy->GetBuddyID() == BuddyID) m_MyBuddy->RelayKadCallback(Address, uPort, BuddyID, FileID); } } // Note: This comes in on the normal UDP Socket, as we provide thesocket now we dont haveto pull it /*foreach(const QVariant& vBufferedPackets, Response["BufferedPackets"].toList()) { QVariantMap BufferedPackets = vBufferedPackets.toMap(); CAddress Address = CAddress(BufferedPackets["Address"].toString()); uint16 uPort = BufferedPackets["UDPPort"].toUInt(); QByteArray Data = BufferedPackets["Data"].toByteArray(); CBuffer Packet((byte*)Data.data(), Data.size(), true); RelayUDPPacket(Address, uPort, Packet); } foreach(const QVariant& vPendingCallback, Response["PendingCallbacks"].toList()) { QVariantMap PendingCallback = vPendingCallback.toMap(); SMuleSource Mule; Mule.SetIP(CAddress(PendingCallback["Address"].toString())); Mule.TCPPort = PendingCallback["TCPPort"].toUInt(); Mule.UserHash = PendingCallback["UserHash"].toByteArray(); Mule.ConOpts.Bits = PendingCallback["ConOpts"].toUInt(); if(Mule.ConOpts.Fields.RequestsCryptLayer) // some cleints seam to mess this up Mule.ConOpts.Fields.SupportsCryptLayer = true; theCore->m_MuleManager->CallbackRequested(Mule); }*/ foreach(const QVariant& vPendingBuddys, Response["PendingBuddys"].toList()) { if(m_MyBuddy) // if we have a buddy we are not interested in new ones break; QVariantMap PendingBuddy = vPendingBuddys.toMap(); SMuleSource Mule; Mule.SetIP(CAddress(PendingBuddy["Address"].toString())); Mule.TCPPort = PendingBuddy["TCPPort"].toUInt(); Mule.KadPort = PendingBuddy["KadPort"].toUInt(); Mule.ConOpts.Bits = PendingBuddy["ConOpts"].toUInt(); if(Mule.ConOpts.Fields.RequestsCryptLayer) // some cleints seam to mess this up Mule.ConOpts.Fields.SupportsCryptLayer = true; Mule.UserHash = PendingBuddy["UserHash"].toByteArray(); Mule.BuddyID = PendingBuddy["BuddyID"].toByteArray(); if(!theCore->m_PeerWatch->CheckPeer(Mule.GetIP(), Mule.TCPPort)) continue; bool bAdded = false; CMuleClient* pClient = theCore->m_MuleManager->GetClient(Mule, &bAdded); if(!bAdded) continue; // already known clients are not viable budies connect(pClient, SIGNAL(HelloRecived()), this, SLOT(OnHelloRecived())); connect(pClient, SIGNAL(SocketClosed()), this, SLOT(OnSocketClosed())); if(m_PendingBuddys.contains(pClient)) continue; // already listes m_PendingBuddys.append(pClient); if(PendingBuddy["Incoming"].toBool()) // is this a lowID client that wants us to become his buddy ans will soon connect us? pClient->ExpectConnection(); else //this is a high ID client that agreed to become our buddy pClient->Connect(); } m_KadStats = Response["Stats"].toMap(); if(Tick & EPerSec) { if(IsConnected()) { SyncFiles(); SyncNotes(); foreach(CAbstractSearch* pSearch, m_RunningSearches) SyncSearch(pSearch); } } }
void ProcessMessageMasternode(CNode* pfrom, std::string& strCommand, CDataStream& vRecv) { if (strCommand == "dsee") { //DarkSend Election Entry if(fLiteMode) return; //disable all darksend/masternode related functionality bool fIsInitialDownload = IsInitialBlockDownload(); if(fIsInitialDownload) return; CTxIn vin; CService addr; CPubKey pubkey; CPubKey pubkey2; vector<unsigned char> vchSig; int64_t sigTime; int count; int current; int64_t lastUpdated; int protocolVersion; std::string strMessage; // 70047 and greater vRecv >> vin >> addr >> vchSig >> sigTime >> pubkey >> pubkey2 >> count >> current >> lastUpdated >> protocolVersion; // make sure signature isn't in the future (past is OK) if (sigTime > GetAdjustedTime() + 60 * 60) { printf("dsee - Signature rejected, too far into the future %s\n", vin.ToString().c_str()); return; } bool isLocal = addr.IsRFC1918() || addr.IsLocal(); //if(Params().MineBlocksOnDemand()) isLocal = false; std::string vchPubKey(pubkey.vchPubKey.begin(), pubkey.vchPubKey.end()); std::string vchPubKey2(pubkey2.vchPubKey.begin(), pubkey2.vchPubKey.end()); strMessage = addr.ToString() + boost::lexical_cast<std::string>(sigTime) + vchPubKey + vchPubKey2 + boost::lexical_cast<std::string>(protocolVersion); if(protocolVersion < MIN_MN_PROTO_VERSION) { printf("dsee - ignoring outdated masternode %s protocol version %d\n", vin.ToString().c_str(), protocolVersion); return; } CScript pubkeyScript; pubkeyScript =GetScriptForDestination(pubkey.GetID()); if(pubkeyScript.size() != 25) { printf("dsee - pubkey the wrong size\n"); pfrom->Misbehaving(100); return; } CScript pubkeyScript2; pubkeyScript2 =GetScriptForDestination(pubkey2.GetID()); if(pubkeyScript2.size() != 25) { printf("dsee - pubkey2 the wrong size\n"); pfrom->Misbehaving(100); return; } std::string errorMessage = ""; if(!darkSendSigner.VerifyMessage(pubkey, vchSig, strMessage, errorMessage)){ printf("dsee - Got bad masternode address signature\n"); pfrom->Misbehaving(100); return; } //search existing masternode list, this is where we update existing masternodes with new dsee broadcasts LOCK(cs_masternodes); BOOST_FOREACH(CMasterNode& mn, vecMasternodes) { if(mn.vin.prevout == vin.prevout) { // count == -1 when it's a new entry // e.g. We don't want the entry relayed/time updated when we're syncing the list // mn.pubkey = pubkey, IsVinAssociatedWithPubkey is validated once below, // after that they just need to match if(count == -1 && mn.pubkey == pubkey && !mn.UpdatedWithin(MASTERNODE_MIN_DSEE_SECONDS)){ mn.UpdateLastSeen(); if(mn.now < sigTime){ //take the newest entry printf("dsee - Got updated entry for %s\n", addr.ToString().c_str()); mn.pubkey2 = pubkey2; mn.now = sigTime; mn.sig = vchSig; mn.protocolVersion = protocolVersion; mn.addr = addr; RelayDarkSendElectionEntry(vin, addr, vchSig, sigTime, pubkey, pubkey2, count, current, lastUpdated, protocolVersion); } } return; } } // make sure the vout that was signed is related to the transaction that spawned the masternode // - this is expensive, so it's only done once per masternode if(!darkSendSigner.IsVinAssociatedWithPubkey(vin, pubkey)) { printf("dsee - Got mismatched pubkey and vin\n"); pfrom->Misbehaving(100); return; } if(fDebug) printf("dsee - Got NEW masternode entry %s\n", addr.ToString().c_str()); // make sure it's still unspent // - this is checked later by .check() in many places and by ThreadCheckDarkSendPool() CTransaction tx = CTransaction(); CTxOut vout = CTxOut(24999*COIN, darkSendPool.collateralPubKey); tx.vin.push_back(vin); tx.vout.push_back(vout); //if(AcceptableInputs(mempool, state, tx)){ bool* pfMissingInputs = false; if(AcceptableInputs(mempool, tx, false, pfMissingInputs)){ if(fDebug) printf("dsee - Accepted masternode entry %i %i\n", count, current); if(GetInputAge(vin) < MASTERNODE_MIN_CONFIRMATIONS){ printf("dsee - Input must have least %d confirmations\n", MASTERNODE_MIN_CONFIRMATIONS); pfrom->Misbehaving(20); return; } // use this as a peer addrman.Add(CAddress(addr), pfrom->addr, 2*60*60); // add our masternode CMasterNode mn(addr, vin, pubkey, vchSig, sigTime, pubkey2, protocolVersion); mn.UpdateLastSeen(lastUpdated); vecMasternodes.push_back(mn); // if it matches our masternodeprivkey, then we've been remotely activated if(pubkey2 == activeMasternode.pubKeyMasternode && protocolVersion == PROTOCOL_VERSION){ activeMasternode.EnableHotColdMasterNode(vin, addr); } if(count == -1 && !isLocal) RelayDarkSendElectionEntry(vin, addr, vchSig, sigTime, pubkey, pubkey2, count, current, lastUpdated, protocolVersion); } else { printf("dsee - Rejected masternode entry %s\n", addr.ToString().c_str()); int nDoS = 0; /* if (state.IsInvalid(nDoS)) { printf("dsee - %s from %s %s was not accepted into the memory pool\n", tx.GetHash().ToString().c_str(), pfrom->addr.ToString().c_str(), pfrom->cleanSubVer.c_str()); if (nDoS > 0) pfrom->Misbehaving(nDoS); }*/ } } else if (strCommand == "dseep") { //DarkSend Election Entry Ping
void ProcessMessageMasternode(CNode* pfrom, std::string& strCommand, CDataStream& vRecv) { if (strCommand == "dsee") { //DarkSend Election Entry if (pfrom->nVersion != darkSendPool.MIN_PEER_PROTO_VERSION) { return; } bool fIsInitialDownload = IsInitialBlockDownload(); if(fIsInitialDownload) return; CTxIn vin; CService addr; CPubKey pubkey; CPubKey pubkey2; vector<unsigned char> vchSig; int64 sigTime; int count; int current; int64 lastUpdated; vRecv >> vin >> addr >> vchSig >> sigTime >> pubkey >> pubkey2 >> count >> current >> lastUpdated; bool isLocal = false; // addr.IsRFC1918(); std::string vchPubKey(pubkey.begin(), pubkey.end()); std::string vchPubKey2(pubkey2.begin(), pubkey2.end()); CScript pubkeyScript; pubkeyScript.SetDestination(pubkey.GetID()); if(pubkeyScript.size() != 25) { LogPrintf("dsee - pubkey the wrong size\n"); pfrom->Misbehaving(100); return; } std::string strMessage = addr.ToString() + boost::lexical_cast<std::string>(sigTime) + vchPubKey + vchPubKey2; CScript pubkeyScript2; pubkeyScript2.SetDestination(pubkey2.GetID()); if(pubkeyScript2.size() != 25) { LogPrintf("dsee - pubkey the wrong size\n"); pfrom->Misbehaving(100); return; } std::string errorMessage = ""; if(!darkSendSigner.VerifyMessage(pubkey, vchSig, strMessage, errorMessage)){ LogPrintf("dsee - Got bad masternode address signature\n"); pfrom->Misbehaving(100); return; } if((fTestNet && addr.GetPort() != 19999) || (!fTestNet && addr.GetPort() != 9999)) return; //LogPrintf("Searching existing masternodes : %s - %s\n", addr.ToString().c_str(), vin.ToString().c_str()); BOOST_FOREACH(CMasterNode& mn, darkSendMasterNodes) { //LogPrintf(" -- %s\n", mn.vin.ToString().c_str()); if(mn.vin.prevout == vin.prevout) { //count == -1 when it's a new entry // e.g. We don't want the entry relayed/time updated when we're syncing the list if(count == -1 && !mn.UpdatedWithin(MASTERNODE_MIN_SECONDS)){ mn.UpdateLastSeen(); if(mn.now < sigTime){ //take the newest entry LogPrintf("dsee - Got updated entry for %s\n", addr.ToString().c_str()); mn.pubkey2 = pubkey2; mn.now = sigTime; mn.sig = vchSig; if(pubkey2 == activeMasternode.pubkeyMasterNode2){ activeMasternode.EnableHotColdMasterNode(vin, sigTime, addr); } RelayDarkSendElectionEntry(vin, addr, vchSig, sigTime, pubkey, pubkey2, count, current, lastUpdated); } } return; } } if(!darkSendSigner.IsVinAssociatedWithPubkey(vin, pubkey)) { LogPrintf("dsee - Got mismatched pubkey and vin\n"); pfrom->Misbehaving(100); return; } LogPrintf("dsee - Got NEW masternode entry %s\n", addr.ToString().c_str()); CValidationState state; CTransaction tx = CTransaction(); CTxOut vout = CTxOut(999.99*COIN, darkSendPool.collateralPubKey); tx.vin.push_back(vin); tx.vout.push_back(vout); if(tx.AcceptableInputs(state, true)){ LogPrintf("dsee - Accepted masternode entry %i %i\n", count, current); if(GetInputAge(vin) < MASTERNODE_MIN_CONFIRMATIONS){ LogPrintf("dsee - Input must have least %d confirmations\n", MASTERNODE_MIN_CONFIRMATIONS); pfrom->Misbehaving(20); return; } addrman.Add(CAddress(addr), pfrom->addr, 2*60*60); CMasterNode mn(addr, vin, pubkey, vchSig, sigTime, pubkey2); mn.UpdateLastSeen(lastUpdated); darkSendMasterNodes.push_back(mn); if(pubkey2 == activeMasternode.pubkeyMasterNode2){ activeMasternode.EnableHotColdMasterNode(vin, sigTime, addr); } if(count == -1 && !isLocal) RelayDarkSendElectionEntry(vin, addr, vchSig, sigTime, pubkey, pubkey2, count, current, lastUpdated); } else { LogPrintf("dsee - Rejected masternode entry\n"); int nDoS = 0; if (state.IsInvalid(nDoS)) { LogPrintf("dsee - %s from %s %s was not accepted into the memory pool\n", tx.GetHash().ToString().c_str(), pfrom->addr.ToString().c_str(), pfrom->cleanSubVer.c_str()); if (nDoS > 0) pfrom->Misbehaving(nDoS); } } } else if (strCommand == "dseep") { //DarkSend Election Entry Ping
void AddRandomOutboundPeer(std::vector<CNode *> &vNodes, PeerLogicValidation &peerLogic) { CAddress addr(ip(GetRandInt(0xffffffff)), NODE_NONE); vNodes.emplace_back(new CNode(id++, ServiceFlags(NODE_NETWORK|NODE_WITNESS), 0, INVALID_SOCKET, addr, 0, 0, CAddress(), "", /*fInboundIn=*/ false)); CNode &node = *vNodes.back(); node.SetSendVersion(PROTOCOL_VERSION); peerLogic.InitializeNode(&node); node.nVersion = 1; node.fSuccessfullyConnected = true; CConnmanTest::AddNode(node); }
CKademlia::CKademlia(uint16 Port, bool bIPv6, const CVariant& Config, const string& Version) { m_Protocol = KAD_PROT_VER; if(!Version.empty()) m_Version += Version; else m_Version = "v " STR(KAD_PROT_MJR) "." STR(KAD_PROT_MIN); m_pConfig = new CKadConfig(this); if(Config.IsValid()) m_pConfig->Merge(Config); LoadData(); if(m_pKadKey->GetAlgorithm() == CAbstractKey::eUndefined) { m_pKadKey->SetAlgorithm(CAbstractKey::eECP); //m_pKadKey->GenerateKey("secp256r1"); // NIST: P-256 m_pKadKey->GenerateKey("brainpoolP256r1"); // dont trust NIST (NSA) curves, use brainpool LogLine(LOG_INFO, L"Generated new Private NodeKey"); SaveData(); } m_pSocket = new CSmartSocket(SEC2MS(Cfg()->GetInt("ConnectionTimeout")), this); CScoped<CPublicKey> pKey = m_pKadKey->PublicKey(); CUInt128 ID; CKadID::MakeID(pKey, ID.GetData(), ID.GetSize()); LogLine(LOG_INFO, L"Neo Kad ID: %s", ID.ToHex().c_str()); uint64 RecvKey; CAbstractKey::Fold(ID.GetData(), ID.GetSize(),(byte*)&RecvKey, sizeof(RecvKey)); m_pSocket->SetupCrypto(RecvKey, m_pKadKey); #ifdef _DEBUG LogLine(LOG_INFO, L"Socket PassKey is %I64u", RecvKey); #endif m_Port = 0; m_IPv4 = CAddress(CAddress::IPv4); m_IPv6 = CAddress(CAddress::IPv6); for(int i=Port; i < Port + 1000; i++) { CUTPSocketListner* pSocketListner = new CUTPSocketListner(m_pSocket); CUTPSocketListner* pSocketListnerV6 = bIPv6 ? new CUTPSocketListner(m_pSocket) : NULL; bool bV4 = pSocketListner->Bind(i, CAddress(CAddress::IPv4)); bool bV6 = !pSocketListnerV6 || pSocketListnerV6->Bind(i, CAddress(CAddress::IPv6)); if(bV4 && bV6) { m_pSocket->InstallListener(pSocketListner); if(pSocketListnerV6) m_pSocket->InstallListener(pSocketListnerV6); m_Port = i; break; } delete pSocketListner; delete pSocketListnerV6; } }
void CSocketThread::UpdateIPs(const QString& NICName, bool bIPv6) { CAddress IPv4; CAddress IPv6; foreach(QNetworkInterface NIC, QNetworkInterface::allInterfaces()) { if ((NIC.flags().testFlag(QNetworkInterface::IsLoopBack) && !NIC.flags().testFlag(QNetworkInterface::IsPointToPoint))) continue; if(!NIC.flags().testFlag(QNetworkInterface::IsUp)) continue; if(!NICName.isEmpty() && NICName != NIC.humanReadableName()) continue; foreach(const QNetworkAddressEntry& IP, NIC.addressEntries()) { switch(IP.ip().protocol()) { case QAbstractSocket::IPv4Protocol: { // We try to select a public IPv4 but if that fais we sattel for the first local we find. if(IPv4.IsNull() || (IsLanIPv4(IPv4.ToIPv4()) && !IsLanIPv4(IP.ip().toIPv4Address()))) IPv4 = IP.ip().toIPv4Address(); break; } case QAbstractSocket::IPv6Protocol: { if(bIPv6 && IPv6.IsNull()) { Q_IPV6ADDR ip = IP.ip().toIPv6Address(); if(ip.c[0] == 0xFE && ip.c[1] == 0x80) continue; // IP that is constructed from MAC address, and is only available to machines on the same switch. if(ip.c[11] == 0xFF && ip.c[12] == 0xFE) continue; // IP that is constructed from MAC address and ISP provided subnet prefix. This could be seen as your static IP. // IP that is constructed from ISP provided subnet prefix and some random digits. // This IP changes every time you power on your PC, and is the IP newer versions of Windows uses as the preferred source IP. IPv6 = IP.ip().toIPv6Address().c; } break; } } } } m_Address[CAddress::IPv4] = IPv4; m_Address[CAddress::IPv6] = IPv6; if(!NICName.isEmpty()) // VPN LockIn { m_IPv4 = IPv4; m_IPv6 = IPv6; } else if(!(!m_IPv4.IsNull() && (m_IPv6 == !m_IPv6.IsNull()))) { m_IPv4 = CAddress(CAddress::IPv4); // any Address m_IPv6 = bIPv6 ? CAddress(CAddress::IPv6) : CAddress(); // any Address } m_Connectable = (m_IPv4.Type() != CAddress::None || m_IPv6.Type() != CAddress::None); }
void ThreadMessageHandler2(void* parg); void ThreadSocketHandler2(void* parg); void ThreadOpenConnections2(void* parg); // // Global state variables // bool fClient = false; uint64 nLocalServices = (fClient ? 0 : NODE_NETWORK); CAddress addrLocalHost(0, DEFAULT_PORT, nLocalServices); CNode nodeLocalHost(INVALID_SOCKET, CAddress("127.0.0.1", nLocalServices)); CNode* pnodeLocalHost = &nodeLocalHost; bool fShutdown = false; array<bool, 10> vfThreadRunning; vector<CNode*> vNodes; CCriticalSection cs_vNodes; map<vector<unsigned char>, CAddress> mapAddresses; CCriticalSection cs_mapAddresses; map<CInv, CDataStream> mapRelay; deque<pair<int64, CInv> > vRelayExpiration; CCriticalSection cs_mapRelay; map<CInv, int64> mapAlreadyAskedFor; CAddress addrProxy;