gpt4 book ai didi

c - 为什么Tracker服务器发送 "\x03\0\0\0r.opConnection ID missmatch."作为响应消息? (比特流协议(protocol))

转载 作者:行者123 更新时间:2023-11-30 17:50:19 25 4
gpt4 key购买 nike

我正在尝试实现 Bittorrent 客户端。但我很难与跟踪服务器进行通信。它不会发送 Bencoded 字典作为对我的请求的响应。
它始终发送以下字符串作为其响应。

"\x03\0\0\0r.opConnection ID missmatch."

这是 torrent 元文件的子字符串。

d8:announce38:udp://tracker.publicbt.com:80/announce13:announce-
listll38:udp://tracker.publicbt.com:80/announceel
44:udp://tracker.openbittorrent.com:80/announceel
43:udp://fr33domtracker.h33t.com:3310/announceel
35:udp://tracker.istole.it:80/announceel
37:http://fr33dom.h33t.com:3310/announceel
36:udp://fr33dom.h33t.com:3310/announceee
7:comment61:Torrent downloaded from torrent cache at http://torcache.net/
10:created by13:uTorrent/330013:creation datei1372123476e8:encoding
5:UTF-8
4:infod13:file-durationli207ee10:file-mediali0ee6:lengthi59625855e4:name
7:Owl.mp412:piece lengthi65536e

我将以下消息发送到跟踪服务器,以获取对等点列表。

udp://tracker.openbittorrent.com:80/announce?info_hash=%%73%%78%%b1%%df%%32%%7c%%78%%0f%%d2%%90%%59%%b8%%0c%%03%%bd%%62%%0f%%45%%af%%26
&left=0
&uploaded=0
&port=6882
&event=started

这是我的代码,它将请求发送到跟踪器服务器,然后收到一个尴尬的响应。

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <errno.h>

#define BUFSIZE 1024

int main( int argc, char** argv )
{
int sockfd, portno, n;
struct sockaddr_in serveraddr;
struct hostent *server;
char buf[BUFSIZE];

portno = 80;

/* socket: create the socket */
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
if (sockfd < 0)
{
fprintf(stderr, "socket error\n");
exit(0);
}

server = gethostbyname("tracker.openbittorrent.com");
printf("%s\n", inet_ntoa( *(struct in_addr*)server->h_addr_list[0]));
/* build the server's Internet address */
bzero((char *) &serveraddr, sizeof(serveraddr));
serveraddr.sin_family = AF_INET;
serveraddr.sin_addr.s_addr = inet_addr( inet_ntoa( *(struct in_addr*)server->h_addr_list[0]) );
serveraddr.sin_port = htons(portno);

/* connect: create a connection with the server */
if (connect(sockfd, (struct sockaddr *)&serveraddr, sizeof(serveraddr)) < 0)
{
printf("error : %d\n", errno);
fprintf(stderr, "connect error\n");
exit(0);
}

/* generate request message into buffer pointed by buf. */
sprintf(buf, "udp://tracker.openbittorrent.com:80/announce"
"?info_hash=%%73%%78%%b1%%df%%32%%7c%%78%%0f%%d2%%90%%59%%b8%%0c%%03%%bd%%62%%0f%%45%%af%%26"
"&left=0"
"&uploaded=0"
"&ip=0"
"&key=0"
"&port=6882"
"&event=started"
);

/* write: send the request to the tracker server */
n = write(sockfd, buf, strlen(buf));
if (n < 0)
{
fprintf(stderr, "fail to send your request.\n");
exit(0);
}
memset(buf, 0x00, sizeof(buf));
n = read(sockfd, buf, BUFSIZE);

printf("%s\n", buf + 4);
close(sockfd);
return 0;

}

附件是 torrent 文件。
Attached

最佳答案

首先,您向使用完全不同协议(protocol)的 UDP 跟踪器发送 http 请求。
请参阅:http://www.bittorrent.org/beps/bep_0015.html

其次,您的 info_hash 的 URL 编码是错误的。
它看起来像这样:

info_hash=%%73%%78%%b1%%df%%32%%7c%%78%%0f%%d2%%90%%59%%b8%%0c%%03%%bd%%62%%0f%%45%%af%%26

它应该看起来像这样:

info_hash=%0C%7Dr%CAQvQf%10%80%CBB%07%3DT_%24%3C%F8%2C

第三,您需要将“compact=1”添加到请求字符串中。
请参阅:Why does tracker server NOT understand my request? (Bittorrent protocol)

尝试:

http://exodus.desync.com:6969/announce?info_hash=%0C%7Dr%CAQvQf%10%80%CBB%07%3DT_%24%3C%F8%2C&left=0&uploaded=0&port=6882&event=started&compact=1

跟踪器将回答:

d8:completei1e10:downloadedi0e10:incompletei0e8:intervali1720e12:min intervali860e5:peers6:******e

关于c - 为什么Tracker服务器发送 "\x03\0\0\0r.opConnection ID missmatch."作为响应消息? (比特流协议(protocol)),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17337793/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com