2006-12-24 06:25:21 +00:00
|
|
|
/* <!-- copyright */
|
|
|
|
/*
|
|
|
|
* aria2 - The high speed download utility
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program 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 General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2010-01-05 16:01:46 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
2006-12-24 06:25:21 +00:00
|
|
|
*
|
|
|
|
* In addition, as a special exception, the copyright holders give
|
|
|
|
* permission to link the code of portions of this program with the
|
|
|
|
* OpenSSL library under certain conditions as described in each
|
|
|
|
* individual source file, and distribute linked combinations
|
|
|
|
* including the two.
|
|
|
|
* You must obey the GNU General Public License in all respects
|
|
|
|
* for all of the code used other than OpenSSL. If you modify
|
|
|
|
* file(s) with this exception, you may extend this exception to your
|
|
|
|
* version of the file(s), but you are not obligated to do so. If you
|
|
|
|
* do not wish to do so, delete this exception statement from your
|
|
|
|
* version. If you delete this exception statement from all source
|
|
|
|
* files in the program, then also delete it here.
|
|
|
|
*/
|
|
|
|
/* copyright --> */
|
2010-10-31 07:23:53 +00:00
|
|
|
#ifndef D_SIMPLE_RANDOMIZER_H
|
|
|
|
#define D_SIMPLE_RANDOMIZER_H
|
2006-12-24 06:25:21 +00:00
|
|
|
|
|
|
|
#include "Randomizer.h"
|
|
|
|
|
2013-06-21 16:10:38 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2011-08-18 09:03:06 +00:00
|
|
|
#ifdef __MINGW32__
|
|
|
|
# include <wincrypt.h>
|
|
|
|
#endif // __MINGW32__
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
namespace aria2 {
|
|
|
|
|
2006-12-24 06:25:21 +00:00
|
|
|
class SimpleRandomizer : public Randomizer {
|
|
|
|
private:
|
2013-06-22 06:49:41 +00:00
|
|
|
static std::unique_ptr<SimpleRandomizer> randomizer_;
|
2006-12-24 06:25:21 +00:00
|
|
|
|
2011-08-18 09:03:06 +00:00
|
|
|
#ifdef __MINGW32__
|
|
|
|
HCRYPTPROV cryProvider_;
|
|
|
|
#endif //__MINGW32__
|
|
|
|
|
2008-09-02 14:11:59 +00:00
|
|
|
SimpleRandomizer();
|
2006-12-24 06:25:21 +00:00
|
|
|
public:
|
2012-09-28 14:27:46 +00:00
|
|
|
|
2013-06-26 14:56:43 +00:00
|
|
|
static const std::unique_ptr<SimpleRandomizer>& getInstance();
|
2012-09-28 14:27:46 +00:00
|
|
|
|
2008-09-02 14:11:59 +00:00
|
|
|
static void init();
|
2006-12-24 06:25:21 +00:00
|
|
|
|
2008-09-02 14:11:59 +00:00
|
|
|
virtual ~SimpleRandomizer();
|
2006-12-24 06:25:21 +00:00
|
|
|
|
2013-07-06 09:15:09 +00:00
|
|
|
virtual long int getRandomNumber() CXX11_OVERRIDE;
|
2006-12-24 06:25:21 +00:00
|
|
|
|
2013-07-06 09:15:09 +00:00
|
|
|
virtual long int getMaxRandomNumber() CXX11_OVERRIDE;
|
2007-07-23 13:04:48 +00:00
|
|
|
|
2007-08-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
MessageDigestHelper is introduced in order to simplify the use
of message digest. Removed repeated code.
The message digest algorithm is now specified by string, like
"sha1",
"md5".
* src/messageDigest.{h, cc}
* src/MessageDigestHelper.{h, cc}: New class.
* src/DefaultPieceStorage.cc
* src/DefaultBtContext.{h, cc}
(computeFastSet): New function.
(setInfoHash): Added for unit testing.
(setNumPieces): Added for unit testing.
* src/DefaultBtInteractive.cc
* src/BtPieceMessage.cc
* src/Peer.cc
* src/Checksum.h
* src/message.h
* src/IteratableChecksumValidator.h
* src/ChunkChecksumValidator.{h, cc}: Use
IteratableChecksumValidator
inside it.
* src/SegmentMan.{h, cc}
(checkIntegrity): Removed.
* src/IteratableChunkChecksumValidator.{h, cc}
* src/Util.h
(sha1Sum): Removed.
(simpleMessageDigest): Removed.
(fileChecksum): Removed.
(computeFastSet): Removed.
* src/ShaVisitor.cc
* src/ChunkChecksum.h
* src/DownloadCommand.cc
Removed messageDigest virtual functions.
* src/MultiDiskAdaptor.{h, cc}
* src/DiskAdaptor.h
* src/ByteArrayDiskWriter.h
* src/DiskWriter.h
* src/DiskAdaptorWriter.h
* src/AbstractSingleDiskAdaptor.{h, cc}
* src/AbstractDiskWriter.{h, cc}
Fixed comilation error when message digest is disabled.
* src/MetalinkEntry.{h, cc}
* src/MetalinkRequestInfo.cc
Removed srandom and random.
* src/SimpleRandomizer.h
Added size() virtual function to DiskAdaptor
* src/MultiDiskAdaptor.h
Fixed the bug that causes that files are not opened correctly in
multi-file torrent.
* src/TorrentRequestInfo.cc
* src/MultiDiskAdaptor.cc
Added SHA256 support
* src/messageDigest.cc
* src/Xml2MetalinkProcessor.cc
Show supported message digest algorithms
* src/main.cc
Updated contact info.
* src/main.cc
2007-08-08 14:40:11 +00:00
|
|
|
/**
|
|
|
|
* Returns random number in [0, to).
|
|
|
|
*/
|
2013-07-06 09:15:09 +00:00
|
|
|
virtual long int getRandomNumber(long int to) CXX11_OVERRIDE;
|
2008-11-16 04:25:24 +00:00
|
|
|
|
|
|
|
long int operator()(long int to);
|
2006-12-24 06:25:21 +00:00
|
|
|
};
|
|
|
|
|
2008-02-08 15:53:45 +00:00
|
|
|
} // namespace aria2
|
|
|
|
|
2010-10-31 07:23:53 +00:00
|
|
|
#endif // D_SIMPLE_RANDOMIZER_H
|