src/peer/queue.c \
src/peer/reject.c \
src/peer/request.c \
+ src/piece.c \
src/pqueue.c \
src/rss/entry.c \
src/rss/footer.c \
inc/meta.h \
inc/net.h \
inc/opt.h \
+ inc/piece.h \
inc/pqueue.h \
inc/rss.h \
inc/session.h \
unsigned int interested: 1;
unsigned char peer_id[PEER_PEER_ID_SIZE];
-
uint8_t infohash[PEER_INFOHASH_SIZE];
+ struct torrent *torrent;
+
uint8_t *bitfield;
size_t bitfield_size;
};
#include<net.h>
+#include<piece.h>
#include<session.h>
int peer_bitfield(struct peer*);
--- /dev/null
+#ifndef __PIECE_H_
+#define __PIECE_H_
+
+#include<stddef.h>
+#include<stdint.h>
+
+struct piece {
+ const char *path;
+ uint64_t start;
+
+ uint8_t *data;
+ size_t data_size;
+};
+
+#include<torrent.h>
+
+struct piece* piece_load(const struct torrent*,size_t);
+
+#endif
static int peer_handshake_receive(struct peer *info) {
char header[HEADER_LENGTH];
- struct torrent *p;
int i;
if((i = net_wait(info,header,HEADER_LENGTH))<=0) {
&(header[HANDSHAKE_STRING_LENGTH+PEER_INFOHASH_SIZE]),
PEER_INFOHASH_SIZE);
- p = session_find_torrent(info->infohash,PEER_INFOHASH_SIZE);
- if(NULL==p) { return -1; }
+ info->torrent = session_find_torrent(info->infohash,PEER_INFOHASH_SIZE);
+ if(NULL==info->torrent) { return -1; }
info->handshake = 1;
#include<peer.h>
int peer_piece(struct peer *info) {
- return -1;
+ struct piece_request *p;
+ struct piece *piece;
+
+ p = info->piece_requests;
+
+ piece = piece_load(info->torrent,p->index);
+ if(NULL==piece) { return -1; }
+
+ if( p->begin + p->length > piece->data_size ) { return -1; }
+
+ if(net_send(info,&(piece->data[p->begin]),p->length)<0) { return -1; }
+ if(info->out!=NULL) { return 0; }
+
+ info->piece_requests = info->piece_requests->next;
+
+ return 1;
}
int peer_piece_queue(struct peer *info, struct piece_request *to_insert) {
--- /dev/null
+#include<piece.h>
+
+int piece_cache_access() {
+ return -1;
+}
+
+int piece_cache_find() {
+ return -1;
+}
+
+int piece_cache_init() {
+ return -1;
+}
+
+int piece_cache_remove() {
+ return -1;
+}
+
+struct piece *piece_load(const struct torrent *torrent, size_t index) {
+ return NULL;
+}