Merge branch '6-bytes-transferred'

This commit is contained in:
Michał Słomkowski 2016-01-20 21:49:23 +01:00
commit fa3956f081
5 changed files with 20 additions and 9 deletions

View File

@ -41,7 +41,7 @@ namespace mumlib {
void sendTextMessage(std::string message); void sendTextMessage(std::string message);
void joinChannel(int channel_id); void joinChannel(int channelId);
private: private:
_Mumlib_Private *impl; _Mumlib_Private *impl;

View File

@ -179,7 +179,7 @@ namespace mumlib {
string welcome_text, string welcome_text,
int32_t session, int32_t session,
int32_t max_bandwidth, int32_t max_bandwidth,
int64_t permissions); int64_t permissions) override;
virtual void channelRemove(uint32_t channel_id) override; virtual void channelRemove(uint32_t channel_id) override;

View File

@ -18,7 +18,7 @@
namespace mumlib { namespace mumlib {
constexpr int MAX_UDP_LENGTH = 1024; constexpr int MAX_UDP_LENGTH = 1024;
constexpr int MAX_TCP_LENGTH = 2048; constexpr int MAX_TCP_LENGTH = 129 * 1024; // 128 kB + some reserve
using namespace std; using namespace std;
using namespace boost::asio; using namespace boost::asio;
@ -85,8 +85,7 @@ namespace mumlib {
ssl::context sslContext; ssl::context sslContext;
ssl::stream<tcp::socket> sslSocket; ssl::stream<tcp::socket> sslSocket;
uint8_t sslIncomingBuffer[MAX_TCP_LENGTH]; uint8_t *sslIncomingBuffer;
deadline_timer pingTimer; deadline_timer pingTimer;
std::chrono::time_point<std::chrono::system_clock> lastReceivedUdpPacketTimestamp; std::chrono::time_point<std::chrono::system_clock> lastReceivedUdpPacketTimestamp;

View File

@ -42,11 +42,14 @@ mumlib::Transport::Transport(
pingTimer(ioService, PING_INTERVAL), pingTimer(ioService, PING_INTERVAL),
asyncBufferPool(max(MAX_UDP_LENGTH, MAX_TCP_LENGTH)) { asyncBufferPool(max(MAX_UDP_LENGTH, MAX_TCP_LENGTH)) {
sslIncomingBuffer = new uint8_t[MAX_TCP_LENGTH];
pingTimer.async_wait(boost::bind(&Transport::pingTimerTick, this, _1)); pingTimer.async_wait(boost::bind(&Transport::pingTimerTick, this, _1));
} }
mumlib::Transport::~Transport() { mumlib::Transport::~Transport() {
disconnect(); disconnect();
delete[] sslIncomingBuffer;
} }
void mumlib::Transport::connect( void mumlib::Transport::connect(
@ -292,9 +295,16 @@ void mumlib::Transport::doReceiveSsl() {
} }
const int payloadSize = ntohl(*reinterpret_cast<uint32_t *>(sslIncomingBuffer + 2)); const int payloadSize = ntohl(*reinterpret_cast<uint32_t *>(sslIncomingBuffer + 2));
size_t remaining = payloadSize + 6 - bytesTransferred; const int wholeMessageLength = payloadSize + 6;
size_t remaining = wholeMessageLength - bytesTransferred;
remaining = max(remaining, (size_t) 0); remaining = max(remaining, (size_t) 0);
if (wholeMessageLength > MAX_TCP_LENGTH) {
throwTransportException(
(boost::format("message bigger (%d B) than max allowed size (%d B)")
% wholeMessageLength % MAX_TCP_LENGTH).str());
}
return remaining; return remaining;
}, },
[this](const boost::system::error_code &ec, size_t bytesTransferred) { [this](const boost::system::error_code &ec, size_t bytesTransferred) {
@ -314,7 +324,8 @@ void mumlib::Transport::doReceiveSsl() {
} else { } else {
logger.error("SSL receiver error: %s. Bytes transferred: %d.", logger.error("SSL receiver error: %s. Bytes transferred: %d.",
ec.message().c_str(), bytesTransferred); ec.message().c_str(), bytesTransferred);
throwTransportException("receive failed: " + ec.message()); //todo temporarily disable exception throwing until issue #6 is solved
//throwTransportException("receive failed: " + ec.message());
} }
}); });
} }

View File

@ -386,9 +386,10 @@ namespace mumlib {
impl->transport.sendControlMessage(MessageType::TEXTMESSAGE, textMessage); impl->transport.sendControlMessage(MessageType::TEXTMESSAGE, textMessage);
} }
void Mumlib::joinChannel(int channel_id) { void Mumlib::joinChannel(int channelId) {
MumbleProto::UserState userState; MumbleProto::UserState userState;
userState.set_channel_id(channel_id); userState.set_channel_id(channelId);
impl->transport.sendControlMessage(MessageType::USERSTATE, userState); impl->transport.sendControlMessage(MessageType::USERSTATE, userState);
impl->channelId = channelId;
} }
} }