mirror of
https://github.com/servalproject/serval-dna.git
synced 2024-12-19 05:07:56 +00:00
Fix bug in Rhizome fetch - byte order of sin_port
Also improve some debug logging
This commit is contained in:
parent
6556637251
commit
4eb3910dc1
@ -598,7 +598,7 @@ int rhizome_queue_manifest_import(rhizome_manifest *m, struct sockaddr_in *peeri
|
||||
|
||||
long long filesize = rhizome_manifest_get_ll(m, "filesize");
|
||||
|
||||
if (1||debug&DEBUG_RHIZOMESYNC)
|
||||
if (debug & DEBUG_RHIZOMESYNC)
|
||||
DEBUGF("Getting ready to fetch file %s for manifest %s", m->fileHexHash, id);
|
||||
|
||||
if (filesize > 0 && m->fileHexHash[0])
|
||||
@ -642,32 +642,38 @@ int rhizome_queue_manifest_import(rhizome_manifest *m, struct sockaddr_in *peeri
|
||||
close(sock);
|
||||
return -1;
|
||||
}
|
||||
struct sockaddr_in addr = *peerip;
|
||||
addr.sin_family = AF_INET;
|
||||
INFOF("HTTP CONNECT family=%u port=%u addr=%u.%u.%u.%u",
|
||||
peerip->sin_family, peerip->sin_port,
|
||||
((unsigned char*)&peerip->sin_addr.s_addr)[0],
|
||||
((unsigned char*)&peerip->sin_addr.s_addr)[1],
|
||||
((unsigned char*)&peerip->sin_addr.s_addr)[2],
|
||||
((unsigned char*)&peerip->sin_addr.s_addr)[3]
|
||||
addr.sin_family, ntohs(addr.sin_port),
|
||||
((unsigned char*)&addr.sin_addr.s_addr)[0],
|
||||
((unsigned char*)&addr.sin_addr.s_addr)[1],
|
||||
((unsigned char*)&addr.sin_addr.s_addr)[2],
|
||||
((unsigned char*)&addr.sin_addr.s_addr)[3]
|
||||
);
|
||||
if (connect(sock, (struct sockaddr*)peerip, sizeof *peerip) == -1 && errno != EINPROGRESS) {
|
||||
WHY_perror("connect");
|
||||
WHY("Failed to open socket to peer's rhizome web server");
|
||||
close(sock);
|
||||
return -1;
|
||||
if (connect(sock, (struct sockaddr*)&addr, sizeof addr) == -1) {
|
||||
if (errno == EINPROGRESS) {
|
||||
if (debug & DEBUG_RHIZOMESYNC)
|
||||
DEBUGF("connect() returned EINPROGRESS");
|
||||
} else {
|
||||
WHY_perror("connect");
|
||||
WHY("Failed to open socket to peer's rhizome web server");
|
||||
close(sock);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
rhizome_file_fetch_record *q=&file_fetch_queue[rhizome_file_fetch_queue_count];
|
||||
q->manifest = m;
|
||||
*manifest_kept = 1;
|
||||
q->alarm.poll.fd=sock;
|
||||
strncpy(q->fileid, m->fileHexHash, RHIZOME_FILEHASH_STRLEN + 1);
|
||||
snprintf(q->request,1024,"GET /rhizome/file/%s HTTP/1.0\r\n\r\n",
|
||||
q->fileid);
|
||||
snprintf(q->request,1024,"GET /rhizome/file/%s HTTP/1.0\r\n\r\n", q->fileid);
|
||||
q->request_len=strlen(q->request);
|
||||
q->request_ofs=0;
|
||||
q->state=RHIZOME_FETCH_CONNECTING;
|
||||
q->file_len=-1;
|
||||
q->file_ofs=0;
|
||||
|
||||
|
||||
/* XXX Don't forget to implement resume */
|
||||
/* XXX We should stream file straight into the database */
|
||||
const char *id = rhizome_manifest_get(q->manifest, "id", NULL, 0);
|
||||
|
@ -270,7 +270,6 @@ void rhizome_client_poll(struct sched_ent *alarm)
|
||||
|
||||
void rhizome_server_poll(struct sched_ent *alarm)
|
||||
{
|
||||
if (debug & DEBUG_RHIZOMESYNC) D;
|
||||
struct sockaddr addr;
|
||||
unsigned int addr_len = sizeof addr;
|
||||
int sock;
|
||||
|
@ -335,14 +335,14 @@ int overlay_rhizome_saw_advertisements(int i,overlay_frame *f, long long now)
|
||||
int ofs=0;
|
||||
int ad_frame_type=f->payload->bytes[ofs++];
|
||||
struct sockaddr_in httpaddr = *(struct sockaddr_in *)f->recvaddr;
|
||||
httpaddr.sin_port = RHIZOME_HTTP_PORT;
|
||||
httpaddr.sin_port = htons(RHIZOME_HTTP_PORT);
|
||||
int manifest_length;
|
||||
rhizome_manifest *m=NULL;
|
||||
|
||||
switch (ad_frame_type) {
|
||||
case 3:
|
||||
/* The same as type=1, but includes the source HTTP port number */
|
||||
httpaddr.sin_port = (f->payload->bytes[ofs] << 8) + f->payload->bytes[ofs + 1];
|
||||
httpaddr.sin_port = htons((f->payload->bytes[ofs] << 8) + f->payload->bytes[ofs + 1]);
|
||||
ofs += 2;
|
||||
// FALL THROUGH ...
|
||||
case 1:
|
||||
|
Loading…
Reference in New Issue
Block a user