* src/TrackerInitCommand.cc (TrackerInitCommand): Added a "key"

parameter to a tracker request.

	* src/TorrentMan.cc (readFileEntryFromMetaInfoFile): Bug fix.

	* src/TrackerWatcherCommand.cc (execute): Call 
req->resetTryCount().
	
	* src/main.cc (setSignalHander): New function.
	(main): Added a handler for SIGTERM.
	(handler): Updated message.
	(torrentHandler): Updated message.
pull/1/head
Tatsuhiro Tsujikawa 2006-04-17 14:15:36 +00:00
parent 28a82bfa4a
commit dcc225a145
6 changed files with 44 additions and 25 deletions

View File

@ -1,3 +1,18 @@
2006-04-17 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* src/TrackerInitCommand.cc (TrackerInitCommand): Added a "key"
parameter to a tracker request.
* src/TorrentMan.cc (readFileEntryFromMetaInfoFile): Bug fix.
* src/TrackerWatcherCommand.cc (execute): Call req->resetTryCount().
* src/main.cc (setSignalHander): New function.
(main): Added a handler for SIGTERM.
(handler): Updated message.
(torrentHandler): Updated message.
2006-04-16 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com> 2006-04-16 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
* src/TorrentConsoleDownloadEngine.cc * src/TorrentConsoleDownloadEngine.cc

4
TODO
View File

@ -13,11 +13,9 @@
* Distinguish seeder from leecher * Distinguish seeder from leecher
0.4.0 release 0.4.0 release
* Add selective downloading mode
* try to use ftruncate to allocate file. * try to use ftruncate to allocate file.
* test all download mode
* Add loggerfactory * Add loggerfactory
* Add SIGTERM signal handler * add log message when download completes
0.4.1 release 0.4.1 release
* Add port command-line option * Add port command-line option

View File

@ -427,9 +427,11 @@ FileEntries TorrentMan::readFileEntryFromMetaInfoFile(const string& metaInfoFile
Dictionary* topDic = (Dictionary*)MetaFileUtil::parseMetaFile(metaInfoFile); Dictionary* topDic = (Dictionary*)MetaFileUtil::parseMetaFile(metaInfoFile);
const Dictionary* infoDic = (const Dictionary*)topDic->get("info"); const Dictionary* infoDic = (const Dictionary*)topDic->get("info");
FileEntries fileEntries; FileEntries fileEntries;
Directory* topDir; Directory* topDir = NULL;
readFileEntry(fileEntries, &topDir, infoDic, metaInfoFile); readFileEntry(fileEntries, &topDir, infoDic, metaInfoFile);
delete topDir; if(topDir != NULL) {
delete topDir;
}
return fileEntries; return fileEntries;
} }

View File

@ -61,7 +61,8 @@ bool TrackerInitCommand::execute() {
"downloaded="+Util::llitos(e->torrentMan->getSessionDownloadLength())+"&"+ "downloaded="+Util::llitos(e->torrentMan->getSessionDownloadLength())+"&"+
"left="+(e->torrentMan->getTotalLength()-e->torrentMan->getDownloadLength() <= 0 "left="+(e->torrentMan->getTotalLength()-e->torrentMan->getDownloadLength() <= 0
? "0" : Util::llitos(e->torrentMan->getTotalLength()-e->torrentMan->getDownloadLength()))+"&"+ ? "0" : Util::llitos(e->torrentMan->getTotalLength()-e->torrentMan->getDownloadLength()))+"&"+
"compact=1"; "compact=1"+"&"+
"key="+e->torrentMan->peerId;
if(!event.empty()) { if(!event.empty()) {
url += string("&")+"event="+event; url += string("&")+"event="+event;
} }

View File

@ -30,6 +30,7 @@ TrackerWatcherCommand::TrackerWatcherCommand(int cuid, Request* req,
TrackerWatcherCommand::~TrackerWatcherCommand() {} TrackerWatcherCommand::~TrackerWatcherCommand() {}
bool TrackerWatcherCommand::execute() { bool TrackerWatcherCommand::execute() {
req->resetTryCount();
Command* command = new TrackerInitCommand(e->torrentMan->getNewCuid(), Command* command = new TrackerInitCommand(e->torrentMan->getNewCuid(),
req, req,
e); e);

View File

@ -71,6 +71,14 @@ void printDownloadAbortMessage() {
printf(_("\nThe download was not complete because of errors. Check the log.\n")); printf(_("\nThe download was not complete because of errors. Check the log.\n"));
} }
void setSignalHander(int signal, void (*handler)(int)) {
struct sigaction sigact;
sigact.sa_handler = handler;
sigact.sa_flags = 0;
sigemptyset(&sigact.sa_mask);
sigaction(signal, &sigact, NULL);
}
void clearRequest(Request* req) { void clearRequest(Request* req) {
delete(req); delete(req);
} }
@ -79,16 +87,19 @@ DownloadEngine* e;
TorrentDownloadEngine* te; TorrentDownloadEngine* te;
void handler(int signal) { void handler(int signal) {
cout << _("\nSIGINT signal received.") << endl; printf(_("\nstopping application...\n"));
fflush(stdout);
e->segmentMan->save(); e->segmentMan->save();
if(e->diskWriter != NULL) { if(e->diskWriter != NULL) {
e->diskWriter->closeFile(); e->diskWriter->closeFile();
} }
printf("done\n");
exit(0); exit(0);
} }
void torrentHandler(int signal) { void torrentHandler(int signal) {
cout << _("\nSIGINT signal received.") << endl; printf(_("\nstopping application...\n"));
fflush(stdout);
if(te->torrentMan->diskAdaptor != NULL) { if(te->torrentMan->diskAdaptor != NULL) {
te->torrentMan->diskAdaptor->closeFile(); te->torrentMan->diskAdaptor->closeFile();
} }
@ -99,7 +110,7 @@ void torrentHandler(int signal) {
} else { } else {
te->torrentMan->save(); te->torrentMan->save();
} }
printf("done\n");
exit(0); exit(0);
} }
@ -533,20 +544,13 @@ int main(int argc, char* argv[]) {
SegmentSplitter* splitter = new SplitSlowestSegmentSplitter(); SegmentSplitter* splitter = new SplitSlowestSegmentSplitter();
splitter->setMinSegmentSize(op->getAsLLInt(PREF_MIN_SEGMENT_SIZE)); splitter->setMinSegmentSize(op->getAsLLInt(PREF_MIN_SEGMENT_SIZE));
struct sigaction sigactIgn; setSignalHander(SIGPIPE, SIG_IGN);
sigactIgn.sa_handler = SIG_IGN;
sigactIgn.sa_flags = 0;
sigemptyset(&sigactIgn.sa_mask);
sigaction(SIGPIPE, &sigactIgn, NULL);
bool readyToTorrentMode = false; bool readyToTorrentMode = false;
string downloadedTorrentFile; string downloadedTorrentFile;
if(torrentFile.empty()) { if(torrentFile.empty()) {
struct sigaction sigact; setSignalHander(SIGINT, handler);
sigact.sa_handler = handler; setSignalHander(SIGTERM, handler);
sigact.sa_flags = 0;
sigemptyset(&sigact.sa_mask);
sigaction(SIGINT, &sigact, NULL);
splitter->logger = logger; splitter->logger = logger;
e = new ConsoleDownloadEngine(); e = new ConsoleDownloadEngine();
@ -590,11 +594,9 @@ int main(int argc, char* argv[]) {
if(!torrentFile.empty() || followTorrent && readyToTorrentMode) { if(!torrentFile.empty() || followTorrent && readyToTorrentMode) {
try { try {
//op->put(PREF_MAX_TRIES, "0"); //op->put(PREF_MAX_TRIES, "0");
struct sigaction sigact; setSignalHander(SIGINT, torrentHandler);
sigact.sa_handler = torrentHandler; setSignalHander(SIGTERM, torrentHandler);
sigact.sa_flags = 0;
sigemptyset(&sigact.sa_mask);
sigaction(SIGINT, &sigact, NULL);
Request* req = new Request(); Request* req = new Request();
req->isTorrent = true; req->isTorrent = true;
req->setTrackerEvent(Request::STARTED); req->setTrackerEvent(Request::STARTED);