bittorrent 学习 tracker peer通讯
Posted itdef
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了bittorrent 学习 tracker peer通讯相关的知识,希望对你有一定的参考价值。
看看 tracker.c文件
http_encode() 为http发送进行编码转换
1 int http_encode(unsigned char *in,int len1,char *out,int len2) 2 { 3 int i, j; 4 char hex_table[16] = "0123456789abcdef"; 5 6 if( (len1 != 20) || (len2 <= 90) ) return -1; 7 for(i = 0, j = 0; i < 20; i++, j++) { 8 if( isalpha(in[i]) || isdigit(in[i]) ) 9 out[j] = in[i]; 10 else { 11 out[j] = ‘%‘; 12 j++; 13 out[j] = hex_table[in[i] >> 4]; 14 j++; 15 out[j] = hex_table[in[i] & 0xf]; 16 } 17 } 18 out[j] = ‘