void CIPFilter::SaveToDefaultFile() { CString strFilePath = thePrefs.GetMuleDirectory(EMULE_CONFIGDIR) + DFLT_IPFILTER_FILENAME; FILE* fp = _tfsopen(strFilePath, _T("wt"), _SH_DENYWR); if (fp != NULL) { for (int i = 0; i < m_iplist.GetCount(); i++) { const SIPFilter* flt = m_iplist[i]; CHAR szStart[16]; ipstrA(szStart, _countof(szStart), htonl(flt->start)); CHAR szEnd[16]; ipstrA(szEnd, _countof(szEnd), htonl(flt->end)); if (fprintf(fp, "%-15s - %-15s , %3u , %s\n", szStart, szEnd, flt->level, flt->desc) == 0 || ferror(fp)) { CString strError; strError.Format(_T("Failed to save IP filter to file \"%s\" - %s"), strFilePath, _tcserror(errno)); throw strError; } } fclose(fp); m_bModified = false; } else { CString strError; strError.Format(_T("Failed to save IP filter to file \"%s\" - %s"), strFilePath, _tcserror(errno)); throw strError; } }
bool CUpDownClient::SendHttpBlockRequests() { USES_CONVERSION; ASSERT( GetDownloadState() == DS_DOWNLOADING ); ASSERT( m_ePeerCacheDownState == PCDS_WAIT_CLIENT_REPLY || m_ePeerCacheDownState == PCDS_DOWNLOADING ); m_bPeerCacheDownHit = false; m_dwLastBlockReceived = ::GetTickCount(); if (reqfile == NULL) throw CString(_T("Failed to send block requests - No 'reqfile' attached")); CreateBlockRequests(1); if (m_PendingBlocks_list.IsEmpty()){ if (m_pPCDownSocket != NULL){ m_pPCDownSocket->Safe_Delete(); ASSERT( m_pPCDownSocket == NULL ); SetPeerCacheDownState(PCDS_NONE); } SetDownloadState(DS_NONEEDEDPARTS); SwapToAnotherFile(_T("A4AF for NNP file. CUpDownClient::SendHttpBlockRequests()"), true, false, false, NULL, true, true); return false; } // PeerCache does not support persistant HTTP connections if (m_pPCDownSocket != NULL) { m_pPCDownSocket->Safe_Delete(); ASSERT( m_pPCDownSocket == NULL ); SetPeerCacheDownState(PCDS_NONE); return SendPeerCacheFileRequest(); } ASSERT( m_pPCDownSocket == NULL ); m_pPCDownSocket = new CPeerCacheDownSocket(this); m_pPCDownSocket->SetTimeOut(GetPeerCacheSocketDownloadTimeout()); if (!m_pPCDownSocket->Create()){ m_pPCDownSocket->Safe_Delete(); ASSERT( m_pPCDownSocket == NULL ); return false; } ASSERT( !m_pPCDownSocket->IsConnected() ); SOCKADDR_IN sockAddr = {0}; sockAddr.sin_family = AF_INET; sockAddr.sin_port = htons( theApp.m_pPeerCache->GetCachePort() ); sockAddr.sin_addr.S_un.S_addr = theApp.m_pPeerCache->GetCacheIP(); //Try to always tell the socket to WaitForOnConnect before you call Connect. m_pPCDownSocket->WaitForOnConnect(); m_pPCDownSocket->Connect((SOCKADDR*)&sockAddr, sizeof sockAddr); POSITION pos = m_PendingBlocks_list.GetHeadPosition(); Pending_Block_Struct* pending = m_PendingBlocks_list.GetNext(pos); ASSERT( pending->block->StartOffset <= pending->block->EndOffset ); m_uReqStart = pending->block->StartOffset; m_uReqEnd = pending->block->EndOffset; m_nUrlStartPos = (uint64)-1; CStringA strPCRequest; strPCRequest.AppendFormat("GET http://%s/.ed2khash=%s HTTP/1.0\r\n", ipstrA(m_uPeerCacheRemoteIP), md4strA(reqfile->GetFileHash())); strPCRequest.AppendFormat("X-ED2K-PushId: %u\r\n", m_uPeerCacheDownloadPushId); strPCRequest.AppendFormat("Range: bytes=%I64u-%I64u\r\n", m_uReqStart, m_uReqEnd); strPCRequest.AppendFormat("User-Agent: eMule/%s\r\n", T2CA(theApp.m_strCurVersionLong)); strPCRequest.AppendFormat("X-Network: eDonkey,Kademlia\r\n"); strPCRequest.AppendFormat("\r\n"); if (thePrefs.GetDebugClientTCPLevel() > 0){ DebugSend("PeerCache-GET", this, reqfile->GetFileHash()); Debug(_T(" %hs\n"), strPCRequest); } CRawPacket* pHttpPacket = new CRawPacket(strPCRequest); theStats.AddUpDataOverheadFileRequest(pHttpPacket->size); m_pPCDownSocket->SendPacket(pHttpPacket); m_pPCDownSocket->SetHttpState(HttpStateRecvExpected); SetPeerCacheDownState(PCDS_WAIT_CACHE_REPLY); return true; }