First implementation of per-chunk CRC32 check. This is triggered

- by the right-click+Force Check on files.
- when a global hash on a downloaded file does not match the announced hash.

When a CRC map check is ordered, the CRC map is requested to one of the sources for the current file download.
When received, all downloaded chunks are checked w.r.t the reference CRC and marked as not done if the CRCs do not match.
The exchange of CRC32 map and requests has been tested, as well as CRC map checking during download (force check).

To be implemented soon:
    - caching of CRC32 maps (although these are fast to compute)
    - CRC32 map packets for normal downloads. For now these work only for turtle tunnels.
    - handling of errors if the CRC never comes. For now, the download will stay stuck in "Checking..." mode.

So, don't play too much with the force check feature for now...





git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3310 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2010-07-21 23:14:10 +00:00
parent db034b026f
commit 8bfc74485a
27 changed files with 1012 additions and 118 deletions

View file

@ -7,11 +7,11 @@ RS_TOP_DIR = ../..
include $(RS_TOP_DIR)/tests/scripts/config.mk
###############################################################
TESTOBJ = ftfileprovidertest.o ftfilecreatortest.o ftextralisttest.o ftdataplextest.o fttransfermoduletest.o
TESTOBJ = ftfileprovidertest.o ftfilecreatortest.o ftextralisttest.o ftdataplextest.o fttransfermoduletest.o ftcrc32test.o
#ftserver1test.o ftserver2test.o ftserver3test.o
TESTS = ftfileprovidertest ftfilecreatortest ftextralisttest ftdataplextest fttransfermoduletest
TESTS = ftfileprovidertest ftfilecreatortest ftextralisttest ftdataplextest fttransfermoduletest ftcrc32test
#ftserver1test ftserver2test fttransfermoduletest ftserver3test
all: tests
@ -40,6 +40,9 @@ ftserver2test : ftserver2test.o
ftserver3test : ftserver3test.o
$(CC) $(CFLAGS) -o ftserver3test ftserver3test.o $(LIBS)
ftcrc32test : ftcrc32test.o
$(CC) $(CFLAGS) -O0 -g -o ftcrc32test ftcrc32test.o $(LIBS)
###############################################################
include $(RS_TOP_DIR)/tests/scripts/rules.mk
###############################################################

View file

@ -0,0 +1,117 @@
/*
* libretroshare/src/ft: ftcrc32test.cc
*
* File Transfer for RetroShare.
*
* Copyright 2008 by Cyril Soler
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License Version 2 as published by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA.
*
* Please report all bugs and problems to "retroshare@lunamutt.com".
*
*/
#include <iostream>
#include <rsiface/rstypes.h>
#include <util/rsdir.h>
#include <ft/ftchunkmap.h>
#ifdef WIN32
#include "util/rswin.h"
#endif
#include "util/rsdir.h"
void usage(char *name)
{
std::cerr << "Computes a CRC32 map of a file." << std::endl;
std::cerr << "Usage: " << name << " -h <path>" << std::endl;
}
int main(int argc, char **argv)
{
int c;
uint32_t period = 1;
uint32_t dPeriod = 600; /* default 10 minutes */
std::list<std::string> hashList;
while(-1 != (c = getopt(argc, argv, "f:h:")))
{
switch (c)
{
case 'f':
hashList.push_back(std::string(optarg));
break;
default:
usage(argv[0]);
break;
}
}
uint32_t flags = 0;
for(std::list<std::string>::const_iterator it(hashList.begin()); it != hashList.end(); it++)
{
std::cerr << "Hashing file :" << *it << std::endl ;
std::string hash ;
RsDirUtil::hashFile( *it,hash) ;
std::cerr << "Hash = " << hash << std::endl;
FILE *f = fopen( (*it).c_str(),"rb" ) ;
if(f == NULL)
{
std::cerr << "Could not open this file! Sorry." << std::endl ;
return 0 ;
}
CRC32Map crc_map ;
if(fseek(f,0,SEEK_END))
{
std::cerr << "Could not fseek to end of this file! Sorry." << std::endl ;
fclose(f) ;
return 0 ;
}
uint64_t size = ftell(f) ;
if(fseek(f,0,SEEK_SET))
{
std::cerr << "Could not fseek to beginning of this file! Sorry." << std::endl ;
fclose(f) ;
return 0 ;
}
std::cerr << "File size:" << size << std::endl ;
RsDirUtil::crc32File(f,size,ChunkMap::CHUNKMAP_FIXED_CHUNK_SIZE,crc_map) ;
fclose(f) ;
std::cerr << "Got this CRC map: "<< std::endl ;
for(uint32_t i=0;i<crc_map.size();++i)
std::cerr << (void*)crc_map[i] ;
std::cerr << std::endl;
return 1 ;
}
}