• 大小: 567KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-10-18
  • 语言: C/C++
  • 标签: p2p  bt  VC++  

资源简介

自行编写的全套BT源代码,C++编写,完全实现BT的功能,并且经过了大量和长期的实际应用。是可以提供正常商业服务的基础P2P文件共享软件。

资源截图

代码片段和文件信息

// Bdecode.cpp: implementation of the CBdecode class.
//
//////////////////////////////////////////////////////////////////////

#include “stdafx.h“
#include “testBT.h“
#include “Bdecode.h“

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CBdecode::CBdecode()
{
m_lsize = 0;
m_pBuf = 0;
}

CBdecode::~CBdecode()
{

}

CVal* CBdecode::decode_int(long &lPos)
{
//*
long lOldPos = lPos;
for (; lPos {
if (m_pBuf[lPos] == ‘e‘)
{
lPos ++;
break;
}
}
if (lPos > m_lsize)
return 0;


char* pstrStop = 0;
long l = strtol(m_pBuf+lOldPos &pstrStop 10);

if (pstrStop[0] != ‘e‘)
return 0;

return new CVal(l);
}


CVal* CBdecode::decode_string(long &lPos)
{
long lOldPos = lPos;

for (; lPos {
if (m_pBuf[lPos] == ‘:‘)
{
lPos ++;
break;
}
}

if (lPos > m_lsize)
return 0;

char* pstrStop = 0;
long len = strtol(m_pBuf+lOldPos &pstrStop 10);

if (pstrStop[0] != ‘:‘)
return 0;

if ((lPos+len) > m_lsize)
return 0;

CVal* pVal = new CVal(m_pBuf+lPos len);
lPos += len;
 
return pVal;
}

void ClearList(VALLIST* pls)
{
VALLIST::iterator iter = pls->begin();
while(iter != pls->end())
{
delete *iter;
iter++;
}
}

CVal* CBdecode::decode_list(long &lPos)
{
VALLIST* ls = new VALLIST();

for (; lPos {
if (m_pBuf[lPos] == ‘e‘)
{
lPos++;
break;
}

CVal* pRet = bdecode_rec(lPos);
if (!pRet)
{
ClearList(ls);
delete ls;
return 0;
}

ls->push_back(pRet);
}

if (lPos > m_lsize)
{
ClearList(ls);
delete ls;
return 0;
}

return new CVal(ls);
}

void ClearMap(VALMAP* pmap)
{
VALMAP::iterator iter = pmap->begin();
while(iter != pmap->end())
{
delete (*iter).second;
iter++;
}
}

CVal*  CBdecode::decode_dict(long& lPos)
{
VALMAP* pmap = new VALMAP();
string strLast;

for (; lPos {
if (m_pBuf[lPos] == ‘e‘)
{
lPos++;
break;
}

CVal* pRet = decode_string(lPos);
if (!pRet)
{
ClearMap(pmap);
delete pmap;
return 0;
}

string strCur = pRet->pstrVal;
delete pRet;

if (strLast.size() > 0)
{
if (strCur <= strLast)
{
ClearMap(pmap);
delete pmap;
return 0;
}
}

strLast = strCur;

CVal* pRetVal = bdecode_rec(lPos);
if (!pRetVal)
{
ClearMap(pmap);
delete pmap;
return 0;
}

(*pmap)[strLast] = pRetVal;
}

if (lPos > m_lsize)
{
ClearMap(pmap);
delete pmap;
return 0;
}


return new CVal(pmap);
}


CVal* CBdecode::bdecode_rec(long& lPos)
{
CVal* pRet = 0;

char t = m_pBuf[lPos];

switch (t)
{
case ‘i‘:
return

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     目录          0  2004-02-27 14:59  GGBT

     文件      33490  2003-09-25 23:04  GGBT\sizecbar.cpp

     文件       4835  2003-08-02 23:00  GGBT\ctrlext.h

     文件       2747  2003-08-02 22:55  GGBT\ctrlext.cpp

     文件       8432  1980-04-26 13:45  GGBT\ctrlext.inl

     文件      24093  2004-02-27 15:04  GGBT\testBT.clw

     文件      13995  2004-02-27 15:21  GGBT\testBT.plg

     文件      49968  2003-10-29 10:48  GGBT\testBT.rc

     文件      18224  2003-10-29 17:45  GGBT\testBT.dsp

     文件       6335  2003-09-25 23:04  GGBT\sizecbar.h

     文件       1544  2003-09-22 01:46  GGBT\Downloader.h

     文件        705  2003-08-03 02:21  GGBT\BTFormat.h

     文件       2011  2003-09-29 10:56  GGBT\Connection.h

     文件       2347  2003-10-12 11:23  GGBT\testBT.h

     文件        522  2003-08-02 23:00  GGBT\Parseargs.h

     文件       4969  2003-08-24 02:16  GGBT\Choker.cpp

     文件     749952  2003-09-25 15:46  GGBT\ip.dat

     文件       1013  2003-08-02 22:55  GGBT\Common.cpp

     文件       1428  2003-10-06 18:44  GGBT\StdAfx.h

     文件       1415  2003-09-28 01:05  GGBT\MonitorBar.h

     文件        537  2003-09-19 11:36  GGBT\testBT.dsw

     文件        900  2003-08-02 23:00  GGBT\SortClass.h

     文件       2694  2003-10-06 13:05  GGBT\MenuSpawn.h

     文件       2195  2003-09-29 01:43  GGBT\testBTDoc.h

     文件       3661  2003-10-11 02:01  GGBT\Download.h

     文件       4229  2004-02-27 15:13  GGBT\IPLocater.cpp

     文件        783  2003-08-02 23:00  GGBT\Measure.h

     文件       2985  2003-10-12 13:59  GGBT\ButtonEx.h

     文件       4203  2003-10-07 23:37  GGBT\ExpandingDialog.cpp

     文件        212  2003-08-02 22:55  GGBT\StdAfx.cpp

............此处省略193个文件信息

评论

共有 条评论