Skip to content

Commit 8484f9d

Browse files
release300.2.5
1 parent 5979a10 commit 8484f9d

File tree

9 files changed

+64
-57
lines changed

9 files changed

+64
-57
lines changed

include/DolphinDB.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
#pragma warning( disable : 4251 )
3434
#endif
3535

36+
#ifdef USE_OPENSSL
37+
constexpr bool HAS_OPENSSL{true};
38+
#else
39+
constexpr bool HAS_OPENSSL{false};
40+
#endif
41+
3642
namespace dolphindb {
3743

3844
class DBConnectionImpl;
@@ -95,7 +101,7 @@ class EXPORT_DECL DBConnection {
95101
throw RuntimeException("Failed to connect to server: " + host + ":" + std::to_string(port));
96102
}
97103
if (!userName.empty()) {
98-
login(userName, password, true);
104+
login(userName, password, HAS_OPENSSL);
99105
}
100106
}
101107
DBConnection(bool enableSSL = false, bool asyncTask = false, int keepAliveTime = 7200, bool compress = false, bool python = false, bool isReverseStreaming = false, bool enableSCRAM = false);

include/SysIO.h

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,6 @@
1919
#include <openssl/err.h>
2020
#include <openssl/ssl.h>
2121

22-
#else
23-
24-
using SSL_CTX = int;
25-
using SSL = int;
26-
2722
#endif
2823

2924
#ifdef __linux__
@@ -75,19 +70,19 @@ class EXPORT_DECL Socket{
7570
bool setBlocking();
7671
bool setTcpNoDelay();
7772
int getErrorCode();
78-
SSL_CTX* initCTX();
73+
void* initCTX();
7974
bool sslInit();
8075
IO_ERR sslConnect();
81-
void showCerts(SSL* ssl);
76+
void showCerts(void* ssl);
8277
private:
8378
std::string host_;
8479
int port_;
8580
SOCKET handle_;
8681
bool blocking_;
8782
bool autoClose_;
8883
bool enableSSL_;
89-
SSL_CTX* ctx_;
90-
SSL* ssl_;
84+
void* ctx_;
85+
void* ssl_;
9186
int keepAliveTime_;
9287
};
9388

src/Crypto.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ auto Crypto::RSAEncrypt(const std::string &text) const -> std::string
4545
{
4646
int rsa_size = EVP_PKEY_size(rsa_);
4747
std::vector<unsigned char> encrypted(rsa_size);
48-
size_t encrypted_len;
48+
size_t encrypted_len = rsa_size;
4949
if (EVP_PKEY_encrypt(ctx_, encrypted.data(), &encrypted_len, (const unsigned char*)text.c_str(), text.size()) != 1) {
5050
printOpenSSLError();
5151
throw RuntimeException("Failed to encrypt userId or password.");

src/DolphinDBImp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ bool DBConnectionImpl::connect() {
115115

116116
if (!userId_.empty()) {
117117
try {
118-
login(userId_, pwd_, false);
118+
login(userId_, pwd_, HAS_OPENSSL);
119119
} catch (...) {
120120
close();
121121
throw;

src/Streaming.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,7 +1402,7 @@ void StreamingClientImpl::sendPublishRequest(DBConnection &conn, SubscribeParam
14021402
info.offset_, info.filter_, info.allowExists_);
14031403
}
14041404
else {
1405-
conn.login(info.userName_, info.password_, false);
1405+
conn.login(info.userName_, info.password_, HAS_OPENSSL);
14061406
re = run(conn, "publishTable", getLocalIP(), listeningPort_, info.info_.tableName, info.info_.actionName,
14071407
info.offset_, info.filter_, info.allowExists_);
14081408
}
@@ -1421,7 +1421,7 @@ void StreamingClientImpl::sendPublishRequest(DBConnection &conn, SubscribeParam
14211421

14221422
string StreamingClientImpl::subscribeInternal(DBConnection &conn, SubscribeParam &info) {
14231423
if (info.userName_.empty() == false)
1424-
conn.login(info.userName_, info.password_, false);
1424+
conn.login(info.userName_, info.password_, HAS_OPENSSL);
14251425
ConstantSP result = run(conn, "getSubscriptionTopic", info.info_.tableName, info.info_.actionName);
14261426
auto topic = result->get(0)->getString();
14271427
ConstantSP colLabels = result->get(1);
@@ -2029,7 +2029,7 @@ ThreadSP ThreadedClient::subscribe(string host, int port, const MessageHandler &
20292029
}
20302030
SubscribeConfig config { offset, msgAsTable, allowExists, false };
20312031
if (!userName.empty()) {
2032-
conn->login(userName, password, false);
2032+
conn->login(userName, password, HAS_OPENSSL);
20332033
}
20342034
udpImpl_->subscribe(info, config, conn, handler, blobDeserializer);
20352035
return nullptr;

src/SysIO.cpp

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -118,25 +118,23 @@ IO_ERR Socket::read(char* buffer, size_t length, size_t& actualLength, bool msgP
118118
//RecordTime record("Socket.read");
119119
if (!enableSSL_) {
120120
#ifdef _WIN32
121-
actualLength = recv(handle_, buffer, static_cast<int>(length), msgPeek ? MSG_PEEK : 0);
122-
RECORD_READ(buffer, actualLength);
123-
if (actualLength < 0) {
121+
actualLength = 0;
122+
int ret = recv(handle_, buffer, static_cast<int>(length), msgPeek ? MSG_PEEK : 0);
123+
if (ret == SOCKET_ERROR) {
124124
DLogger::Error("socket read error", actualLength);
125-
}
126-
if (actualLength == 0)
127-
return DISCONNECTED;
128-
else if (actualLength != (size_t)SOCKET_ERROR)
129-
return OK;
130-
else {
131-
actualLength = 0;
132125
int error = WSAGetLastError();
133126
if (error == WSAENOTCONN || error == WSAESHUTDOWN || error == WSAENETRESET)
134127
return DISCONNECTED;
135-
else if (error == WSAEWOULDBLOCK)
128+
if (error == WSAEWOULDBLOCK)
136129
return NODATA;
137-
else
138-
return OTHERERR;
130+
return OTHERERR;
139131
}
132+
if (ret == 0) {
133+
return DISCONNECTED;
134+
}
135+
actualLength = ret;
136+
RECORD_READ(buffer, ret);
137+
return OK;
140138
#else //Linux
141139
readdata:
142140
actualLength = recv(handle_, (void*)buffer, length, (blocking_ ? 0 : MSG_DONTWAIT) | (msgPeek ? MSG_PEEK : 0));
@@ -156,20 +154,20 @@ IO_ERR Socket::read(char* buffer, size_t length, size_t& actualLength, bool msgP
156154
} else {
157155
#ifdef USE_OPENSSL
158156
readdata2:
159-
int ret = SSL_read(ssl_, buffer, static_cast<int>(length));
157+
int ret = SSL_read((SSL*)ssl_, buffer, static_cast<int>(length));
160158
if (ret > 0) {
161159
actualLength = ret;
162160
RECORD_READ(buffer, ret);
163161
} else {
164162
DLogger::Error("socket read error", ret);
165-
ret = SSL_get_error(ssl_, ret);
163+
ret = SSL_get_error((SSL*)ssl_, ret);
166164
if(ret == SSL_ERROR_WANT_READ) goto readdata2;
167165
LOG_ERR("Socket(SSL)::read err =" + std::to_string(ret));
168166
return OTHERERR;
169167
}
170168
#endif
171-
return OK;
172169
}
170+
return OK;
173171
}
174172

175173
IO_ERR Socket::write(const char* buffer, size_t length, size_t& actualLength){
@@ -218,12 +216,12 @@ IO_ERR Socket::write(const char* buffer, size_t length, size_t& actualLength){
218216
else {
219217
#ifdef USE_OPENSSL
220218
senddata2:
221-
int ret = SSL_write(ssl_, (const void*)buffer, static_cast<int>(length));
219+
int ret = SSL_write((SSL*)ssl_, (const void*)buffer, static_cast<int>(length));
222220
if (ret > 0) {
223221
actualLength = ret;
224222
RECORD_WRITE(buffer, ret);
225223
} else {
226-
int err = SSL_get_error(ssl_, ret);
224+
int err = SSL_get_error((SSL*)ssl_, ret);
227225
if (err == SSL_ERROR_WANT_WRITE) goto senddata2;
228226
DLogger::Error("socket write error", err);
229227
LOG_ERR("Socket(SSL)::write err =" + std::to_string(err));
@@ -387,10 +385,10 @@ IO_ERR Socket::close(){
387385
#ifdef USE_OPENSSL
388386
if(ssl_ != nullptr) {
389387
//shutdown until it done.
390-
while (SSL_shutdown(ssl_) == 0) {
388+
while (SSL_shutdown((SSL*)ssl_) == 0) {
391389
Util::sleep(10);
392390
}
393-
SSL_free(ssl_);
391+
SSL_free((SSL*)ssl_);
394392
ssl_ = nullptr;
395393
}
396394
#endif
@@ -407,7 +405,7 @@ IO_ERR Socket::close(){
407405
}
408406
#ifdef USE_OPENSSL
409407
if (ctx_ != nullptr) {
410-
SSL_CTX_free(ctx_);
408+
SSL_CTX_free((SSL_CTX*)ctx_);
411409
ctx_ = nullptr;
412410
}
413411
#endif
@@ -552,7 +550,7 @@ int Socket::getErrorCode(){
552550
}
553551

554552
#ifdef USE_OPENSSL
555-
SSL_CTX* Socket::initCTX(){
553+
void* Socket::initCTX(){
556554
const SSL_METHOD* method;
557555
SSL_CTX* ctx;
558556

@@ -576,11 +574,11 @@ bool Socket::sslInit() {
576574
if (ctx_ == nullptr) {
577575
return false;
578576
}
579-
ssl_ = SSL_new(ctx_);
577+
ssl_ = SSL_new((SSL_CTX*)ctx_);
580578
if (ssl_ == nullptr) {
581579
return false;
582580
}
583-
SSL_set_fd(ssl_, static_cast<int>(handle_));
581+
SSL_set_fd((SSL*)ssl_, static_cast<int>(handle_));
584582
return true;
585583
}
586584

@@ -589,7 +587,7 @@ IO_ERR Socket::sslConnect() {
589587
if (!sslInit()) {
590588
return OTHERERR;
591589
}
592-
if (SSL_connect(ssl_) == -1) {
590+
if (SSL_connect((SSL*)ssl_) == -1) {
593591
if (!blocking_) {
594592
//TODO: solve error
595593
}
@@ -599,10 +597,10 @@ IO_ERR Socket::sslConnect() {
599597
return OK;
600598
}
601599

602-
void Socket::showCerts(SSL *ssl) {
600+
void Socket::showCerts(void *ssl) {
603601
X509 *cert;
604602
char *line;
605-
cert = SSL_get_peer_certificate(ssl); /* get the server's certificate */
603+
cert = SSL_get_peer_certificate((SSL*)ssl); /* get the server's certificate */
606604
if ( cert != NULL ){
607605
std::cout << "Server certificates:\n";
608606
line = X509_NAME_oneline(X509_get_subject_name(cert), 0, 0);

src/Util.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ using std::vector;
4040

4141
static SmartPointer<ConstantFactory> s_constFactory(new ConstantFactory());
4242
const bool Util::LITTLE_ENDIAN_ORDER = isLittleEndian();
43-
string Util::VER = "3.00.2.4";
43+
string Util::VER = "3.00.2.5";
4444
#ifndef _MSC_VER
4545
constexpr int Util::BUF_SIZE;
4646
#endif
47-
int Util::VERNUM = 30024;
48-
string Util::BUILD = "2025.03.11";
47+
int Util::VERNUM = 30025;
48+
string Util::BUILD = "2025.05.19";
4949

5050
int Util::SEQUENCE_SEARCH_NUM_THRESHOLD = 10;
5151
int Util::MAX_LENGTH_FOR_ANY_VECTOR = 1048576;

test/DBConnectionTest_gtest.cpp

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,18 +57,10 @@ void StopCurNode(string cur_node)
5757

5858
conn1.run("try{stopDataNode(\"" + cur_node + "\")}catch(ex){};");
5959
cout << cur_node + " has stopped..." << endl;
60-
std::this_thread::sleep_for(std::chrono::seconds(5));
61-
// std::this_thread::yield();
62-
conn1.run("try{startDataNode(\"" + cur_node + "\")}catch(ex){};");
63-
bool state = conn1.run("exec state from getClusterPerf() where name = `" + cur_node)->getBool();
64-
int wait_time = 0;
65-
while (!state && wait_time < 60){
66-
conn1.run("try{startDataNode(\"" + cur_node + "\")}catch(ex){};");
67-
state = conn1.run("exec state from getClusterPerf() where name = `" + cur_node)->getBool();
68-
cout << "waiting for " + cur_node + " to start..." << endl;
69-
Util::sleep(1000);
70-
wait_time += 1;
71-
}
60+
Util::sleep(5000);
61+
cout << "restarting " + cur_node + "..." << endl;
62+
conn1.run("startDataNode(exec name from getClusterPerf() where mode !=1 and state != 1);go;"
63+
"do{sleep(1000);}while((exec distinct state from getClusterPerf()).size() !=1);");
7264
}
7365

7466
bool assertUnConnect()
@@ -856,6 +848,21 @@ TEST_F(DBConnectionTest, test_connection_SCRAM){
856848
_c.close();
857849
cout << "test_connection_SCRAM2 passed" << endl;
858850
}
851+
{ // login with no scram auth user admin
852+
DBConnection _c = DBConnection(false, false, 7200, false, false, false, true);
853+
_c.connect(hostName, port, "admin", "123456"); // stdout: [debug] [140591328847872] : user 'admin' doesn't support scram authMode.
854+
}
855+
{ // enableEncryption with scram user
856+
DBConnection _c = DBConnection(hostName, port);
857+
_c.connect();
858+
_c.login("scramUser", "123456", true);
859+
ConstantSP res = _c.run("getCurrentSessionAndUser()[1]");
860+
EXPECT_EQ(res->getString(), "scramUser");
861+
_c.close();
862+
}
863+
{ // async login with scram user
864+
EXPECT_ANY_THROW(DBConnection(false, true, 7200, false, false, false, true));
865+
}
859866
}
860867

861868
TEST_F(DBConnectionTest, test_connectionPool_SCRAM){

test/StreamingSubscribeHAstreamTableTest_gtest.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,6 +1409,7 @@ TEST_P(StreamingSubscribeHighAvailableTest, test_Pollingclient_stopDataNode)
14091409
if (msg1_total == insert_total_rows)
14101410
{
14111411
cout << "get all msg successfully!" << endl;
1412+
break;
14121413
}
14131414
}
14141415
} };

0 commit comments

Comments
 (0)