Skip to content

Commit c3e3188

Browse files
authored
[DXFC-395] Add the ability to enumerate all resolved IP addresses by DNS names (#93)
1 parent 0c01f57 commit c3e3188

18 files changed

+914
-440
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ jobs:
4444

4545
# Initializes the CodeQL tools for scanning.
4646
- name: Initialize CodeQL
47-
uses: github/codeql-action/init@v1
47+
uses: github/codeql-action/init@v2
4848
with:
4949
languages: ${{ matrix.language }}
5050
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -57,4 +57,4 @@ jobs:
5757
make all
5858
5959
- name: Perform CodeQL Analysis
60-
uses: github/codeql-action/analyze@v1
60+
uses: github/codeql-action/analyze@v2

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ cmake-build-release*/**
2424
/docs/dxfeed*/
2525
**/*.swp
2626

27+
*-build/**

.lgtm.yml

Lines changed: 0 additions & 5 deletions
This file was deleted.

DXFeed.vcxproj

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,24 @@
373373
</PostBuildEvent>
374374
</ItemDefinitionGroup>
375375
<ItemGroup>
376+
<ClCompile Include="src\AddressesManager.cpp">
377+
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">CompileAsCpp</CompileAs>
378+
<CompileAs Condition="'$(Configuration)|$(Platform)'=='ReleaseNoTLS|Win32'">CompileAsCpp</CompileAs>
379+
<CompileAs Condition="'$(Configuration)|$(Platform)'=='DebugNoTLS|Win32'">CompileAsCpp</CompileAs>
380+
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">CompileAsCpp</CompileAs>
381+
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">CompileAsCpp</CompileAs>
382+
<CompileAs Condition="'$(Configuration)|$(Platform)'=='ReleaseNoTLS|x64'">CompileAsCpp</CompileAs>
383+
<CompileAs Condition="'$(Configuration)|$(Platform)'=='DebugNoTLS|x64'">CompileAsCpp</CompileAs>
384+
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Release|x64'">CompileAsCpp</CompileAs>
385+
<ExceptionHandling Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">Sync</ExceptionHandling>
386+
<ExceptionHandling Condition="'$(Configuration)|$(Platform)'=='ReleaseNoTLS|Win32'">Sync</ExceptionHandling>
387+
<ExceptionHandling Condition="'$(Configuration)|$(Platform)'=='DebugNoTLS|Win32'">Sync</ExceptionHandling>
388+
<ExceptionHandling Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">Sync</ExceptionHandling>
389+
<ExceptionHandling Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">Sync</ExceptionHandling>
390+
<ExceptionHandling Condition="'$(Configuration)|$(Platform)'=='ReleaseNoTLS|x64'">Sync</ExceptionHandling>
391+
<ExceptionHandling Condition="'$(Configuration)|$(Platform)'=='DebugNoTLS|x64'">Sync</ExceptionHandling>
392+
<ExceptionHandling Condition="'$(Configuration)|$(Platform)'=='Release|x64'">Sync</ExceptionHandling>
393+
</ClCompile>
376394
<ClCompile Include="src\BinaryQTPComposer.cpp">
377395
<CompileAs Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">CompileAsCpp</CompileAs>
378396
<CompileAs Condition="'$(Configuration)|$(Platform)'=='ReleaseNoTLS|Win32'">CompileAsCpp</CompileAs>
@@ -566,6 +584,8 @@
566584
<None Include="DXFeedd_64.def" />
567585
</ItemGroup>
568586
<ItemGroup>
587+
<ClInclude Include="src\AddressesManager.hpp" />
588+
<ClInclude Include="src\AddressesManager.h" />
569589
<ClInclude Include="src\BinaryQTPComposer.hpp" />
570590
<ClInclude Include="src\BinaryQTPParser.hpp" />
571591
<ClInclude Include="src\ConfigurationDeserializer.h" />

DXFeed.vcxproj.filters

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@
146146
<ClCompile Include="src\Configuration.cpp">
147147
<Filter>Source Files</Filter>
148148
</ClCompile>
149+
<ClCompile Include="src\AddressesManager.cpp">
150+
<Filter>Source Files</Filter>
151+
</ClCompile>
149152
<ClCompile Include="src\BinaryQTPComposer.cpp">
150153
<Filter>Source Files</Filter>
151154
</ClCompile>
@@ -177,6 +180,12 @@
177180
</None>
178181
</ItemGroup>
179182
<ItemGroup>
183+
<ClInclude Include="src\AddressesManager.hpp">
184+
<Filter>Header Files</Filter>
185+
</ClInclude>
186+
<ClInclude Include="src\AddressesManager.h">
187+
<Filter>Header Files</Filter>
188+
</ClInclude>
180189
<ClInclude Include="src\ClientMessageProcessor.h">
181190
<Filter>Header Files</Filter>
182191
</ClInclude>

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ This package provides access to **[dxFeed](https://www.dxfeed.com/)** market dat
77
[![Release](https://img.shields.io/github/v/release/dxFeed/dxfeed-c-api)](https://github.com/dxFeed/dxfeed-c-api/releases/latest)
88
[![License](https://img.shields.io/badge/license-MPL--2.0-orange)](https://github.com/dxFeed/dxfeed-c-api/blob/master/LICENSE)
99
[![Downloads](https://img.shields.io/github/downloads/dxFeed/dxfeed-c-api/total)](https://github.com/dxFeed/dxfeed-c-api/releases/latest)
10-
[![Language grade: C/C++](https://img.shields.io/lgtm/grade/cpp/g/dxFeed/dxfeed-c-api.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/dxFeed/dxfeed-c-api/context:cpp)
11-
1210

1311
## Table of Contents
1412
- [Documentation](#documentation)

ReleaseNotes.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
Version 8.7.0
2-
* [DXFC-394] [Breaking changes] Disabled mixing of specified addresses for connection in the form: (hos1:port1)(host2:port2)(host3:port3)
2+
* [DXFC-395] Added the ability to enumerate all resolved IP addresses by DNS names. IP addresses will be shuffled.
3+
- For the address of QD endpoints specified in the form `(host1:port1)(host2:port2)(host3:port3)` IP addresses will be determined, then they will be shuffled.
4+
- Shuffled addresses will be selected in order until a connection occurs. When the end of the list is reached, the endpoints will again be determined by IP addresses, and so on.
5+
- If a disconnect occurs, the next IP from the list will be selected and an attempt will be made to reconnect.
6+
* [DXFC-394] Disabled shuffling of specified addresses (DNS names) for connection in the form: `(hos1:port1)(host2:port2)(host3:port3)`
37
* [DXFC-334] Fixed a bug with precision error when converting WideDecimal to Double
48
* [DXFC-376] The SnapshotConsoleSample was improved: added an ability to specify from-time and to-time arguments.
59

samples/CommandLineSample/CommandLineSample.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,7 @@ int main(int argc, char* argv[]) {
749749

750750
dxf_initialize_logger_v2("command-line-api.log", true, true, true, log_data_transfer_flag);
751751
//dxf_load_config_from_string("network.heartbeatTimeout = 11\n");
752+
dxf_load_config_from_string("logger.level = \"debug\"\n");
752753

753754
wprintf(L"Command line sample started.\n");
754755
wprintf(L"Connecting to host %hs...\n", dxfeed_host);

src/AddressesManager.cpp

Lines changed: 147 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
/*
2-
* The contents of this file are subject to the Mozilla Public License Version
3-
* 2.0 (the "License"); you may not use this file except in compliance with
4-
* the License. You may obtain a copy of the License at
5-
* http://www.mozilla.org/MPL/
6-
*
7-
* Software distributed under the License is distributed on an "AS IS" basis,
8-
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
9-
* for the specific language governing rights and limitations under the
10-
* License.
11-
*
12-
* The Initial Developer of the Original Code is Devexperts LLC.
13-
* Portions created by the Initial Developer are Copyright (C) 2010
14-
* the Initial Developer. All Rights Reserved.
15-
*
16-
* Contributor(s):
17-
*
18-
*/
2+
* The contents of this file are subject to the Mozilla Public License Version
3+
* 2.0 (the "License"); you may not use this file except in compliance with
4+
* the License. You may obtain a copy of the License at
5+
* http://www.mozilla.org/MPL/
6+
*
7+
* Software distributed under the License is distributed on an "AS IS" basis,
8+
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
9+
* for the specific language governing rights and limitations under the
10+
* License.
11+
*
12+
* The Initial Developer of the Original Code is Devexperts LLC.
13+
* Portions created by the Initial Developer are Copyright (C) 2010
14+
* the Initial Developer. All Rights Reserved.
15+
*
16+
* Contributor(s):
17+
*
18+
*/
1919

2020
extern "C" {
2121
#include "AddressesManager.h"
@@ -25,4 +25,134 @@ extern "C" {
2525

2626
extern "C" {
2727

28+
int dx_am_next_socket_address(dxf_connection_t connection) {
29+
return dx::AddressesManager::getInstance()->nextSocketAddress(connection);
30+
}
31+
32+
void dx_am_clear_addresses(dxf_connection_t connection) {
33+
return dx::AddressesManager::getInstance()->clearAddresses(connection);
34+
}
35+
36+
int dx_am_is_current_address_tls_enabled(dxf_connection_t connection) {
37+
return dx::AddressesManager::getInstance()->isCurrentAddressTlsEnabled(connection);
38+
}
39+
40+
int dx_am_is_current_socket_address_connection_failed(dxf_connection_t connection) {
41+
return dx::AddressesManager::getInstance()->isCurrentSocketAddressConnectionFailed(connection);
42+
}
43+
44+
void dx_am_set_current_socket_address_connection_failed(dxf_connection_t connection, int is_connection_failed) {
45+
return dx::AddressesManager::getInstance()->setCurrentSocketAddressConnectionFailed(connection,
46+
is_connection_failed != 0);
47+
}
48+
49+
const char* dx_am_get_current_address_username(dxf_connection_t connection) {
50+
thread_local std::string currentAddressUsername{};
51+
52+
currentAddressUsername = dx::AddressesManager::getInstance()->getCurrentAddressUsername(connection);
53+
54+
return currentAddressUsername.c_str();
55+
}
56+
57+
const char* dx_am_get_current_address_password(dxf_connection_t connection) {
58+
thread_local std::string currentAddressPassword{};
59+
60+
currentAddressPassword = dx::AddressesManager::getInstance()->getCurrentAddressPassword(connection);
61+
62+
return currentAddressPassword.c_str();
63+
}
64+
65+
const char* dx_am_get_current_address_host(dxf_connection_t connection) {
66+
thread_local std::string currentAddressHost{};
67+
68+
currentAddressHost = dx::AddressesManager::getInstance()->getCurrentAddressHost(connection);
69+
70+
return currentAddressHost.c_str();
71+
}
72+
73+
const char* dx_am_get_current_address_port(dxf_connection_t connection) {
74+
thread_local std::string currentAddressPort{};
75+
76+
currentAddressPort = dx::AddressesManager::getInstance()->getCurrentAddressPort(connection);
77+
78+
return currentAddressPort.c_str();
79+
};
80+
81+
int dx_ma_get_current_socket_address_info(dxf_connection_t connection, int* address_family, int* address_socket_type,
82+
int* address_protocol, struct sockaddr* native_socket_address,
83+
size_t* native_socket_address_length) {
84+
return dx::AddressesManager::getInstance()->getCurrentSocketAddressInfo(
85+
connection, address_family, address_socket_type, address_protocol, native_socket_address,
86+
native_socket_address_length);
87+
}
88+
89+
const char* dx_am_get_current_address_tls_trust_store(dxf_connection_t connection) {
90+
thread_local std::string currentAddressTlsTrustStore{};
91+
92+
currentAddressTlsTrustStore = dx::AddressesManager::getInstance()->getCurrentAddressTlsTrustStore(connection);
93+
94+
return currentAddressTlsTrustStore.c_str();
95+
}
96+
97+
const char* dx_am_get_current_address_tls_trust_store_password(dxf_connection_t connection) {
98+
thread_local std::string currentAddressTlsTrustStorePassword{};
99+
100+
currentAddressTlsTrustStorePassword =
101+
dx::AddressesManager::getInstance()->getCurrentAddressTlsTrustStorePassword(connection);
102+
103+
return currentAddressTlsTrustStorePassword.c_str();
104+
}
105+
106+
const char* dx_am_get_current_address_tls_key_store(dxf_connection_t connection) {
107+
thread_local std::string currentAddressTlsKeyStore{};
108+
109+
currentAddressTlsKeyStore = dx::AddressesManager::getInstance()->getCurrentAddressTlsKeyStore(connection);
110+
111+
return currentAddressTlsKeyStore.c_str();
112+
}
113+
114+
const char* dx_am_get_current_address_tls_key_store_password(dxf_connection_t connection) {
115+
thread_local std::string currentAddressTlsKeyStorePassword{};
116+
117+
currentAddressTlsKeyStorePassword =
118+
dx::AddressesManager::getInstance()->getCurrentAddressTlsKeyStorePassword(connection);
119+
120+
return currentAddressTlsKeyStorePassword.c_str();
121+
}
122+
123+
#ifdef DXFEED_CODEC_TLS_ENABLED
124+
void dx_am_set_current_address_tls_trust_store_mem(dxf_connection_t connection, uint8_t* trust_store_mem) {
125+
dx::AddressesManager::getInstance()->setCurrentAddressTlsTrustStoreMem(connection, trust_store_mem);
126+
}
127+
128+
void dx_am_set_current_address_tls_trust_store_len(dxf_connection_t connection, size_t trust_store_len) {
129+
dx::AddressesManager::getInstance()->setCurrentAddressTlsTrustStoreLen(connection, trust_store_len);
130+
}
131+
132+
void dx_am_set_current_address_tls_key_store_mem(dxf_connection_t connection, uint8_t* key_store_mem) {
133+
dx::AddressesManager::getInstance()->setCurrentAddressTlsKeyStoreMem(connection, key_store_mem);
134+
}
135+
136+
void dx_am_set_current_address_tls_key_store_len(dxf_connection_t connection, size_t key_store_len) {
137+
dx::AddressesManager::getInstance()->setCurrentAddressTlsKeyStoreLen(connection, key_store_len);
138+
}
139+
#endif
140+
141+
const char* dx_am_get_current_connected_address(dxf_connection_t connection) {
142+
thread_local std::string currentConnectedAddress{};
143+
144+
currentConnectedAddress = dx::AddressesManager::getInstance()->getCurrentAddressHost(connection) + ":" +
145+
dx::AddressesManager::getInstance()->getCurrentAddressPort(connection);
146+
147+
return currentConnectedAddress.c_str();
148+
}
149+
150+
const char* dx_am_get_current_connected_socket_address(dxf_connection_t connection) {
151+
thread_local std::string currentConnectedSocketAddress{};
152+
153+
currentConnectedSocketAddress = dx::AddressesManager::getInstance()->getCurrentSocketIpAddress(connection) + ":" +
154+
dx::AddressesManager::getInstance()->getCurrentAddressPort(connection);
155+
156+
return currentConnectedSocketAddress.c_str();
157+
}
28158
}

src/AddressesManager.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,45 @@
1919

2020
#pragma once
2121

22+
#include "DXSockets.h"
2223
#include "DXTypes.h"
2324
#include "EventData.h"
2425
#include "PrimitiveTypes.h"
2526

2627
#ifdef __cplusplus
2728
extern "C" {
29+
# include <cstdint>
30+
#else
31+
# include <stdint.h>
2832
#endif
2933

34+
int dx_am_next_socket_address(dxf_connection_t connection);
35+
void dx_am_clear_addresses(dxf_connection_t connection);
36+
int dx_am_is_current_address_tls_enabled(dxf_connection_t connection);
37+
int dx_am_is_current_socket_address_connection_failed(dxf_connection_t connection);
38+
void dx_am_set_current_socket_address_connection_failed(dxf_connection_t connection, int is_connection_failed);
39+
const char* dx_am_get_current_address_username(dxf_connection_t connection);
40+
const char* dx_am_get_current_address_password(dxf_connection_t connection);
41+
const char* dx_am_get_current_address_host(dxf_connection_t connection);
42+
const char* dx_am_get_current_address_port(dxf_connection_t connection);
43+
int dx_ma_get_current_socket_address_info(dxf_connection_t connection, int* address_family, int* address_socket_type,
44+
int* address_protocol, struct sockaddr* native_socket_address,
45+
size_t* native_socket_address_length);
46+
const char* dx_am_get_current_address_tls_trust_store(dxf_connection_t connection);
47+
const char* dx_am_get_current_address_tls_trust_store_password(dxf_connection_t connection);
48+
const char* dx_am_get_current_address_tls_key_store(dxf_connection_t connection);
49+
const char* dx_am_get_current_address_tls_key_store_password(dxf_connection_t connection);
50+
51+
#ifdef DXFEED_CODEC_TLS_ENABLED
52+
void dx_am_set_current_address_tls_trust_store_mem(dxf_connection_t connection, uint8_t* trust_store_mem);
53+
void dx_am_set_current_address_tls_trust_store_len(dxf_connection_t connection, size_t trust_store_len);
54+
void dx_am_set_current_address_tls_key_store_mem(dxf_connection_t connection, uint8_t* key_store_mem);
55+
void dx_am_set_current_address_tls_key_store_len(dxf_connection_t connection, size_t key_store_len);
56+
#endif
57+
58+
const char* dx_am_get_current_connected_address(dxf_connection_t connection);
59+
const char* dx_am_get_current_connected_socket_address(dxf_connection_t connection);
60+
3061
#ifdef __cplusplus
3162
}
3263
#endif

0 commit comments

Comments
 (0)