summaryrefslogtreecommitdiff
path: root/src/MultiDiskWriter.cc
diff options
context:
space:
mode:
authorTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2006-07-03 14:19:23 +0000
committerTatsuhiro Tsujikawa <tatsuhiro.t@gmail.com>2006-07-03 14:19:23 +0000
commit78eff232546a5fa6f48c151dc2343915ed94fa8c (patch)
tree6d30c01c1586f0513ab152de48473dad2746fe5d /src/MultiDiskWriter.cc
parent003a47435758a976a57c483c37859989105e204e (diff)
2006-07-03 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
To add Metalink support(http/ftp only): * src/AbstractCommand.h (tryReserved): New function. * src/AbstractCommand.cc (execute): Call tryReserved(). (tryReserved): New function. * src/Request.h (Requests): New type definition. * src/SegmentMan.h (reserved): New variable. * src/Util.h (fileChecksum): New function. (toUpper): New function. (toLower): New function. * src/Util.cc (messageDigest.h): Included. (trim): Trim \r\n\t. (fileChecksum): New function. (toUpper): New function. (toLower): New function. * src/main.cc (normalDownload): New function. (main): Added 2 command-line options: metalink-file, metalink-connection. Their usage has not been written yet. * src/MetalinkProcessor.h: New class. * src/Xml2MetalinkProcessor.h: New class. * src/Xml2MetalinkProcessor.cc: New class. * src/MetalinkEntry.h: New class. * src/MetalinkEntry.cc: New class. * src/MetalinkResource.h: New class. * src/MetalinkResource.cc: New class. To add md5 message digest checking: * src/messageDigest.h: Rewritten. * src/MultiDiskWriter.cc: Updated according to the changes in messageDigest.h. * src/ShaVisitor.cc: Updated according to the changes in messageDigest.h. * src/Util.cc: Updated according to the changes in messageDigest.h. * src/AbstractDiskWriter.cc: Updated according to the changes in messageDigest.h. To fix a bug that causes segfault when the payload length in peer message is less than 0: * src/PeerConnection.cc: (receiveMessage): Fixed the bug. * src/PeerMessageUtil.cc (checkLength): Throw an exception if length is less than or equals to 0. To add new interfaces to Base64 encoding/decoding: * src/Base64.h (part_encode): Changed the method signature. (encode): New function(overload). (decode): New function(overload). * src/Base64.cc (part_encode): Rewritten. (encode): Rewritten. (encode): New function(overload). To prevent a peer to download same piece if there is an error in checksum: * src/PieceMessage.cc (receivedAction): Call peerInteraction->abortPiece().
Diffstat (limited to 'src/MultiDiskWriter.cc')
-rw-r--r--src/MultiDiskWriter.cc13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/MultiDiskWriter.cc b/src/MultiDiskWriter.cc
index 044796ff..3a67a920 100644
--- a/src/MultiDiskWriter.cc
+++ b/src/MultiDiskWriter.cc
@@ -27,14 +27,15 @@
MultiDiskWriter::MultiDiskWriter(int pieceLength):pieceLength(pieceLength) {
#ifdef ENABLE_SHA1DIGEST
- sha1DigestInit(ctx);
+ ctx.setAlgo(MessageDigestContext::ALGO_SHA1);
+ digestInit(ctx);
#endif // ENABLE_SHA1DIGEST
}
MultiDiskWriter::~MultiDiskWriter() {
clearEntries();
#ifdef ENABLE_SHA1DIGEST
- sha1DigestFree(ctx);
+ digestFree(ctx);
#endif // ENABLE_SHA1DIGEST
}
@@ -150,7 +151,7 @@ void MultiDiskWriter::hashUpdate(DiskWriterEntry* entry, long long int offset, l
if(BUFSIZE != entry->diskWriter->readData(buf, BUFSIZE, offset)) {
throw string("error");
}
- sha1DigestUpdate(ctx, buf, BUFSIZE);
+ digestUpdate(ctx, buf, BUFSIZE);
offset += BUFSIZE;
}
int r = length%BUFSIZE;
@@ -158,7 +159,7 @@ void MultiDiskWriter::hashUpdate(DiskWriterEntry* entry, long long int offset, l
if(r != entry->diskWriter->readData(buf, r, offset)) {
throw string("error");
}
- sha1DigestUpdate(ctx, buf, r);
+ digestUpdate(ctx, buf, r);
}
}
#endif // ENABLE_SHA1DIGEST
@@ -168,7 +169,7 @@ string MultiDiskWriter::sha1Sum(long long int offset, long long int length) {
long long int fileOffset = offset;
bool reading = false;
int rem = length;
- sha1DigestReset(ctx);
+ digestReset(ctx);
try {
for(DiskWriterEntries::iterator itr = diskWriterEntries.begin();
itr != diskWriterEntries.end() && rem != 0; itr++) {
@@ -186,7 +187,7 @@ string MultiDiskWriter::sha1Sum(long long int offset, long long int length) {
throw new DlAbortEx(EX_FILE_OFFSET_OUT_OF_RANGE, offset);
}
unsigned char hashValue[20];
- sha1DigestFinal(ctx, hashValue);
+ digestFinal(ctx, hashValue);
return Util::toHex(hashValue, 20);
} catch(string ex) {
throw new DlAbortEx(EX_FILE_SHA1SUM, "", strerror(errno));