49
49
#include " torrent/peer/connection_list.h"
50
50
#include " torrent/peer/peer_info.h"
51
51
#include " rak/functional.h"
52
+ #include " torrent/utils/log.h"
52
53
53
54
#include " extensions.h"
54
55
#include " peer_connection_metadata.h"
55
56
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
+
56
62
namespace torrent {
57
63
58
64
PeerConnectionMetadata::~PeerConnectionMetadata () {
@@ -162,7 +168,7 @@ PeerConnectionMetadata::read_message() {
162
168
return true ;
163
169
164
170
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 );
166
172
167
173
if (!m_down->can_read_extension_body ())
168
174
break ;
@@ -181,7 +187,7 @@ PeerConnectionMetadata::read_message() {
181
187
if (!down_extension ())
182
188
return false ;
183
189
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 );
185
191
186
192
// Drop peer if it disabled the metadata extension.
187
193
if (!m_extensions->is_remote_supported (ProtocolExtension::UT_METADATA))
@@ -259,7 +265,7 @@ PeerConnectionMetadata::event_read() {
259
265
if (!m_extensions->is_remote_supported (ProtocolExtension::UT_METADATA))
260
266
throw close_connection ();
261
267
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 );
263
269
264
270
m_down->set_state (ProtocolRead::IDLE);
265
271
m_tryRequest = true ;
@@ -288,14 +294,13 @@ PeerConnectionMetadata::event_read() {
288
294
m_download->connection_list ()->erase (this , 0 );
289
295
290
296
} catch (blocked_connection& e) {
291
- rak::slot_list_call (m_download->info ()->signal_network_log (), " Momentarily blocked read connection." );
292
297
m_download->connection_list ()->erase (this , 0 );
293
298
294
299
} catch (network_error& e) {
295
300
m_download->connection_list ()->erase (this , 0 );
296
301
297
302
} 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 ());
299
304
m_download->connection_list ()->erase (this , 0 );
300
305
301
306
} catch (base_error& e) {
@@ -375,14 +380,13 @@ PeerConnectionMetadata::event_write() {
375
380
m_download->connection_list ()->erase (this , 0 );
376
381
377
382
} catch (blocked_connection& e) {
378
- rak::slot_list_call (m_download->info ()->signal_network_log (), " Momentarily blocked write connection." );
379
383
m_download->connection_list ()->erase (this , 0 );
380
384
381
385
} catch (network_error& e) {
382
386
m_download->connection_list ()->erase (this , 0 );
383
387
384
388
} 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 ());
386
390
m_download->connection_list ()->erase (this , 0 );
387
391
388
392
} catch (base_error& e) {
@@ -440,14 +444,12 @@ PeerConnectionMetadata::try_request_metadata_pieces() {
440
444
if (!m_download->file_list ()->is_valid_piece (*p) || !m_peerChunks.bitfield ()->get (p->index ()))
441
445
throw internal_error (" PeerConnectionMetadata::try_request_metadata_pieces() tried to use an invalid piece." );
442
446
443
- // return m_extensions->request_metadata_piece(p);
444
-
445
447
// DEBUG:
446
448
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 );
448
450
return true ;
449
451
} 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 );
451
453
return false ;
452
454
}
453
455
}
@@ -464,15 +466,15 @@ PeerConnectionMetadata::receive_metadata_piece(uint32_t piece, const char* data,
464
466
m_tryRequest = false ;
465
467
read_cancel_piece (Piece (0 , piece << ProtocolExtension::metadata_piece_shift, length));
466
468
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 );
468
470
return ;
469
471
}
470
472
471
473
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 );
473
475
down_chunk_skip_process (data, length);
474
476
} 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 );
476
478
down_chunk_process (data, length);
477
479
}
478
480
0 commit comments