mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-26 16:09:35 -05:00
forgot to add these two files
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@1839 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
75a32ad032
commit
426fc06938
34
libretroshare/src/ft/ftchunkmap.cc
Normal file
34
libretroshare/src/ft/ftchunkmap.cc
Normal file
@ -0,0 +1,34 @@
|
||||
#include <math.h>
|
||||
#include "ftchunkmap.h"
|
||||
|
||||
ChunkMap::ChunkMap(uint64_t s)
|
||||
{
|
||||
file_size = s ;
|
||||
|
||||
chunk_size = 1024*1024 ; // 1MB chunks
|
||||
uint64_t n = s/chunk_size ;
|
||||
if(s% (uint64_t)chunk_size != 0)
|
||||
++n ;
|
||||
|
||||
chunks.resize(n,CHUNK_OUTSTANDING) ;
|
||||
}
|
||||
|
||||
void ChunkMap::received(uint64_t offset)
|
||||
{
|
||||
uint64_t n = offset/chunk_size ;
|
||||
|
||||
for(uint64_t i=0;i<n;++i)
|
||||
chunks[i] = CHUNK_DONE ;
|
||||
|
||||
if(offset == file_size)
|
||||
chunks.back() = CHUNK_DONE ;
|
||||
}
|
||||
|
||||
void ChunkMap::requested(uint64_t offset, uint32_t size)
|
||||
{
|
||||
int start = offset/chunk_size ;
|
||||
int end = (int)ceil((offset+size)/chunk_size) ;
|
||||
|
||||
for(int i=start;i<=end;++i)
|
||||
chunks[i] = CHUNK_ACTIVE ;
|
||||
}
|
13
libretroshare/src/ft/ftchunkmap.h
Normal file
13
libretroshare/src/ft/ftchunkmap.h
Normal file
@ -0,0 +1,13 @@
|
||||
#pragma once
|
||||
|
||||
#include <rsiface/rstypes.h>
|
||||
|
||||
class ChunkMap: public FileChunksInfo
|
||||
{
|
||||
public:
|
||||
ChunkMap(uint64_t size) ;
|
||||
|
||||
virtual void received(uint64_t offset) ;
|
||||
virtual void requested(uint64_t offset, uint32_t chunk_size) ;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user