From 79c90dde6e0ef72c3f410640cc231e572253178b Mon Sep 17 00:00:00 2001 From: gardners Date: Fri, 30 Nov 2012 22:26:31 +1030 Subject: [PATCH] now rhizome mdp replies get parsed and the appropriate slot, if any, is located. --- overlay_mdp_services.c | 19 +++++++++++++++---- rhizome.h | 3 +++ rhizome_fetch.c | 23 +++++++++++++++++++++++ 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/overlay_mdp_services.c b/overlay_mdp_services.c index a4bc72fe..169cc706 100644 --- a/overlay_mdp_services.c +++ b/overlay_mdp_services.c @@ -141,12 +141,23 @@ int overlay_mdp_service_rhizomeresponse(overlay_mdp_frame *mdp) case 'B': /* data block */ { if (mdp->out.payload_length<(1+16+8+8+1)) RETURN(-1); - unsigned char *bid=&mdp->out.payload[1]; + unsigned char *bidprefix=&mdp->out.payload[1]; uint64_t version=read_uint64(&mdp->out.payload[1+16]); uint64_t offset=read_uint64(&mdp->out.payload[1+16+8]); - int bytes=mdp->out.payload_length-(1+16+8+8); - DEBUGF("Received %d bytes @ 0x%llx for %s version 0x%llx", - bytes,offset,alloca_tohex_bid(bid),version); + int count=mdp->out.payload_length-(1+16+8+8); + unsigned char *bytes=&mdp->out.payload[1+16+8+8]; + DEBUGF("Received %d bytes @ 0x%llx for %s* version 0x%llx", + count,offset,alloca_tohex(bidprefix,16),version); + + /* Now see if there is a slot that matches. If so, then + see if the bytes are in the window, and write them. + + If there is not matching slot, then consider setting + a slot to capture this files as it is being requested + by someone else. + */ + rhizome_received_content(bidprefix,version,offset,count,bytes); + RETURN(-1); } break; diff --git a/rhizome.h b/rhizome.h index 6e72aac2..3c4eab97 100644 --- a/rhizome.h +++ b/rhizome.h @@ -428,6 +428,9 @@ struct http_response { unsigned long long content_length; const char * body; }; + +int rhizome_received_content(unsigned char *bid,uint64_t version, uint64_t offset, + int count,unsigned char *bytes); int rhizome_server_set_response(rhizome_http_request *r, const struct http_response *h); int rhizome_server_free_http_request(rhizome_http_request *r); int rhizome_server_http_send_bytes(rhizome_http_request *r); diff --git a/rhizome_fetch.c b/rhizome_fetch.c index c981e6a6..d432b983 100644 --- a/rhizome_fetch.c +++ b/rhizome_fetch.c @@ -1178,6 +1178,29 @@ void rhizome_fetch_write(struct rhizome_fetch_slot *slot) } } +int rhizome_received_content(unsigned char *bidprefix,uint64_t version, uint64_t offset, + int count,unsigned char *bytes) +{ + IN(); + int i; + for(i=0;i(slot->file_len-slot->file_ofs))