diff options
Diffstat (limited to 'Swiften/FileTransfer/SOCKS5BytestreamClientSession.cpp')
| -rw-r--r-- | Swiften/FileTransfer/SOCKS5BytestreamClientSession.cpp | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/Swiften/FileTransfer/SOCKS5BytestreamClientSession.cpp b/Swiften/FileTransfer/SOCKS5BytestreamClientSession.cpp index 5ddd32b..a3f0dab 100644 --- a/Swiften/FileTransfer/SOCKS5BytestreamClientSession.cpp +++ b/Swiften/FileTransfer/SOCKS5BytestreamClientSession.cpp | |||
| @@ -5,7 +5,7 @@ | |||
| 5 | */ | 5 | */ |
| 6 | 6 | ||
| 7 | /* | 7 | /* |
| 8 | * Copyright (c) 2013-2016 Isode Limited. | 8 | * Copyright (c) 2013-2019 Isode Limited. |
| 9 | * All rights reserved. | 9 | * All rights reserved. |
| 10 | * See the COPYING file for more information. | 10 | * See the COPYING file for more information. |
| 11 | */ | 11 | */ |
| @@ -49,7 +49,7 @@ SOCKS5BytestreamClientSession::~SOCKS5BytestreamClientSession() { | |||
| 49 | 49 | ||
| 50 | void SOCKS5BytestreamClientSession::start() { | 50 | void SOCKS5BytestreamClientSession::start() { |
| 51 | assert(state == Initial); | 51 | assert(state == Initial); |
| 52 | SWIFT_LOG(debug) << "Trying to connect via TCP to " << addressPort.toString() << "." << std::endl; | 52 | SWIFT_LOG(debug) << "Trying to connect via TCP to " << addressPort.toString() << "."; |
| 53 | weFailedTimeout->start(); | 53 | weFailedTimeout->start(); |
| 54 | connectFinishedConnection = connection->onConnectFinished.connect( | 54 | connectFinishedConnection = connection->onConnectFinished.connect( |
| 55 | boost::bind(&SOCKS5BytestreamClientSession::handleConnectFinished, this, _1)); | 55 | boost::bind(&SOCKS5BytestreamClientSession::handleConnectFinished, this, _1)); |
| @@ -57,7 +57,7 @@ void SOCKS5BytestreamClientSession::start() { | |||
| 57 | } | 57 | } |
| 58 | 58 | ||
| 59 | void SOCKS5BytestreamClientSession::stop() { | 59 | void SOCKS5BytestreamClientSession::stop() { |
| 60 | SWIFT_LOG(debug) << std::endl; | 60 | SWIFT_LOG(debug); |
| 61 | if (state < Ready) { | 61 | if (state < Ready) { |
| 62 | weFailedTimeout->stop(); | 62 | weFailedTimeout->stop(); |
| 63 | } | 63 | } |
| @@ -70,7 +70,7 @@ void SOCKS5BytestreamClientSession::stop() { | |||
| 70 | } | 70 | } |
| 71 | 71 | ||
| 72 | void SOCKS5BytestreamClientSession::process() { | 72 | void SOCKS5BytestreamClientSession::process() { |
| 73 | SWIFT_LOG(debug) << "unprocessedData.size(): " << unprocessedData.size() << std::endl; | 73 | SWIFT_LOG(debug) << "unprocessedData.size(): " << unprocessedData.size(); |
| 74 | ByteArray bndAddress; | 74 | ByteArray bndAddress; |
| 75 | switch(state) { | 75 | switch(state) { |
| 76 | case Initial: | 76 | case Initial: |
| @@ -124,19 +124,19 @@ void SOCKS5BytestreamClientSession::process() { | |||
| 124 | } | 124 | } |
| 125 | unprocessedData.clear(); | 125 | unprocessedData.clear(); |
| 126 | state = Ready; | 126 | state = Ready; |
| 127 | SWIFT_LOG(debug) << "session ready" << std::endl; | 127 | SWIFT_LOG(debug) << "session ready"; |
| 128 | // issue ready signal so the bytestream can be used for reading or writing | 128 | // issue ready signal so the bytestream can be used for reading or writing |
| 129 | weFailedTimeout->stop(); | 129 | weFailedTimeout->stop(); |
| 130 | onSessionReady(false); | 130 | onSessionReady(false); |
| 131 | break; | 131 | break; |
| 132 | case Ready: | 132 | case Ready: |
| 133 | SWIFT_LOG(debug) << "Received further data in Ready state." << std::endl; | 133 | SWIFT_LOG(debug) << "Received further data in Ready state."; |
| 134 | break; | 134 | break; |
| 135 | case Reading: | 135 | case Reading: |
| 136 | case Writing: | 136 | case Writing: |
| 137 | case Finished: | 137 | case Finished: |
| 138 | SWIFT_LOG(debug) << "Unexpected receive of data. Current state: " << state << std::endl; | 138 | SWIFT_LOG(debug) << "Unexpected receive of data. Current state: " << state; |
| 139 | SWIFT_LOG(debug) << "Data: " << Hexify::hexify(unprocessedData) << std::endl; | 139 | SWIFT_LOG(debug) << "Data: " << Hexify::hexify(unprocessedData); |
| 140 | unprocessedData.clear(); | 140 | unprocessedData.clear(); |
| 141 | //assert(false); | 141 | //assert(false); |
| 142 | } | 142 | } |
| @@ -150,7 +150,7 @@ void SOCKS5BytestreamClientSession::hello() { | |||
| 150 | } | 150 | } |
| 151 | 151 | ||
| 152 | void SOCKS5BytestreamClientSession::authenticate() { | 152 | void SOCKS5BytestreamClientSession::authenticate() { |
| 153 | SWIFT_LOG(debug) << std::endl; | 153 | SWIFT_LOG(debug); |
| 154 | SafeByteArray header = createSafeByteArray("\x05\x01\x00\x03", 4); | 154 | SafeByteArray header = createSafeByteArray("\x05\x01\x00\x03", 4); |
| 155 | SafeByteArray message = header; | 155 | SafeByteArray message = header; |
| 156 | append(message, createSafeByteArray(boost::numeric_cast<char>(destination.size()))); | 156 | append(message, createSafeByteArray(boost::numeric_cast<char>(destination.size()))); |
| @@ -168,7 +168,7 @@ void SOCKS5BytestreamClientSession::startReceiving(std::shared_ptr<WriteBytestre | |||
| 168 | writeBytestream->write(unprocessedData); | 168 | writeBytestream->write(unprocessedData); |
| 169 | unprocessedData.clear(); | 169 | unprocessedData.clear(); |
| 170 | } else { | 170 | } else { |
| 171 | SWIFT_LOG(debug) << "Session isn't ready for transfer yet!" << std::endl; | 171 | SWIFT_LOG(debug) << "Session isn't ready for transfer yet!"; |
| 172 | } | 172 | } |
| 173 | } | 173 | } |
| 174 | 174 | ||
| @@ -180,7 +180,7 @@ void SOCKS5BytestreamClientSession::startSending(std::shared_ptr<ReadBytestream> | |||
| 180 | boost::bind(&SOCKS5BytestreamClientSession::sendData, this)); | 180 | boost::bind(&SOCKS5BytestreamClientSession::sendData, this)); |
| 181 | sendData(); | 181 | sendData(); |
| 182 | } else { | 182 | } else { |
| 183 | SWIFT_LOG(debug) << "Session isn't ready for transfer yet!" << std::endl; | 183 | SWIFT_LOG(debug) << "Session isn't ready for transfer yet!"; |
| 184 | } | 184 | } |
| 185 | } | 185 | } |
| 186 | 186 | ||
| @@ -205,7 +205,7 @@ void SOCKS5BytestreamClientSession::sendData() { | |||
| 205 | } | 205 | } |
| 206 | 206 | ||
| 207 | void SOCKS5BytestreamClientSession::finish(bool error) { | 207 | void SOCKS5BytestreamClientSession::finish(bool error) { |
| 208 | SWIFT_LOG(debug) << std::endl; | 208 | SWIFT_LOG(debug); |
| 209 | if (state < Ready) { | 209 | if (state < Ready) { |
| 210 | weFailedTimeout->stop(); | 210 | weFailedTimeout->stop(); |
| 211 | } | 211 | } |
| @@ -227,10 +227,10 @@ void SOCKS5BytestreamClientSession::finish(bool error) { | |||
| 227 | void SOCKS5BytestreamClientSession::handleConnectFinished(bool error) { | 227 | void SOCKS5BytestreamClientSession::handleConnectFinished(bool error) { |
| 228 | connectFinishedConnection.disconnect(); | 228 | connectFinishedConnection.disconnect(); |
| 229 | if (error) { | 229 | if (error) { |
| 230 | SWIFT_LOG(debug) << "Failed to connect via TCP to " << addressPort.toString() << "." << std::endl; | 230 | SWIFT_LOG(debug) << "Failed to connect via TCP to " << addressPort.toString() << "."; |
| 231 | finish(true); | 231 | finish(true); |
| 232 | } else { | 232 | } else { |
| 233 | SWIFT_LOG(debug) << "Successfully connected via TCP" << addressPort.toString() << "." << std::endl; | 233 | SWIFT_LOG(debug) << "Successfully connected via TCP" << addressPort.toString() << "."; |
| 234 | disconnectedConnection = connection->onDisconnected.connect( | 234 | disconnectedConnection = connection->onDisconnected.connect( |
| 235 | boost::bind(&SOCKS5BytestreamClientSession::handleDisconnected, this, _1)); | 235 | boost::bind(&SOCKS5BytestreamClientSession::handleDisconnected, this, _1)); |
| 236 | dataReadConnection = connection->onDataRead.connect( | 236 | dataReadConnection = connection->onDataRead.connect( |
| @@ -242,7 +242,7 @@ void SOCKS5BytestreamClientSession::handleConnectFinished(bool error) { | |||
| 242 | } | 242 | } |
| 243 | 243 | ||
| 244 | void SOCKS5BytestreamClientSession::handleDataRead(std::shared_ptr<SafeByteArray> data) { | 244 | void SOCKS5BytestreamClientSession::handleDataRead(std::shared_ptr<SafeByteArray> data) { |
| 245 | SWIFT_LOG(debug) << "state: " << state << " data.size() = " << data->size() << std::endl; | 245 | SWIFT_LOG(debug) << "state: " << state << " data.size() = " << data->size(); |
| 246 | if (state != Reading) { | 246 | if (state != Reading) { |
| 247 | append(unprocessedData, *data); | 247 | append(unprocessedData, *data); |
| 248 | process(); | 248 | process(); |
| @@ -254,14 +254,14 @@ void SOCKS5BytestreamClientSession::handleDataRead(std::shared_ptr<SafeByteArray | |||
| 254 | } | 254 | } |
| 255 | 255 | ||
| 256 | void SOCKS5BytestreamClientSession::handleDisconnected(const boost::optional<Connection::Error>& error) { | 256 | void SOCKS5BytestreamClientSession::handleDisconnected(const boost::optional<Connection::Error>& error) { |
| 257 | SWIFT_LOG(debug) << (error ? (error == Connection::ReadError ? "Read Error" : "Write Error") : "No Error") << std::endl; | 257 | SWIFT_LOG(debug) << (error ? (error == Connection::ReadError ? "Read Error" : "Write Error") : "No Error"); |
| 258 | if (error) { | 258 | if (error) { |
| 259 | finish(true); | 259 | finish(true); |
| 260 | } | 260 | } |
| 261 | } | 261 | } |
| 262 | 262 | ||
| 263 | void SOCKS5BytestreamClientSession::handleWeFailedTimeout() { | 263 | void SOCKS5BytestreamClientSession::handleWeFailedTimeout() { |
| 264 | SWIFT_LOG(debug) << "Failed due to timeout!" << std::endl; | 264 | SWIFT_LOG(debug) << "Failed due to timeout!"; |
| 265 | finish(true); | 265 | finish(true); |
| 266 | } | 266 | } |
| 267 | 267 | ||
Swift