mirror of
https://github.com/RetroShare/RetroShare.git
synced 2025-05-22 07:41:20 -04:00
Added deferred check of chunks during file transfer. Chunk sha1 sums are requested to the sources and checked for downloaded data.
Validated chunks are shared to other peers. Force check is now very simple since it just turns all chunks into "needs checking" mode and sums are asked to sources. Sources maintain a temporary cache of chunks. Since sums are requested sparsely, this should not affect the sources in terms of performance. We can still imagine precomputing and saving sha1 of chunks while hashing them. For backward compatibility reasons, the following has been setup *temporarily* in this version: - unvalidated chunks are still considered as already obtained, and are shared and saved - force check has been disabled - final file check is maintained - in case of file fail, the old checking mode will be used. All changes for next version are kept in the define 'USE_NEW_CHUNK_CHECKING_CODE' that will be made the default in a few weeks. At start, I expect most chunk to stya yellow during download, until most sources are able to provide chunk hashs. git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@5019 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
7ab5b54266
commit
889a2b2433
31 changed files with 1540 additions and 35 deletions
24
libretroshare/src/tests/util/Makefile
Normal file
24
libretroshare/src/tests/util/Makefile
Normal file
|
@ -0,0 +1,24 @@
|
|||
|
||||
RS_TOP_DIR = ../..
|
||||
DHT_TOP_DIR = ../../../../libbitdht/src
|
||||
##### Define any flags that are needed for this section #######
|
||||
###############################################################
|
||||
|
||||
###############################################################
|
||||
include $(RS_TOP_DIR)/tests/scripts/config.mk
|
||||
###############################################################
|
||||
|
||||
TESTOBJ = dirtest.o sha1_test.o
|
||||
TESTS = dirtest sha1_test
|
||||
|
||||
all: tests
|
||||
|
||||
sha1_test: sha1_test.o
|
||||
$(CC) $(CFLAGS) -o sha1_test sha1_test.o $(LIBS)
|
||||
dirtest: dirtest.o
|
||||
$(CC) $(CFLAGS) -o dirtest dirtest.o $(LIBS)
|
||||
|
||||
###############################################################
|
||||
include $(RS_TOP_DIR)/tests/scripts/rules.mk
|
||||
###############################################################
|
||||
|
80
libretroshare/src/tests/util/sha1_test.cc
Normal file
80
libretroshare/src/tests/util/sha1_test.cc
Normal file
|
@ -0,0 +1,80 @@
|
|||
|
||||
/*
|
||||
* "$Id: dirtest.cc,v 1.1 2007-02-19 20:08:30 rmf24 Exp $"
|
||||
*
|
||||
* RetroShare C++ Interface.
|
||||
*
|
||||
* Copyright 2012-2012 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 "util/rsdir.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <list>
|
||||
#include <string>
|
||||
#include <stdio.h>
|
||||
|
||||
void printHelp(int argc,char *argv[])
|
||||
{
|
||||
std::cerr << argv[0] << ": test RS sha1sum class implementation." << std::endl;
|
||||
std::cerr << "Usage: " << argv[0] << " [test file]" << std::endl ;
|
||||
}
|
||||
|
||||
int main(int argc,char *argv[])
|
||||
{
|
||||
if(argc != 2)
|
||||
{
|
||||
printHelp(argc,argv) ;
|
||||
return -1 ;
|
||||
}
|
||||
|
||||
FILE *f = fopen(argv[1],"r") ;
|
||||
|
||||
if(f == NULL)
|
||||
{
|
||||
std::cerr << "Cannot open file " << argv[1] << " for read !" << std::endl;
|
||||
return -1 ;
|
||||
}
|
||||
|
||||
std::cerr << "Testing sha1" << std::endl;
|
||||
uint32_t SIZE = 1024*1024 ;
|
||||
unsigned char *buf = new unsigned char[SIZE] ;
|
||||
int len = fread(buf,1,SIZE,f) ;
|
||||
|
||||
std::cerr << "Read " << len << " bytes" << std::endl;
|
||||
|
||||
Sha1CheckSum sum = RsDirUtil::sha1sum(buf,len) ;
|
||||
std::cerr << std::hex << sum.fourbytes[0] << std::endl;
|
||||
std::cerr << "New method : " << sum.toStdString() << std::endl;
|
||||
|
||||
std::string hash ;
|
||||
uint64_t size ;
|
||||
RsDirUtil::getFileHash(argv[1],hash,size) ;
|
||||
|
||||
std::cerr << "Old method : " << hash << std::endl;
|
||||
|
||||
Sha1CheckSum H(hash) ;
|
||||
std::cerr << "Hashed transformed: " << H.toStdString() << std::endl;
|
||||
|
||||
return 0 ;
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue