Skip to content

Commit 9a274ef

Browse files
committed
Converted storage and network log signals to the new logging api.
1 parent f4f108f commit 9a274ef

8 files changed

+51
-33
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
Makefile
2020
aclocal.m4
2121
autom4te.cache
22+
compile
2223
config.h
2324
config.guess
2425
config.status

src/download/download_wrapper.cc

+5-1
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,16 @@
5555
#include "torrent/peer/connection_list.h"
5656
#include "torrent/tracker_controller.h"
5757
#include "torrent/tracker_list.h"
58+
#include "torrent/utils/log.h"
5859

5960
#include "available_list.h"
6061
#include "chunk_selector.h"
6162

6263
#include "download_wrapper.h"
6364

65+
#define LT_LOG_STORAGE_ERRORS(log_fmt, ...) \
66+
lt_log_print_info(LOG_PROTOCOL_STORAGE_ERRORS, this->info(), "storage_errors", log_fmt, __VA_ARGS__);
67+
6468
namespace tr1 { using namespace std::tr1; }
6569

6670
namespace torrent {
@@ -251,7 +255,7 @@ DownloadWrapper::receive_storage_error(const std::string& str) {
251255
m_main->tracker_controller()->disable();
252256
m_main->tracker_controller()->close();
253257

254-
rak::slot_list_call(info()->signal_storage_error(), str);
258+
LT_LOG_STORAGE_ERRORS("%s", str.c_str());
255259
}
256260

257261
uint32_t

src/protocol/peer_connection_base.cc

+9-5
Original file line numberDiff line numberDiff line change
@@ -451,11 +451,14 @@ PeerConnectionBase::should_connection_unchoke(choke_queue* cq) const {
451451
bool
452452
PeerConnectionBase::down_chunk_start(const Piece& piece) {
453453
if (!download_queue()->downloading(piece)) {
454-
if (piece.length() == 0)
455-
rak::slot_list_call(m_download->info()->signal_network_log(), "Received piece with length zero.");
454+
if (piece.length() == 0) {
455+
LT_LOG_PIECE_EVENTS("(down) skipping empty %" PRIu32 " %" PRIu32 " %" PRIu32,
456+
piece.index(), piece.offset(), piece.length());
457+
} else {
458+
LT_LOG_PIECE_EVENTS("(down) skipping unneeded %" PRIu32 " %" PRIu32 " %" PRIu32,
459+
piece.index(), piece.offset(), piece.length());
460+
}
456461

457-
LT_LOG_PIECE_EVENTS("(down) skipping unneeded %" PRIu32 " %" PRIu32 " %" PRIu32,
458-
piece.index(), piece.offset(), piece.length());
459462
return false;
460463
}
461464

@@ -669,7 +672,8 @@ PeerConnectionBase::down_chunk_skip_process(const void* buffer, uint32_t length)
669672
// The data doesn't match with what has previously been downloaded,
670673
// bork this transfer.
671674
if (!m_downChunk.chunk()->compare_buffer(buffer, transfer->piece().offset() + transfer->position(), compareLength)) {
672-
rak::slot_list_call(m_download->info()->signal_network_log(), "Data does not match what was previously downloaded.");
675+
LT_LOG_PIECE_EVENTS("(down) download data mismatch %" PRIu32 " %" PRIu32 " %" PRIu32,
676+
transfer->piece().index(), transfer->piece().offset(), transfer->piece().length());
673677

674678
m_downloadQueue.transfer_dissimilar();
675679
m_downloadQueue.transfer()->adjust_position(length);

src/protocol/peer_connection_leech.cc

+14-7
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,17 @@
5151
#include "torrent/download/choke_queue.h"
5252
#include "torrent/peer/connection_list.h"
5353
#include "torrent/peer/peer_info.h"
54+
#include "torrent/utils/log.h"
5455

5556
#include "extensions.h"
5657
#include "initial_seed.h"
5758
#include "peer_connection_leech.h"
5859

60+
#define LT_LOG_NETWORK_ERRORS(log_fmt, ...) \
61+
lt_log_print_info(LOG_PROTOCOL_NETWORK_ERRORS, this->download()->info(), "network_errors", "%40s " log_fmt, this->peer_info()->id_hex(), __VA_ARGS__);
62+
#define LT_LOG_STORAGE_ERRORS(log_fmt, ...) \
63+
lt_log_print_info(LOG_PROTOCOL_STORAGE_ERRORS, this->download()->info(), "storage_errors", "%40s " log_fmt, this->peer_info()->id_hex(), __VA_ARGS__);
64+
5965
namespace torrent {
6066

6167
template<Download::ConnectionType type>
@@ -457,16 +463,16 @@ PeerConnection<type>::event_read() {
457463
m_download->connection_list()->erase(this, 0);
458464

459465
} catch (blocked_connection& e) {
460-
rak::slot_list_call(m_download->info()->signal_network_log(), "Momentarily blocked read connection.");
461466
m_download->connection_list()->erase(this, 0);
462467

463468
} catch (network_error& e) {
464-
rak::slot_list_call(m_download->info()->signal_network_log(), (rak::socket_address::cast_from(m_peerInfo->socket_address())->address_str() + " " + rak::copy_escape_html(std::string(m_peerInfo->id().c_str(), 8)) + ": " + e.what()).c_str());
465-
469+
LT_LOG_NETWORK_ERRORS("%s network read error: %s",
470+
rak::socket_address::cast_from(m_peerInfo->socket_address())->address_str().c_str(),
471+
e.what());
466472
m_download->connection_list()->erase(this, 0);
467473

468474
} catch (storage_error& e) {
469-
rak::slot_list_call(m_download->info()->signal_storage_error(), e.what());
475+
LT_LOG_NETWORK_ERRORS("storage read error: %s", e.what());
470476
m_download->connection_list()->erase(this, 0);
471477

472478
} catch (base_error& e) {
@@ -637,15 +643,16 @@ PeerConnection<type>::event_write() {
637643
m_download->connection_list()->erase(this, 0);
638644

639645
} catch (blocked_connection& e) {
640-
rak::slot_list_call(m_download->info()->signal_network_log(), "Momentarily blocked write connection.");
641646
m_download->connection_list()->erase(this, 0);
642647

643648
} catch (network_error& e) {
644-
rak::slot_list_call(m_download->info()->signal_network_log(), e.what());
649+
LT_LOG_NETWORK_ERRORS("%s write error: %s",
650+
rak::socket_address::cast_from(m_peerInfo->socket_address())->address_str().c_str(),
651+
e.what());
645652
m_download->connection_list()->erase(this, 0);
646653

647654
} catch (storage_error& e) {
648-
rak::slot_list_call(m_download->info()->signal_storage_error(), e.what());
655+
LT_LOG_STORAGE_ERRORS("write error: %s", e.what());
649656
m_download->connection_list()->erase(this, 0);
650657

651658
} catch (base_error& e) {

src/protocol/peer_connection_metadata.cc

+16-14
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,16 @@
4949
#include "torrent/peer/connection_list.h"
5050
#include "torrent/peer/peer_info.h"
5151
#include "rak/functional.h"
52+
#include "torrent/utils/log.h"
5253

5354
#include "extensions.h"
5455
#include "peer_connection_metadata.h"
5556

57+
#define LT_LOG_METADATA_EVENTS(log_fmt, ...) \
58+
lt_log_print_info(LOG_PROTOCOL_METADATA_EVENTS, this->download()->info(), "metadata_events", "%40s " log_fmt, this->peer_info()->id_hex(), __VA_ARGS__);
59+
#define LT_LOG_STORAGE_ERRORS(log_fmt, ...) \
60+
lt_log_print_info(LOG_PROTOCOL_STORAGE_ERRORS, this->download()->info(), "storage_errors", "%40s " log_fmt, this->peer_info()->id_hex(), __VA_ARGS__);
61+
5662
namespace torrent {
5763

5864
PeerConnectionMetadata::~PeerConnectionMetadata() {
@@ -162,7 +168,7 @@ PeerConnectionMetadata::read_message() {
162168
return true;
163169

164170
case ProtocolBase::EXTENSION_PROTOCOL:
165-
rak::slot_list_call(m_download->info()->signal_network_log(), "PeerConnectionMetadata::read_message() case ProtocolBase::EXTENSION_PROTOCOL:");
171+
LT_LOG_METADATA_EVENTS("protocol extension message", 0);
166172

167173
if (!m_down->can_read_extension_body())
168174
break;
@@ -181,7 +187,7 @@ PeerConnectionMetadata::read_message() {
181187
if (!down_extension())
182188
return false;
183189

184-
rak::slot_list_call(m_download->info()->signal_network_log(), "PeerConnectionMetadata::read_message() case ProtocolBase::EXTENSION_PROTOCOL: finished");
190+
LT_LOG_METADATA_EVENTS("protocol extension done", 0);
185191

186192
// Drop peer if it disabled the metadata extension.
187193
if (!m_extensions->is_remote_supported(ProtocolExtension::UT_METADATA))
@@ -259,7 +265,7 @@ PeerConnectionMetadata::event_read() {
259265
if (!m_extensions->is_remote_supported(ProtocolExtension::UT_METADATA))
260266
throw close_connection();
261267

262-
rak::slot_list_call(m_download->info()->signal_network_log(), "PeerConnectionMetadata::event_read() case ProtocolRead::READ_EXTENSION:");
268+
LT_LOG_METADATA_EVENTS("reading extension message", 0);
263269

264270
m_down->set_state(ProtocolRead::IDLE);
265271
m_tryRequest = true;
@@ -288,14 +294,13 @@ PeerConnectionMetadata::event_read() {
288294
m_download->connection_list()->erase(this, 0);
289295

290296
} catch (blocked_connection& e) {
291-
rak::slot_list_call(m_download->info()->signal_network_log(), "Momentarily blocked read connection.");
292297
m_download->connection_list()->erase(this, 0);
293298

294299
} catch (network_error& e) {
295300
m_download->connection_list()->erase(this, 0);
296301

297302
} catch (storage_error& e) {
298-
rak::slot_list_call(m_download->info()->signal_storage_error(), e.what());
303+
LT_LOG_STORAGE_ERRORS("read error: %s", e.what());
299304
m_download->connection_list()->erase(this, 0);
300305

301306
} catch (base_error& e) {
@@ -375,14 +380,13 @@ PeerConnectionMetadata::event_write() {
375380
m_download->connection_list()->erase(this, 0);
376381

377382
} catch (blocked_connection& e) {
378-
rak::slot_list_call(m_download->info()->signal_network_log(), "Momentarily blocked write connection.");
379383
m_download->connection_list()->erase(this, 0);
380384

381385
} catch (network_error& e) {
382386
m_download->connection_list()->erase(this, 0);
383387

384388
} catch (storage_error& e) {
385-
rak::slot_list_call(m_download->info()->signal_storage_error(), e.what());
389+
LT_LOG_STORAGE_ERRORS("read error: %s", e.what());
386390
m_download->connection_list()->erase(this, 0);
387391

388392
} catch (base_error& e) {
@@ -440,14 +444,12 @@ PeerConnectionMetadata::try_request_metadata_pieces() {
440444
if (!m_download->file_list()->is_valid_piece(*p) || !m_peerChunks.bitfield()->get(p->index()))
441445
throw internal_error("PeerConnectionMetadata::try_request_metadata_pieces() tried to use an invalid piece.");
442446

443-
// return m_extensions->request_metadata_piece(p);
444-
445447
// DEBUG:
446448
if (m_extensions->request_metadata_piece(p)) {
447-
rak::slot_list_call(m_download->info()->signal_network_log(), "PeerConnectionMetadata::try_request_metadata_pieces() succeded.");
449+
LT_LOG_METADATA_EVENTS("request metadata piece succeded", 0);
448450
return true;
449451
} else {
450-
rak::slot_list_call(m_download->info()->signal_network_log(), "PeerConnectionMetadata::try_request_metadata_pieces() failed.");
452+
LT_LOG_METADATA_EVENTS("request metadata piece failed", 0);
451453
return false;
452454
}
453455
}
@@ -464,15 +466,15 @@ PeerConnectionMetadata::receive_metadata_piece(uint32_t piece, const char* data,
464466
m_tryRequest = false;
465467
read_cancel_piece(Piece(0, piece << ProtocolExtension::metadata_piece_shift, length));
466468

467-
rak::slot_list_call(m_download->info()->signal_network_log(), "PeerConnectionMetadata::receive_metadata_piece reject.");
469+
LT_LOG_METADATA_EVENTS("rejected metadata piece", 0);
468470
return;
469471
}
470472

471473
if (!down_chunk_start(Piece(0, piece << ProtocolExtension::metadata_piece_shift, length))) {
472-
rak::slot_list_call(m_download->info()->signal_network_log(), "PeerConnectionMetadata::receive_metadata_piece skip.");
474+
LT_LOG_METADATA_EVENTS("skipped metadata piece", 0);
473475
down_chunk_skip_process(data, length);
474476
} else {
475-
rak::slot_list_call(m_download->info()->signal_network_log(), "PeerConnectionMetadata::receive_metadata_piece process.");
477+
LT_LOG_METADATA_EVENTS("processed metadata piece", 0);
476478
down_chunk_process(data, length);
477479
}
478480

src/torrent/download_info.h

-6
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,6 @@ class DownloadInfo {
158158
uint32_t upload_unchoked() const { return m_upload_unchoked; }
159159
uint32_t download_unchoked() const { return m_download_unchoked; }
160160

161-
signal_string_type& signal_network_log() const { return m_signalNetworkLog; }
162-
signal_string_type& signal_storage_error() const { return m_signalStorageError; }
163-
164161
// The list of addresses is guaranteed to be sorted and unique.
165162
signal_void_type& signal_tracker_success() const { return m_signalTrackerSuccess; }
166163
signal_string_type& signal_tracker_failed() const { return m_signalTrackerFailed; }
@@ -207,9 +204,6 @@ class DownloadInfo {
207204
slot_stat_type m_slotStatLeft;
208205
slot_stat_type m_slotStatCompleted;
209206

210-
mutable signal_string_type m_signalNetworkLog;
211-
mutable signal_string_type m_signalStorageError;
212-
213207
mutable signal_void_type m_signalTrackerSuccess;
214208
mutable signal_string_type m_signalTrackerFailed;
215209

src/torrent/utils/log.h

+3
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ enum {
127127
LOG_INSTRUMENTATION_POLLING,
128128

129129
LOG_PROTOCOL_PIECE_EVENTS,
130+
LOG_PROTOCOL_METADATA_EVENTS,
131+
LOG_PROTOCOL_NETWORK_ERRORS,
132+
LOG_PROTOCOL_STORAGE_ERRORS,
130133

131134
LOG_GROUP_MAX_SIZE
132135
};

src/torrent/utils/option_strings.cc

+3
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ const char* option_list_log_group[] = {
203203
"instrumentation_polling",
204204

205205
"protocol_piece_events",
206+
"protocol_metadata_events",
207+
"protocol_network_errors",
208+
"protocol_storage_errors",
206209

207210
NULL
208211
};

0 commit comments

Comments
 (0)