summaryrefslogtreecommitdiff
path: root/src/SimpleRandomizer.cc
Commit message (Collapse)AuthorAgeFilesLines
* Fix assertion failure in SimpleRandomizer::getRandomBytesTatsuhiro Tsujikawa2017-01-061-12/+1
| | | | | | | errno might not be initialized to 0, and we may get both rv == -1 and errno != ENOSYS. This leads to assertion failure. Since getrandom_linux always returns -1 on failure, checking errno is useless in this function.
* clang-format-3.9Tatsuhiro Tsujikawa2016-10-151-2/+1
|
* migw: Fix build failureTatsuhiro Tsujikawa2016-01-221-3/+5
|
* Don't use std::random_device directly as suggested by documentTatsuhiro Tsujikawa2016-01-171-4/+8
| | | | See http://en.cppreference.com/w/cpp/numeric/random/random_device
* make clang-format using clang-format-3.6Tatsuhiro Tsujikawa2015-12-271-13/+12
|
* Comment getrandom code a bitNils Maier2015-03-181-0/+1
|
* Fix getrandom for system with libc not including errno or systemsNils Maier2015-03-181-1/+11
| | | | | | not supporting ENOSYS in the first place. Fixes GH-347
* Handle linux getrandom returning EINTR on interrupts/signalsNils Maier2015-02-071-3/+19
| | | | | | | Also handle ENOTSUP failures where aria2 was build with linux headers newer than the actual running kernel. Fixes GH-336
* Revise getRandom facilitiesNils Maier2015-01-201-50/+28
| | | | | | | | | | | | | | Use one of the following to provide random bytes: - Windows CryptGenRandom - Linux getrandom (syscall interface to urandom, without nasty corner cases such as file descriptor exhaustion or re-linked /dev/urandom) - std::device_random (C++ random device, which usually will be urandom) This also equalizes util::getRandom and SimpleRandomizer (the former will now use the latter) instead of having essentially two different PRNG interfaces with potentially different quality. Closes GH-320
* Use std::make_shared and make_unique where possible, part 2Tatsuhiro Tsujikawa2014-09-131-0/+1
|
* Randomizer: Remove unused interfacesTatsuhiro Tsujikawa2013-09-281-21/+3
|
* SimpleRandomizer: Use std::randomTatsuhiro Tsujikawa2013-09-281-14/+22
|
* SimpleRandmizer: Fix certain bits generated by getRandomBytes are always 0Tatsuhiro Tsujikawa2013-09-261-4/+5
| | | | | | | | This is because in Linux RAND_MAX is 2**31-1 and we used int32_t to hold random number from random() and got each bytes. This means that highest bit is always unset. In little endian system, every 4n-th (n >=0) byte has highest bit is unset. To fix this, we just use lower 2 bytes of random().
* Make generateRandomBytes less biased.Nils Maier2013-09-241-0/+19
|
* Convert most 0/NULL pointers to nullptrNils Maier2013-08-201-1/+1
| | | | Courtesy of llvm cpp11-migrate 3.3
* Return std::unique_ptr member as const refTatsuhiro Tsujikawa2013-06-261-2/+2
| | | | | Returning raw pointer has a risk that it may be stolen by std::shared_ptr in accident.
* Use std::unique_ptr instead of std::shared_ptrTatsuhiro Tsujikawa2013-06-221-3/+3
|
* Fix mingw32 compile errorTatsuhiro Tsujikawa2013-06-221-1/+2
|
* Require -std=c++11 and use std::shared_ptr instead of SharedHandleTatsuhiro Tsujikawa2013-06-221-2/+2
|
* Removed trailing spacesTatsuhiro Tsujikawa2012-10-011-1/+1
|
* Fixed segmentation fault in open solaris in unit test.Tatsuhiro Tsujikawa2012-03-251-2/+3
| | | | | This is due to the fact that the maximum value of random() in open solaris is not RAND_MAX, but (2**31)-1.
* MinGW32: Use CryptGenRandom() to generate random number.Tatsuhiro Tsujikawa2011-08-181-3/+37
| | | | | | | MinGW32 lacks random(), so we use CryptGenRandom() as a replacement. In the implementation, SimpleRandomizer::getRandomNumber() returns the random number in range [0, INT32_MAX]. Thus, simpleRandomizer::getMaxRandomNumber() returns INT32_MAX.
* Use random() instead of rand().Tatsuhiro Tsujikawa2011-08-111-3/+3
|
* 2010-11-12 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>Tatsuhiro Tsujikawa2010-11-121-1/+1
| | | | | | | | Removed SharedHandle::isNull(). Instead we added operator* and operator unspecified_bool_type. Removed use of WeakHandle and replaced with raw pointer.
* 2010-06-21 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>Tatsuhiro Tsujikawa2010-06-211-4/+4
| | | | | | | Changed naming standards for class member variable: now it looks like var_ instead of _var.
* 2010-05-08 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>Tatsuhiro Tsujikawa2010-05-081-1/+1
| | | | | | | | | | | | | | Return const reference. * src/DefaultPieceStorage.h * src/DownloadContext.h * src/FeatureConfig.cc * src/FeatureConfig.h * src/OptionParser.cc * src/OptionParser.h * src/SimpleRandomizer.cc * src/SimpleRandomizer.h
* 2010-01-06 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>Tatsuhiro Tsujikawa2010-01-051-1/+1
| | | | | | | | | Untabify. Fixed one line in copyright which is longer than 80 columns. * src * test
* 2008-11-15 Tatsuhiro Tsujikawa <t-tujikawa@users.sourceforge.net>Tatsuhiro Tsujikawa2008-11-161-2/+7
| | | | | | | | | | | | | | Given custom random number generator to std::random_shuffle. * src/AnnounceList.cc * src/BtLeecherStateChoke.cc * src/BtSeederStateChoke.cc * src/DefaultBtRequestFactory.cc * src/MetalinkEntry.cc * src/RarestPieceSelector.cc * src/SimpleRandomizer.cc * src/SimpleRandomizer.h
* 2008-09-02 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>Tatsuhiro Tsujikawa2008-09-021-1/+37
| | | | | | | | | | | | Moved implementation to SimpleRandomizer.cc from SimpleRandomizer.h. Added return value of getpid() to argument of srand() to achieve more randomized value. * src/SimpleRandomizer.cc * src/SimpleRandomizer.h
* 2008-04-20 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>Tatsuhiro Tsujikawa2008-04-201-1/+1
| | | | | | | | | | | | | | | Rewritten SharedHandle. Now copy constructor taking raw pointer has keyword explicit and SharedHandle's default constructor initializes its internal obj to null, old implementation initializes it using obj's default constructor. To assign null, write SharedHandle<T> x(...); x.reset(); TODO: test/SharedHandleTest.cc needs more tests. * src/SharedHandle.h
* 2008-02-08 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>Tatsuhiro Tsujikawa2008-02-081-0/+4
| | | | | | | | | Removed "using namespace std;" from all sources. Appended std:: prefix to c++ standard classes. Included string.h where mem* function are used.
* 2007-02-06 Tatsuhiro Tsujikawa <tujikawa dot rednoah dot com>Tatsuhiro Tsujikawa2007-02-061-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | To fix the bug that causes crash on Max OS X: * src/SimpleRandomizer.h (getInstance): Create new instance if the static variable is null. * src/SimpleRandomizer.cc (randomizer): Initialized to 0. * src/BitfieldManFactory.h (getNewFactory): Removed the call to setRandomizer(). To fix the miscalculation of the range of checksum: * src/BitfieldMan.h (isBitSetOffsetRange): New function. * src/BitfieldMan.cc (isBitSetOffsetRange): New function. * src/SegmentMan.cc (tryChunkChecksumValidation): Use BitfieldMan::isBitSetOffsetRange(). Use bitfield->getBlockLength() instead of segment.segmentLength.
* 2006-12-24 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>Tatsuhiro Tsujikawa2006-12-241-0/+37
Rewritten a portion of bittorrent implementation: * src/BtMessageValidator.h: New class. * src/BtBitfieldMessageValidator.h: New class. * src/BtHandshakeMessageValidator.h: New class. * src/BtRequestMessageValidator.h: New class. * src/BtSuggestPieceMessageValidator.h: New class. * src/BtAllowedFastMessageValidator.h: New class. * src/BtRejectMessageValidator.h: New class. * src/BtCancelMessageValidator.h: New class. * src/BtPieceMessageValidator.h: New class. * src/BtHaveMessageValidator.h: New class. * src/BtEventListener.h: New class. * src/AbstractBtEventListener.h: New class. * src/BtEvent.h: New class. * src/BtChokingEvent.h: New class. * src/BtChokedEvent.h: New class. * src/BtCancelSendingPieceEvent.h: New class. * src/BtAbortOutstandingRequestEvent.h: New class. * src/Randomizer.h: New class. * src/SimpleRandomizer.h: New class. * src/BtMessage.h: New class. * src/AbstractBtMessage.h: New class. * src/SimpleBtMessage.h: New class. * src/BtHaveMessage.h: New class. * src/BtInterestedMessage.h: New class. * src/BtAllowedFastMessage.h: New class. * src/BtUnchokeMessage.h: New class. * src/BtCancelMessage.h: New class. * src/BtNotInterestedMessage.h: New class. * src/BtChokeMessage.h: New class. * src/BtHaveNoneMessage.h: New class. * src/BtHandshakeMessage.h: New class. * src/BtSuggestPieceMessage.h: New class. * src/BtHaveMessage.h: New class. * src/BtPieceMessage.h: New class. * src/BtHaveAllMessage.h: New class. * src/BtKeepAliveMessage.h: New class. * src/BtPortMessage.h: New class. * src/BtRejectMessage.h: New class. * src/BtBitfieldMessage.h: New class. * src/BtRequestMessage.h: New class. * src/DefaultBtRequestFactory.h: New class. * src/DefaultBtMessageReceiver.h: New class. * src/BtInteractive.h: New class. * src/BtMessageDispatcher.h: New class. * src/DefaultBtMessageDispatcher.h: New class. * src/DefaultBtInteractive.h: New class. * src/BitfieldManFactory.h: New class. * src/HandleRegistry.h: New class. * src/BtMessageFactory.h: New class. * src/BtMessageReceiver.h: New class. * src/DefaultBtMessageFactory.h: New class. * src/PeerObject.h: New class. * src/BtRequestFactory.h: New class.