当前位置: 首页>>代码示例>>C++>>正文


C++ CService类代码示例

本文整理汇总了C++中CService的典型用法代码示例。如果您正苦于以下问题:C++ CService类的具体用法?C++ CService怎么用?C++ CService使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CService类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Log

bool CMasternodeBroadcast::Create(const std::string& strService, const std::string& strKeyMasternode, const std::string& strTxHash, const std::string& strOutputIndex, std::string& strErrorRet, CMasternodeBroadcast& mnbRet, bool fOffline)
{
    COutPoint outpoint;
    CPubKey pubKeyCollateralAddressNew;
    CKey keyCollateralAddressNew;
    CPubKey pubKeyMasternodeNew;
    CKey keyMasternodeNew;

    auto Log = [&strErrorRet](std::string sErr) -> bool {
        strErrorRet = sErr;
        return false;
    };

    // Wait for sync to finish because mnb simply won't be relayed otherwise
    if (!fOffline && !masternodeSync.IsSynced())
        return Log("Sync in progress. Must wait until sync is complete to start Masternode");

    if (!CMessageSigner::GetKeysFromSecret(strKeyMasternode, keyMasternodeNew, pubKeyMasternodeNew))
        return Log(strprintf("Invalid masternode key %s", strKeyMasternode));

    const COutPoint outpt(uint256S(strTxHash), std::stoi(strOutputIndex));

    for (CWalletRef pwallet : vpwallets) {
        pwallet->UnlockCoin(outpt);
        if (pwallet->GetMasternodeOutpointAndKeys(outpoint, pubKeyCollateralAddressNew, keyCollateralAddressNew, strTxHash, strOutputIndex)) {
            pwallet->LockCoin(outpt);
        } else {
            return Log(strprintf("Could not allocate outpoint %s:%s for masternode %s", strTxHash, strOutputIndex, strService));
        }
    }

    CService service;
    if (!Lookup(strService.c_str(), service, 0, false))
        return Log(strprintf("Invalid address %s for masternode.", strService));
    int mainnetDefaultPort = CreateChainParams(CBaseChainParams::MAIN)->GetDefaultPort();
    if (Params().NetworkIDString() == CBaseChainParams::MAIN) {
        if (service.GetPort() != mainnetDefaultPort)
            return Log(strprintf("Invalid port %u for masternode %s, only %d is supported on mainnet.", service.GetPort(), strService, mainnetDefaultPort));
    } else if (service.GetPort() == mainnetDefaultPort)
        return Log(strprintf("Invalid port %u for masternode %s, %d is the only supported on mainnet.", service.GetPort(), strService, mainnetDefaultPort));

    return Create(outpoint, service, keyCollateralAddressNew, pubKeyCollateralAddressNew, keyMasternodeNew, pubKeyMasternodeNew, strErrorRet, mnbRet);
}
开发者ID:machinecoin-project,项目名称:machinecoin-core,代码行数:43,代码来源:masternode.cpp

示例2: Socks4

bool static Socks4(const CService &addrDest, SOCKET& hSocket)
{
    printf("SOCKS4 connecting %s\n", addrDest.ToString().c_str());
    if (!addrDest.IsIPv4())
    {
        closesocket(hSocket);
        return error("Proxy destination is not IPv4");
    }
    char pszSocks4IP[] = "\4\1\0\0\0\0\0\0user";
    struct sockaddr_in addr;
    socklen_t len = sizeof(addr);
    if (!addrDest.GetSockAddr((struct sockaddr*)&addr, &len) || addr.sin_family != AF_INET)
    {
        closesocket(hSocket);
        return error("Cannot get proxy destination address");
    }
    memcpy(pszSocks4IP + 2, &addr.sin_port, 2);
    memcpy(pszSocks4IP + 4, &addr.sin_addr, 4);
    char* pszSocks4 = pszSocks4IP;
    int nSize = sizeof(pszSocks4IP);

    int ret = send(hSocket, pszSocks4, nSize, MSG_NOSIGNAL);
    if (ret != nSize)
    {
        closesocket(hSocket);
        return error("Error sending to proxy");
    }
    char pchRet[8];
    if (recv(hSocket, pchRet, 8, 0) != 8)
    {
        closesocket(hSocket);
        return error("Error reading proxy response");
    }
    if (pchRet[1] != 0x5a)
    {
        closesocket(hSocket);
        if (pchRet[1] != 0x5b)
            printf("ERROR: Proxy returned error %d\n", pchRet[1]);
        return false;
    }
    printf("SOCKS4 connected %s\n", addrDest.ToString().c_str());
    return true;
}
开发者ID:indocoinproject,项目名称:indocoin,代码行数:43,代码来源:netbase.cpp

示例3: SetProxy

bool SetProxy(enum Network net, CService addrProxy, int nSocksVersion) {
    assert(net >= 0 && net < NET_MAX);
    if (nSocksVersion != 0 && nSocksVersion != 4 && nSocksVersion != 5)
        return false;
    if (nSocksVersion != 0 && !addrProxy.IsValid())
        return false;
    LOCK(cs_proxyInfos);
    proxyInfo[net] = std::make_pair(addrProxy, nSocksVersion);
    return true;
}
开发者ID:indocoinproject,项目名称:indocoin,代码行数:10,代码来源:netbase.cpp

示例4: Find

void CAddrMan::Good_(const CService &addr, int64_t nTime)
{
//    printf("Good: addr=%s\n", addr.ToString().c_str());

    int nId;
    CAddrInfo *pinfo = Find(addr, &nId);

    // if not found, bail out
    if (!pinfo)
        return;

    CAddrInfo &info = *pinfo;

    // check whether we are talking about the exact same CService (including same port)
    if (info != addr)
        return;

    // update info
    info.nLastSuccess = nTime;
    info.nLastTry = nTime;
    info.nTime = nTime;
    info.nAttempts = 0;

    // if it is already in the tried set, don't do anything else
    if (info.fInTried)
        return;

    // find a bucket it is in now
    int nRnd = GetRandInt(ADDRMAN_NEW_BUCKET_COUNT);
    int nUBucket = -1;
 /* for (unsigned int n = 0; n < vvNew.size(); n++)
    {
        int nB = (n+nRnd) % vvNew.size();
        std::set<int> &vNew = vvNew[nB];
        if (vNew.count(nId))
        {
 */
    for (unsigned int n = 0; n < ADDRMAN_NEW_BUCKET_COUNT; n++) {
        int nB = (n + nRnd) % ADDRMAN_NEW_BUCKET_COUNT;
        int nBpos = info.GetBucketPosition(nKey, true, nB);
        if (vvNew[nB][nBpos] == nId) {
            nUBucket = nB;
            break;
        }
    }

    // if no bucket is found, something bad happened;
    // TODO: maybe re-add the node, but for now, just bail out
    if (nUBucket == -1) return;

    printf("Moving %s to tried\n", addr.ToString().c_str());

    // move nId to the tried tables
    MakeTried(info, nId);
}
开发者ID:birty,项目名称:netcoin,代码行数:55,代码来源:addrman.cpp

示例5: ConnectSocket

bool ConnectSocket(const CService &addrDest, SOCKET& hSocketRet, int nTimeout)
{
    const proxyType &proxy = proxyInfo[addrDest.GetNetwork()];

#ifdef USE_NATIVE_I2P
    if (addrDest.IsNativeI2P()&&IsI2PEnabled()) {
        SOCKET streamSocket = I2PSession::Instance().connect(addrDest.GetI2PDestination(), false/*, streamSocket*/);
        if (SetSocketOptions(streamSocket)) {
            hSocketRet = streamSocket;
            return true;
        }
        return false;
    }
#endif

    // no proxy needed
    if (!proxy.second)
        return ConnectSocketDirectly(addrDest, hSocketRet, nTimeout);

    SOCKET hSocket = INVALID_SOCKET;

    // first connect to proxy server
    if (!ConnectSocketDirectly(proxy.first, hSocket, nTimeout))
        return false;
 
    // do socks negotiation
    switch (proxy.second) {
    case 4:
        if (!Socks4(addrDest, hSocket))
            return false;
        break;
    case 5:
        if (!Socks5(addrDest.ToStringIP(), addrDest.GetPort(), hSocket))
            return false;
        break;
    default:
        return false;
    }

    hSocketRet = hSocket;
    return true;
}
开发者ID:12gaugeaxe,项目名称:anoncoin,代码行数:42,代码来源:netbase.cpp

示例6: LOG4CPLUS_TRACE_METHOD

 bool CServiceManager::unload(const Service::Uid &service)
 {
    LOG4CPLUS_TRACE_METHOD(msLogger, __PRETTY_FUNCTION__);
    mActiveServicesMutex.lock();
    tServiceMap::iterator it = mActiveServices.find(service);
    if (mActiveServices.end() == it)
    {
       mActiveServicesMutex.unlock();
       return false;
    }
    CService * pService = it->second;
    pService->unload();
    if (!pService->hasUnloadWaits())
    {
       mActiveServices.erase(it);
       delete pService;
    }
    mActiveServicesMutex.unlock();
    return true;
 }
开发者ID:Luxoft,项目名称:iviLink,代码行数:20,代码来源:CServiceManager.cpp

示例7: Find

void CAddrMan::Good_(const CService& addr, int64_t nTime)
{
    int nId;

    nLastGood = nTime;

    CAddrInfo* pinfo = Find(addr, &nId);

    // if not found, bail out
    if (!pinfo)
        return;

    CAddrInfo& info = *pinfo;

    // check whether we are talking about the exact same CService (including same port)
    if (info != addr)
        return;

    // update info
    info.nLastSuccess = nTime;
    info.nLastTry = nTime;
    info.nAttempts = 0;
    // nTime is not updated here, to avoid leaking information about
    // currently-connected peers.

    // if it is already in the tried set, don't do anything else
    if (info.fInTried)
        return;

    // find a bucket it is in now
    int nRnd = RandomInt(ADDRMAN_NEW_BUCKET_COUNT);
    int nUBucket = -1;
    for (unsigned int n = 0; n < ADDRMAN_NEW_BUCKET_COUNT; n++) {
        int nB = (n + nRnd) % ADDRMAN_NEW_BUCKET_COUNT;
        int nBpos = info.GetBucketPosition(nKey, true, nB);
        if (vvNew[nB][nBpos] == nId) {
            nUBucket = nB;
            break;
        }
    }

    // if no bucket is found, something bad happened;
    // TODO: maybe re-add the node, but for now, just bail out
    if (nUBucket == -1)
        return;

    LogPrint("addrman", "Moving %s to tried\n", addr.ToString());

    // move nId to the tried tables
    MakeTried(info, nId);
}
开发者ID:sipa,项目名称:bitcoin,代码行数:51,代码来源:addrman.cpp

示例8: Find

void CAddrMan::Good_(const CService &addr, int64 nTime)
{
//    printf("Good: addr=%s\n", addr.ToString().c_str());

    int nId;
    CAddrInfo *pinfo = Find(addr, &nId);

    // if not found, bail out                                                       если не найдено, bail out(аварийное завершение)
    if (!pinfo)
        return;

    CAddrInfo &info = *pinfo;

    // check whether we are talking about the exact same CService (including same port)    убедитесь, что мы говорим о том же CService (в том числе тот же порт)
    if (info != addr)
        return;

    // update info                                                                  обновление информации
    info.nLastSuccess = nTime;
    info.nLastTry = nTime;
    info.nTime = nTime;
    info.nAttempts = 0;

    // if it is already in the tried set, don't do anything else                    исли это уже в пыталась установить, не делать что-либо еще
    if (info.fInTried)
        return;

    // find a bucket it is in now                                                   найдите бакет, в котором это находится теперь
    int nRnd = GetRandInt(vvNew.size());
    int nUBucket = -1;
    for (unsigned int n = 0; n < vvNew.size(); n++)
    {
        int nB = (n+nRnd) % vvNew.size();
        std::set<int> &vNew = vvNew[nB];
        if (vNew.count(nId))
        {
            nUBucket = nB;
            break;
        }
    }

    // if no bucket is found, something bad happened;                               если бакет не найден, что-то плохое случилось;
    // TODO: maybe re-add the node, but for now, just bail out                      может быть повторно добавить узел, но сейчас только bail out(аварийное завершение)
    if (nUBucket == -1) return;

    printf("Moving %s to tried\n", addr.ToString().c_str());

    // move nId to the tried tables
    MakeTried(info, nId, nUBucket);
}
开发者ID:neiros,项目名称:Dcoin,代码行数:50,代码来源:addrman.cpp

示例9: GenerateUniqueName

void CSocketListener::StartServiceL()
	{
/*	HBufC* threadName = HBufC::NewLC(KMaxFileName);
	TPtr ptr = threadName->Des();
	GenerateUniqueName(ptr, this);
	RThread service;
	TRequestStatus status;
	User::LeaveIfError(service.Create(*threadName, CSocketListener::ThreadFunc,
			KStackSize, NULL, this));
	service.Resume();
	service.Close();
	CleanupStack::PopAndDestroy(threadName);
*/
/*	CService* service = CService::NewLC(iServerT);
	service->StartL(iSockClient);
	iSockClient = NULL;
*/
	for(TInt8 i=0; i< iServicePool.Count(); i++)
		{
		CService* service = iServicePool[i]; 
		if(service->IsIdle())
			{
			service->StartL(iSockClient);
			iSockClient = NULL;
			break;
			}
		}
	
	if(iSockClient!=NULL) // if the service pool is fulled, deny a service.
		{
		iSockClient->Close();
		delete iSockClient;
		iSockClient = NULL;
		}
	
	// SetActive();
	}
开发者ID:kkskipper,项目名称:KNOWME,代码行数:37,代码来源:SocketListener.cpp

示例10: DeviceNotificationCallback

DWORD WINAPI CService::DeviceNotificationCallback(HCMNOTIFICATION Notify,
    PVOID Context, CM_NOTIFY_ACTION Action, PCM_NOTIFY_EVENT_DATA EventData,
    DWORD EventDataSize)
{
    CService *pThis = reinterpret_cast<CService *>(Context);
    DWORD event = 0;

    switch (Action)
    {
        case CM_NOTIFY_ACTION_DEVICEINTERFACEARRIVAL:
            event = DBT_DEVICEARRIVAL;
            break;

        case CM_NOTIFY_ACTION_DEVICEQUERYREMOVE:
            event = DBT_DEVICEQUERYREMOVE;
            break;

        case CM_NOTIFY_ACTION_DEVICEQUERYREMOVEFAILED:
            event = DBT_DEVICEQUERYREMOVEFAILED;
            break;

        case CM_NOTIFY_ACTION_DEVICEREMOVECOMPLETE:
            event = DBT_DEVICEREMOVECOMPLETE;
            break;

        default:
            break;
    }

    if (event > 0)
    {
        pThis->ServiceHandleDeviceChange(event);
    }

    return ERROR_SUCCESS;
}
开发者ID:daynix,项目名称:kvm-guest-drivers-windows,代码行数:36,代码来源:service.cpp

示例11: RemoveLocal

void TorController::disconnected_cb(TorControlConnection& conn)
{
    // Stop advertising service when disconnected
    if (service.IsValid())
        RemoveLocal(service);
    service = CService();
    if (!reconnect)
        return;

    LogPrint("tor", "tor: Not connected to Tor control port %s, trying to reconnect\n", target);

    // Single-shot timer for reconnect. Use exponential backoff.
    struct timeval time = MillisToTimeval(int64_t(reconnect_timeout * 1000.0));
    if (reconnect_ev)
        event_add(reconnect_ev, &time);
    reconnect_timeout *= RECONNECT_TIMEOUT_EXP;
}
开发者ID:experiencecoin,项目名称:experiencecoin,代码行数:17,代码来源:torcontrol.cpp

示例12: Dseep

bool CActiveMasternode::Dseep(CTxIn vin, CService service, CKey keyMasternode, CPubKey pubKeyMasternode, std::string &retErrorMessage, bool stop) {
    std::string errorMessage;
    std::vector<unsigned char> vchMasterNodeSignature;
    std::string strMasterNodeSignMessage;
    int64_t masterNodeSignatureTime = GetAdjustedTime();

    std::string strMessage = service.ToString() + boost::lexical_cast<std::string>(masterNodeSignatureTime) + boost::lexical_cast<std::string>(stop);

    if(!darkSendSigner.SignMessage(strMessage, errorMessage, vchMasterNodeSignature, keyMasternode)) {
    	retErrorMessage = "sign message failed: " + errorMessage;
    	LogPrintf("CActiveMasternode::Dseep() - Error: %s\n", retErrorMessage.c_str());
        return false;
    }

    if(!darkSendSigner.VerifyMessage(pubKeyMasternode, vchMasterNodeSignature, strMessage, errorMessage)) {
    	retErrorMessage = "Verify message failed: " + errorMessage;
    	LogPrintf("CActiveMasternode::Dseep() - Error: %s\n", retErrorMessage.c_str());
        return false;
    }

    // Update Last Seen timestamp in masternode list
    bool found = false;
    BOOST_FOREACH(CMasterNode& mn, vecMasternodes) {
        //LogPrintf(" -- %s\n", mn.vin.ToString().c_str());
        if(mn.vin == vin) {
            found = true;
            mn.UpdateLastSeen();
        }
    }

    if(!found){
    	// Seems like we are trying to send a ping while the masternode is not registered in the network
    	retErrorMessage = "Darksend Masternode List doesn't include our masternode, Shutting down masternode pinging service! " + vin.ToString();
    	LogPrintf("CActiveMasternode::Dseep() - Error: %s\n", retErrorMessage.c_str());
        status = MASTERNODE_NOT_CAPABLE;
        notCapableReason = retErrorMessage;
        return false;
    }

    //send to all peers
    LogPrintf("CActiveMasternode::Dseep() - SendDarkSendElectionEntryPing vin = %s\n", vin.ToString().c_str());
    SendDarkSendElectionEntryPing(vin, vchMasterNodeSignature, masterNodeSignatureTime, stop);

    return true;
}
开发者ID:nodexcoin,项目名称:nodex,代码行数:45,代码来源:activemasternode.cpp

示例13: Dseep

bool CActiveThrone::Dseep(CTxIn vin, CService service, CKey keyThrone, CPubKey pubKeyThrone, std::string &retErrorMessage, bool stop) {
    std::string errorMessage;
    std::vector<unsigned char> vchThroNeSignature;
    std::string strThroNeSignMessage;
    int64_t ThroneSignatureTime = GetAdjustedTime();

    std::string strMessage = service.ToString() + boost::lexical_cast<std::string>(ThroneSignatureTime) + boost::lexical_cast<std::string>(stop);

    if(!darkSendSigner.SignMessage(strMessage, errorMessage, vchThroNeSignature, keyThrone)) {
        retErrorMessage = "sign message failed: " + errorMessage;
        LogPrintf("CActiveThrone::Dseep() - Error: %s\n", retErrorMessage.c_str());
        return false;
    }

    if(!darkSendSigner.VerifyMessage(pubKeyThrone, vchThroNeSignature, strMessage, errorMessage)) {
        retErrorMessage = "Verify message failed: " + errorMessage;
        LogPrintf("CActiveThrone::Dseep() - Error: %s\n", retErrorMessage.c_str());
        return false;
    }

    // Update Last Seen timestamp in Throne list
    CThrone* pmn = mnodeman.Find(vin);
    if(pmn != NULL)
    {
        if(stop)
            mnodeman.Remove(pmn->vin);
        else
            pmn->UpdateLastSeen();
    }
    else
    {
        // Seems like we are trying to send a ping while the Throne is not registered in the network
        retErrorMessage = "Darksend Throne List doesn't include our Throne, Shutting down Throne pinging service! " + vin.ToString();
        LogPrintf("CActiveThrone::Dseep() - Error: %s\n", retErrorMessage.c_str());
        status = THRONE_NOT_CAPABLE;
        notCapableReason = retErrorMessage;
        return false;
    }

    //send to all peers
    LogPrintf("CActiveThrone::Dseep() - RelayThroneEntryPing vin = %s\n", vin.ToString().c_str());
    mnodeman.RelayThroneEntryPing(vin, vchThroNeSignature, ThroneSignatureTime, stop);

    return true;
}
开发者ID:mergepool,项目名称:crowncoin,代码行数:45,代码来源:activethrone.cpp

示例14: Sseep

bool CActiveBlanknode::Sseep(CTxIn vin, CService service, CKey keyBlanknode, CPubKey pubKeyBlanknode, std::string &retErrorMessage, bool stop) {
    std::string errorMessage;
    std::vector<unsigned char> vchBlankNodeSignature;
    std::string strBlankNodeSignMessage;
    int64_t blankNodeSignatureTime = GetAdjustedTime();

    std::string strMessage = service.ToString() + boost::lexical_cast<std::string>(blankNodeSignatureTime) + boost::lexical_cast<std::string>(stop);

    if(!zeroSendSigner.SignMessage(strMessage, errorMessage, vchBlankNodeSignature, keyBlanknode)) {
    	retErrorMessage = "sign message failed: " + errorMessage;
    	LogPrintf("CActiveBlanknode::Sseep() - Error: %s\n", retErrorMessage.c_str());
        return false;
    }

    if(!zeroSendSigner.VerifyMessage(pubKeyBlanknode, vchBlankNodeSignature, strMessage, errorMessage)) {
    	retErrorMessage = "Verify message failed: " + errorMessage;
    	LogPrintf("CActiveBlanknode::Sseep() - Error: %s\n", retErrorMessage.c_str());
        return false;
    }

    CBlanknode* psn = snodeman.Find(vin);
    if(psn != NULL)
    {
        if(stop)
            snodeman.Remove(psn->vin);
        else
            psn->UpdateLastSeen();
    } else {
    	// Seems like we are trying to send a ping while the blanknode is not registered in the network
    	retErrorMessage = "Zerosend Blanknode List doesn't include our blanknode, Shutting down blanknode pinging service! " + vin.ToString();
    	LogPrintf("CActiveBlanknode::Sseep() - Error: %s\n", retErrorMessage.c_str());
        status = BLANKNODE_NOT_CAPABLE;
        notCapableReason = retErrorMessage;
        return false;
    }

    //send to all peers
    LogPrintf("CActiveBlanknode::Sseep() - RelayBlanknodeEntryPing vin = %s\n", vin.ToString().c_str());
    snodeman.RelayBlanknodeEntryPing(vin, vchBlankNodeSignature, blankNodeSignatureTime, stop);

    return true;
}
开发者ID:ch1c4um,项目名称:fantom,代码行数:42,代码来源:activeblanknode.cpp

示例15: GetMyExternalIP2

bool GetMyExternalIP2(const CService& addrConnect, const char* pszGet, const char* pszKeyword, CNetAddr& ipRet)
{
  SOCKET hSocket;
  if(!ConnectSocket(addrConnect, hSocket))
    return error("GetMyExternalIP() : connection to %s failed", addrConnect.ToString().c_str());

  send(hSocket, pszGet, strlen(pszGet), MSG_NOSIGNAL);

  string strLine;
  while(RecvLine(hSocket, strLine))
  {
    if(strLine.empty()) // HTTP response is separated from headers by blank line
    {
      loop
      {
        if(!RecvLine(hSocket, strLine))
        {
          closesocket(hSocket);
          return false;
        }
        if(pszKeyword == NULL)
          break;
        if(strLine.find(pszKeyword) != string::npos)
        {
          strLine = strLine.substr(strLine.find(pszKeyword) + strlen(pszKeyword));
          break;
        }
      }
      closesocket(hSocket);
      if(strLine.find("<") != string::npos)
        strLine = strLine.substr(0, strLine.find("<"));
      strLine = strLine.substr(strspn(strLine.c_str(), " \t\n\r"));
      while(strLine.size() > 0 && isspace(strLine[strLine.size()-1]))
        strLine.resize(strLine.size()-1);
      CService addr(strLine,0,true);
      printf("GetMyExternalIP() received [%s] %s\n", strLine.c_str(), addr.ToString().c_str());
      if(!addr.IsValid() || !addr.IsRoutable())
        return false;
      ipRet.SetIP(addr);
      return true;
    }
  }
开发者ID:TGCproject,项目名称:ThirdGenerationCoin,代码行数:42,代码来源:net.cpp


注:本文中的CService类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。