8000 added srv:// endpoint · lethalbrains/arangodb@d64bf2d · GitHub
[go: up one dir, main page]

Skip to content

Commit d64bf2d

Browse files
committed
added srv:// endpoint
1 parent 53749a8 commit d64bf2d

File tree

9 files changed

+1130
-938
lines changed

9 files changed

+1130
-938
lines changed

CHANGELOG

Lines changed: 756 additions & 752 deletions
Large diffs are not rendered by default.

CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,18 @@ if (USE_TCMALLOC)
357357
find_package(tcmalloc)
358358
endif ()
359359

360+
################################################################################
361+
## LIBRARY RESOLV
362+
################################################################################
363+
364+
if (NOT WINDOWS)
365+
check_library_exists(resolv dn_expand "" RESOLV_LIB_REQ)
366+
367+
if (RESOLV_LIB_REQ)
368+
set(NET_LIBS ${NET_LIBS} resolv)
369+
endif ()
370+
endif ()
371+
360372
################################################################################
361373
## FLAGS
362374
################################################################################
@@ -703,6 +715,7 @@ list(INSERT SYSTEM_LIBRARIES 0
703715
${BASE_LIBS}
704716
${CMAKE_THREAD_LIBS_INIT}
705717
${CMAKE_DL_LIBS}
718+
${NET_LIBS}
706719
)
707720

708721
add_subdirectory(lib)

lib/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ else ()
9696
Basics/terminal-utils-posix.cpp
9797
Basics/threads-posix.cpp
9898
Rest/EndpointUnixDomain.cpp
99+
Rest/EndpointSrv.cpp
99100
)
100101
endif ()
101102

lib/Rest/Endpoint.cpp

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#endif
3333
#include "Rest/EndpointIpV4.h"
3434
#include "Rest/EndpointIpV6.h"
35+
#include "Rest/EndpointSrv.h"
3536

3637
using namespace arangodb::basics;
3738
using namespace arangodb::rest;
@@ -40,8 +41,7 @@ using namespace arangodb::rest;
4041
/// @brief create an endpoint
4142
////////////////////////////////////////////////////////////////////////////////
4243

43-
Endpoint::Endpoint(Endpoint::EndpointType type,
44-
Endpoint::DomainType domainType,
44+
Endpoint::Endpoint(Endpoint::EndpointType type, Endpoint::DomainType domainType,
4545
Endpoint::EncryptionType encryption,
4646
std::string const& specification, int listenBacklog)
4747
: _connected(false),
@@ -94,25 +94,18 @@ std::string Endpoint::getUnifiedForm(std::string const& specification) {
9494
return "";
9595
}
9696
#endif
97-
else if (!StringUtils::isPrefix(copy, "ssl://") &&
98-
!StringUtils::isPrefix(copy, "tcp://")) {
97+
else if (StringUtils::isPrefix(copy, "srv://")) {
98+
return copy;
99+
} else if (!StringUtils::isPrefix(copy, "ssl://") &&
100+
!StringUtils::isPrefix(copy, "tcp://")) {
99101
// invalid type
100102
return "";
101103
}
102104

103-
size_t found;
104-
/*
105-
// turn "localhost" into "127.0.0.1"
106-
// technically this is not always correct, but circumvents obvious problems
107-
// when the configuration contains both "127.0.0.1" and "localhost" endpoints
108-
found = copy.find("localhost");
109-
if (found != string::npos && found >= 6 && found < 10) {
110-
copy = copy.replace(found, strlen("localhost"), "127.0.0.1");
111-
}
112-
*/
113-
114105
// tcp/ip or ssl
106+
size_t found;
115107
std::string temp = copy.substr(6, copy.length()); // strip tcp:// or ssl://
108+
116109
if (temp[0] == '[') {
117110
// ipv6
118111
found = temp.find("]:", 1);
@@ -221,6 +214,14 @@ Endpoint* Endpoint::factory(const Endpoint::EndpointType type,
221214
}
222215
#endif
223216

217+
else if (StringUtils::isPrefix(domainType, "srv://")) {
218+
if (type != ENDPOINT_CLIENT) {
219+
return nullptr;
220+
}
221+
222+
return new EndpointSrv(specification.substr(6));
223+
}
224+
224225
else if (!StringUtils::isPrefix(domainType, "tcp://")) {
225226
// invalid type
226227
return nullptr;
@@ -307,7 +308,8 @@ bool Endpoint::setSocketFlags(TRI_socket_t s) {
307308
bool ok = TRI_SetNonBlockingSocket(s);
308309

309310
if (!ok) {
310-
LOG(ERR) << "cannot switch to non-blocking: " << errno << " (" << strerror(errno) << ")";
311+
LOG(ERR) << "cannot switch to non-blocking: " << errno << " ("
312+
<< strerror(errno) << ")";
311313

312314
return false;
313315
}
@@ -316,7 +318,8 @@ bool Endpoint::setSocketFlags(TRI_socket_t s) {
316318
ok = TRI_SetCloseOnExecSocket(s);
317319

318320
if (!ok) {
319-
LOG(ERR) << "cannot set close-on-exit: " << errno << " (" << strerror(errno) << ")";
321+
LOG(ERR) << "cannot set close-on-exit: " << errno << " (" << strerror(errno)
322+
<< ")";
320323

321324
return false;
322325
}

lib/Rest/Endpoint.h

Lines changed: 16 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -44,216 +44,64 @@
4444

4545
namespace arangodb {
4646
namespace rest {
47-
48-
////////////////////////////////////////////////////////////////////////////////
49-
/// @brief endpoint specification
50-
////////////////////////////////////////////////////////////////////////////////
51-
5247
class Endpoint {
5348
public:
54-
//////////////////////////////////////////////////////////////////////////////
55-
/// @brief endpoint types
56-
//////////////////////////////////////////////////////////////////////////////
57-
5849
enum EndpointType { ENDPOINT_SERVER, ENDPOINT_CLIENT };
5950

60-
//////////////////////////////////////////////////////////////////////////////
61-
/// @brief endpoint types
62-
//////////////////////////////////////////////////////////////////////////////
63-
64-
enum DomainType { DOMAIN_UNKNOWN = 0, DOMAIN_UNIX, DOMAIN_IPV4, DOMAIN_IPV6 };
65-
66-
//////////////////////////////////////////////////////////////////////////////
67-
/// @brief encryption used when talking to endpoint
68-
//////////////////////////////////////////////////////////////////////////////
51+
enum DomainType {
52+
DOMAIN_UNKNOWN = 0,
53+
DOMAIN_UNIX,
54+
DOMAIN_IPV4,
55+
DOMAIN_IPV6,
56+
DOMAIN_SRV
57+
};
6958

7059
enum EncryptionType { ENCRYPTION_NONE = 0, ENCRYPTION_SSL };
7160

7261
protected:
73-
//////////////////////////////////////////////////////////////////////////////
74-
/// @brief creates an endpoint
75-
//////////////////////////////////////////////////////////////////////////////
76-
77-
Endpoint(EndpointType, DomainType, EncryptionType,
78-
std::string const&, int);
62+
Endpoint(EndpointType, DomainType, EncryptionType, std::string const&, int);
7963

8064
public:
81-
//////////////////////////////////////////////////////////////////////////////
82-
/// @brief destroys an endpoint
83-
//////////////////////////////////////////////////////////////////////////////
84-
8565
virtual ~Endpoint();
8666

8767
public:
88-
//////////////////////////////////////////////////////////////////////////////
89-
/// @brief return the endpoint specification in a unified form
90-
//////////////////////////////////////////////////////////////////////////////
91-
9268
static std::string getUnifiedForm(std::string const&);
93-
94-
//////////////////////////////////////////////////////////////////////////////
95-
/// @brief creates a server endpoint from a string value
96-
//////////////////////////////////////////////////////////////////////////////
97-
9869
static Endpoint* serverFactory(std::string const&, int, bool reuseAddress);
99-
100-
//////////////////////////////////////////////////////////////////////////////
101-
/// @brief creates a client endpoint from a string value
102-
//////////////////////////////////////////////////////////////////////////////
103-
10470
static Endpoint* clientFactory(std::string const&);
105-
106-
//////////////////////////////////////////////////////////////////////////////
107-
/// @brief creates an endpoint from a string value
108-
//////////////////////////////////////////////////////////////////////////////
109-
11071
static Endpoint* factory(const EndpointType type, std::string const&, int,
11172
bool);
112-
113-
//////////////////////////////////////////////////////////////////////////////
114-
/// @brief compare two endpoints
115-
//////////////////////////////////////////////////////////////////////////////
116-
117-
bool operator==(Endpoint const&) const;
118-
119-
//////////////////////////////////////////////////////////////////////////////
120-
/// @brief return the default endpoint
121-
//////////////////////////////////////////////////////////////////////////////
122-
12373
static std::string const getDefaultEndpoint();
12474

125-
//////////////////////////////////////////////////////////////////////////////
126-
/// @brief connect the endpoint
127-
//////////////////////////////////////////////////////////////////////////////
75+
public:
76+
bool operator==(Endpoint const&) const;
77+
EndpointType getType() const { return _type; }
78+
EncryptionType getEncryption() const { return _encryption; }
79+
std::string getSpecification() const { return _specification; }
12880

81+
public:
12982
virtual TRI_socket_t connect(double, double) = 0;
130-
131-
//////////////////////////////////////////////////////////////////////////////
132-
/// @brief disconnect the endpoint
133-
//////////////////////////////////////////////////////////////////////////////
134-
13583
virtual void disconnect() = 0;
13684

137-
//////////////////////////////////////////////////////////////////////////////
138-
/// @brief init an incoming connection
139-
//////////////////////////////////////////////////////////////////////////////
140-
14185
virtual bool initIncoming(TRI_socket_t) = 0;
142-
143-
//////////////////////////////////////////////////////////////////////////////
144-
/// @brief set socket timeout
145-
//////////////////////////////////////////////////////////////////////////////
146-
14786
virtual bool setTimeout(TRI_socket_t, double);
148< F438 code class="diff-text syntax-highlighted-line deletion">-
149-
//////////////////////////////////////////////////////////////////////////////
150-
/// @brief initialize socket flags
151-
//////////////////////////////////////////////////////////////////////////////
152-
87+
virtual bool isConnected() const { return _connected; }
15388
virtual bool setSocketFlags(TRI_socket_t);
154-
155-
//////////////////////////////////////////////////////////////////////////////
156-
/// @brief return whether the endpoint is connected
157-
//////////////////////////////////////////////////////////////////////////////
158-
159-
bool isConnected() const { return _connected; }
160-
161-
//////////////////////////////////////////////////////////////////////////////
162-
/// @brief get the type of an endpoint
163-
//////////////////////////////////////////////////////////////////////////////
164-
165-
EndpointType getType() const { return _type; }
166-
167-
//////////////////////////////////////////////////////////////////////////////
168-
/// @brief get the domain type of an endpoint
169-
//////////////////////////////////////////////////////////////////////////////
170-
171-
DomainType getDomainType() const { return _domainType; }
172-
173-
//////////////////////////////////////////////////////////////////////////////
174-
/// @brief get the encryption used
175-
//////////////////////////////////////////////////////////////////////////////
176-
177-
EncryptionType getEncryption() const { return _encryption; }
178-
179-
//////////////////////////////////////////////////////////////////////////////
180-
/// @brief get the original endpoint specification
181-
//////////////////////////////////////////////////////////////////////////////
182-
183-
std::string getSpecification() const { return _specification; }
184-
185-
//////////////////////////////////////////////////////////////////////////////
186-
/// @brief get endpoint domain
187-
//////////////////////////////////////////////////////////////////////////////
188-
89+
virtual DomainType getDomainType() const { return _domainType; }
18990
virtual int getDomain() const = 0;
190-
191-
//////////////////////////////////////////////////////////////////////////////
192-
/// @brief get port number
193-
//////////////////////////////////////////////////////////////////////////////
194-
19591
virtual int getPort() const = 0;
196-
197-
//////////////////////////////////////////////////////////////////////////////
198-
/// @brief get host name
199-
//////////////////////////////////////////////////////////////////////////////
200-
20192
virtual std::string getHost() const = 0;
202-
203-
//////////////////////////////////////////////////////////////////////////////
204-
/// @brief get address
205-
//////////////////////////////////////////////////////////////////////////////
206-
20793
virtual std::string getHostString() const = 0;
20894

20995
public:
210-
//////////////////////////////////////////////////////////////////////////////
211-
/// @brief error message if failure occurred
212-
//////////////////////////////////////////////////////////////////////////////
213-
21496
std::string _errorMessage;
21597

21698
protected:
217-
//////////////////////////////////////////////////////////////////////////////
218-
/// @brief whether or not the endpoint is connected
219-
//////////////////////////////////////////////////////////////////////////////
220-
22199
bool _connected;
222-
223-
//////////////////////////////////////////////////////////////////////////////
224-
/// @brief the actual socket
225-
//////////////////////////////////////////////////////////////////////////////
226-
227100
TRI_socket_t _socket;
228-
229-
//////////////////////////////////////////////////////////////////////////////
230-
/// @brief endpoint type
231-
//////////////////////////////////////////////////////////////////////////////
232-
233101
EndpointType _type;
234-
235-
//////////////////////////////////////////////////////////////////////////////
236-
/// @brief endpoint domain type
237-
//////////////////////////////////////////////////////////////////////////////
238-
239102
DomainType _domainType;
240-
241-
//////////////////////////////////////////////////////////////////////////////
242-
/// @brief encryption used
243-
//////////////////////////////////////////////////////////////////////////////
244-
245103
EncryptionType _encryption;
246-
247-
//////////////////////////////////////////////////////////////////////////////
248-
/// @brief original endpoint specification
249-
//////////////////////////////////////////////////////////////////////////////
250-
251104
std::string _specification;
252-
253-
//////////////////////////////////////////////////////////////////////////////
254-
/// @brief listen backlog size
255-
//////////////////////////////////////////////////////////////////////////////
256-
257105
int _listenBacklog;
258106
};
259107
}

lib/Rest/EndpointIp.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ TRI_socket_t EndpointIp::connectSocket(const struct addrinfo* aip,
9393
#ifdef _WIN32
9494
char windowsErrorBuf[256];
9595
#endif
96+
9697
// set address and port
9798
char host[NI_MAXHOST];
9899
char serv[NI_MAXSERV];

0 commit comments

Comments
 (0)
0