Skip to content

Commit 826557e

Browse files
authored
Merge pull request #33 from JoyStream/development
dev to master - v0.1.4
2 parents aa6d18d + 71a8eab commit 826557e

5 files changed

Lines changed: 24 additions & 14 deletions

File tree

conan_package/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
class ExtensionBase(ConanFile):
55
name = "Extension"
6-
version = "0.1.3"
6+
version = "0.1.4"
77
license = "(c) JoyStream Inc. 2016-2017"
88
url = "https://github.com/JoyStream/extension-conan.git"
99
git_repo = "git@github.com:JoyStream/extension-cpp.git"

sources/include/extension/PeerPlugin.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,19 +158,19 @@ namespace status {
158158
try {
159159
written = writer.write(payload);
160160
} catch(std::exception &e) {
161-
std::clog << "Error writing message payload, message not sent." << std::endl;
161+
std::clog << "Error Writing message payload, " << getMessageName(messageType) << " message not sent!" << std::endl;
162162
return;
163163
}
164164

165165
if(size != written) {
166-
std::clog << "Error payload not fully written, message not sent." << std::endl;
166+
std::clog << "Error Payload not fully written, " << getMessageName(messageType) << " message not sent!" << std::endl;
167167
return;
168168
}
169169

170170
// Send message buffer
171171
m.send(_connection);
172172

173-
std::clog << "SENT:" << getMessageName(messageType) << " = " << written << "bytes" << std::endl;
173+
std::clog << "SENT: " << getMessageName(messageType) << " (" << written << ") bytes" << std::endl;
174174
}
175175

176176
// Status of plugin

sources/include/extension/TorrentPlugin.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class TorrentPlugin : public libtorrent::torrent_plugin {
186186
// Removes peer from session, if present
187187
void removeFromSession(PeerPlugin*);
188188

189-
int pickNextPiece(const std::vector<protocol_session::detail::Piece<libtorrent::peer_id>> * pieces);
189+
int pickNextPiece(const std::vector<protocol_session::detail::Piece<libtorrent::peer_id>> * pieces);
190190

191191
// Processes extended message from peer
192192
template<class M>

sources/src/PeerPlugin.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ namespace extension {
5454
}
5555

5656
PeerPlugin::~PeerPlugin() {
57-
std::clog << "~PeerPlugin() called." << std::endl;
57+
//std::clog << "~PeerPlugin() called." << std::endl;
5858
}
5959

6060
char const* PeerPlugin::type() const {
@@ -176,6 +176,7 @@ namespace extension {
176176
if(_peerBEP10SupportStatus != BEPSupportStatus::supported) {
177177

178178
// Remove peer
179+
std::clog << "Dropping Peer: bad handshake (non-BEP10 peer sent extended handshake)" << std::endl;
179180
libtorrent::error_code ec; // "Peer misbehaved: didn't support BEP10, but it sent extended handshake."
180181
drop(ec);
181182

@@ -191,6 +192,7 @@ namespace extension {
191192
_peerPaymentBEPSupportStatus = BEPSupportStatus::not_supported;
192193

193194
// Remove peer
195+
std::clog << "Dropping Peer: bad handshake (not dictionary)" << std::endl;
194196
libtorrent::error_code ec; // "Malformed handshake received: not dictionary."
195197
drop(ec);
196198

@@ -211,6 +213,7 @@ namespace extension {
211213
// If the version string is not in the extension, it has not properly sent an unmapping
212214

213215
// Remove peer
216+
std::clog << "Dropping Peer: bad handshake - peer sent full mapping without first sending unmapping" << std::endl;
214217
libtorrent::error_code ec; // "Malformed protocol version format provided: " << versionString
215218
drop(ec);
216219
}
@@ -230,6 +233,7 @@ namespace extension {
230233
_peerPaymentBEPSupportStatus = BEPSupportStatus::not_supported;
231234

232235
// Remove peer
236+
std::clog << "Dropping Peer: bad handshake (malformed protocol vesrion format)" << std::endl;
233237
libtorrent::error_code ec; // "Malformed protocol version format provided: " << versionString
234238
drop(ec);
235239

@@ -246,6 +250,7 @@ namespace extension {
246250
_peerPaymentBEPSupportStatus = BEPSupportStatus::not_supported;
247251

248252
// Remove peer
253+
std::clog << "Dropping Peer: bad handshake (m key not present)" << std::endl;
249254
libtorrent::error_code ec; // "Malformed handshake received: m key not present."
250255
drop(ec);
251256

@@ -260,6 +265,7 @@ namespace extension {
260265
_peerPaymentBEPSupportStatus = BEPSupportStatus::not_supported;
261266

262267
// Remove peer
268+
std::clog << "Dropping Peer: bad handshake (m key not mapping to dictionary)" << std::endl;
263269
libtorrent::error_code ec; // "Malformed handshake received: m key not mapping to dictionary."
264270
drop(ec);
265271

@@ -282,6 +288,7 @@ namespace extension {
282288
_peerPaymentBEPSupportStatus = BEPSupportStatus::not_supported;
283289

284290
// Remove peer
291+
std::clog << "Dropping Peer: bad handshake (peer already sent full mapping)" << std::endl;
285292
libtorrent::error_code ec; // "Peer misbehaved: sent uninstall mapping, despite not recently annoncing valid mapping to uninstall."
286293
drop(ec);
287294

@@ -299,11 +306,11 @@ namespace extension {
299306
// If the uninstall mapping was valid we do not need to disconnect the peer
300307
if(e.problem == exception::InvalidMessageMappingDictionary::Problem::UninstallMappingFound) {
301308
if(peerMappingWasPreviouslySet) {
302-
std::clog << "Uninstall mapping was found." << std::endl;
309+
std::clog << "Removing Peer from Session - Uninstall mapping was sent." << std::endl;
303310
// Remove from session if present
304311
_plugin->removeFromSession(this);
305312
} else {
306-
std::clog << "Uninstall mapping was found, but no mapping has been previoulsy installed" << std::endl;
313+
std::clog << "Dropping Peer: bad handshake (attempting to uninstall mapping but no mapping exists)" << std::endl;
307314
libtorrent::error_code ec;
308315
drop(ec);
309316
}
@@ -449,12 +456,12 @@ namespace extension {
449456

450457
// If this peer is not part of this session, then we ignore the message
451458
if(_plugin->_session.mode() == protocol_session::SessionMode::not_set) {
452-
std::clog << "Ignoring extended message, session mode not set" << std::endl;
459+
std::clog << "Warning: Ignoring extended message, session mode not set" << std::endl;
453460
return false;
454461
}
455462

456463
if(!_plugin->peerInSession(this)) {
457-
std::clog << "Ignoring extended message, connection not in session" << std::endl;
464+
std::clog << "Warning: Ignoring extended message, connection not in session" << std::endl;
458465
return false;
459466
}
460467

@@ -552,7 +559,7 @@ namespace extension {
552559

553560
} catch (std::exception & e) {
554561

555-
std::clog << "Extended Message was Malformed" << std::endl;
562+
std::clog << "Dropping Peer: Extended Message was Malformed" << std::endl;
556563

557564
// Remove this peer
558565
libtorrent::error_code ec; // <-- "Malformed extended message received, removing."

sources/src/TorrentPlugin.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ TorrentPlugin::TorrentPlugin(Plugin * plugin,
5050
}
5151

5252
TorrentPlugin::~TorrentPlugin() {
53-
std::clog << "~TorrentPlugin()" << std::endl;
53+
//std::clog << "~TorrentPlugin()" << std::endl;
5454
}
5555

5656
boost::shared_ptr<libtorrent::peer_plugin> TorrentPlugin::new_connection(const libtorrent::peer_connection_handle & connection) {
@@ -718,8 +718,11 @@ protocol_session::RemovedConnectionCallbackHandler<libtorrent::peer_id> TorrentP
718718
// triggers callback.
719719
if(cause == protocol_session::DisconnectCause::client)
720720
return;
721-
else // all other reasons are considered misbehaviour
722-
_misbehavedPeers.insert(endPoint);
721+
else {
722+
std::clog << "Adding peer to misbehavedPeers list: " << endPoint << " cause: " << (int)cause << std::endl;
723+
// all other reasons are considered misbehaviour
724+
_misbehavedPeers.insert(endPoint);
725+
}
723726

724727
// *** Record cause for some purpose? ***
725728

0 commit comments

Comments
 (0)