opal-up 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/up_ext/App.h +665 -544
- data/ext/up_ext/AsyncSocket.h +307 -284
- data/ext/up_ext/AsyncSocketData.h +35 -51
- data/ext/up_ext/BloomFilter.h +37 -42
- data/ext/up_ext/ChunkedEncoding.h +174 -175
- data/ext/up_ext/ClientApp.h +20 -23
- data/ext/up_ext/HttpContext.h +476 -381
- data/ext/up_ext/HttpContextData.h +20 -20
- data/ext/up_ext/HttpErrors.h +14 -10
- data/ext/up_ext/HttpParser.h +631 -563
- data/ext/up_ext/HttpResponse.h +526 -460
- data/ext/up_ext/HttpResponseData.h +59 -55
- data/ext/up_ext/HttpRouter.h +328 -310
- data/ext/up_ext/Loop.h +174 -168
- data/ext/up_ext/LoopData.h +60 -67
- data/ext/up_ext/MoveOnlyFunction.h +71 -80
- data/ext/up_ext/PerMessageDeflate.h +218 -198
- data/ext/up_ext/ProxyParser.h +100 -99
- data/ext/up_ext/QueryParser.h +91 -84
- data/ext/up_ext/TopicTree.h +273 -268
- data/ext/up_ext/Utilities.h +25 -25
- data/ext/up_ext/WebSocket.h +376 -310
- data/ext/up_ext/WebSocketContext.h +487 -372
- data/ext/up_ext/WebSocketContextData.h +74 -62
- data/ext/up_ext/WebSocketData.h +53 -46
- data/ext/up_ext/WebSocketExtensions.h +194 -178
- data/ext/up_ext/WebSocketHandshake.h +115 -110
- data/ext/up_ext/WebSocketProtocol.h +441 -398
- data/ext/up_ext/up_ext.c +43 -5
- data/lib/up/ruby/cluster.rb +29 -6
- data/lib/up/version.rb +1 -1
- metadata +2 -2
@@ -18,128 +18,133 @@
|
|
18
18
|
#ifndef UWS_WEBSOCKETHANDSHAKE_H
|
19
19
|
#define UWS_WEBSOCKETHANDSHAKE_H
|
20
20
|
|
21
|
-
#include <cstdint>
|
22
21
|
#include <cstddef>
|
22
|
+
#include <cstdint>
|
23
23
|
|
24
24
|
namespace uWS {
|
25
25
|
|
26
26
|
struct WebSocketHandshake {
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
T::template f<N - 1>(a, b);
|
32
|
-
}
|
33
|
-
};
|
34
|
-
|
35
|
-
template <typename T>
|
36
|
-
struct static_for<0, T> {
|
37
|
-
void operator()(uint32_t */*a*/, uint32_t */*hash*/) {}
|
38
|
-
};
|
39
|
-
|
40
|
-
static inline uint32_t rol(uint32_t value, size_t bits) {return (value << bits) | (value >> (32 - bits));}
|
41
|
-
static inline uint32_t blk(uint32_t b[16], size_t i) {
|
42
|
-
return rol(b[(i + 13) & 15] ^ b[(i + 8) & 15] ^ b[(i + 2) & 15] ^ b[i], 1);
|
27
|
+
template <int N, typename T> struct static_for {
|
28
|
+
void operator()(uint32_t *a, uint32_t *b) {
|
29
|
+
static_for<N - 1, T>()(a, b);
|
30
|
+
T::template f<N - 1>(a, b);
|
43
31
|
}
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
b[(i + 4) % 16] = blk(b, (i + 4) % 16);
|
64
|
-
a[i % 5] += (a[(3 + i) % 5] ^ a[(2 + i) % 5] ^ a[(1 + i) % 5]) + b[(i + 4) % 16] + 0x6ed9eba1 + rol(a[(4 + i) % 5], 5);
|
65
|
-
a[(3 + i) % 5] = rol(a[(3 + i) % 5], 30);
|
66
|
-
}
|
67
|
-
};
|
68
|
-
struct Sha1Loop4 {
|
69
|
-
template <int i>
|
70
|
-
static inline void f(uint32_t *a, uint32_t *b) {
|
71
|
-
b[(i + 8) % 16] = blk(b, (i + 8) % 16);
|
72
|
-
a[i % 5] += (((a[(3 + i) % 5] | a[(2 + i) % 5]) & a[(1 + i) % 5]) | (a[(3 + i) % 5] & a[(2 + i) % 5])) + b[(i + 8) % 16] + 0x8f1bbcdc + rol(a[(4 + i) % 5], 5);
|
73
|
-
a[(3 + i) % 5] = rol(a[(3 + i) % 5], 30);
|
74
|
-
}
|
75
|
-
};
|
76
|
-
struct Sha1Loop5 {
|
77
|
-
template <int i>
|
78
|
-
static inline void f(uint32_t *a, uint32_t *b) {
|
79
|
-
b[(i + 12) % 16] = blk(b, (i + 12) % 16);
|
80
|
-
a[i % 5] += (a[(3 + i) % 5] ^ a[(2 + i) % 5] ^ a[(1 + i) % 5]) + b[(i + 12) % 16] + 0xca62c1d6 + rol(a[(4 + i) % 5], 5);
|
81
|
-
a[(3 + i) % 5] = rol(a[(3 + i) % 5], 30);
|
82
|
-
}
|
83
|
-
};
|
84
|
-
struct Sha1Loop6 {
|
85
|
-
template <int i>
|
86
|
-
static inline void f(uint32_t *a, uint32_t *b) {
|
87
|
-
b[i] += a[4 - i];
|
88
|
-
}
|
89
|
-
};
|
90
|
-
|
91
|
-
static inline void sha1(uint32_t hash[5], uint32_t b[16]) {
|
92
|
-
uint32_t a[5] = {hash[4], hash[3], hash[2], hash[1], hash[0]};
|
93
|
-
static_for<16, Sha1Loop1>()(a, b);
|
94
|
-
static_for<4, Sha1Loop2>()(a, b);
|
95
|
-
static_for<20, Sha1Loop3>()(a, b);
|
96
|
-
static_for<20, Sha1Loop4>()(a, b);
|
97
|
-
static_for<20, Sha1Loop5>()(a, b);
|
98
|
-
static_for<5, Sha1Loop6>()(a, hash);
|
32
|
+
};
|
33
|
+
|
34
|
+
template <typename T> struct static_for<0, T> {
|
35
|
+
void operator()(uint32_t * /*a*/, uint32_t * /*hash*/) {}
|
36
|
+
};
|
37
|
+
|
38
|
+
static inline uint32_t rol(uint32_t value, size_t bits) {
|
39
|
+
return (value << bits) | (value >> (32 - bits));
|
40
|
+
}
|
41
|
+
static inline uint32_t blk(uint32_t b[16], size_t i) {
|
42
|
+
return rol(b[(i + 13) & 15] ^ b[(i + 8) & 15] ^ b[(i + 2) & 15] ^ b[i], 1);
|
43
|
+
}
|
44
|
+
|
45
|
+
struct Sha1Loop1 {
|
46
|
+
template <int i> static inline void f(uint32_t *a, uint32_t *b) {
|
47
|
+
a[i % 5] += ((a[(3 + i) % 5] & (a[(2 + i) % 5] ^ a[(1 + i) % 5])) ^
|
48
|
+
a[(1 + i) % 5]) +
|
49
|
+
b[i] + 0x5a827999 + rol(a[(4 + i) % 5], 5);
|
50
|
+
a[(3 + i) % 5] = rol(a[(3 + i) % 5], 30);
|
99
51
|
}
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
52
|
+
};
|
53
|
+
struct Sha1Loop2 {
|
54
|
+
template <int i> static inline void f(uint32_t *a, uint32_t *b) {
|
55
|
+
b[i] = blk(b, i);
|
56
|
+
a[(1 + i) % 5] += ((a[(4 + i) % 5] & (a[(3 + i) % 5] ^ a[(2 + i) % 5])) ^
|
57
|
+
a[(2 + i) % 5]) +
|
58
|
+
b[i] + 0x5a827999 + rol(a[(5 + i) % 5], 5);
|
59
|
+
a[(4 + i) % 5] = rol(a[(4 + i) % 5], 30);
|
60
|
+
}
|
61
|
+
};
|
62
|
+
struct Sha1Loop3 {
|
63
|
+
template <int i> static inline void f(uint32_t *a, uint32_t *b) {
|
64
|
+
b[(i + 4) % 16] = blk(b, (i + 4) % 16);
|
65
|
+
a[i % 5] += (a[(3 + i) % 5] ^ a[(2 + i) % 5] ^ a[(1 + i) % 5]) +
|
66
|
+
b[(i + 4) % 16] + 0x6ed9eba1 + rol(a[(4 + i) % 5], 5);
|
67
|
+
a[(3 + i) % 5] = rol(a[(3 + i) % 5], 30);
|
113
68
|
}
|
69
|
+
};
|
70
|
+
struct Sha1Loop4 {
|
71
|
+
template <int i> static inline void f(uint32_t *a, uint32_t *b) {
|
72
|
+
b[(i + 8) % 16] = blk(b, (i + 8) % 16);
|
73
|
+
a[i % 5] += (((a[(3 + i) % 5] | a[(2 + i) % 5]) & a[(1 + i) % 5]) |
|
74
|
+
(a[(3 + i) % 5] & a[(2 + i) % 5])) +
|
75
|
+
b[(i + 8) % 16] + 0x8f1bbcdc + rol(a[(4 + i) % 5], 5);
|
76
|
+
a[(3 + i) % 5] = rol(a[(3 + i) % 5], 30);
|
77
|
+
}
|
78
|
+
};
|
79
|
+
struct Sha1Loop5 {
|
80
|
+
template <int i> static inline void f(uint32_t *a, uint32_t *b) {
|
81
|
+
b[(i + 12) % 16] = blk(b, (i + 12) % 16);
|
82
|
+
a[i % 5] += (a[(3 + i) % 5] ^ a[(2 + i) % 5] ^ a[(1 + i) % 5]) +
|
83
|
+
b[(i + 12) % 16] + 0xca62c1d6 + rol(a[(4 + i) % 5], 5);
|
84
|
+
a[(3 + i) % 5] = rol(a[(3 + i) % 5], 30);
|
85
|
+
}
|
86
|
+
};
|
87
|
+
struct Sha1Loop6 {
|
88
|
+
template <int i> static inline void f(uint32_t *a, uint32_t *b) {
|
89
|
+
b[i] += a[4 - i];
|
90
|
+
}
|
91
|
+
};
|
92
|
+
|
93
|
+
static inline void sha1(uint32_t hash[5], uint32_t b[16]) {
|
94
|
+
uint32_t a[5] = {hash[4], hash[3], hash[2], hash[1], hash[0]};
|
95
|
+
static_for<16, Sha1Loop1>()(a, b);
|
96
|
+
static_for<4, Sha1Loop2>()(a, b);
|
97
|
+
static_for<20, Sha1Loop3>()(a, b);
|
98
|
+
static_for<20, Sha1Loop4>()(a, b);
|
99
|
+
static_for<20, Sha1Loop5>()(a, b);
|
100
|
+
static_for<5, Sha1Loop6>()(a, hash);
|
101
|
+
}
|
102
|
+
|
103
|
+
static inline void base64(unsigned char *src, char *dst) {
|
104
|
+
const char *b64 =
|
105
|
+
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
106
|
+
for (int i = 0; i < 18; i += 3) {
|
107
|
+
*dst++ = b64[(src[i] >> 2) & 63];
|
108
|
+
*dst++ = b64[((src[i] & 3) << 4) | ((src[i + 1] & 240) >> 4)];
|
109
|
+
*dst++ = b64[((src[i + 1] & 15) << 2) | ((src[i + 2] & 192) >> 6)];
|
110
|
+
*dst++ = b64[src[i + 2] & 63];
|
111
|
+
}
|
112
|
+
*dst++ = b64[(src[18] >> 2) & 63];
|
113
|
+
*dst++ = b64[((src[18] & 3) << 4) | ((src[19] & 240) >> 4)];
|
114
|
+
*dst++ = b64[((src[19] & 15) << 2)];
|
115
|
+
*dst++ = '=';
|
116
|
+
}
|
114
117
|
|
115
118
|
public:
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
119
|
+
static inline void generate(const char input[24], char output[28]) {
|
120
|
+
uint32_t b_output[5] = {0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476,
|
121
|
+
0xc3d2e1f0};
|
122
|
+
uint32_t b_input[16] = {0, 0, 0, 0,
|
123
|
+
0, 0, 0x32353845, 0x41464135,
|
124
|
+
0x2d453931, 0x342d3437, 0x44412d39, 0x3543412d,
|
125
|
+
0x43354142, 0x30444338, 0x35423131, 0x80000000};
|
126
|
+
|
127
|
+
for (int i = 0; i < 6; i++) {
|
128
|
+
b_input[i] = (uint32_t)((input[4 * i + 3] & 0xff) |
|
129
|
+
(input[4 * i + 2] & 0xff) << 8 |
|
130
|
+
(input[4 * i + 1] & 0xff) << 16 |
|
131
|
+
(input[4 * i + 0] & 0xff) << 24);
|
132
|
+
}
|
133
|
+
sha1(b_output, b_input);
|
134
|
+
uint32_t last_b[16] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 480};
|
135
|
+
sha1(b_output, last_b);
|
136
|
+
for (int i = 0; i < 5; i++) {
|
137
|
+
uint32_t tmp = b_output[i];
|
138
|
+
char *bytes = (char *)&b_output[i];
|
139
|
+
bytes[3] = (char)(tmp & 0xff);
|
140
|
+
bytes[2] = (char)((tmp >> 8) & 0xff);
|
141
|
+
bytes[1] = (char)((tmp >> 16) & 0xff);
|
142
|
+
bytes[0] = (char)((tmp >> 24) & 0xff);
|
140
143
|
}
|
144
|
+
base64((unsigned char *)b_output, output);
|
145
|
+
}
|
141
146
|
};
|
142
147
|
|
143
|
-
}
|
148
|
+
} // namespace uWS
|
144
149
|
|
145
150
|
#endif // UWS_WEBSOCKETHANDSHAKE_H
|