nutcracker 0.2.4.12 → 0.3.0.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/Rakefile +1 -1
- data/ext/nutcracker/ChangeLog +10 -0
- data/ext/nutcracker/Makefile.am +2 -0
- data/ext/nutcracker/Makefile.in +101 -14
- data/ext/nutcracker/README.md +18 -1
- data/ext/nutcracker/config.h.in +18 -0
- data/ext/nutcracker/configure +196 -25
- data/ext/nutcracker/configure.ac +64 -6
- data/ext/nutcracker/extconf.rb +1 -1
- data/ext/nutcracker/man/nutcracker.8 +76 -0
- data/ext/nutcracker/notes/debug.txt +116 -16
- data/ext/nutcracker/notes/kqueue.pdf +0 -0
- data/ext/nutcracker/notes/recommendation.md +20 -0
- data/ext/nutcracker/notes/redis.md +2 -2
- data/ext/nutcracker/scripts/nutcracker.spec +1 -1
- data/ext/nutcracker/scripts/redis-check.sh +3 -1
- data/ext/nutcracker/src/Makefile.am +15 -6
- data/ext/nutcracker/src/Makefile.in +39 -36
- data/ext/nutcracker/src/event/Makefile.am +16 -0
- data/ext/nutcracker/src/event/Makefile.in +492 -0
- data/ext/nutcracker/src/event/nc_epoll.c +344 -0
- data/ext/nutcracker/src/event/nc_event.h +88 -0
- data/ext/nutcracker/src/event/nc_evport.c +420 -0
- data/ext/nutcracker/src/event/nc_kqueue.c +412 -0
- data/ext/nutcracker/src/hashkit/nc_crc32.c +19 -1
- data/ext/nutcracker/src/hashkit/nc_hashkit.h +3 -1
- data/ext/nutcracker/src/hashkit/nc_md5.c +257 -315
- data/ext/nutcracker/src/nc.c +12 -1
- data/ext/nutcracker/src/nc_connection.c +18 -1
- data/ext/nutcracker/src/nc_connection.h +1 -0
- data/ext/nutcracker/src/nc_core.c +22 -30
- data/ext/nutcracker/src/nc_core.h +22 -7
- data/ext/nutcracker/src/nc_proxy.c +8 -9
- data/ext/nutcracker/src/nc_queue.h +2 -0
- data/ext/nutcracker/src/nc_request.c +3 -4
- data/ext/nutcracker/src/nc_response.c +25 -8
- data/ext/nutcracker/src/nc_server.c +8 -6
- data/ext/nutcracker/src/nc_stats.c +46 -43
- data/ext/nutcracker/src/nc_stats.h +37 -30
- data/ext/nutcracker/src/nc_util.c +6 -1
- data/ext/nutcracker/src/proto/nc_redis.c +19 -5
- data/lib/nutcracker/version.rb +1 -1
- data/lib/nutcracker.rb +1 -1
- metadata +10 -4
- data/ext/nutcracker/src/nc_event.c +0 -214
- data/ext/nutcracker/src/nc_event.h +0 -39
@@ -15,365 +15,307 @@
|
|
15
15
|
* limitations under the License.
|
16
16
|
*/
|
17
17
|
|
18
|
+
#include <nc_core.h>
|
19
|
+
|
18
20
|
/*
|
19
|
-
* This
|
20
|
-
*
|
21
|
-
*
|
22
|
-
* See below for original Copyright.
|
23
|
-
*/
|
24
|
-
/* MD5C.C - RSA Data Security, Inc., MD5 message-digest algorithm
|
25
|
-
*
|
26
|
-
* Copyright (C) 1991-2, RSA Data Security, Inc. Created 1991. All
|
27
|
-
* rights reserved.
|
21
|
+
* This is an OpenSSL-compatible implementation of the RSA Data Security, Inc.
|
22
|
+
* MD5 Message-Digest Algorithm (RFC 1321).
|
28
23
|
*
|
29
|
-
*
|
30
|
-
* is identified as the "RSA Data Security, Inc. MD5 Message-Digest
|
31
|
-
* Algorithm" in all material mentioning or referencing this software
|
32
|
-
* or this function.
|
24
|
+
* Homepage: http://openwall.info/wiki/people/solar/software/public-domain-source-code/md5
|
33
25
|
*
|
34
|
-
*
|
35
|
-
* that such works are identified as "derived from the RSA Data
|
36
|
-
* Security, Inc. MD5 Message-Digest Algorithm" in all material
|
37
|
-
* mentioning or referencing the derived work.
|
38
|
-
*
|
39
|
-
* RSA Data Security, Inc. makes no representations concerning either
|
40
|
-
* the merchantability of this software or the suitability of this
|
41
|
-
* software for any particular purpose. It is provided "as is"
|
42
|
-
* without express or implied warranty of any kind.
|
43
|
-
*
|
44
|
-
* These notices must be retained in any copies of any part of this
|
45
|
-
* documentation and/or software.
|
26
|
+
* Author: Alexander Peslyak, better known as Solar Designer <solar at openwall.com>
|
46
27
|
*/
|
47
28
|
|
48
|
-
#include <
|
49
|
-
|
50
|
-
/* POINTER defines a generic pointer type */
|
51
|
-
typedef unsigned char *POINTER;
|
52
|
-
|
29
|
+
#include <string.h>
|
53
30
|
|
54
|
-
|
55
|
-
typedef unsigned int UINT4;
|
31
|
+
typedef unsigned int MD5_u32plus;
|
56
32
|
|
57
|
-
|
58
|
-
/* MD5 context. */
|
59
33
|
typedef struct {
|
60
|
-
|
61
|
-
|
62
|
-
|
34
|
+
MD5_u32plus lo, hi;
|
35
|
+
MD5_u32plus a, b, c, d;
|
36
|
+
unsigned char buffer[64];
|
37
|
+
MD5_u32plus block[16];
|
63
38
|
} MD5_CTX;
|
64
39
|
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
/* Constants for MD5Transform routine. */
|
73
|
-
|
74
|
-
#define S11 7
|
75
|
-
#define S12 12
|
76
|
-
#define S13 17
|
77
|
-
#define S14 22
|
78
|
-
#define S21 5
|
79
|
-
#define S22 9
|
80
|
-
#define S23 14
|
81
|
-
#define S24 20
|
82
|
-
#define S31 4
|
83
|
-
#define S32 11
|
84
|
-
#define S33 16
|
85
|
-
#define S34 23
|
86
|
-
#define S41 6
|
87
|
-
#define S42 10
|
88
|
-
#define S43 15
|
89
|
-
#define S44 21
|
90
|
-
|
91
|
-
|
92
|
-
static void MD5Transform (UINT4 state[4],
|
93
|
-
unsigned char block[64]);
|
94
|
-
static void Encode (unsigned char *output,
|
95
|
-
UINT4 *input,
|
96
|
-
unsigned int len);
|
97
|
-
static void Decode(UINT4 *output, unsigned char *input, unsigned int len);
|
98
|
-
|
99
|
-
static unsigned char PADDING[64] = {
|
100
|
-
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
101
|
-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
102
|
-
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
103
|
-
};
|
104
|
-
|
105
|
-
/* F, G, H and I are basic MD5 functions.
|
40
|
+
/*
|
41
|
+
* The basic MD5 functions.
|
42
|
+
*
|
43
|
+
* F and G are optimized compared to their RFC 1321 definitions for
|
44
|
+
* architectures that lack an AND-NOT instruction, just like in Colin Plumb's
|
45
|
+
* implementation.
|
106
46
|
*/
|
107
|
-
#define F(x, y, z)
|
108
|
-
#define G(x, y, z)
|
109
|
-
#define H(x, y, z)
|
110
|
-
#define I(x, y, z)
|
47
|
+
#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z))))
|
48
|
+
#define G(x, y, z) ((y) ^ ((z) & ((x) ^ (y))))
|
49
|
+
#define H(x, y, z) ((x) ^ (y) ^ (z))
|
50
|
+
#define I(x, y, z) ((y) ^ ((x) | ~(z)))
|
111
51
|
|
112
|
-
/*
|
52
|
+
/*
|
53
|
+
* The MD5 transformation for all four rounds.
|
113
54
|
*/
|
114
|
-
#define
|
55
|
+
#define STEP(f, a, b, c, d, x, t, s) \
|
56
|
+
(a) += f((b), (c), (d)) + (x) + (t); \
|
57
|
+
(a) = (((a) << (s)) | (((a) & 0xffffffff) >> (32 - (s)))); \
|
58
|
+
(a) += (b);
|
115
59
|
|
116
|
-
/*
|
117
|
-
|
60
|
+
/*
|
61
|
+
* SET reads 4 input bytes in little-endian byte order and stores them
|
62
|
+
* in a properly aligned word in host byte order.
|
63
|
+
*
|
64
|
+
* The check for little-endian architectures that tolerate unaligned
|
65
|
+
* memory accesses is just an optimization. Nothing will break if it
|
66
|
+
* doesn't work.
|
118
67
|
*/
|
119
|
-
#
|
120
|
-
(
|
121
|
-
(
|
122
|
-
(
|
123
|
-
|
124
|
-
#
|
125
|
-
(
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
(
|
132
|
-
|
133
|
-
|
134
|
-
#define II(a, b, c, d, x, s, ac) { \
|
135
|
-
(a) += I ((b), (c), (d)) + (x) + (UINT4)(ac); \
|
136
|
-
(a) = ROTATE_LEFT ((a), (s)); \
|
137
|
-
(a) += (b); \
|
138
|
-
}
|
139
|
-
|
140
|
-
|
141
|
-
/*
|
142
|
-
Just a simple method for getting the signature
|
143
|
-
result must be == 16
|
144
|
-
*/
|
145
|
-
void md5_signature(const unsigned char *key, unsigned int length, unsigned char *result)
|
146
|
-
{
|
147
|
-
MD5_CTX my_md5;
|
148
|
-
|
149
|
-
MD5Init(&my_md5);
|
150
|
-
(void)MD5Update(&my_md5, key, length);
|
151
|
-
MD5Final(result, &my_md5);
|
152
|
-
}
|
68
|
+
#if defined(__i386__) || defined(__x86_64__) || defined(__vax__)
|
69
|
+
#define SET(n) \
|
70
|
+
(*(MD5_u32plus *)&ptr[(n) * 4])
|
71
|
+
#define GET(n) \
|
72
|
+
SET(n)
|
73
|
+
#else
|
74
|
+
#define SET(n) \
|
75
|
+
(ctx->block[(n)] = \
|
76
|
+
(MD5_u32plus)ptr[(n) * 4] | \
|
77
|
+
((MD5_u32plus)ptr[(n) * 4 + 1] << 8) | \
|
78
|
+
((MD5_u32plus)ptr[(n) * 4 + 2] << 16) | \
|
79
|
+
((MD5_u32plus)ptr[(n) * 4 + 3] << 24))
|
80
|
+
#define GET(n) \
|
81
|
+
(ctx->block[(n)])
|
82
|
+
#endif
|
153
83
|
|
154
|
-
/*
|
84
|
+
/*
|
85
|
+
* This processes one or more 64-byte data blocks, but does NOT update
|
86
|
+
* the bit counters. There are no alignment requirements.
|
155
87
|
*/
|
156
|
-
static void
|
88
|
+
static void *
|
89
|
+
body(MD5_CTX *ctx, void *data, unsigned long size)
|
157
90
|
{
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
91
|
+
unsigned char *ptr;
|
92
|
+
MD5_u32plus a, b, c, d;
|
93
|
+
MD5_u32plus saved_a, saved_b, saved_c, saved_d;
|
94
|
+
|
95
|
+
ptr = data;
|
96
|
+
|
97
|
+
a = ctx->a;
|
98
|
+
b = ctx->b;
|
99
|
+
c = ctx->c;
|
100
|
+
d = ctx->d;
|
101
|
+
|
102
|
+
do {
|
103
|
+
saved_a = a;
|
104
|
+
saved_b = b;
|
105
|
+
saved_c = c;
|
106
|
+
saved_d = d;
|
107
|
+
|
108
|
+
/* Round 1 */
|
109
|
+
STEP(F, a, b, c, d, SET(0), 0xd76aa478, 7)
|
110
|
+
STEP(F, d, a, b, c, SET(1), 0xe8c7b756, 12)
|
111
|
+
STEP(F, c, d, a, b, SET(2), 0x242070db, 17)
|
112
|
+
STEP(F, b, c, d, a, SET(3), 0xc1bdceee, 22)
|
113
|
+
STEP(F, a, b, c, d, SET(4), 0xf57c0faf, 7)
|
114
|
+
STEP(F, d, a, b, c, SET(5), 0x4787c62a, 12)
|
115
|
+
STEP(F, c, d, a, b, SET(6), 0xa8304613, 17)
|
116
|
+
STEP(F, b, c, d, a, SET(7), 0xfd469501, 22)
|
117
|
+
STEP(F, a, b, c, d, SET(8), 0x698098d8, 7)
|
118
|
+
STEP(F, d, a, b, c, SET(9), 0x8b44f7af, 12)
|
119
|
+
STEP(F, c, d, a, b, SET(10), 0xffff5bb1, 17)
|
120
|
+
STEP(F, b, c, d, a, SET(11), 0x895cd7be, 22)
|
121
|
+
STEP(F, a, b, c, d, SET(12), 0x6b901122, 7)
|
122
|
+
STEP(F, d, a, b, c, SET(13), 0xfd987193, 12)
|
123
|
+
STEP(F, c, d, a, b, SET(14), 0xa679438e, 17)
|
124
|
+
STEP(F, b, c, d, a, SET(15), 0x49b40821, 22)
|
125
|
+
|
126
|
+
/* Round 2 */
|
127
|
+
STEP(G, a, b, c, d, GET(1), 0xf61e2562, 5)
|
128
|
+
STEP(G, d, a, b, c, GET(6), 0xc040b340, 9)
|
129
|
+
STEP(G, c, d, a, b, GET(11), 0x265e5a51, 14)
|
130
|
+
STEP(G, b, c, d, a, GET(0), 0xe9b6c7aa, 20)
|
131
|
+
STEP(G, a, b, c, d, GET(5), 0xd62f105d, 5)
|
132
|
+
STEP(G, d, a, b, c, GET(10), 0x02441453, 9)
|
133
|
+
STEP(G, c, d, a, b, GET(15), 0xd8a1e681, 14)
|
134
|
+
STEP(G, b, c, d, a, GET(4), 0xe7d3fbc8, 20)
|
135
|
+
STEP(G, a, b, c, d, GET(9), 0x21e1cde6, 5)
|
136
|
+
STEP(G, d, a, b, c, GET(14), 0xc33707d6, 9)
|
137
|
+
STEP(G, c, d, a, b, GET(3), 0xf4d50d87, 14)
|
138
|
+
STEP(G, b, c, d, a, GET(8), 0x455a14ed, 20)
|
139
|
+
STEP(G, a, b, c, d, GET(13), 0xa9e3e905, 5)
|
140
|
+
STEP(G, d, a, b, c, GET(2), 0xfcefa3f8, 9)
|
141
|
+
STEP(G, c, d, a, b, GET(7), 0x676f02d9, 14)
|
142
|
+
STEP(G, b, c, d, a, GET(12), 0x8d2a4c8a, 20)
|
143
|
+
|
144
|
+
/* Round 3 */
|
145
|
+
STEP(H, a, b, c, d, GET(5), 0xfffa3942, 4)
|
146
|
+
STEP(H, d, a, b, c, GET(8), 0x8771f681, 11)
|
147
|
+
STEP(H, c, d, a, b, GET(11), 0x6d9d6122, 16)
|
148
|
+
STEP(H, b, c, d, a, GET(14), 0xfde5380c, 23)
|
149
|
+
STEP(H, a, b, c, d, GET(1), 0xa4beea44, 4)
|
150
|
+
STEP(H, d, a, b, c, GET(4), 0x4bdecfa9, 11)
|
151
|
+
STEP(H, c, d, a, b, GET(7), 0xf6bb4b60, 16)
|
152
|
+
STEP(H, b, c, d, a, GET(10), 0xbebfbc70, 23)
|
153
|
+
STEP(H, a, b, c, d, GET(13), 0x289b7ec6, 4)
|
154
|
+
STEP(H, d, a, b, c, GET(0), 0xeaa127fa, 11)
|
155
|
+
STEP(H, c, d, a, b, GET(3), 0xd4ef3085, 16)
|
156
|
+
STEP(H, b, c, d, a, GET(6), 0x04881d05, 23)
|
157
|
+
STEP(H, a, b, c, d, GET(9), 0xd9d4d039, 4)
|
158
|
+
STEP(H, d, a, b, c, GET(12), 0xe6db99e5, 11)
|
159
|
+
STEP(H, c, d, a, b, GET(15), 0x1fa27cf8, 16)
|
160
|
+
STEP(H, b, c, d, a, GET(2), 0xc4ac5665, 23)
|
161
|
+
|
162
|
+
/* Round 4 */
|
163
|
+
STEP(I, a, b, c, d, GET(0), 0xf4292244, 6)
|
164
|
+
STEP(I, d, a, b, c, GET(7), 0x432aff97, 10)
|
165
|
+
STEP(I, c, d, a, b, GET(14), 0xab9423a7, 15)
|
166
|
+
STEP(I, b, c, d, a, GET(5), 0xfc93a039, 21)
|
167
|
+
STEP(I, a, b, c, d, GET(12), 0x655b59c3, 6)
|
168
|
+
STEP(I, d, a, b, c, GET(3), 0x8f0ccc92, 10)
|
169
|
+
STEP(I, c, d, a, b, GET(10), 0xffeff47d, 15)
|
170
|
+
STEP(I, b, c, d, a, GET(1), 0x85845dd1, 21)
|
171
|
+
STEP(I, a, b, c, d, GET(8), 0x6fa87e4f, 6)
|
172
|
+
STEP(I, d, a, b, c, GET(15), 0xfe2ce6e0, 10)
|
173
|
+
STEP(I, c, d, a, b, GET(6), 0xa3014314, 15)
|
174
|
+
STEP(I, b, c, d, a, GET(13), 0x4e0811a1, 21)
|
175
|
+
STEP(I, a, b, c, d, GET(4), 0xf7537e82, 6)
|
176
|
+
STEP(I, d, a, b, c, GET(11), 0xbd3af235, 10)
|
177
|
+
STEP(I, c, d, a, b, GET(2), 0x2ad7d2bb, 15)
|
178
|
+
STEP(I, b, c, d, a, GET(9), 0xeb86d391, 21)
|
179
|
+
|
180
|
+
a += saved_a;
|
181
|
+
b += saved_b;
|
182
|
+
c += saved_c;
|
183
|
+
d += saved_d;
|
184
|
+
|
185
|
+
ptr += 64;
|
186
|
+
} while (size -= 64);
|
187
|
+
|
188
|
+
ctx->a = a;
|
189
|
+
ctx->b = b;
|
190
|
+
ctx->c = c;
|
191
|
+
ctx->d = d;
|
192
|
+
|
193
|
+
return ptr;
|
165
194
|
}
|
166
195
|
|
167
|
-
|
168
|
-
|
169
|
-
context.
|
170
|
-
*/
|
171
|
-
|
172
|
-
static void MD5Update (
|
173
|
-
MD5_CTX *context, /* context */
|
174
|
-
const unsigned char *input, /* input block */
|
175
|
-
unsigned int inputLen) /* length of input block */
|
196
|
+
void
|
197
|
+
MD5_Init(MD5_CTX *ctx)
|
176
198
|
{
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
/* Update number of bits */
|
184
|
-
if ((context->count[0] += ((UINT4)inputLen << 3))
|
185
|
-
< ((UINT4)inputLen << 3))
|
186
|
-
context->count[1]++;
|
187
|
-
context->count[1] += ((UINT4)inputLen >> 29);
|
188
|
-
|
189
|
-
partLen = 64 - idx;
|
190
|
-
|
191
|
-
/* Transform as many times as possible.
|
192
|
-
*/
|
193
|
-
if (inputLen >= partLen) {
|
194
|
-
memcpy((POINTER)&context->buffer[idx], (POINTER)input, partLen);
|
195
|
-
MD5Transform(context->state, context->buffer);
|
196
|
-
|
197
|
-
for (i = partLen; i + 63 < inputLen; i += 64)
|
198
|
-
MD5Transform (context->state, (unsigned char *)&input[i]);
|
199
|
-
|
200
|
-
idx = 0;
|
201
|
-
}
|
202
|
-
else
|
203
|
-
i = 0;
|
199
|
+
ctx->a = 0x67452301;
|
200
|
+
ctx->b = 0xefcdab89;
|
201
|
+
ctx->c = 0x98badcfe;
|
202
|
+
ctx->d = 0x10325476;
|
204
203
|
|
205
|
-
|
206
|
-
|
207
|
-
inputLen-i);
|
204
|
+
ctx->lo = 0;
|
205
|
+
ctx->hi = 0;
|
208
206
|
}
|
209
207
|
|
210
|
-
|
211
|
-
|
212
|
-
*/
|
213
|
-
|
214
|
-
static void MD5Final (
|
215
|
-
unsigned char digest[16], /* message digest */
|
216
|
-
MD5_CTX *context) /* context */
|
208
|
+
void
|
209
|
+
MD5_Update(MD5_CTX *ctx, void *data, unsigned long size)
|
217
210
|
{
|
218
|
-
|
219
|
-
|
211
|
+
MD5_u32plus saved_lo;
|
212
|
+
unsigned long used, free;
|
220
213
|
|
221
|
-
|
222
|
-
|
214
|
+
saved_lo = ctx->lo;
|
215
|
+
if ((ctx->lo = (saved_lo + size) & 0x1fffffff) < saved_lo) {
|
216
|
+
ctx->hi++;
|
217
|
+
}
|
218
|
+
ctx->hi += size >> 29;
|
223
219
|
|
224
|
-
|
225
|
-
*/
|
226
|
-
idx = (unsigned int)((context->count[0] >> 3) & 0x3f);
|
227
|
-
padLen = (idx < 56) ? (56 - idx) : (120 - idx);
|
228
|
-
MD5Update (context, PADDING, padLen);
|
220
|
+
used = saved_lo & 0x3f;
|
229
221
|
|
230
|
-
|
231
|
-
|
222
|
+
if (used) {
|
223
|
+
free = 64 - used;
|
232
224
|
|
233
|
-
|
234
|
-
|
225
|
+
if (size < free) {
|
226
|
+
memcpy(&ctx->buffer[used], data, size);
|
227
|
+
return;
|
228
|
+
}
|
235
229
|
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
230
|
+
memcpy(&ctx->buffer[used], data, free);
|
231
|
+
data = (unsigned char *)data + free;
|
232
|
+
size -= free;
|
233
|
+
body(ctx, ctx->buffer, 64);
|
234
|
+
}
|
240
235
|
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
UINT4 a = state[0], b = state[1], c = state[2], d = state[3], x[16];
|
248
|
-
|
249
|
-
Decode (x, block, 64);
|
250
|
-
|
251
|
-
/* Round 1 */
|
252
|
-
FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
|
253
|
-
FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
|
254
|
-
FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
|
255
|
-
FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
|
256
|
-
FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
|
257
|
-
FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
|
258
|
-
FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
|
259
|
-
FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
|
260
|
-
FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
|
261
|
-
FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
|
262
|
-
FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
|
263
|
-
FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
|
264
|
-
FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
|
265
|
-
FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
|
266
|
-
FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
|
267
|
-
FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
|
268
|
-
|
269
|
-
/* Round 2 */
|
270
|
-
GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
|
271
|
-
GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
|
272
|
-
GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
|
273
|
-
GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
|
274
|
-
GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
|
275
|
-
GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
|
276
|
-
GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
|
277
|
-
GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
|
278
|
-
GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
|
279
|
-
GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
|
280
|
-
GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
|
281
|
-
GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
|
282
|
-
GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
|
283
|
-
GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
|
284
|
-
GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
|
285
|
-
GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
|
286
|
-
|
287
|
-
/* Round 3 */
|
288
|
-
HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
|
289
|
-
HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
|
290
|
-
HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
|
291
|
-
HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
|
292
|
-
HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
|
293
|
-
HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
|
294
|
-
HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
|
295
|
-
HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
|
296
|
-
HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
|
297
|
-
HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
|
298
|
-
HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
|
299
|
-
HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
|
300
|
-
HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
|
301
|
-
HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
|
302
|
-
HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
|
303
|
-
HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
|
304
|
-
|
305
|
-
/* Round 4 */
|
306
|
-
II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
|
307
|
-
II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
|
308
|
-
II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
|
309
|
-
II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
|
310
|
-
II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
|
311
|
-
II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
|
312
|
-
II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
|
313
|
-
II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
|
314
|
-
II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
|
315
|
-
II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
|
316
|
-
II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
|
317
|
-
II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
|
318
|
-
II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
|
319
|
-
II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
|
320
|
-
II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
|
321
|
-
II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
|
322
|
-
|
323
|
-
|
324
|
-
state[0] += a;
|
325
|
-
state[1] += b;
|
326
|
-
state[2] += c;
|
327
|
-
state[3] += d;
|
328
|
-
|
329
|
-
/* Zeroize sensitive information.
|
330
|
-
*/
|
331
|
-
memset((POINTER)x, 0, sizeof (x));
|
236
|
+
if (size >= 64) {
|
237
|
+
data = body(ctx, data, size & ~(unsigned long)0x3f);
|
238
|
+
size &= 0x3f;
|
239
|
+
}
|
240
|
+
|
241
|
+
memcpy(ctx->buffer, data, size);
|
332
242
|
}
|
333
243
|
|
334
|
-
|
335
|
-
|
336
|
-
*/
|
337
|
-
static void Encode (
|
338
|
-
unsigned char *output,
|
339
|
-
UINT4 *input,
|
340
|
-
unsigned int len)
|
244
|
+
void
|
245
|
+
MD5_Final(unsigned char *result, MD5_CTX *ctx)
|
341
246
|
{
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
247
|
+
unsigned long used, free;
|
248
|
+
|
249
|
+
used = ctx->lo & 0x3f;
|
250
|
+
|
251
|
+
ctx->buffer[used++] = 0x80;
|
252
|
+
|
253
|
+
free = 64 - used;
|
254
|
+
|
255
|
+
if (free < 8) {
|
256
|
+
memset(&ctx->buffer[used], 0, free);
|
257
|
+
body(ctx, ctx->buffer, 64);
|
258
|
+
used = 0;
|
259
|
+
free = 64;
|
260
|
+
}
|
261
|
+
|
262
|
+
memset(&ctx->buffer[used], 0, free - 8);
|
263
|
+
|
264
|
+
ctx->lo <<= 3;
|
265
|
+
ctx->buffer[56] = ctx->lo;
|
266
|
+
ctx->buffer[57] = ctx->lo >> 8;
|
267
|
+
ctx->buffer[58] = ctx->lo >> 16;
|
268
|
+
ctx->buffer[59] = ctx->lo >> 24;
|
269
|
+
ctx->buffer[60] = ctx->hi;
|
270
|
+
ctx->buffer[61] = ctx->hi >> 8;
|
271
|
+
ctx->buffer[62] = ctx->hi >> 16;
|
272
|
+
ctx->buffer[63] = ctx->hi >> 24;
|
273
|
+
|
274
|
+
body(ctx, ctx->buffer, 64);
|
275
|
+
|
276
|
+
result[0] = ctx->a;
|
277
|
+
result[1] = ctx->a >> 8;
|
278
|
+
result[2] = ctx->a >> 16;
|
279
|
+
result[3] = ctx->a >> 24;
|
280
|
+
result[4] = ctx->b;
|
281
|
+
result[5] = ctx->b >> 8;
|
282
|
+
result[6] = ctx->b >> 16;
|
283
|
+
result[7] = ctx->b >> 24;
|
284
|
+
result[8] = ctx->c;
|
285
|
+
result[9] = ctx->c >> 8;
|
286
|
+
result[10] = ctx->c >> 16;
|
287
|
+
result[11] = ctx->c >> 24;
|
288
|
+
result[12] = ctx->d;
|
289
|
+
result[13] = ctx->d >> 8;
|
290
|
+
result[14] = ctx->d >> 16;
|
291
|
+
result[15] = ctx->d >> 24;
|
292
|
+
|
293
|
+
memset(ctx, 0, sizeof(*ctx));
|
350
294
|
}
|
351
295
|
|
352
|
-
|
353
|
-
|
354
|
-
|
296
|
+
/*
|
297
|
+
* Just a simple method for getting the signature
|
298
|
+
* result must be == 16
|
355
299
|
*/
|
356
|
-
|
357
|
-
|
358
|
-
unsigned char *input,
|
359
|
-
unsigned int len)
|
300
|
+
void
|
301
|
+
md5_signature(unsigned char *key, unsigned long length, unsigned char *result)
|
360
302
|
{
|
361
|
-
|
303
|
+
MD5_CTX my_md5;
|
362
304
|
|
363
|
-
|
364
|
-
|
365
|
-
|
305
|
+
MD5_Init(&my_md5);
|
306
|
+
(void)MD5_Update(&my_md5, key, length);
|
307
|
+
MD5_Final(result, &my_md5);
|
366
308
|
}
|
367
309
|
|
368
310
|
uint32_t
|
369
311
|
hash_md5(const char *key, size_t key_length)
|
370
312
|
{
|
371
|
-
|
313
|
+
unsigned char results[16];
|
372
314
|
|
373
|
-
|
315
|
+
md5_signature((unsigned char*)key, (unsigned long)key_length, results);
|
374
316
|
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
317
|
+
return ((uint32_t) (results[3] & 0xFF) << 24) |
|
318
|
+
((uint32_t) (results[2] & 0xFF) << 16) |
|
319
|
+
((uint32_t) (results[1] & 0xFF) << 8) |
|
320
|
+
(results[0] & 0xFF);
|
379
321
|
}
|
data/ext/nutcracker/src/nc.c
CHANGED
@@ -22,6 +22,7 @@
|
|
22
22
|
#include <getopt.h>
|
23
23
|
#include <fcntl.h>
|
24
24
|
#include <sys/stat.h>
|
25
|
+
#include <sys/utsname.h>
|
25
26
|
|
26
27
|
#include <nc_core.h>
|
27
28
|
#include <nc_conf.h>
|
@@ -174,7 +175,17 @@ nc_daemonize(int dump_core)
|
|
174
175
|
static void
|
175
176
|
nc_print_run(struct instance *nci)
|
176
177
|
{
|
177
|
-
|
178
|
+
int status;
|
179
|
+
struct utsname name;
|
180
|
+
|
181
|
+
status = uname(&name);
|
182
|
+
if (status < 0) {
|
183
|
+
loga("nutcracker-%s started on pid %d", NC_VERSION_STRING, nci->pid);
|
184
|
+
} else {
|
185
|
+
loga("nutcracker-%s built for %s %s %s started on pid %d",
|
186
|
+
NC_VERSION_STRING, name.sysname, name.release, name.machine,
|
187
|
+
nci->pid);
|
188
|
+
}
|
178
189
|
|
179
190
|
loga("run, rabbit run / dig that hole, forget the sun / "
|
180
191
|
"and when at last the work is done / don't sit down / "
|
@@ -79,12 +79,29 @@
|
|
79
79
|
* out_q ensures that we always send back the response of request at the head
|
80
80
|
* of the queue, before sending out responses of other completed requests in
|
81
81
|
* the queue.
|
82
|
-
*
|
83
82
|
*/
|
84
83
|
|
85
84
|
static uint32_t nfree_connq; /* # free conn q */
|
86
85
|
static struct conn_tqh free_connq; /* free conn q */
|
87
86
|
|
87
|
+
/*
|
88
|
+
* Return the context associated with this connection.
|
89
|
+
*/
|
90
|
+
struct context *
|
91
|
+
conn_to_ctx(struct conn *conn)
|
92
|
+
{
|
93
|
+
struct server_pool *pool;
|
94
|
+
|
95
|
+
if (conn->proxy || conn->client) {
|
96
|
+
pool = conn->owner;
|
97
|
+
} else {
|
98
|
+
struct server *server = conn->owner;
|
99
|
+
pool = server->owner;
|
100
|
+
}
|
101
|
+
|
102
|
+
return pool->ctx;
|
103
|
+
}
|
104
|
+
|
88
105
|
static struct conn *
|
89
106
|
_conn_get(void)
|
90
107
|
{
|