📄 ftkernelapi.pas
字号:
{
//////////////////////////////////////////////////////////////////////////
// FTKernelAPI.pas
//
// English Notes:
//
// Copyright @ 2004-2006 p2plib.com All rights reserved.
// MSN: FlashBT@Hotmail.com
// Homepage: http://www.p2plib.com
//
// FTKernelAPI is a kernel API based on Bittorrent protocol.
//
// Please use and enjoy. Please let me know of any bugs/mods/improvements
// that you have found and I will fix them into this library.
//
// Please visit http://www.p2plib.com for the detailed information.
//
// ***********************************************************************
// Chinese Notes:
//
// 版权所有 2004-2006 北京惠软畅联网络技术有限公司 保留所有权利. 中国.
// 官方网站: http://www.p2plib.com/
//
// FTKernelAPI 是基于BitTorrent协议的内核库, 并做了强大扩展. 可以帮助您
// 快速的开发自己的P2P软件系统.
//
// FTKernelAPI 兼容BT协议内核库, 分为4个版本:
// 1. 免费版本, 使用受限制, 只支持一个并发任务, 无技术支持
// 2. 初级版本, 需付费, 支持多个任务并发, 有技术支持
// 3. 中级版本, 需付费, 支持自定义协议, 数据加密, 封锁指定IP, 限速等功能, 有技术支持
// 4. 高级版本, 需付费, 支持顺序下载, 流媒体点播, 被动回调加载任务, 有技术支持
//
// 如果发现任何错误/建议, 请通知我们, 我们将在以后的版本中很快改进和实现.
// 更详细信息请访问我的网站: http://www.p2plib.com
//////////////////////////////////////////////////////////////////////////
}
unit FTKernelAPI;
interface
uses
windows, SysUtils;
type
//定义64位无符号长整型
//Define 64bit long integer type
QWORD = int64;
//定义配置文件对象的句柄
//Define Config INI file handle
HConfigIni = PLongWord;
//定义下载任务的句柄
//Define downloader handle
HDownloader = PLongWord;
//定义读取Torrent文件的句柄
//Define Torrent file handle
HTorrentFile = PLongWord;
//定义生成Torrent文件的句柄
//Define Making Torrent file handle
HMakeTorrent = PLongWord;
//定义一个对应C语言中的字节数组
//Define Array of byte like C language
ArrayByte = array of BYTE;
//定义被动通知的回调函数
//Define callback function type
FTK_CALLBACK_FUNC = function(nSocket: UINT = 0; pData: PByte = nil): Boolean; stdcall;
//外部设置内网连接通知回调函数的指针
//Define callback function for Nat PEER notification
FTK_NAT_PEER_CALLBACK = function(pInfoHash: PByte; lpszIP: PChar; nPort: Short; pPeerID: PByte): Boolean; stdcall;
//通知外部远程呼叫结果的函数的函数
//Tell external module, a remote call is coming
FTK_UPDT_PEERCALL_CALLBACK = procedure(nActive: Byte; pPeerIP: PChar; nTCPPort: Short; pPeerID: PByte; pInfoHash: PByte; nNetType: Byte; pTransIP: PChar; nTransPort: Short); stdcall;
const
//FTKernelAPI 动态库的名称
//Name of FTKernelAPI dynamic library
FTKernelAPI_Library = 'FTKernelAPI.dll';
//用户标识的长度
//length of client identifier
IDSIZE = 20;
//BitTorrent 客户端版本信息长度
//bitorrent client version information
AGENTSIZE = 64;
//生成的SHA的散列的长度
//Length of SHA1
SHA1_DIGEST_LENGTH = 20;
//代理的类型
//Proxytypes
PROXYTYPE_NOPROXY = 0;
PROXYTYPE_SOCKS4 = 1;
PROXYTYPE_SOCKS4A = 2;
PROXYTYPE_SOCKS5 = 3;
PROXYTYPE_HTTP11 = 4;
////////////////////////
//下载状态
//Download status
DLSTATE_NONE = 0;
DLSTATE_ALLOCING = 1;
DLSTATE_CHECKING = 2;
DLSTATE_DOWNLOAD = 3;
DLSTATE_PAUSING = 4;
DLSTATE_CHECKEND = 5;
DLSTATE_FETALERR = 6;
DLSTATE_TERMINATE = 7;
//定义Piece的状态
//Piece status
PIECESTATE_INCOMPLETE = 0;
PIECESTATE_DOWNLOADING = 1;
PIECESTATE_COMPLETE = 2;
//Port type of Firewall and UPnP
//操做Windows防火墙或者UPnP时的端口类型定义
WCXT_TCP_PORT = 1;
WCXT_UDP_PORT = 2;
type
_tagPeerData = packed record
m_dwIP: DWORD;
m_nPort: WORD;
m_pPeerID: array[0..IDSIZE - 1] of BYTE;
//-------------------------------------
m_bIsLocal: BYTE;
m_szVersion: array[0..AGENTSIZE - 1] of Char;
m_qwPeerHaveSize: QWORD;
m_fDownRate: Single;
m_fUpRate: Single;
m_qwDownloaded: QWORD;
m_qwUploaded: QWORD;
m_fTimeElapsed: Single;
m_fPeerDownRate: Single;
m_szExtInfo: array[0..256 - 1] of char;
end;
ArrayPeerData = array of _tagPeerData;
type
_tagMiniPeerData = packed record
m_dwIP: DWORD;
m_nPort: WORD;
end;
ArrayMiniPeerData = array of _tagMiniPeerData;
type
_tagAnnounceData = packed record
m_szURL: array[0..512 - 1] of char;
m_bWorking: BYTE;
m_bHeader: BYTE;
m_nCount: UINT;
m_nFailed: UINT;
m_fTimeLeft: Single;
m_fLastTime: Single;
m_szExtInfo: array[0..512 - 1] of char;
end;
ArrayAnnounceData = array of _tagAnnounceData;
type
_tagFileInfo = packed record
m_szFileName: array[0..512 - 1] of char;
m_qwFileSize: QWORD;
end;
ArrayFileInfo = array of _tagFileInfo;
PFileInfoX = ^_tagFileInfo;
type
_tagErrInfo = packed record
m_szErrInfo: array[0..1024 - 1] of char;
end;
PErrorInfo = ^_tagErrInfo;
type
_tagAnnounce = packed record
m_szAnnounce: array[0..512 - 1] of char;
m_szStatus: array[0..512 - 1] of char;
m_fLastTime: double;
m_nTotalCount: UINT;
m_nFailCount: UINT;
m_nTimeOut: UINT;
end;
ArrayAnnounce = array of _tagAnnounce;
//////////////////////////////////////////////////////////////////////////
//Libary License Interface
//Set license key
//设置license的密钥
procedure FTK_License_Set(lpszLicense: PChar); stdcall; external FTKernelAPI_Library;
//////////////////////////////////////////////////////////////////////////
//Library version information
//获取当前库的版本信息, 例如: nMajor = 1, nMinor = 1 => ver: 1.1
//Get library major version, example: nMajor = 1, nMinor = 1 => ver: 1.1
procedure FTK_Version_Info(nMajor: PInteger; nMinor: PInteger); stdcall; external FTKernelAPI_Library;
//////////////////////////////////////////////////////////////////////////
//Define yourself protocol identifier string
//Define yourself protocol identifier string(to avoid Router filter)
//定义你自己的网络协议标识,可以避开某些网络运营商的协议封锁
procedure FTK_Protocol_IDS(pIDS: PChar; bAllowOtherIDS: Boolean = False); stdcall; external FTKernelAPI_Library;
//////////////////////////////////////////////////////////////////////////
//Define yourself user identifier
//Define yourself user identifier(read by tracker)
//定义自己的用户标识信息(Tracker服务器可以获取到)
procedure FTK_Identifier_String10(pS: PChar); stdcall; external FTKernelAPI_Library;
//////////////////////////////////////////////////////////////////////////
//Define yourself http tracker "UserAgent"
//Define yourself http tracker "UserAgent"
//定义自己的提交给http tracker的http协议中的"UserAgent"
procedure FTK_Http_UserAgent(lpszUA: PChar); stdcall; external FTKernelAPI_Library;
//////////////////////////////////////////////////////////////////////////
//Config INI file interface
//创建一个新的配置文件句柄
//Create a new Config INI file handle
function FTK_Config_Open(): HConfigIni; stdcall; external FTKernelAPI_Library;
//销毁一个存在的配置文件句柄
//Destroy a HConfigIni hanle
procedure FTK_Config_Close(hConfigIni: HConfigIni); stdcall; external FTKernelAPI_Library;
//设置字符串选项
//Set string value item
procedure FTK_Config_SetStr(hConfigIni: HConfigIni; lpszName: LPCTSTR; lpszValue: LPCTSTR); stdcall; external FTKernelAPI_Library;
//设置整型值选项
//Set integer value item
procedure FTK_Config_SetInt(hConfigIni: HConfigIni; lpszName: LPCTSTR; nValue: QWORD); stdcall; external FTKernelAPI_Library;
//设置浮点型选项
//Set float value item
procedure FTK_Config_SetFloat(hConfigIni: HConfigIni; lpszName: LPCTSTR; fValue: double); stdcall; external FTKernelAPI_Library;
//////////////////////////////////////////////////////////////////////////
//Context interface
//预先初始化Context的是否需要截获系统的异常
//Preinitialize param, whether to handle system exceptions
procedure FTK_Context_PreInitException(bHandleException: Boolean = True); stdcall; external FTKernelAPI_Library;
//环境初始化
//Initialize context
//@lpszIniFile: kernel configuration file - INI file
function FTK_Context_Init(lpszIniFile: LPCTSTR = nil; bLog: Boolean = True): boolean; stdcall; external FTKernelAPI_Library;
//环境初始化
//Initialize context
//@lpszIniFile: kernel configuration file - INI file
function FTK_Context_Init2(hConfigIni: HConfigIni; bLog: Boolean = True): boolean; stdcall; external FTKernelAPI_Library;
//设置被动通知的回调函数
//Set callback funtion pointer
procedure FTK_Context_NotifyCB(pfn: FTK_CALLBACK_FUNC); stdcall; external FTKernelAPI_Library;
//释放整个环境
//Release context
procedure FTK_Context_Release(); stdcall; external FTKernelAPI_Library;
//整个环境的事件驱动引擎
//Context event driver
function FTK_Context_Run(): boolean; stdcall; external FTKernelAPI_Library;
//强迫退出环境, 停止运行
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -