Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Started FilePartList

  • Loading branch information...
commit f92b3ade6bf330b8bfc63ef70c73d4ec93143dc4 1 parent 2535379
@Detegr authored
View
3  core/core.c
@@ -528,6 +528,8 @@ void* read_thread(void* args)
break;
}
// Event types that won't be sent to pipe listeners
+ case RequestFilePartList:
+ case FilePartList:
case Metadata:
case FilePart:
event_run_callbacks(e);
@@ -761,6 +763,7 @@ int core_start(void)
event_addlistener(RequestFileList, &handlerequestfilelist, NULL);
event_addlistener(RequestFileListLocal, &handlerequestfilelistlocal, NULL);
event_addlistener(AddFile, &handleaddfile, NULL);
+ event_addlistener(RequestFilePartList, &handlefilepartlistrequest, NULL);
while(run_threads)
{
View
2  core/event.h
@@ -20,6 +20,8 @@ typedef enum {
AddFile,
Setup,
Status,
+ RequestFilePartList,
+ FilePartList,
EventCount // For iterating through eventtypes
} EventType;
View
15 core/file.c
@@ -6,6 +6,7 @@
#include <stdlib.h>
#include <string.h>
#include "peer.h"
+#include "peermanager.h"
#include "event.h"
#include "core.h"
@@ -124,3 +125,17 @@ void request_file_part_from_peer(int partnum, const char* sha_str, struct peer*
send_event_to_peer_nonblocking(p, e);
free(e);
}
+
+void request_file_part_listing_from_peers(const char *sha_str, struct peer *exclude_current)
+{
+ printf("Requesting file part listing from all peers\n");
+ evt_t* e=event_new(RequestFilePartList, sha_str, strnlen(sha_str, SHA_DIGEST_STR_MAX_LENGTH-1)+1);
+ printf("Hash: %s, len: %lu\n", sha_str, strnlen(sha_str, SHA_DIGEST_STR_MAX_LENGTH-1)+1);
+ struct peer* p;
+ while((p=peer_next()))
+ {
+ if(p != exclude_current) send_event_to_peer(p, e);
+ }
+ send_to_all(e);
+ free(e);
+}
View
2  core/file.h
@@ -43,5 +43,7 @@ void sha_to_str(const unsigned char* sha, char* out);
void create_metadata_file(const char* from, char* file_sha_as_str);
void check_or_create_metadata(const unsigned char* sha_data, size_t sha_size);
void request_file_part_from_peer(int partnum, const char* sha_str, struct peer* p);
+void request_file_part_listing_from_peers(const char *sha_str, struct peer *exclude_current);
+const metadata_t *get_metadata(const char *sha_str);
#endif
View
9 core/handlers.c
@@ -91,6 +91,7 @@ static void* send_file_part_thread(void* args)
struct file_part_thread_data* td=args;
send_file_part(td);
pthread_mutex_unlock(&td->transfer->file_lock);
+ clear_file_transfer(td->transfer);
free(td);
return 0;
}
@@ -322,6 +323,7 @@ void handlemetadata(evt_t* e, void* data)
sha_to_str(md->data, sha_str);
check_or_create_metadata(md->data, e->data_len-sizeof(metadata_t));
create_file_transfer(p, sha_str, md);
+ //request_file_part_listing_from_peers(sha_str, p);
request_file_part_from_peer(0, sha_str, p);
}
else
@@ -557,3 +559,10 @@ void handlestatus(pipeevt_t *e, void *data)
free(jsonstr);
json_decref(root);
}
+
+void handlefilepartlistrequest(evt_t *e, void *data)
+{
+ const char *hash_str=(const char*)e->data;
+ printf("File part list requested for hash %s\n", hash_str);
+
+}
View
1  core/handlers.h
@@ -16,5 +16,6 @@ void handlerequestfilelist(evt_t* e, void* data);
void handleaddfile(evt_t* e, void* data);
void handlesetup(pipeevt_t *e, void *data);
void handlestatus(pipeevt_t *e, void *data);
+void handlefilepartlistrequest(evt_t *e, void *data);
#endif
Please sign in to comment.
Something went wrong with that request. Please try again.