Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KAA-1087: [C++ SDK] Bad padding in PKCS7 #1529

Merged
merged 5 commits into from
May 24, 2017
Merged

KAA-1087: [C++ SDK] Bad padding in PKCS7 #1529

merged 5 commits into from
May 24, 2017

Conversation

RostakaGmfun
Copy link
Contributor

Copy link
Contributor

@rasendubi rasendubi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(setq-default indent-tabs-mode nil)

boost::asio::deadline_timer connAckTimer_;
IKaaDataMultiplexer *multiplexer_ = nullptr;
IKaaDataDemultiplexer *demultiplexer_ = nullptr;
KeyPair clientKeys_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clientKeys_ only used in the constructor. There is no need to store them.


std::deque<std::vector<uint8_t>> requestQueue_;

std::shared_ptr<RsaEncoderDecoder> encDec_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't be a pointer. It is neither reinitialized, nor shared.


std::shared_ptr<RsaEncoderDecoder> encDec_;

std::shared_ptr<IPTransportInfo> currentServer_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

currentServer_ is only used in the constructor. No need to store it.

isConnected_ = true;
if (state_ != State::Disconnected) {
readFromSocket();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation.

void setPingTimer();
void setConnAckTimer();

void run();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would say, ChannelConnection should not support run/shutdown. They only complicate things. (Then we don't need Disconnected state.) Constructor is run, destructor is shutdown. RAII FTW!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed


boost::asio::io_service io_;
boost::asio::io_service::work work_;
std::vector<std::thread> ioThreads_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we support more than one IO thread?

void ChannelConnection::readFromSocket()
{
std::lock_guard<std::mutex> lock(connectionMutex_);
KAA_LOG_INFO(boost::format("readFromSocket() %1%") % this);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trace?

channel_->onServerFailed();
return;
} else {
if (err != boost::asio::error::operation_aborted){
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code style. (){)

clientKeys_.getPrivateKey(),
currentServer_->getPublicKey(),
context_);
KAA_LOG_INFO(boost::format("Channel [%1%] scheduling open connection") % getId());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this add anything to the previous line?

closeConnection();

KAA_LOG_TRACE(boost::format("Channel [%1%] stopping IO service: isStopped '%2%'")
% getId()
% getId()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation.

auto data = request.getRawMessage();
strand_.post([this, data] {
requestQueue_.push_back(data);
if (requestQueue_.size() > 1) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

requestQueue_.push_back(data);
if (requestQueue_.size() == 1) {
    sendDataImpl();
}

boost::asio::buffer(reinterpret_cast<const char *>(data.data()), data.size()),
strand_.wrap(boost::bind(&ChannelConnection::onWriteEvent, shared_from_this(),
boost::asio::placeholders::error,
boost::asio::placeholders::bytes_transferred)));}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code style. Why closing } is here?

}

boost::system::error_code DefaultOperationTcpChannel::sendKaaSync(const std::map<TransportType, ChannelDirection>& transportTypes)
void ChannelConnection::sendKaaSync(const std::map<TransportType, ChannelDirection>& transportTypes)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code style: add an empty line before the function.


KAA_LOG_ERROR(boost::format("Channel [%1%] failed to process PING: %2%") % getId() % err.message());
onServerFailed();
if (err != boost::asio::error::operation_aborted && state_ != State::Disconnected) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can flatten conditionals now using else if.

} else {
if (isConnected_) {
KAA_LOG_DEBUG(boost::format("Channel [%1%] CONNACK processed") % getId());
if (state_ != State::Disconnected) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flatten ifs.

% getId()
% errorCode.message());
onServerFailed();
//TODO: http://jira.kaaproject.org/browse/KAA-1321
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// TODO(KAA-1321):

void DefaultOperationTcpChannel::sync(TransportType type)
{
std::lock_guard<std::recursive_mutex> lock(channelGuard_);
if (!connection_) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (connection_) {
    connection_->sync(type);
} else {
...

@@ -84,91 +85,46 @@ class DefaultOperationTcpChannel : public IDataChannel {
}

virtual void setFailoverStrategy(IFailoverStrategyPtr strategy) {
failoverStrategy_ = strategy;
static_cast<void>(strategy);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also adjust code style?

virtual void setFailoverStrategy(IFailoverStrategyPtr strategy)
{

bool isPaused_ = false;
bool isFailoverInProgress_ = false;
std::shared_ptr<ChannelConnection> connection_;
std::shared_ptr<IPTransportInfo> currentServer_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure. The only place it is passed as a reference is

channelManager_.onServerFailed(currentServer_, finalFailoverReason);

@rasendubi rasendubi merged commit 4832315 into kaaproject:release-0.10 May 24, 2017
@rasendubi
Copy link
Contributor

@RostakaGmfun, please port the patch to master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants