now rhizome mdp replies get parsed and the appropriate slot, if

any, is located.
This commit is contained in:
gardners 2012-11-30 22:26:31 +10:30
parent ebbc8001cf
commit 79c90dde6e
3 changed files with 41 additions and 4 deletions

View File

@ -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;

View File

@ -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);

View File

@ -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<NQUEUES;i++) {
if (rhizome_fetch_queues[i].active.bidP) {
if (!bcmp(rhizome_fetch_queues[i].active.bid,bidprefix,
16))
{
DEBUGF("This response matches slot 0x%p",
rhizome_fetch_queues[i].active);
RETURN(0);
}
else
DEBUGF("Doesn't match this slot, because BIDs don't match: %s* vs %s",
alloca_tohex(bidprefix,16),
alloca_tohex_bid(rhizome_fetch_queues[i].active.bid));
}
}
RETURN(-1);
}
void rhizome_write_content(struct rhizome_fetch_slot *slot, char *buffer, int bytes)
{
if (bytes>(slot->file_len-slot->file_ofs))