diff options
Diffstat (limited to 'src/Util.cc')
| -rw-r--r-- | src/Util.cc | 87 |
1 files changed, 0 insertions, 87 deletions
diff --git a/src/Util.cc b/src/Util.cc index 3c90208b..7e231c9c 100644 --- a/src/Util.cc +++ b/src/Util.cc @@ -480,93 +480,6 @@ string Util::getContentDispositionFilename(const string& header) { return trim(header.substr(filenamesp, filenameep-filenamesp), "\r\n '\""); } -#ifdef ENABLE_MESSAGE_DIGEST -void Util::sha1Sum(unsigned char* digest, const void* data, int32_t dataLength) { - MessageDigestContext ctx(DIGEST_ALGO_SHA1); - ctx.digestInit(); - ctx.digestUpdate(data, dataLength); - ctx.digestFinal(digest); -} - -string Util::simpleMessageDigest(const string& data) { - unsigned char checksum[20]; - sha1Sum(checksum, data.c_str(), data.size()); - return Util::toHex(checksum, sizeof(checksum)); -} - -#endif // ENABLE_MESSAGE_DIGEST - -#ifdef ENABLE_MESSAGE_DIGEST -void Util::fileChecksum(const string& filename, unsigned char* digest, - MessageDigestContext::DigestAlgo algo) { - MessageDigestContext ctx(algo); - ctx.digestInit(); - - int32_t BUFLEN = 4096; - char buf[BUFLEN]; - - int32_t fd; - if((fd = open(filename.c_str(), O_RDWR|O_BINARY, OPEN_MODE)) < 0) { - throw new DlAbortEx(EX_FILE_OPEN, filename.c_str(), strerror(errno)); - } - while(1) { - int32_t size = read(fd, buf, BUFLEN); - if(size == -1) { - if(errno == EINTR) { - continue; - } else { - close(fd); - throw new DlAbortEx(EX_FILE_READ, filename.c_str(), strerror(errno)); - } - } else if(size > 0) { - ctx.digestUpdate(buf, size); - } - if(size < BUFLEN) { - break; - } - } - ctx.digestFinal(digest); -} -#endif // ENABLE_MESSAGE_DIGEST - -#ifdef ENABLE_BITTORRENT -Integers Util::computeFastSet(string ipaddr, const unsigned char* infoHash, - int32_t pieces, int32_t fastSetSize) { - Integers fastSet; - struct in_addr saddr; - if(inet_aton(ipaddr.c_str(), &saddr) == 0) { - abort(); - } - unsigned char tx[24]; - memcpy(tx, (void*)&saddr.s_addr, 4); - if((tx[0] & 0x80) == 0 || (tx[0] & 0x40) == 0) { - tx[2] = 0x00; - tx[3] = 0x00; - } else { - tx[3] = 0x00; - } - memcpy(tx+4, infoHash, 20); - unsigned char x[20]; - sha1Sum(x, tx, 24); - while((int32_t)fastSet.size() < fastSetSize) { - for(int32_t i = 0; i < 5 && (int32_t)fastSet.size() < fastSetSize; i++) { - int32_t j = i*4; - uint32_t ny; - memcpy(&ny, x+j, 4); - uint32_t y = ntohl(ny); - int32_t index = y%pieces; - if(find(fastSet.begin(), fastSet.end(), index) == fastSet.end()) { - fastSet.push_back(index); - } - } - unsigned char temp[20]; - sha1Sum(temp, x, 20); - memcpy(x, temp, sizeof(x)); - } - return fastSet; -} -#endif // ENABLE_BITTORRENT - static int32_t nbits[] = { 0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, |
