hints.ai_next = NULL; \
}
+#define BYTES_TO_UINT32_T(x) \
+ (uint32_t) \
+ (x[0]<<24) + \
+ (x[1]<<16) + \
+ (x[2]<<8) + \
+ x[3]
+
int net_cache(void**,size_t*,void*,size_t);
ssize_t net_expected(struct peer*,enum peer_message*);
void net_handler(int,struct peer*);
if(buf[4]!=0xff) { (*type) = (uint8_t)buf[4]; }
- i = 0;
- for(size_t j=0;j<4;j++) {
- i <<= 8;
- i += buf[j];
- }
+ i = BYTES_TO_UINT32_T(buf);
return i+4;
}
#include<peer.h>
int peer_bitfield(struct peer *info) {
- return -1;
+ uint8_t *buf;
+ buf = malloc(info->bitfield_size);
+ if(NULL==buf) { return -1; }
+
+ memset(buf,0xff,info->bitfield_size);
+
+ if(net_send(info,buf,info->bitfield_size)<0) { return -1; }
+
+ free(buf);
+
+ return 1;
}
int peer_bitfield_init(struct peer *info, size_t pieces) {
}
int peer_request_received(struct peer *info, ssize_t len) {
+ unsigned char buf[17];
+// struct peer_request *req;
+// unsigned char *p;
+// size_t index, begin, length;
+
+ if(net_wait(info,buf,17)<0) { return -1; }
+ if(info->in!=NULL) { return 0; }
+
+/* if(peer_request_init(&req)<0) { return -1; }
+
+ p = &(buf[5]);
+ req->index = BYTES_TO_UINT32_T(p);
+ p = &(buf[9]);
+ req->begin = BYTES_TO_UINT32_T(p);
+ p = &(buf[13]);
+ req->length = BYTES_TO_UINT32_T(p);
+
+ if(peer_piece_queue(info,req)<0) { return -1; }
+*/
return -1;
}