`
ruilinruirui
  • 浏览: 1050562 次
文章分类
社区版块
存档分类
最新评论

Libbt 编译简记

 
阅读更多
libbt是一个比较简单的,C语言写的Bittorrent的库。更新的速度很慢。
官方网站是:http://sourceforge.net/projects/libbt
最新的版本是1.06(2007-09-19),之前的一个版本是1.05(2005-12-10)
另外一个网站应该也是。不过似乎停止更新了:http://libbt.sourceforge.net/

编译还是比较简单的,有点小问题,比较快的得到了解决。
./configure
make
如有需要,make clean 清楚一下之前的编译。

报错的地方似乎是两三个:stddef.h stdarg.h size_t
前两个是说在指定的几个lib或者include的地方找不到。
于是我用 find / -name "stddef.h" 把这些文件找到放到它要找的地方就行了。

关于size_t的问题,情况大概是这样的。
报错消息类似是这样(我的报错没有及时保存,用的网页上的。基本上没区别):
i686-pc-linux-gnu-gcc -O2 -march=i686 -pipe -g -Wall -I../include -I../include
-DVERSION=1.05 -g -L. -o btlist btlist.c -lbt -lresolv -luuid -lssl -lcurl
`curl-config --libs` -lm
In file included from btlist.c:16:
/usr/include/openssl/sha.h:109: error: expected declaration specifiers or '...'
before 'size_t'
/usr/include/openssl/sha.h:111: error: expected declaration specifiers or '...'
before 'size_t'
/usr/include/openssl/sha.h:116: error: expected declaration specifiers or '...'
before 'size_t'
/usr/include/openssl/sha.h:118: error: expected declaration specifiers or '...'
before 'size_t'
/usr/include/openssl/sha.h:138: error: expected declaration specifiers or '...'
before 'size_t'
/usr/include/openssl/sha.h:140: error: expected declaration specifiers or '...'
before 'size_t'
/usr/include/openssl/sha.h:142: error: expected declaration specifiers or '...'
before 'size_t'
/usr/include/openssl/sha.h:144: error: expected declaration specifiers or '...'
before 'size_t'
/usr/include/openssl/sha.h:185: error: expected declaration specifiers or '...'
before 'size_t'
/usr/include/openssl/sha.h:187: error: expected declaration specifiers or '...'
before 'size_t'
/usr/include/openssl/sha.h:189: error: expected declaration specifiers or '...'
before 'size_t'
/usr/include/openssl/sha.h:191: error: expected declaration specifiers or '...'
before 'size_t'
btlist.c: In function 'main':
btlist.c:106: warning: pointer targets in passing argument 1 of 'SHA1' differ
in signedness
btlist.c:106: warning: passing argument 2 of 'SHA1' makes pointer from integer
without a cast
btlist.c:106: error: too many arguments to function 'SHA1'
make[1]: *** [btlist] Error 1
make[1]: Leaving directory `/var/tmp/portage/libbt-1.05/work/libbt-1.05/src'
make: *** [compile] Error 2

!!! ERROR: net-libs/libbt-1.05 failed.
后来从http://bugs.gentoo.org/show_bug.cgi?id=152489 找到了答案。
  Adding " #include <sys/types.h> " to src/btlist.c solved the problem for both
1.04 and 1.05 on my box.Diff looks like this:

--- libbt-1.04/src/btlist.c 2004-04-18 09:56:26.000000000 +0300
+++ libbt-1.04-fixed/src/btlist.c 2006-11-04 14:39:18.000000000 +0200
@@ -1,5 +1,6 @@
#include "config.h"

+#include <sys/types.h>
#include <openssl/sha.h>
#include <stdlib.h>
#include <string.h>

实际上也就是要加上这么一句在头文件的引用中:
#include <sys/types.h>

然后make clean之后再重新./configure 和 make 就搞定了。

生成了三个可执行文件:btcheck, btlist, btget
使用方式很简单:
就是命令后面跟种子文件名就行了。
比如:
btcheck OpenOffice.torrent 检查种子文件,分块信息
btlist OpenOffice.torrent 列举种子文件内信息,比如文件名,hash值,tracker的url和list之类的。
btget OpenOffice.torrent 最有用的就这个啦,就是下载文件了。时不时的给出peer在列表array中的进入退出情况。
同时给出下载的百分比,等等。。。

给出几个下载中的状态界面,我用它下载了OpenOffice:
中间下载的时候,也许是网络临时断了一下。我也不知道,生成了一个后缀为.fastresume的文件。2个Byte。
文本打开后就两个字母:fc。具体做什么的不太清楚。

1。有peer退出,发送消息(似乎是确认吧,还没仔细看程序)
Peer 85.132.136.165:6881 not found in arrayUpload 0bps
Peer 85.132.136.165:6881 not found in array
Sending message to peer 85.132.136.165:
00000000: 64353a61 64646564 363a5584 88a5e11a 373a6164 |dded6:U?????7:added.|
00000014: 6465642e 66303a65 ........ ........ ........ |f0:e?????...........|

2。有peer加入
Peer 85.132.136.165:6881 found in array at position 0
Sending message to peer 85.132.136.165:
00000000: 64373a61 64646564 2e66303a 65...... ........ |dded.f0:e?????......|

3。时间间隔,以及某个block hash值准备完毕。
Time 1224753594
Time 1224753595
Time 1224753596
hash ok for block 124
Time 1224753597
Time 1224753598
Time 1224753599

4。下载完成时
0x8ae6e78(DICT)={
0x8ae84c8(STRING)=(8)'complete'
=>
0x8ae8318(INTEGER)=4
0x8ae84dc(STRING)=(10)'incomplete'
=>
0x8ae8368(INTEGER)=1
0x8ae84f0(STRING)=(8)'interval'
=>
0x8ae8330(INTEGER)=1800
0x8ae8504(STRING)=(12)'min interval'
=>
0x8ae8418(INTEGER)=1500
0x8ae8518(STRING)=(5)'peers'
=>
0x8ae84a0(STRING)=(0)''
0x8ae852c(STRING)=(7)'private'
=>
0x8ae00d8(INTEGER)=0
}
Tracker notified of complete
Time 1224753811
read: [503] Peer disconnected after repeated errorsbps
6: Read error Peer disconnected after repeated errors
6: Peer 85.132.136.165 shutdown read (Peer disconnected after repeated errors)
Time 1224753812
Time 1224753813
Time 1224753814
Time 1224753815
Time 1224753816
Time 1224753817
Time 1224753818
Time 1224753819
Time 1224753820
Time 1224753821
Time 1224753822
Time 1224753823
Time 1224753824
Time 1224753825
Time 1224753826
Time 1224753827
Time 1224753828
Time 1224753829
Time 1224753830
Time 1224753831
Time 1224753832
Time 1224753833
Writing fast resume data for OOo_3.0.0rc4_20080930_LinuxIntel_install_en-US.tar.gz...done
0x8ae6e78(DICT)={
0x8ae8120(STRING)=(8)'complete'
=>
0x8ae7f90(INTEGER)=5
0
x8ae8134(STRING)=(10)'incomplete'
=>
0x8ae7fc0(INTEGER)=0
0x8ae8148(STRING)=(8)'interval'
=>
0x8ae7fa8(INTEGER)=1800
0x8ae815c(STRING)=(12)'min interval'
=>
0x8ae8070(INTEGER)=1500
0x8ae8170(STRING)=(5)'peers'
=>
0x8ae80f8(STRING)=(0)''
0x8ae8184(STRING)=(7)'private'
=>
0x8ae1680(INTEGER)=0
}
Tracker shutdown complete
[root@localhost LibbtExe]#
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics