-
Notifications
You must be signed in to change notification settings - Fork 472
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
Conversation
There was a problem hiding this 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_; |
There was a problem hiding this comment.
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_; |
There was a problem hiding this comment.
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_; |
There was a problem hiding this comment.
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(); | ||
} |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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_; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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){ |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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)));} |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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_) { |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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_; |
There was a problem hiding this comment.
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);
@RostakaGmfun, please port the patch to master |
/cc @rasendubi