Skip to content

Commit d699116

Browse files
committed
mac deps
1 parent 8f3a0b1 commit d699116

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+434
-15121
lines changed

Diff for: controller/PostgreSQL.cpp

+21-1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ PostgreSQL::PostgreSQL(const Identity &myId, const char *path, int listenPort, R
7878
, _waitNoticePrinted(false)
7979
, _listenPort(listenPort)
8080
, _rc(rc)
81+
, _redis(NULL)
82+
, _cluster(NULL)
8183
{
8284
char myAddress[64];
8385
_myAddressStr = myId.address().toString(myAddress);
@@ -113,6 +115,21 @@ PostgreSQL::PostgreSQL(const Identity &myId, const char *path, int listenPort, R
113115
PQfinish(conn);
114116
conn = NULL;
115117

118+
if (_rc != NULL) {
119+
sw::redis::ConnectionOptions opts;
120+
sw::redis::ConnectionPoolOptions poolOpts;
121+
opts.host = _rc->hostname;
122+
opts.port = _rc->port;
123+
opts.password = _rc->password;
124+
opts.db = 0;
125+
poolOpts.size = 10;
126+
if (_rc->clusterMode) {
127+
_cluster = new sw::redis::RedisCluster(opts, poolOpts);
128+
} else {
129+
_redis = new sw::redis::Redis(opts, poolOpts);
130+
}
131+
}
132+
116133
_readyLock.lock();
117134
_heartbeatThread = std::thread(&PostgreSQL::heartbeat, this);
118135
_membersDbWatcher = std::thread(&PostgreSQL::membersDbWatcher, this);
@@ -128,14 +145,17 @@ PostgreSQL::~PostgreSQL()
128145
_run = 0;
129146
std::this_thread::sleep_for(std::chrono::milliseconds(100));
130147

148+
149+
131150
_heartbeatThread.join();
132151
_membersDbWatcher.join();
133152
_networksDbWatcher.join();
134153
for (int i = 0; i < ZT_CENTRAL_CONTROLLER_COMMIT_THREADS; ++i) {
135154
_commitThread[i].join();
136155
}
137156
_onlineNotificationThread.join();
138-
157+
delete _redis;
158+
delete _cluster;
139159
}
140160

141161

Diff for: controller/PostgreSQL.hpp

+4
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020

2121
#define ZT_CENTRAL_CONTROLLER_COMMIT_THREADS 4
2222

23+
#include <redis++/redis++.h>
24+
2325
extern "C" {
2426
typedef struct pg_conn PGconn;
2527
}
@@ -98,6 +100,8 @@ class PostgreSQL : public DB
98100
int _listenPort;
99101

100102
RedisConfig *_rc;
103+
sw::redis::Redis *_redis;
104+
sw::redis::RedisCluster *_cluster;
101105
};
102106

103107
} // namespace ZeroTier

Diff for: controller/Redis.hpp

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#ifndef ZT_CONTROLLER_REDIS_HPP
2+
#define ZT_CONTROLLER_REDIS_HPP
3+
4+
#include <string>
5+
6+
namespace ZeroTier {
7+
struct RedisConfig {
8+
std::string hostname;
9+
int port;
10+
std::string password;
11+
bool clusterMode;
12+
};
13+
}
14+
15+
#endif

Diff for: ext/hiredis-0.14.1/.gitignore

-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,4 @@
33
/*.o
44
/*.so
55
/*.dylib
6-
/*.a
76
/*.pc

Diff for: ext/hiredis-0.14.1/include/hiredis/alloc.h

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Copyright (c) 2020, Michael Grunder <michael dot grunder at gmail dot com>
3+
*
4+
* All rights reserved.
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions are met:
8+
*
9+
* * Redistributions of source code must retain the above copyright notice,
10+
* this list of conditions and the following disclaimer.
11+
* * Redistributions in binary form must reproduce the above copyright
12+
* notice, this list of conditions and the following disclaimer in the
13+
* documentation and/or other materials provided with the distribution.
14+
* * Neither the name of Redis nor the names of its contributors may be used
15+
* to endorse or promote products derived from this software without
16+
* specific prior written permission.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
* POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
#ifndef HIREDIS_ALLOC_H
32+
#define HIREDIS_ALLOC_H
33+
34+
#include <stdlib.h> /* for size_t */
35+
36+
#ifndef HIREDIS_OOM_HANDLER
37+
#define HIREDIS_OOM_HANDLER abort()
38+
#endif
39+
40+
#ifdef __cplusplus
41+
extern "C" {
42+
#endif
43+
44+
void *hi_malloc(size_t size);
45+
void *hi_calloc(size_t nmemb, size_t size);
46+
void *hi_realloc(void *ptr, size_t size);
47+
char *hi_strdup(const char *str);
48+
49+
#ifdef __cplusplus
50+
}
51+
#endif
52+
53+
#endif /* HIREDIS_ALLOC_H */

Diff for: ext/hiredis-vip-0.3.0/async.h renamed to ext/hiredis-0.14.1/include/hiredis/async.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ typedef void (redisCallbackFn)(struct redisAsyncContext*, void*, void*);
4545
typedef struct redisCallback {
4646
struct redisCallback *next; /* simple singly linked list */
4747
redisCallbackFn *fn;
48+
int pending_subs;
4849
void *privdata;
4950
} redisCallback;
5051

@@ -68,7 +69,6 @@ typedef struct redisAsyncContext {
6869

6970
/* Not used by hiredis */
7071
void *data;
71-
void (*dataHandler)(struct redisAsyncContext* ac);
7272

7373
/* Event library data and hooks */
7474
struct {
File renamed without changes.

Diff for: ext/hiredis-0.14.1/include/hiredis/fmacros.h

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#ifndef __HIREDIS_FMACRO_H
2+
#define __HIREDIS_FMACRO_H
3+
4+
#define _XOPEN_SOURCE 600
5+
#define _POSIX_C_SOURCE 200112L
6+
7+
#if defined(__APPLE__) && defined(__MACH__)
8+
/* Enable TCP_KEEPALIVE */
9+
#define _DARWIN_C_SOURCE
10+
#endif
11+
12+
#endif

Diff for: ext/hiredis-vip-0.3.0/hiredis.h renamed to ext/hiredis-0.14.1/include/hiredis/hiredis.h

+7-28
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@
3838
#include <sys/time.h> /* for struct timeval */
3939
#include <stdint.h> /* uintXX_t, etc */
4040
#include "sds.h" /* for sds */
41+
#include "alloc.h" /* for allocation wrappers */
4142

4243
#define HIREDIS_MAJOR 0
43-
#define HIREDIS_MINOR 13
44+
#define HIREDIS_MINOR 14
4445
#define HIREDIS_PATCH 1
46+
#define HIREDIS_SONAME 0.14
4547

4648
/* Connection type can be blocking or non-blocking and is set in the
4749
* least significant bit of the flags field in redisContext. */
@@ -79,30 +81,6 @@
7981
* SO_REUSEADDR is being used. */
8082
#define REDIS_CONNECT_RETRIES 10
8183

82-
/* strerror_r has two completely different prototypes and behaviors
83-
* depending on system issues, so we need to operate on the error buffer
84-
* differently depending on which strerror_r we're using. */
85-
#ifndef _GNU_SOURCE
86-
/* "regular" POSIX strerror_r that does the right thing. */
87-
#define __redis_strerror_r(errno, buf, len) \
88-
do { \
89-
strerror_r((errno), (buf), (len)); \
90-
} while (0)
91-
#else
92-
/* "bad" GNU strerror_r we need to clean up after. */
93-
#define __redis_strerror_r(errno, buf, len) \
94-
do { \
95-
char *err_str = strerror_r((errno), (buf), (len)); \
96-
/* If return value _isn't_ the start of the buffer we passed in, \
97-
* then GNU strerror_r returned an internal static buffer and we \
98-
* need to copy the result into our private buffer. */ \
99-
if (err_str != (buf)) { \
100-
buf[(len)] = '\0'; \
101-
strncat((buf), err_str, ((len) - 1)); \
102-
} \
103-
} while (0)
104-
#endif
105-
10684
#ifdef __cplusplus
10785
extern "C" {
10886
#endif
@@ -111,7 +89,7 @@ extern "C" {
11189
typedef struct redisReply {
11290
int type; /* REDIS_REPLY_* */
11391
long long integer; /* The integer when type is REDIS_REPLY_INTEGER */
114-
int len; /* Length of string */
92+
size_t len; /* Length of string */
11593
char *str; /* Used for both REDIS_REPLY_ERROR and REDIS_REPLY_STRING */
11694
size_t elements; /* number of elements, for REDIS_REPLY_ARRAY */
11795
struct redisReply **element; /* elements vector for REDIS_REPLY_ARRAY */
@@ -132,7 +110,7 @@ void redisFreeSdsCommand(sds cmd);
132110

133111
enum redisConnectionType {
134112
REDIS_CONN_TCP,
135-
REDIS_CONN_UNIX,
113+
REDIS_CONN_UNIX
136114
};
137115

138116
/* Context for a connection to Redis */
@@ -156,6 +134,7 @@ typedef struct redisContext {
156134
struct {
157135
char *path;
158136
} unix_sock;
137+
159138
} redisContext;
160139

161140
redisContext *redisConnect(const char *ip, int port);
@@ -177,7 +156,7 @@ redisContext *redisConnectFd(int fd);
177156
* host, ip (or path), timeout and bind address are reused,
178157
* flags are used unmodified from the existing context.
179158
*
180-
* Returns REDIS_OK on successfull connect or REDIS_ERR otherwise.
159+
* Returns REDIS_OK on successful connect or REDIS_ERR otherwise.
181160
*/
182161
int redisReconnect(redisContext *c);
183162

Diff for: ext/hiredis-vip-0.3.0/net.h renamed to ext/hiredis-0.14.1/include/hiredis/net.h

-4
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@
3737

3838
#include "hiredis.h"
3939

40-
#if defined(__sun)
41-
#define AF_LOCAL AF_UNIX
42-
#endif
43-
4440
int redisCheckSocketError(redisContext *c);
4541
int redisContextSetTimeout(redisContext *c, const struct timeval tv);
4642
int redisContextConnectTcp(redisContext *c, const char *addr, int port, const struct timeval *timeout);

Diff for: ext/hiredis-vip-0.3.0/read.h renamed to ext/hiredis-0.14.1/include/hiredis/read.h

+4-22
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,14 @@
3838
#define REDIS_OK 0
3939

4040
/* When an error occurs, the err flag in a context is set to hold the type of
41-
* error that occured. REDIS_ERR_IO means there was an I/O error and you
41+
* error that occurred. REDIS_ERR_IO means there was an I/O error and you
4242
* should use the "errno" variable to find out what is wrong.
4343
* For other values, the "errstr" field will hold a description. */
4444
#define REDIS_ERR_IO 1 /* Error in read or write */
4545
#define REDIS_ERR_EOF 3 /* End of file */
4646
#define REDIS_ERR_PROTOCOL 4 /* Protocol error */
4747
#define REDIS_ERR_OOM 5 /* Out of memory */
4848
#define REDIS_ERR_OTHER 2 /* Everything else... */
49-
#if 1 //shenzheng 2015-8-10 redis cluster
50-
#define REDIS_ERR_CLUSTER_TOO_MANY_REDIRECT 6
51-
#endif //shenzheng 2015-8-10 redis cluster
5249

5350
#define REDIS_REPLY_STRING 1
5451
#define REDIS_REPLY_ARRAY 2
@@ -59,16 +56,6 @@
5956

6057
#define REDIS_READER_MAX_BUF (1024*16) /* Default max unused reader buffer. */
6158

62-
#if 1 //shenzheng 2015-8-22 redis cluster
63-
#define REDIS_ERROR_MOVED "MOVED"
64-
#define REDIS_ERROR_ASK "ASK"
65-
#define REDIS_ERROR_TRYAGAIN "TRYAGAIN"
66-
#define REDIS_ERROR_CROSSSLOT "CROSSSLOT"
67-
#define REDIS_ERROR_CLUSTERDOWN "CLUSTERDOWN"
68-
69-
#define REDIS_STATUS_OK "OK"
70-
#endif //shenzheng 2015-9-24 redis cluster
71-
7259
#ifdef __cplusplus
7360
extern "C" {
7461
#endif
@@ -113,14 +100,9 @@ void redisReaderFree(redisReader *r);
113100
int redisReaderFeed(redisReader *r, const char *buf, size_t len);
114101
int redisReaderGetReply(redisReader *r, void **reply);
115102

116-
/* Backwards compatibility, can be removed on big version bump. */
117-
#define redisReplyReaderCreate redisReaderCreate
118-
#define redisReplyReaderFree redisReaderFree
119-
#define redisReplyReaderFeed redisReaderFeed
120-
#define redisReplyReaderGetReply redisReaderGetReply
121-
#define redisReplyReaderSetPrivdata(_r, _p) (int)(((redisReader*)(_r))->privdata = (_p))
122-
#define redisReplyReaderGetObject(_r) (((redisReader*)(_r))->reply)
123-
#define redisReplyReaderGetError(_r) (((redisReader*)(_r))->errstr)
103+
#define redisReaderSetPrivdata(_r, _p) (int)(((redisReader*)(_r))->privdata = (_p))
104+
#define redisReaderGetObject(_r) (((redisReader*)(_r))->reply)
105+
#define redisReaderGetError(_r) (((redisReader*)(_r))->errstr)
124106

125107
#ifdef __cplusplus
126108
}

0 commit comments

Comments
 (0)