mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2025-06-25 02:29:25 +00:00
Compare commits
3476 Commits
1.1.12
...
hello-encr
Author | SHA1 | Date | |
---|---|---|---|
74404f56ee | |||
e53abe8bde | |||
29ef10e759 | |||
1e679cc94d | |||
96ba1079b2 | |||
f190df8621 | |||
6b078ee935 | |||
3de5cbd105 | |||
6faee38395 | |||
a44fd40889 | |||
5b7e1ceb68 | |||
307befa892 | |||
7647c8e8d1 | |||
b2d71f900a | |||
9e4ce68444 | |||
4920b68d2c | |||
5ce3d1e7a1 | |||
a0acc82e99 | |||
98e532de20 | |||
e1ee3eb494 | |||
4a485df0c7 | |||
2522d29fdc | |||
560d6fba1b | |||
223ec0c59d | |||
6bc785e771 | |||
fb8cbb69aa | |||
861147b845 | |||
763caaebab | |||
276259394a | |||
46c0d1a732 | |||
31d2dcec17 | |||
c9234ee027 | |||
9a8d715666 | |||
8d474e1395 | |||
52e3d9b804 | |||
8f5cc4ed33 | |||
059d05f41f | |||
c86b91c5f0 | |||
e42848d37d | |||
bf7dddbd84 | |||
95983ba168 | |||
c97943d69d | |||
b813ea70a5 | |||
e734019216 | |||
b7d9290de9 | |||
b1a30ae4ff | |||
8283a6d6d4 | |||
36adae3d82 | |||
f176e2539e | |||
d6bfb8889a | |||
24fb1ced3c | |||
82b8a4f584 | |||
979bca57d5 | |||
93fd93da5c | |||
508527f7cd | |||
64634c916c | |||
34cc26176c | |||
e2840b0eb8 | |||
f4edb092b7 | |||
8caede300c | |||
f9c6ee0181 | |||
f5cc7746b6 | |||
41a4690372 | |||
9d57ccd7b1 | |||
ad60d708e1 | |||
f79af92599 | |||
2f3ea8882b | |||
e32fecd16d | |||
dca77cb0d2 | |||
9ec6c2901c | |||
e915d10953 | |||
ddb2759a52 | |||
28cf1423c9 | |||
0fb9d43998 | |||
91e7ce87f0 | |||
e59790b401 | |||
d0b8f76ecb | |||
fe05372c67 | |||
4394ab58d7 | |||
fcaf008beb | |||
1e15a510fd | |||
9de2b90528 | |||
a71e0bf551 | |||
280cc77e23 | |||
a681fbf533 | |||
448df73a35 | |||
1982071d46 | |||
4dfb15e37c | |||
154b72b4f1 | |||
de4ee08ad4 | |||
5ae862ff54 | |||
859031dcd9 | |||
39e1aabd2a | |||
9f499827af | |||
9bde5b9065 | |||
acaebbd75e | |||
3ed6379c4c | |||
b4eb39fb16 | |||
6be0e67a5c | |||
abad7d8fe1 | |||
72cf3f2315 | |||
c02ea1bf60 | |||
b9d0cf9c89 | |||
80cfc2bd26 | |||
08d85d4ae1 | |||
43b141547e | |||
d658c1187c | |||
1f4c00c7b5 | |||
bbe97dd080 | |||
9724e04e6e | |||
364ac499eb | |||
8b15fa2422 | |||
41cb6fb0d5 | |||
5d8bd674cd | |||
2e6cda38f6 | |||
6e8fcce777 | |||
559e8a907b | |||
024649c175 | |||
7fb3711ed6 | |||
1dff0c6b5f | |||
768c6242cd | |||
bca650e1fc | |||
0bf67bf67c | |||
99ef1e2696 | |||
57b6b790c1 | |||
3593a2d49f | |||
dad33c9bde | |||
683d332abc | |||
ac6d532651 | |||
d1a306a021 | |||
4cd1dcfee1 | |||
3ab31545f4 | |||
197bbbb267 | |||
58adecc3a1 | |||
830d96d2ed | |||
f027d8f519 | |||
8b44ac984c | |||
5542dbcc0b | |||
0ca8ae7970 | |||
0b83f850e4 | |||
06399c86f6 | |||
663ed73768 | |||
d37dce508a | |||
2e882b4af2 | |||
1aa31e0414 | |||
a477688e51 | |||
5533b82450 | |||
1bd2fecbf6 | |||
8b5ac93388 | |||
2fd50b104c | |||
0088cef2fc | |||
85cab3d0f1 | |||
f89cde8186 | |||
e171384c19 | |||
c89683fb0f | |||
e7ed1e4f93 | |||
c6d5dc1534 | |||
9ae8b0b3b6 | |||
327eb9013b | |||
42f290b037 | |||
b7fb4eeda5 | |||
f03aae7a34 | |||
78eb35010f | |||
fd9afdce34 | |||
21e4e2924e | |||
e3d1565261 | |||
557b92a167 | |||
e299eea2b1 | |||
e1f1d05e08 | |||
125257f264 | |||
2d49931300 | |||
8426677c55 | |||
d322f332e8 | |||
f8359f554b | |||
60fb8c941a | |||
cb6a99408c | |||
d865c42ef8 | |||
69c590ff81 | |||
72533cbd13 | |||
c974a159af | |||
54efb62731 | |||
464bca5d20 | |||
7637ef10d7 | |||
0e5651f353 | |||
ffb63f3ee5 | |||
0859a0d1e5 | |||
e41a6f2ec4 | |||
c53c6bd9c3 | |||
707d7deed2 | |||
ed0a388bcd | |||
826a1ee346 | |||
d4e63fcdfe | |||
0806b881ea | |||
5becb41bd4 | |||
ead68038a3 | |||
b8b5d0bff8 | |||
e18172d434 | |||
a15883d49b | |||
714ef59814 | |||
1d095e81d9 | |||
d976a9f5a0 | |||
f2060e0c76 | |||
b81ad9a84d | |||
53bc05fe89 | |||
a6d5c452d5 | |||
515fdc22a5 | |||
424e276150 | |||
b071d6bbec | |||
27a9cc6254 | |||
bb9ad5e41a | |||
d91f80464d | |||
d826ddb294 | |||
a7600c8072 | |||
82a9122fc3 | |||
0e9e7f2ebc | |||
14671009f8 | |||
802c9907a1 | |||
88b96265d7 | |||
0bc10923a1 | |||
0dc92c2d7b | |||
04a3206e53 | |||
98360d94a5 | |||
a9c8307d97 | |||
581489f67b | |||
5e89d5a03f | |||
d71d051c53 | |||
d2aeff6752 | |||
36be14de06 | |||
f9af9a15f2 | |||
4674bb5c8b | |||
a6b764bf7c | |||
c6f07ee19f | |||
e36127283c | |||
230ae6bd16 | |||
5b5ef07350 | |||
fb6af1971b | |||
41f9bdc5db | |||
12e64aa191 | |||
22ab673480 | |||
03841dcb81 | |||
64c2634b71 | |||
f1019dc4ee | |||
50ede37a58 | |||
60ddca1354 | |||
19f1f02d91 | |||
5a36b315a3 | |||
b67cd2cf7a | |||
97492eec7c | |||
fdc2e0f692 | |||
2672d037a8 | |||
ee663d61cd | |||
008a768f15 | |||
33b2e6a856 | |||
6540107ccb | |||
1ce08a62a9 | |||
b82bdc7782 | |||
e0e21dfdda | |||
981d09cc28 | |||
2fbd5dc828 | |||
931b02dbb1 | |||
0962af5e72 | |||
9b7d13476f | |||
3efb731b40 | |||
ce989d0d67 | |||
405f96c4b7 | |||
5ad0212b93 | |||
30799dd73f | |||
8ebe2c563a | |||
57588dec7a | |||
9a8b74d744 | |||
e11d70e408 | |||
60d2138f30 | |||
259ee610a6 | |||
4192f6a6d9 | |||
54decda7a4 | |||
f42841a6ab | |||
524363dcf7 | |||
17f6b3a10b | |||
da71e2524c | |||
f3da2b4031 | |||
e2dad367b4 | |||
9b7ff43118 | |||
adfbbc3fb0 | |||
f621261ff9 | |||
00d55fc4b4 | |||
74dc41c7c7 | |||
925599cab0 | |||
a43048a1ad | |||
d6c5a6cd59 | |||
54f339f0c0 | |||
115b9147b9 | |||
6b5c9b1b8e | |||
06b487119d | |||
4ca3f27293 | |||
785a121825 | |||
f73e51e94c | |||
e6802690b8 | |||
595e033776 | |||
e5fc89821f | |||
411e54023a | |||
8f05c85838 | |||
e4cb74896b | |||
8e6e4ede6d | |||
0b03ad9a21 | |||
0e6a314d86 | |||
1b59712c48 | |||
7c8d5b0afd | |||
7f63d896f9 | |||
2115b18ae3 | |||
4ac3e7b864 | |||
03bd96d1d1 | |||
4a85cf5e74 | |||
a8fde9e530 | |||
1f9a15dd18 | |||
a872cc3418 | |||
646147c275 | |||
314099a267 | |||
ce9330e9bb | |||
b2a981f353 | |||
a372619fee | |||
12cdf39165 | |||
19c5343a0a | |||
4a4c8f84d5 | |||
f94208f493 | |||
f2cb9b36b2 | |||
1c5897895b | |||
64423f3a09 | |||
9fb3f04385 | |||
dd627cd7f4 | |||
eedf270127 | |||
a1af94f4e9 | |||
9f5bf06f95 | |||
40705caf7e | |||
9d5b9efc2f | |||
cc4251c5b7 | |||
8d74d34f2a | |||
7f996ea6d5 | |||
0aa4a4ba7a | |||
1ab36d891c | |||
5b5625a6f0 | |||
33a9cd02ba | |||
ca73651e12 | |||
fbd834716f | |||
914b4fae7b | |||
a1bf139188 | |||
a2f753986b | |||
d28f44335a | |||
0a925a6f21 | |||
132bff25df | |||
e1c16a8e68 | |||
4ee73fa272 | |||
30cfe65b39 | |||
40d5f9b5d2 | |||
809022b273 | |||
d0c0585553 | |||
d60929514b | |||
920e1f56c2 | |||
86122e1646 | |||
f9a27d6778 | |||
8b0be5c1fc | |||
686561dc5b | |||
b8b8e58586 | |||
54fd7c7e9a | |||
e060ae3176 | |||
7392a32cd8 | |||
8b724493cc | |||
9cb16accfd | |||
d5944ae69c | |||
6102c70855 | |||
6cc055dbba | |||
f51ce077a3 | |||
2de4c95446 | |||
63f70ba465 | |||
7ef68a9d6a | |||
90bf300bd8 | |||
f9528f1248 | |||
4861ec5a40 | |||
acf5b3579b | |||
d1460ab65b | |||
85bd773c55 | |||
ed3918b508 | |||
7c2766096c | |||
acd8b95114 | |||
34ff813e2a | |||
056cef7292 | |||
7c5f256d4a | |||
82749e4442 | |||
7890185e81 | |||
71fc0dd097 | |||
8373a0fa60 | |||
21264baaae | |||
703f9290c9 | |||
dd1b52c7d9 | |||
01003617cd | |||
bfe4bc2894 | |||
1c88037ea0 | |||
0027e6bdab | |||
87edbb2d3a | |||
5be92a96df | |||
0733af5239 | |||
216ed8c8ea | |||
58e3b8c5ad | |||
c6adfd9d67 | |||
672c58be01 | |||
6cf3b65953 | |||
936dda4773 | |||
047e327f01 | |||
032dc5c108 | |||
dc54e0e1c4 | |||
9124b0a7a3 | |||
dea47f601d | |||
67cf4c42d5 | |||
dc762196dc | |||
0a900dc275 | |||
6f58510431 | |||
666fb7ea2d | |||
f0778860e5 | |||
6aea546d6f | |||
e0a3291235 | |||
b88d7091c8 | |||
15cfa3bf62 | |||
9c9d1650d1 | |||
0ae09577f6 | |||
a59f82093a | |||
be95b56c10 | |||
ea0f7dde95 | |||
a59626c971 | |||
67a7534c21 | |||
39f3f5b2d9 | |||
eccc31a4b9 | |||
d31f238be0 | |||
27c26a77a2 | |||
ab503902c8 | |||
ed53b62f1b | |||
ad5ba54cd4 | |||
a6742b7f82 | |||
91bae4b1a8 | |||
4959d8079b | |||
a558bd9312 | |||
3e41163bbe | |||
10170b41c3 | |||
e0e91e8397 | |||
d2de0292cc | |||
0210ba9c13 | |||
117d7194af | |||
7587ef5136 | |||
087a797257 | |||
a02f42188c | |||
98e0bf22d3 | |||
1e2ff042b4 | |||
b8eb9196e8 | |||
db1df58955 | |||
2f5dc10399 | |||
4100615cd6 | |||
e27c3edaba | |||
3c9ea2b667 | |||
065f42af1d | |||
1d503f45ad | |||
5b5f9a069a | |||
77c7f9133f | |||
475281935e | |||
cdf248b1e2 | |||
85c0322313 | |||
ebc1ed4015 | |||
a25da7f771 | |||
c78f103ca6 | |||
4d50ed0b9d | |||
9ac2cfe611 | |||
85da0b419c | |||
3ddaa60de9 | |||
25641d956e | |||
3b8c33d49a | |||
f74a594e98 | |||
668ab8b85c | |||
98b190c626 | |||
9568a4f2b4 | |||
b41e0910b0 | |||
6448189d20 | |||
1694d510ec | |||
af7ccff846 | |||
381460fd97 | |||
b02a41751c | |||
e0acccc3c9 | |||
bcf27d78e5 | |||
ad54d0ed52 | |||
880a99adf8 | |||
3b11915eab | |||
82c799b9d1 | |||
99c0ca621b | |||
e1f60e3f83 | |||
5a6c229b27 | |||
86a436e9bf | |||
7516fd03a3 | |||
9826c20d1a | |||
12392b5190 | |||
4e57abb159 | |||
2b1ba60f24 | |||
638c868a07 | |||
b909330518 | |||
802072ec17 | |||
3c343eb775 | |||
8b67d06272 | |||
bc521504ca | |||
0797adf223 | |||
718039561e | |||
85698860ae | |||
50e131a4ff | |||
b733bb8ead | |||
e18d206248 | |||
2248b1f846 | |||
58e19e86f4 | |||
04d1862e3a | |||
7ecfc37854 | |||
21d7806064 | |||
c5b2d6cbc8 | |||
75c7e501ef | |||
dba0931b58 | |||
e0a7d6bfb9 | |||
add854d31b | |||
66b70a8043 | |||
1d1843bf3b | |||
0e23ba8f1a | |||
b6074da498 | |||
7e92d478a1 | |||
a9ec057b91 | |||
64a5e0d93f | |||
378e4ea34e | |||
ff670d044a | |||
fac212fafa | |||
e83c7e6691 | |||
e0c4877d76 | |||
457b5d2fe8 | |||
9cf8dacfbb | |||
b5d7d71e1e | |||
6fdc7be502 | |||
8fe858c5c6 | |||
0d7197381a | |||
651f45fe29 | |||
02270e0e3d | |||
cb692d73c8 | |||
1300cf23c5 | |||
3cb24410a8 | |||
be7ce4110e | |||
c07e4a8c01 | |||
ff8da9d246 | |||
b1faebae4a | |||
e96515433d | |||
5a8d2c3cb4 | |||
183a9d7088 | |||
c1384422c3 | |||
ccc0ebd0f9 | |||
9d4336d296 | |||
17bc9d3085 | |||
436f481a34 | |||
9e8215b213 | |||
e958a83dd4 | |||
f44b122262 | |||
26d1cf9186 | |||
895ee77c38 | |||
caf8b15f6d | |||
bc7f18064f | |||
355d3f44fb | |||
9de863e68b | |||
64b7f8e445 | |||
626f488cb4 | |||
10212e376a | |||
81462cd530 | |||
7d4e4ac646 | |||
0ed339f19d | |||
c6fc3560f2 | |||
b4cec0b4a8 | |||
d7030b6e9c | |||
7ed5bde426 | |||
75652ce667 | |||
91f801ee72 | |||
c6f567ae4a | |||
e1ca3c995d | |||
addc327f17 | |||
f2c12d548d | |||
ef36acb970 | |||
d5ca4e5f52 | |||
373ca30269 | |||
0d9d3a90de | |||
363481b0f1 | |||
38058450ce | |||
e672dc8094 | |||
c6682f2a3f | |||
4508a6687e | |||
a47c3cb16f | |||
9b42ced27f | |||
1a400d33fd | |||
96ee7252c2 | |||
b0624d3fd1 | |||
c329fab966 | |||
127c19fecd | |||
4c22793850 | |||
da74b9651c | |||
ce23a8dd32 | |||
30d106766a | |||
c4df88354b | |||
b65c1ed3a0 | |||
b329fb68a9 | |||
da179d9930 | |||
e7fee4c6ce | |||
4151749dc9 | |||
aee9521c91 | |||
7e46c83592 | |||
ba74abb753 | |||
9ddc0327d4 | |||
c34325fee7 | |||
db8443ef7d | |||
6c85f8c7a7 | |||
eea93d2607 | |||
e9f8ecbf7e | |||
48852e8cb4 | |||
55ec325961 | |||
59151fbf86 | |||
1c700b7b41 | |||
ff18bacd94 | |||
caf1de3bcf | |||
a9ad2924ac | |||
7ea2354540 | |||
760bba67e7 | |||
1fe3a4402d | |||
166c7978ee | |||
4f80e79886 | |||
b47a2c9ac5 | |||
1a5274b86b | |||
66236e91a2 | |||
36475aebc7 | |||
acd1f24a3f | |||
a74532fa0b | |||
59d4aef7c2 | |||
dfb291090d | |||
dac32f863e | |||
f3b56d3d94 | |||
eb95a427fa | |||
f16299b10b | |||
76bce44280 | |||
ee0a194b25 | |||
ef08346a74 | |||
fe0068da52 | |||
cd70fefc5e | |||
877f86a896 | |||
912036b260 | |||
a4e8847664 | |||
c492bf7eea | |||
cb086ff97f | |||
7e4da53c0b | |||
fe376f6a1e | |||
55a99f34d0 | |||
99df637aae | |||
d0c68096df | |||
1c464c2da1 | |||
5b15da98b4 | |||
d5a95f9224 | |||
a7dcfa18a2 | |||
4389b9feff | |||
cf03996bf2 | |||
e1a3bd3a92 | |||
58119598ae | |||
42a2afaef9 | |||
c2cfb4d1dc | |||
f0b0172434 | |||
8217cadc08 | |||
6ad047a8fc | |||
23ef742e08 | |||
1294767b44 | |||
eca645fc52 | |||
8598f34ebf | |||
cade483a00 | |||
df46248a0c | |||
6cddb94509 | |||
0e658828fb | |||
de04240ca6 | |||
40681328ec | |||
4dbdfb6972 | |||
bd9c8d65ef | |||
24ec634005 | |||
ff0e6a53fc | |||
ffb444dbeb | |||
d6f32516d8 | |||
29566bfe7d | |||
16d2b85c71 | |||
193b357a0c | |||
8ee8870c27 | |||
3c59de7c00 | |||
e87bf87046 | |||
b4f7a9a4f4 | |||
a360416655 | |||
26dbebbba7 | |||
04b77773c4 | |||
6f4a69703b | |||
d67f59f5b5 | |||
00d9abb612 | |||
c8920cff19 | |||
7293ba7d71 | |||
e73d7d9349 | |||
0e3be9b837 | |||
c600590aa6 | |||
1343f15a07 | |||
5fcaed086d | |||
130689d82b | |||
1efceb86fc | |||
1d92974447 | |||
de56f571c7 | |||
3670b8cefd | |||
425f5201a2 | |||
df3b29e6ff | |||
96a49bf476 | |||
2d975f275c | |||
76e30cf165 | |||
da603208b4 | |||
6dc7bdf72e | |||
d52ebaa412 | |||
c30a1f60ea | |||
2388c9f4e4 | |||
f41372680d | |||
7efb1cf7d3 | |||
0547fd3593 | |||
2800534445 | |||
e464050a40 | |||
73ec8cddd7 | |||
1c171b5d99 | |||
32f49b44b0 | |||
e2d4571ade | |||
3f19e7d73c | |||
93076dde56 | |||
3e78785dea | |||
68c9398f71 | |||
4b3a13797a | |||
4a2c75a609 | |||
34a64f30de | |||
4bdf0317c3 | |||
8624972d01 | |||
6bfaaaa557 | |||
b42c998095 | |||
56357c077b | |||
3def00370e | |||
e1a3285273 | |||
59b392af10 | |||
a8dde7b89b | |||
ecde26c823 | |||
567969d33c | |||
544a4de1e0 | |||
c341bf6d8c | |||
297869163e | |||
3ead6b67cd | |||
3cbea6c898 | |||
1f73ab4b05 | |||
8148c658cf | |||
15ddf28c6a | |||
16b5274963 | |||
f8e24f4629 | |||
1cf8a1f493 | |||
bc2c4cf80a | |||
9933d83cf8 | |||
1918c29fd7 | |||
84705aafc7 | |||
618202d426 | |||
8b9a7d2c8f | |||
d1335dca11 | |||
5e13b42abc | |||
b4b5a70a03 | |||
96aa1c30a6 | |||
1b0c183913 | |||
5d4a9a4aa1 | |||
31c12aebb5 | |||
40269c2a97 | |||
ed74ed6ed2 | |||
26e684eb0e | |||
fc66f79988 | |||
3c85a7f074 | |||
62d2a00e74 | |||
bb2b109707 | |||
c5008031b9 | |||
1d15d4e8d3 | |||
da898d5a19 | |||
f9c84c8c52 | |||
5d63ed6739 | |||
fdf4ebd43c | |||
dc9fdb7da8 | |||
2652c71c9e | |||
806d1fff42 | |||
c065e88e1e | |||
4641a44029 | |||
f544f75c36 | |||
720168f0a0 | |||
6dfecca91e | |||
10b38b5b0a | |||
dbc5d5c453 | |||
a3e0ba16f5 | |||
3c906102e1 | |||
566ac113e4 | |||
5abc8bd2af | |||
926b2e168e | |||
e475e8151d | |||
440f10e353 | |||
30256c7106 | |||
21946f38d0 | |||
549673664d | |||
b45d0c5a36 | |||
4df05c2890 | |||
d886089091 | |||
51158dde93 | |||
09fff7f1cb | |||
91f435f32f | |||
726ffddce2 | |||
4ecf692f46 | |||
2a461a9aac | |||
211b1fc23c | |||
df6bbb0b0c | |||
cfae20e0df | |||
3c0adde0c7 | |||
f511c9c938 | |||
20f88b37ef | |||
269501eaa0 | |||
330e1de3d1 | |||
25e14e2164 | |||
aa97aabb4e | |||
59cd2766e3 | |||
b7952d7f39 | |||
c380a4e4bd | |||
9c487cbfb8 | |||
6fc636535f | |||
4190318c85 | |||
2f554fd6f8 | |||
ae93cccde6 | |||
46e955e3a1 | |||
60057d7072 | |||
2850f131e2 | |||
440568a516 | |||
e31088aaf9 | |||
63b36e8569 | |||
726d359335 | |||
fc0858a4a3 | |||
f80103778a | |||
c09010c25a | |||
9cd1466e6b | |||
801be64ed3 | |||
d719137565 | |||
58aba96494 | |||
f8d7796099 | |||
241c41267b | |||
2ac1ff9be2 | |||
cb31b3987f | |||
c256398095 | |||
7bb8703bf9 | |||
0da00bf546 | |||
4866490cdf | |||
1547b1a581 | |||
511c77aa99 | |||
692a0e7ac2 | |||
fa25b45198 | |||
cdd25c389e | |||
133a6ff7b3 | |||
96add0ba65 | |||
f5096a1f26 | |||
3d4d087f07 | |||
953e62f103 | |||
084727c54a | |||
8ea192fcab | |||
dceba1f2f1 | |||
73878fbdc4 | |||
87d17088cc | |||
cc6c48fca8 | |||
e556a2ee23 | |||
50b866c5cf | |||
f83eed9ef9 | |||
cb9313a454 | |||
cf411efd1d | |||
1c956494a4 | |||
dbe3aa1efc | |||
4128d80974 | |||
057356a725 | |||
a69e91c541 | |||
8fccf3136c | |||
2435ab70ab | |||
f489862500 | |||
2642fa1ee2 | |||
2293b0703f | |||
1375e3e2f5 | |||
0ab5cce878 | |||
b567e91f68 | |||
eee31605b1 | |||
df9a7497b1 | |||
c6adb6df12 | |||
aeec7dae36 | |||
fa58909d44 | |||
06ed114fb6 | |||
bdef9d3bd7 | |||
b154b7296c | |||
8019f13479 | |||
1c6fd4125d | |||
1f99f1d5f4 | |||
30c77cfee5 | |||
afdc91f21f | |||
3470c5314d | |||
f0e824416b | |||
52ff67fb2c | |||
e9375b50b0 | |||
1f43a736b2 | |||
05a0a20197 | |||
2ee595553a | |||
2d4fe9e6d0 | |||
dc12bde068 | |||
b3fbbd3124 | |||
983336911c | |||
48b39ab005 | |||
5095d73de3 | |||
1192b1b422 | |||
43c528fdb6 | |||
da4b9922d4 | |||
7a8c89be9d | |||
3b37db1a36 | |||
5ae0f9d03f | |||
1dd1bf8bac | |||
8966002685 | |||
4ce810b421 | |||
730482e62f | |||
eac56a2e25 | |||
5c3a2357ef | |||
663a09b38d | |||
eaccce743f | |||
7cce23ae79 | |||
73c186b111 | |||
5ce0019ee5 | |||
ca8d315924 | |||
dfdac7adbd | |||
a33d7c64fe | |||
e37c9055b3 | |||
d15516f0ef | |||
4a1d6f4cc8 | |||
6393a4beec | |||
06125c48bc | |||
8cda04cc98 | |||
f20b7e8cee | |||
19dded141a | |||
d19cf1eaac | |||
d6b00bcd40 | |||
1b1fe61fd0 | |||
3bce783cbc | |||
5966f7d9d2 | |||
aed0b4941f | |||
9ef75c0e13 | |||
5f548705dd | |||
39d3c8402e | |||
5cb6265547 | |||
03dd537ea4 | |||
4af8f1bf03 | |||
ae8df648d5 | |||
5e24166318 | |||
4e10b4e017 | |||
87fdd644d4 | |||
2e356613ec | |||
91e9b736dd | |||
7f4cc1a239 | |||
3e3d46e72e | |||
460c2552a8 | |||
1a7fb83882 | |||
dfac6303bc | |||
8b77a93d60 | |||
fabfb10b97 | |||
65549cb0da | |||
bee137c6d9 | |||
a2a7122da9 | |||
0e798222a7 | |||
c890f1762a | |||
ea4d7ae92f | |||
1ef385b685 | |||
0875fb5fe0 | |||
b5186f7293 | |||
fa21fdc1cc | |||
3f4cd7f5a2 | |||
272fb2ca96 | |||
a7116bc971 | |||
502cbc2175 | |||
953d22de14 | |||
cacfc294d9 | |||
f8ca7002c2 | |||
6c728313f5 | |||
1a2dc67702 | |||
f7dbd050af | |||
c16b03c8b8 | |||
357e1aca54 | |||
c15890b4db | |||
f268237372 | |||
4d021e16a5 | |||
62ce6e6a60 | |||
c7109c646a | |||
43433cdb5a | |||
8d39c9a861 | |||
f8bf91426b | |||
f7934972ea | |||
4cadfd736f | |||
c46309ea8a | |||
37f26beb50 | |||
1c7a5439d5 | |||
ebc4c898ff | |||
56cf874d99 | |||
079ff50622 | |||
31888f5ef8 | |||
7a626abf15 | |||
3c7bd65bc9 | |||
01bf3b8245 | |||
a6c1998c81 | |||
0069b1bac3 | |||
25c5cad1d1 | |||
c689c0bd8c | |||
271dfc0d2b | |||
0032df3bf1 | |||
993e58773a | |||
8f4c038e23 | |||
81f2c57656 | |||
594853e251 | |||
cce8411c22 | |||
786906b0f7 | |||
aed37a391d | |||
cc6de583be | |||
b277e04efa | |||
95032cc74d | |||
3818351287 | |||
4d26b5a868 | |||
ac0dc7844f | |||
27e3597d5e | |||
9e8de2a702 | |||
165757176a | |||
a411b83a65 | |||
12900d914a | |||
190e9464ce | |||
57dd26baa9 | |||
19f3a97a8d | |||
375e5ee7dd | |||
05df378dce | |||
f1efea6800 | |||
eb1cafcd01 | |||
81de6d2dfa | |||
9e38c31b64 | |||
7d1f447458 | |||
1b66a1cd2f | |||
eabe091038 | |||
b403f106fb | |||
75a45eeb27 | |||
452b1e806b | |||
9f9a870399 | |||
48ce7632fa | |||
30d5d5a892 | |||
9bc79f94df | |||
a0239e17e9 | |||
c8a58b4b04 | |||
b72e5e8386 | |||
565885a4c0 | |||
134d33c218 | |||
9cfb807fcb | |||
46adc1f059 | |||
9002555596 | |||
3b375b55c2 | |||
3f49570f45 | |||
7c3166e9be | |||
39b97f9163 | |||
af79be5002 | |||
a20a290836 | |||
e822463916 | |||
d2c3ea6901 | |||
83265768c1 | |||
27ce787fbd | |||
9c6ec2c52e | |||
3a4425fd4e | |||
6bb1598fa3 | |||
4eb6a4286e | |||
a9942ca412 | |||
8d21ae9813 | |||
ff8044f0c0 | |||
1b8917a57c | |||
a91c49fa52 | |||
e607348c7e | |||
b6ed919fbc | |||
109252be4e | |||
a4b98518e3 | |||
c3a42bf590 | |||
8b95afa96a | |||
6a49a766ca | |||
932584f8fc | |||
d7ba2957cd | |||
16ff14bda7 | |||
57c1d96b71 | |||
40f376e2b9 | |||
1a1d7d9ada | |||
d1c88971ae | |||
dc61f78916 | |||
a2ffe8c05e | |||
e1af003e4f | |||
19391858d4 | |||
5005244d1b | |||
15380cfc14 | |||
11b352458e | |||
b6680b18e7 | |||
ec4c2aa12f | |||
0e8c43cfdd | |||
958420ee44 | |||
2d8a54f05d | |||
d0f4cfe6b4 | |||
3ec23f92ec | |||
6baac1b4e0 | |||
1d8b8d8e9c | |||
50b0b2e2e9 | |||
20721491e8 | |||
eec46a137e | |||
9eae444104 | |||
576b4f03a5 | |||
2d0f76bb9c | |||
6492f4487b | |||
126669b718 | |||
6fd45c1f9d | |||
4eb3b762d4 | |||
f24afca1ba | |||
461810b06a | |||
20050662b2 | |||
2053415418 | |||
613d7b5ece | |||
db29c3ac13 | |||
c101d71d7c | |||
63a44c9268 | |||
5623a0b420 | |||
663e748b8d | |||
0cf62d334d | |||
0872012cd9 | |||
c2d8fe46d5 | |||
0310bfa3e3 | |||
efe0e8aa7b | |||
5c7e51feaf | |||
34de579c91 | |||
0ed9db05d2 | |||
46387e2f2b | |||
8913f13b36 | |||
e5007f1290 | |||
740c77a488 | |||
73ddea8864 | |||
10215af96d | |||
e67fee0264 | |||
5ece4f734a | |||
27409b615a | |||
8866fbd618 | |||
8885149cd3 | |||
89ddf2991b | |||
547b0de8a5 | |||
0461b24db3 | |||
c698e9c122 | |||
8f84a968de | |||
f8ea7fdc2b | |||
7b0d11b187 | |||
8dd3639576 | |||
364ad87e2b | |||
9380ef708a | |||
fd174b3459 | |||
21d27c314c | |||
0b89a49201 | |||
de718d9743 | |||
e6b4fb5af7 | |||
c227330d09 | |||
c769e282fb | |||
98722ed7ea | |||
b16f40c0de | |||
fd85f87ade | |||
add33f1ab3 | |||
3bfc438ae8 | |||
1dfe909bab | |||
75d17ea3c8 | |||
96d15337bb | |||
74a678c1e1 | |||
fed1846c6f | |||
f27d193cf6 | |||
7941b63543 | |||
21965ac8e8 | |||
7ca2ecb421 | |||
1dcfc03cbc | |||
0702e581a1 | |||
c78792a705 | |||
287c19e822 | |||
bc901d613d | |||
2192a8b0ec | |||
6cb4c58d9a | |||
4f521baafd | |||
81fda3f5b8 | |||
91c4dfc7c0 | |||
788296ea29 | |||
60c1fcbc48 | |||
fc6d90a04a | |||
faf0c6bbfa | |||
79f1e81745 | |||
7427961fcf | |||
d2f1d05a06 | |||
19f4146aca | |||
47154fa623 | |||
5c508515c4 | |||
2824139510 | |||
c2efdcabc5 | |||
6f622e4551 | |||
6d8c96b89f | |||
bf4bb414dd | |||
dee3361c1d | |||
c470c6255e | |||
6faca86bb4 | |||
4fed56443e | |||
1859365f9d | |||
ab87b8f881 | |||
b8b65da51c | |||
198e6f765c | |||
810e2a761f | |||
6ce71c1bc3 | |||
6b3a7ec827 | |||
ed2360d9f7 | |||
1ce71f9dc0 | |||
18508b5a2e | |||
621898f3c5 | |||
2c1d7f3dcc | |||
8bb5bc736d | |||
b270d527f4 | |||
1bd9e9078e | |||
a3361a7d97 | |||
ca1715118f | |||
27ecb7c7b6 | |||
be7fca254f | |||
b64ae8c8a5 | |||
b984eb2808 | |||
15905b2fe3 | |||
24615ed24b | |||
13481cea18 | |||
7faaa55436 | |||
11ddbc6f30 | |||
29e5880d8b | |||
63fd2cbaeb | |||
9c58308e6a | |||
5fb814a04f | |||
c69d2df0a2 | |||
46a7136b0d | |||
d2974f2e60 | |||
ed8fe8990b | |||
50703534b1 | |||
4a7c156bf8 | |||
54680a6edc | |||
bac57e355d | |||
b8b1f64959 | |||
cdcd6c4886 | |||
4e8640b380 | |||
9374e45449 | |||
31ffe4403c | |||
e8f7d5ef9e | |||
ee0e306685 | |||
b37e9de24d | |||
df0007d532 | |||
b70c5b94bd | |||
23f9baa9f2 | |||
537ce83498 | |||
1732f7371c | |||
5262a2f753 | |||
79e2fd4586 | |||
353905394e | |||
3870f7af27 | |||
b8e23e6fcc | |||
a7f652781f | |||
d3fd0d3916 | |||
1beacf3000 | |||
88a1170966 | |||
315a5cfd58 | |||
a5a94e3c49 | |||
ef784611b7 | |||
d526dca1bb | |||
e8390afad5 | |||
9fdf83be60 | |||
147945d20f | |||
3af693af34 | |||
0a18e66a83 | |||
57a225cb39 | |||
1bd1923964 | |||
7c2066c258 | |||
ac808d51d6 | |||
378bc73bf8 | |||
8430db4dc7 | |||
0f049da84f | |||
a1b6cc44fc | |||
201fd7c421 | |||
89efd09e20 | |||
3eccb5a6f0 | |||
191b802c50 | |||
f4703905b9 | |||
41a85b1de7 | |||
9021302578 | |||
e1aec2cb03 | |||
3aa0390dba | |||
d3770eeccc | |||
1d6b8393e3 | |||
c14d1047d2 | |||
343ccd911b | |||
697c8c9882 | |||
72d48da210 | |||
b2b3271a96 | |||
717e9238fe | |||
12c77459d0 | |||
5b1c55023f | |||
a401b21f3d | |||
3a6cc1d8b7 | |||
4944d044ce | |||
b3228ab307 | |||
68b0e13991 | |||
70d81277e0 | |||
48814c1bfe | |||
0587e432c0 | |||
e4404164bd | |||
9d0b492642 | |||
5391e95fce | |||
954f6a77e5 | |||
e8c6b4ab16 | |||
21993819a5 | |||
904348b2ad | |||
e59cec4e3c | |||
c2eeb5d553 | |||
dea4bd01f4 | |||
ec52af420e | |||
2aecb547d9 | |||
3db328cc94 | |||
a624dfd776 | |||
af705ac504 | |||
af6d01e79b | |||
1ef3b2d526 | |||
1afd097445 | |||
52fad6e18f | |||
3f921c01a6 | |||
eefe34354e | |||
5188c7d41f | |||
f2ba613fb5 | |||
6cfdd5b2c1 | |||
f2cd7cd4eb | |||
0a8b692482 | |||
1542163689 | |||
9d66d876f4 | |||
0456a71295 | |||
70b1b4ecc7 | |||
bc4bd29488 | |||
f906eec42e | |||
73b5eadd3c | |||
1f8905dfc9 | |||
4465d36db5 | |||
d64c5a92c6 | |||
0ba358a3d4 | |||
86ff1e7cd2 | |||
13d7e2f2b9 | |||
bad1e0d529 | |||
6b21a4f494 | |||
891815054c | |||
ce2fb18c02 | |||
2f359a43bf | |||
a1b72f0e1a | |||
de308f05e0 | |||
ecfac0601a | |||
93ffd75b02 | |||
8af4eff43e | |||
167645ba6d | |||
baeab92737 | |||
24162fd490 | |||
95da2bcbcf | |||
a9e4fb0ed9 | |||
45b092532e | |||
3ec932e194 | |||
565bef05af | |||
a0c78da1ad | |||
7b14aeb53e | |||
f934a09baa | |||
414c248cc5 | |||
ca428233ba | |||
3712f9b318 | |||
11545bdb5d | |||
a390629371 | |||
e3e188109d | |||
7cbbc38b89 | |||
bd1861ef4d | |||
b152f9e1d3 | |||
24339092f7 | |||
4bd58d47cf | |||
982c32322b | |||
2fcc344299 | |||
3acd901c88 | |||
0795dbf5f1 | |||
101a3a7d74 | |||
2da162bed7 | |||
5282e06fd4 | |||
dc806dd718 | |||
31d8758ad9 | |||
ae70db0535 | |||
6b67cb0e2a | |||
250f0ef9db | |||
a690ffdb7c | |||
4aab9121d9 | |||
5ea7ef6b65 | |||
a3875f9965 | |||
4e3a59f329 | |||
3730917dda | |||
57516cfbe6 | |||
bb62279a20 | |||
e8be28734b | |||
6c5a097711 | |||
16a878adb1 | |||
020d882e82 | |||
44af828aa4 | |||
26a0cbcd73 | |||
1a106bca3b | |||
cc42d6f4e0 | |||
1316ee3127 | |||
eadca9dd75 | |||
59dd71187e | |||
36e167013a | |||
2d489a8679 | |||
d735a1d04c | |||
9480ff1f37 | |||
d2f2abe525 | |||
e9e20fdad8 | |||
53ba413d32 | |||
7280fcdec2 | |||
cbcd2be232 | |||
83a2dcb65a | |||
dd65680150 | |||
90f18f7ee7 | |||
317263b31c | |||
52679d2784 | |||
763d1cc3dc | |||
c9fe04d8ea | |||
f2c490345c | |||
fe5aad3cef | |||
927bc2e33d | |||
1331739ee4 | |||
3da8f5f053 | |||
fbbcf292c6 | |||
2851a9577c | |||
ed9b09e980 | |||
bcb3fc7fc0 | |||
70f37962cf | |||
fd7f61bab7 | |||
5f8714a0cd | |||
8d83b9b7c5 | |||
2c75be0d64 | |||
ee04118172 | |||
fe1ce885a0 | |||
24769219b5 | |||
da6fe18e17 | |||
a973a6e10e | |||
5bc64c4c4e | |||
bd92990165 | |||
e26a8be3df | |||
3ef1c8e3fa | |||
0ab4b903f4 | |||
b2ea5aa747 | |||
c80843e496 | |||
f9396f979f | |||
610d4ff016 | |||
f16421225d | |||
d82b3684ac | |||
d7e5a92fe6 | |||
bb45f9ca3c | |||
c7dcbba442 | |||
255dee7a5e | |||
c86418934c | |||
70efa5f606 | |||
69b2fcd5af | |||
1f93099e1a | |||
b3331c5ec2 | |||
ff23d3051f | |||
7d8cfb1fee | |||
8131680735 | |||
9e6dba9066 | |||
0f2887265c | |||
1ff45020e2 | |||
45c5abe05b | |||
e7dafb3ae6 | |||
04f6140da6 | |||
afcbc6dd9f | |||
4da9bed4fa | |||
221e4ecb12 | |||
1883a8c9ee | |||
83d92858c1 | |||
cff3152985 | |||
5090e95003 | |||
927aeb15f6 | |||
361ca1e8b4 | |||
9adf656db5 | |||
7219ca0c0f | |||
3a75950ff4 | |||
fa86b8bae0 | |||
f3c9ab8a7e | |||
ace03d7c7b | |||
97801b3b56 | |||
74d9e1e558 | |||
c210e9e5cf | |||
df640dc39b | |||
d980bba49f | |||
059dfee0c3 | |||
55f442f1a9 | |||
2b9d9168e0 | |||
94669a4709 | |||
be560eb704 | |||
36d867c3fa | |||
cf47618ffb | |||
62f23e0cfd | |||
0e8b54f7a1 | |||
1c9407e016 | |||
cb8d773634 | |||
bbb307aff7 | |||
3db263284b | |||
d8f041a484 | |||
120bcbc2c9 | |||
10ccaa2620 | |||
e6b5f8aabd | |||
4798689bf3 | |||
0545e70bd5 | |||
5032a8eeac | |||
1ad555a071 | |||
7d0f6933d6 | |||
4cd3d0bb76 | |||
8374553b6a | |||
eca4052884 | |||
2d7a96416c | |||
f2734dc3d8 | |||
a1f4397959 | |||
53d5c9890f | |||
43c108f077 | |||
33cc59914a | |||
45b6d11126 | |||
b7b01da742 | |||
93d6b41898 | |||
47e9fb3ddb | |||
b1ddba0438 | |||
e7891bfcb0 | |||
7f99c4a779 | |||
2ac49d99dd | |||
3fd8efe642 | |||
06730c7d1d | |||
81c9db7a15 | |||
8d0a3563e4 | |||
c0c215c83c | |||
058d888311 | |||
30b18d925f | |||
137d05e799 | |||
d9c4e644de | |||
edd960566a | |||
6868e98904 | |||
85a5b0b948 | |||
b9a1719cb1 | |||
d6e3164ea1 | |||
302ac8fefe | |||
d2708daa8e | |||
88a3c685fb | |||
2e52a1eebf | |||
d098a99d09 | |||
6b197e067a | |||
9f4985b11a | |||
5b700fa497 | |||
c92e030a4b | |||
251b06d812 | |||
ff50762649 | |||
29ebda62ef | |||
a1b2ff772a | |||
dc784f6213 | |||
387039456d | |||
c1f4168d2f | |||
ffebcd247f | |||
fd0c906b1b | |||
decd5add2a | |||
8eb453e042 | |||
bd6c97aeb8 | |||
29e7fa5c4b | |||
a23b6d09c0 | |||
1bb1dfa87b | |||
a33a494d60 | |||
5f0ee4fc78 | |||
d0aacfddb7 | |||
9b92ad7772 | |||
17c7ae20cc | |||
fa5c8ef434 | |||
1dca7b92cf | |||
5e122b95e7 | |||
135a547889 | |||
06de25a680 | |||
5692402d32 | |||
ad7ae5a372 | |||
9794e31a64 | |||
2f0f0e4f53 | |||
7bde004c7c | |||
a8f830aa9c | |||
7266550c22 | |||
7ed960297b | |||
39da360725 | |||
beedee4401 | |||
fb0e8aebdb | |||
13929aee6f | |||
c2409ad6c9 | |||
08cb72bdba | |||
d24c8d858c | |||
879ef58565 | |||
8b8399efbc | |||
0f17508cac | |||
7a138f963c | |||
b637ced1ee | |||
ee91c81799 | |||
8ac42b4600 | |||
844725237d | |||
58d567c331 | |||
4465952d11 | |||
f8ba1962e6 | |||
701960def5 | |||
15c0c1db39 | |||
c9f942f79b | |||
663df9118a | |||
5d47697ade | |||
5babd01d40 | |||
aab96964b6 | |||
c6518afa7a | |||
563655a1a4 | |||
a50e8e9878 | |||
de9cfbe9b0 | |||
d699116795 | |||
8f3a0b17ad | |||
b5c661c5d5 | |||
154470b570 | |||
73b1d57b13 | |||
acb4ef0f12 | |||
d2db307bee | |||
182f16d2a4 | |||
bfe5c758ba | |||
32a78b5f61 | |||
54f9f2ad53 | |||
f12c75e68b | |||
b6b11dbf82 | |||
0d42108254 | |||
f6026f94a5 | |||
e702942041 | |||
00ac35ad62 | |||
12a92fc4a1 | |||
baa14a63c9 | |||
cce51cea5d | |||
ba4324f992 | |||
81e982991b | |||
f6f4fba90e | |||
23d5a972ba | |||
d5467e130e | |||
5faf0f8ab6 | |||
0f17cd4791 | |||
e0518ab176 | |||
28df0c2e38 | |||
7696d45093 | |||
2a7d4fcde5 | |||
c9f07e855e | |||
995fa4a76c | |||
d8597884f6 | |||
a993ddc54d | |||
54e25084fe | |||
e58a0b3efb | |||
381f15382c | |||
91d679af15 | |||
8396f16dd2 | |||
bb84c9b65c | |||
e744c95c5b | |||
a725d1a29a | |||
38feda1594 | |||
dc19deb6c3 | |||
86abd31659 | |||
b8e70d866a | |||
e1e27eb19d | |||
088dab4f04 | |||
cc79ec6179 | |||
74478b24b0 | |||
bad95d7c67 | |||
de127056c2 | |||
0767ea5d69 | |||
8454a14eac | |||
ecee310087 | |||
bcdab95e4c | |||
a16377cea5 | |||
ef69f1bb27 | |||
27c8eb0d6d | |||
3c0f54257b | |||
e6ead35884 | |||
a6dff8ff2f | |||
4281b6b448 | |||
6897f602bf | |||
075321fd0d | |||
5e8e935189 | |||
ebb5f1256f | |||
7c6d0d3c0f | |||
1b6b38e395 | |||
1cf953c046 | |||
e5bf4565da | |||
ddc904a502 | |||
5cda292d15 | |||
e51cf0d4d2 | |||
d8de837c60 | |||
ca89695270 | |||
91b16310ea | |||
609873e6d1 | |||
4c616621c2 | |||
05470bf202 | |||
633cf9ec04 | |||
f3c3a90393 | |||
25a48f2f44 | |||
d214a5437f | |||
de0a5aa840 | |||
6f9e3e3b78 | |||
5c5e7fc7ff | |||
43e98930e9 | |||
51ebefc3ab | |||
86add4a6d3 | |||
221a3f9a08 | |||
2f74bd5150 | |||
e8ae333443 | |||
52a166a71f | |||
509da3ac34 | |||
afca5c2536 | |||
5453cab22b | |||
b0a91c0187 | |||
963113b86d | |||
0634214f2c | |||
fe18579061 | |||
15e44f0ddd | |||
b0e86d11c9 | |||
2ec53df7ab | |||
1c7b553331 | |||
5b7d60f5cd | |||
640567a021 | |||
2593c6efee | |||
36d368cb78 | |||
a0fb519696 | |||
2e9fa7a811 | |||
d8ce1f7914 | |||
83e6864b78 | |||
3c7e25ed58 | |||
98af3c0dc1 | |||
77ae929eb3 | |||
5341c216a7 | |||
96a0c3d764 | |||
783b49e383 | |||
d4dc983a01 | |||
72ccd1020a | |||
6a9a577c59 | |||
730305ecc7 | |||
f8f2432ece | |||
55087521f6 | |||
760ae07d72 | |||
28d0070ce2 | |||
ad2a7c2590 | |||
8b97755fc5 | |||
7bb0d9be1b | |||
6c44fcc290 | |||
c8e7031198 | |||
fb3b2820b5 | |||
c83a4aef55 | |||
af7a70bf02 | |||
4d70640a15 | |||
b11627a8bc | |||
7436f85ad0 | |||
237c379866 | |||
aca31c7055 | |||
6073e7972f | |||
f7e8d8f1dd | |||
87016ae815 | |||
3ed8e46782 | |||
3db0197865 | |||
6174c0c103 | |||
8898cb342b | |||
9cc76d1115 | |||
5289d3327c | |||
00fb9c475e | |||
3c776675b3 | |||
37d508ab96 | |||
f4f8fef82e | |||
cd2e3c79f2 | |||
7722350178 | |||
a77b4ecddb | |||
818b7e4a2e | |||
00d63f6046 | |||
639fc60257 | |||
21467596bc | |||
75ebe5172f | |||
4a9030b4a0 | |||
fdc708a624 | |||
67beea1e3d | |||
34364ab8ee | |||
bb99ef1351 | |||
b3891e5506 | |||
632d6e04ad | |||
db813db7e8 | |||
837c6270f2 | |||
8c3c07cb5d | |||
5cc0dd7f55 | |||
79c4d98b61 | |||
678e11530e | |||
a8f2b39f15 | |||
add2ac0369 | |||
1e475edd1c | |||
745483708a | |||
d9432f2f1e | |||
eb7081d2a3 | |||
d9befe3fb3 | |||
0618452615 | |||
f6b080b8a2 | |||
c8c33db1d1 | |||
196bac726c | |||
ac2688de58 | |||
d2af12b6a0 | |||
6958ba9557 | |||
5f11daadf2 | |||
99df3fe433 | |||
d4d350a285 | |||
8a0b75c83a | |||
9cf74657e0 | |||
5edd04638d | |||
eb2f851e65 | |||
a0f47b12b4 | |||
1b2d9e202e | |||
daa8839005 | |||
80124bb753 | |||
861a319014 | |||
d43e810ecb | |||
7afcc17024 | |||
2ab2f68725 | |||
90872c906f | |||
bdc2ec1f5e | |||
692733fffb | |||
d3728d5859 | |||
389331ca29 | |||
b2c4b7e99f | |||
fee6aae442 | |||
409406d114 | |||
203414910f | |||
ac0082a67e | |||
9ccbe85923 | |||
dffbd2113a | |||
7db073d993 | |||
3c02c2e4bd | |||
a17c760181 | |||
54d2fa65dd | |||
a019c3dd5d | |||
a3ef9b8a15 | |||
554e0b7c6d | |||
fd74e2a583 | |||
af5d3a7f0b | |||
bb0808c99c | |||
f0295b154b | |||
b041de831a | |||
21e844cd82 | |||
4e2439bd12 | |||
c5a07c7f20 | |||
e2900f4f3c | |||
aa831dd843 | |||
2dc783214c | |||
523df47a65 | |||
f66fac3982 | |||
9c51ce9c40 | |||
9797540212 | |||
ce2338c24a | |||
3b188ba672 | |||
eb84d61deb | |||
47d29ddcaf | |||
f411eb1651 | |||
94bd2918fa | |||
c3bfcf560b | |||
5b2b088714 | |||
0bdfad52e7 | |||
cf046a4039 | |||
700cc92083 | |||
2eb9c0924a | |||
ebadc6f203 | |||
87bce1a36b | |||
848f822171 | |||
d4199ddb3e | |||
e4abc91d35 | |||
37d321afc8 | |||
541e5c510e | |||
90d324ae96 | |||
cacdb445c7 | |||
4743ad0b16 | |||
2d5c6fa975 | |||
95ef13f7a1 | |||
298e1d5a74 | |||
87c75d033e | |||
71ae678930 | |||
6a027c9c0a | |||
6014df2847 | |||
55a9e6e05e | |||
02f0eead1c | |||
d77846dcea | |||
92c811deb7 | |||
92f199ab98 | |||
b65feeba85 | |||
6914425b03 | |||
89f57124b2 | |||
65823332d4 | |||
ee8682ac75 | |||
e3e5137757 | |||
d81549a7b1 | |||
d5ac8512e3 | |||
f23e354272 | |||
6475e1faf6 | |||
752fc0742e | |||
e1091611da | |||
678116b6d1 | |||
0a9e2227e8 | |||
2600b1f144 | |||
b56753ea9f | |||
97046b265c | |||
2966eac64f | |||
d530356055 | |||
af3ec000a0 | |||
8051127c3b | |||
e37eb0aa54 | |||
130fa35bb1 | |||
39e1021f62 | |||
63ec19674c | |||
af60e769b0 | |||
087c75d5ee | |||
e03102dbcb | |||
9d7b7c72b2 | |||
99c3f02343 | |||
95bfc29c92 | |||
e3cc7c9a80 | |||
d4c0349de9 | |||
d7a6357393 | |||
6fbf21b4f0 | |||
993d850f69 | |||
cda07b20a2 | |||
52c85aa605 | |||
e5155df6d5 | |||
293d2064c4 | |||
171cc3e01a | |||
8141043560 | |||
9a3cc93d74 | |||
fcb4221f97 | |||
1f13374a4f | |||
801401a6e7 | |||
de1fc43cc5 | |||
270debb3fc | |||
59a0a25f35 | |||
a788486803 | |||
3d21f0a91f | |||
f726044e29 | |||
a4b1917361 | |||
a3b2aeb001 | |||
5b1ef2fb03 | |||
d0f78f1e03 | |||
541e91ed8e | |||
321cada1d7 | |||
34c1023ba7 | |||
82a21d4b71 | |||
23996c7e6b | |||
d7091a0bac | |||
7414418e2e | |||
2294770e56 | |||
d98bdb5643 | |||
21f4f16e63 | |||
0e597191b8 | |||
001ba1a4a7 | |||
b59c4a2106 | |||
c35933cd1e | |||
0da2efa633 | |||
e23d95bf03 | |||
f6e9f0e2a2 | |||
4a89729529 | |||
56a58f2b11 | |||
e959908c51 | |||
6e3144370a | |||
20f02bb772 | |||
1c86f25fab | |||
e6f9ab929d | |||
18d1772bb4 | |||
5535cad773 | |||
ec84934d48 | |||
328d08781a | |||
c8d5215870 | |||
62ccb48a0b | |||
82409eb345 | |||
b75f212d70 | |||
ccb856749f | |||
9d2bc9bf4e | |||
52c4385c16 | |||
5da7d6d1ae | |||
65e0a74718 | |||
01d5d7d78b | |||
e3381a4c1f | |||
03e35b25b8 | |||
e2b0fb26b1 | |||
01c18cc442 | |||
01e6df4d46 | |||
882b03436d | |||
690bd933d5 | |||
6684559cd9 | |||
4ed7d20a48 | |||
350116c513 | |||
7bde2c089d | |||
90631adb9b | |||
f6450cd7e1 | |||
3b6b1d1674 | |||
33d7b22abe | |||
2f9712e6a7 | |||
b937aeb857 | |||
f3d8846df3 | |||
2729db9555 | |||
1cec4b1c4c | |||
7048c77ebc | |||
c9c17eaddd | |||
f1b82b734a | |||
4c0e7aa8b0 | |||
296e4616cc | |||
15649334a6 | |||
b3c2c0866f | |||
c6ae81fac7 | |||
79086f0858 | |||
c148a23df4 | |||
c56831767e | |||
72a724f075 | |||
96e1df5854 | |||
2e44b90f63 | |||
5a0adba798 | |||
761cc5c923 | |||
f901b9dd6b | |||
d87fcca176 | |||
7c72653385 | |||
7dbccf08ae | |||
2d21c18ebd | |||
15d0aad3c0 | |||
f0fc9b1766 | |||
7c0331997a | |||
04de2302a7 | |||
1da1409db2 | |||
c1ea1329c1 | |||
417aa9547b | |||
60d5a3c631 | |||
7a42416a78 | |||
2a143a7505 | |||
0510f85a8f | |||
5b222d0a09 | |||
133b64679c | |||
79b88a22c3 | |||
88d879987d | |||
27c37a18f3 | |||
b8268d894b | |||
79b47b055a | |||
8e260bae11 | |||
af61ee6f3a | |||
04d7a1df96 | |||
b9fd50e348 | |||
ef48d11266 | |||
a47559d9e3 | |||
cffb992ae8 | |||
39e720e811 | |||
258b1c8b55 | |||
7b87e9c0cb | |||
3dd9b1aa9b | |||
0fddebc791 | |||
701d64936d | |||
0ec6215493 | |||
de45bdb448 | |||
7b608c6ca3 | |||
6ff78c9c26 | |||
d701f4e331 | |||
92abc92463 | |||
a4be9ceb5a | |||
e21b6e1daf | |||
2e3b03fff9 | |||
cd657da431 | |||
17af09a5cc | |||
ceff48b07c | |||
199566965e | |||
46e46e9b7b | |||
8b292d2dc7 | |||
88abd6ffc6 | |||
76b4ec12a0 | |||
0e4cfd897b | |||
515d7962b0 | |||
553101e8b5 | |||
1e66854b59 | |||
12f2df5586 | |||
20a25a6a45 | |||
08d9dc5c68 | |||
3cd0ab1b3b | |||
fc6dba0797 | |||
e01c0adff2 | |||
e75a093a8c | |||
dcffb042ff | |||
d724af6a99 | |||
b30f423fc9 | |||
1fc14292fe | |||
fa7e7fc6f9 | |||
5b114791e5 | |||
9bc11a369c | |||
ac40f2191c | |||
62a93c58fd | |||
65b0030342 | |||
f302fac423 | |||
f94aea8119 | |||
28cb40529d | |||
37ae3b2b80 | |||
73e4286fbf | |||
4e6151ebd9 | |||
fc225401a5 | |||
d74817f79f | |||
bdcdccfcc3 | |||
352ec3430f | |||
978d2fcb56 | |||
52264d5e28 | |||
17fbb020e7 | |||
f8005b88ad | |||
0faa655b83 | |||
6fddf31db3 | |||
01257a461e | |||
817b9d012e | |||
04b3525e0f | |||
d55c732e19 | |||
d223427e22 | |||
64856adc3c | |||
7c53adbcfe | |||
dce9cb27c1 | |||
4199c56e99 | |||
9681fedbb4 | |||
b6d97af451 | |||
a9ca26c698 | |||
9463d4abe4 | |||
b9975845ff | |||
b22405b64b | |||
62210e57f1 | |||
4dd093efc9 | |||
91a22a686a | |||
a307dff3b7 | |||
20f0bed2f6 | |||
46a7a2be2e | |||
8199dbd0dc | |||
dfe426e4e0 | |||
3ace61ef85 | |||
442595d6fc | |||
be469f4dd0 | |||
7da4b0af15 | |||
2fff651378 | |||
c24d16e62e | |||
c36c92e077 | |||
c0efba79c7 | |||
5809941ae9 | |||
535ba8a207 | |||
43331d3fe8 | |||
9765ba334a | |||
0cd01b6ff8 | |||
5f85e33510 | |||
22301a4599 | |||
c8a907fd71 | |||
d01b1ffde5 | |||
f4e993c814 | |||
91c8e82c42 | |||
776ff46db7 | |||
9001ab5858 | |||
1debe2292d | |||
6a2ba4baca | |||
836d897aec | |||
740b0fbbf6 | |||
92e716d93d | |||
c7115a0671 | |||
020bbed935 | |||
0c60963a94 | |||
d704f5f2d2 | |||
381bbb0e5e | |||
0ebd19c14a | |||
d4160afac8 | |||
fffb037873 | |||
1df5d0453d | |||
19d453cb90 | |||
6e7437a0d0 | |||
caf849fcba | |||
7533d244a9 | |||
0a52840fa3 | |||
a7d0905b74 | |||
05bfafbce8 | |||
d32a26f780 | |||
42ec780a6f | |||
4608880fb0 | |||
7492e2789f | |||
9564a8eaf6 | |||
f12c0e79c9 | |||
e4e0be979e | |||
86637cda9f | |||
94f41e2332 | |||
3d2a50f811 | |||
c2ffbb8627 | |||
54218f6c3c | |||
6fdbdf9272 | |||
3de7691af3 | |||
bbed93bcf4 | |||
8900b30b6e | |||
ae4fb799e4 | |||
3f1d1fb3c3 | |||
f0a23ae0ea | |||
c14f9cc247 | |||
e276b6463e | |||
9da7967197 | |||
74f2b78c04 | |||
2021f8cb5f | |||
40a9ebd078 | |||
8c1b73b29c | |||
6679a55693 | |||
1101c1d919 | |||
fcb529b348 | |||
680b1ca208 | |||
af74fe1711 | |||
494cf4049e | |||
c908b9f67a | |||
209f6d9d2d | |||
916077012e | |||
beb170e4fb | |||
a59912f3af | |||
610e594a50 | |||
b4e2547052 | |||
a9778549f2 | |||
b601041b5b | |||
0945d6ec0d | |||
78d9cee416 | |||
bbdb2aa672 | |||
574b24c082 | |||
874a187c7f | |||
e8fb443313 | |||
57b96af2c4 | |||
e61d4ab67a | |||
2ee358dbfc | |||
e3bb67d188 | |||
2d289a3308 | |||
bdb2cc7c85 | |||
7793060723 | |||
84302ae9c7 | |||
cd801b96fa | |||
5ff0653f9e | |||
9574d635c1 | |||
1bec8ddce4 | |||
f9b07c63db | |||
8828fc7520 | |||
978d8fcd4a | |||
51aadcf901 | |||
db952a050a | |||
f049740ae5 | |||
73ca9b6373 | |||
c6949aad2d | |||
e57d0fdccc | |||
82f383be43 | |||
26aaf253ac | |||
51715376bf | |||
ff95b0278c | |||
fe1fa20c6c | |||
a867fe404b | |||
d6e8a5f3ca | |||
4878d8ec15 | |||
f7019d9e80 | |||
6d8e1e8783 | |||
939ab43ceb | |||
d3d58ba8a7 | |||
f03fd57997 | |||
e74cd4b4ef | |||
f3dfd63634 | |||
5f5302e595 | |||
125ec622ca | |||
384e5b66de | |||
7e7723e98f | |||
4419734a7d | |||
f821db29f3 | |||
6c64f1816d | |||
34e2ad0dfc | |||
055b99c3cb | |||
531842dc6b | |||
d7f3c33d72 | |||
4e689998f9 | |||
cd2a4b709c | |||
d96aeac335 | |||
c594351bcc | |||
5f976d7430 | |||
f87326fc21 | |||
0574a70fac | |||
4e79804cd3 | |||
86d5264167 | |||
5bc4399a58 | |||
406bcf7d3f | |||
f17cc1c6d8 | |||
57077e4607 | |||
6304c85d3f | |||
a1992d76f2 | |||
98b07f7f3c | |||
6e1823ac81 | |||
640cc22749 | |||
9bab49d2f9 | |||
2751a6d56d | |||
07cb62a503 | |||
8a3b698407 | |||
0c71d658fb | |||
7e2d614975 | |||
09e4ab9aa1 | |||
2e1bc6e500 | |||
1aea096b63 | |||
30694f0b20 | |||
01b4cb64ee | |||
6fbd15f8b2 | |||
65c07afe05 | |||
e338c5f91d | |||
0b0b5da240 | |||
9c7ee5a21e | |||
f7b3ffe8a0 | |||
381857ea49 | |||
50aef368f6 | |||
a9c4ce38f0 | |||
bbc39d7648 | |||
d3e8e9629b | |||
1f0b3a32d5 | |||
0608704626 | |||
cb8e7b4d5e | |||
346fa4d7f4 | |||
7a22f01dd8 | |||
4704d115c4 | |||
12c621c230 | |||
cba65d897a | |||
e4a10cc510 | |||
249c27afd5 | |||
38cc89b2ca | |||
aeb1794be1 | |||
dae728124e | |||
cf30b1fcdf | |||
19bfef36f1 | |||
8d9464c414 | |||
ada611d597 | |||
f13886d343 | |||
520b0601db | |||
926ecf9640 | |||
c57198decd | |||
431716e249 | |||
694709f392 | |||
16613ab5fb | |||
c26bf45e28 | |||
23e5c7b38d | |||
382dd82eb6 | |||
f18d5b2efe | |||
0fb22df633 | |||
750e36993f | |||
f7f658605d | |||
192e5dbff8 | |||
ef224c3547 | |||
c12b68a6b2 | |||
4166d8ca35 | |||
53e7e950f1 | |||
0612879dec | |||
3b21f946e4 | |||
9f85371073 | |||
cb550ab4fe | |||
b8cbf08617 | |||
1613f42d00 | |||
e5d1243dd2 | |||
7fc9094d8e | |||
92c7070aa8 | |||
b68bca35db | |||
d97adc8789 | |||
f5014d7d71 | |||
4e88c80a22 | |||
a6203ed038 | |||
1db547d607 | |||
2cc4dc5a6f | |||
fac7dc9c91 | |||
508fa6a7fe | |||
71bdaa9508 | |||
459f1e7bfb | |||
0d8b8d8426 | |||
2d0dc62a53 | |||
0d8e134f9f | |||
c7d370c17f | |||
395d8b3139 | |||
b92ef67e56 | |||
5a8aa66641 | |||
e87ef18826 | |||
7b78d4f11f | |||
65ac61b2ea | |||
629a3a2a24 | |||
ee4783e3fb | |||
f2c69ede96 | |||
ceeb35eaac | |||
099bedd2e9 | |||
4177a11522 | |||
3d4a1b575e | |||
b1d60df44c | |||
7cf70d111a | |||
e564c56dce | |||
239c2540d6 | |||
c53d140145 | |||
12a6a2f2d2 | |||
9c903567bb | |||
6782dee64a | |||
302c15140e | |||
c666f92e35 | |||
eb42ef68ee | |||
52916eebcf | |||
f8014413a3 | |||
2d858b05ac | |||
b1fb020aea | |||
02ed84774c | |||
283e8d5bc0 | |||
f39e2e2a53 | |||
5bf5d5e9cb | |||
e51e212b95 | |||
6418d02572 | |||
49fa30d495 | |||
dd8b03a5c5 | |||
4d5983114c | |||
0a9c3b5571 | |||
180049a277 | |||
6ee201865b | |||
b1d94c9f93 | |||
a156a4dbe2 | |||
2cebe7a5e0 | |||
9cfc109527 | |||
64758c46b6 | |||
4352202349 | |||
ba07a60c44 | |||
72bfe0953a | |||
bab5647522 | |||
fcaf1d89c2 | |||
106dff0d53 | |||
174ba8884e | |||
1ce0dcf0ea | |||
1387e15c1b | |||
50e7ea088b | |||
59b7cbb591 | |||
23fe8975e7 | |||
a4bc40542b | |||
ee1dc16e8f | |||
1c04cc0485 | |||
2c682b4d1c | |||
6842490c1f | |||
ff5e22031a | |||
e3cf756785 | |||
7e6598e9ca | |||
48d2017629 | |||
e4823381c6 | |||
66feaeb519 | |||
8c6b833fb3 | |||
b62296a40b | |||
fc7728212f | |||
31785f7f6e | |||
ae65eb5105 | |||
727ccb1125 | |||
77ce238457 | |||
1685659e37 | |||
0f03d4ef51 | |||
bcf697cc2b | |||
5e2ea4a81a | |||
b9e1d53d7a | |||
ab0806a036 | |||
3a1ec07db0 | |||
d939d8d21d | |||
d9552fb120 | |||
4ecc0c59ca | |||
0655a1fcbe | |||
c8d0cf2c40 | |||
c692f2e740 | |||
a83c7c0d07 | |||
ba6fd16823 | |||
54893c35c1 | |||
495c5ce81d | |||
4cc773ec1b | |||
69ae35494e | |||
512c3af4ea | |||
d8f1c3dff7 | |||
0a11dd2d24 | |||
78ee7f6573 | |||
dab0fb9e05 | |||
e14d5d49a1 | |||
782b2b1514 | |||
a9582417e2 | |||
69922b6c39 | |||
6fc70f7c16 | |||
a274e774ee | |||
f23a43fb81 | |||
88997a0314 | |||
d2415dee00 | |||
53728b79b4 | |||
dff8c02cfe | |||
640ad577d1 | |||
cd63ecd3f3 | |||
f18158a52d | |||
84748aab51 | |||
3fadc64ee0 | |||
47594f7c99 | |||
2f20258807 | |||
47122a3804 | |||
1730f8f5b7 | |||
d258a75cd3 | |||
baa10c2995 | |||
207d6572e0 | |||
10264cec2f | |||
0ea1749c59 | |||
dd83c680e5 | |||
1a40f35fd4 | |||
8a99113c88 | |||
ada2ea3a6b | |||
355cce3938 | |||
9b2e08dd09 | |||
04cee3b8d3 | |||
c61440efea | |||
02d18af57d | |||
2225bb093a | |||
75a6a7baca | |||
6b130e8311 | |||
1b18923824 | |||
fc2ce439e2 | |||
5b3d9f9184 | |||
dd68c207f4 | |||
9a3c34b5b3 | |||
951d911531 | |||
4f2179b0df | |||
9b287392a4 | |||
aa06470cb6 | |||
d7b4f24a7a | |||
e8d11eb5c5 | |||
7f4da08ff7 | |||
1f9414a30f | |||
6015b529a0 | |||
76452b4e28 | |||
64b7d9ef82 | |||
7bc9666aac | |||
2a4a50b1da | |||
2ec88e8008 | |||
36049a940c | |||
952834f7f3 | |||
f9a9c2d009 | |||
fb71a6e2b4 | |||
5e6a2a17b0 | |||
92289c1981 | |||
99e2098a48 | |||
5fc1c1de28 | |||
2fac693243 | |||
e9b956ed71 | |||
236a952458 | |||
426b7c2c76 | |||
22780a8504 | |||
a437fd420c | |||
2d74c60d47 | |||
ceee56af51 | |||
d297d8fe2e | |||
f479b76772 | |||
73f7088b45 | |||
b3dd5c0e3a | |||
ee7ee22555 | |||
cf49e511a5 | |||
505b9c7f56 | |||
8c30b2b9f5 | |||
b9c1407013 | |||
d905607353 | |||
e5e90b1f71 | |||
d5ed025871 | |||
b55422a528 | |||
909a14fb48 | |||
107e3e4106 | |||
6ef247fb93 | |||
b8e46b835b | |||
0900fee5d9 | |||
1f26cb98de | |||
ceeb8ee0bc | |||
54c47a1e03 | |||
6bb855873d | |||
39db45e144 | |||
41c187ba12 | |||
d7c99728bc | |||
8e19188f49 | |||
625e3e8e25 | |||
fde99e2fcf | |||
132643cd4a | |||
faf7b81c01 | |||
bcc6799902 | |||
718e1d6c08 | |||
a9ce773584 | |||
d69bc4fb5e | |||
1b68d6dbdc | |||
62578a2162 | |||
9e80db0fd1 | |||
e8ab6adf89 | |||
7c184cf991 | |||
72def658d0 | |||
e7cd888c7d | |||
1205578935 | |||
4e77365e8d | |||
4f2a779769 | |||
cafbe44dde | |||
6234bfd8bf | |||
77796caba6 | |||
97f1d7ae2e | |||
487e89d4d0 | |||
fe5257df81 | |||
9161424c97 | |||
cdda0dd043 | |||
f4feccc626 | |||
44cb2f4efd | |||
cacb8fae0d | |||
fa99a5cf12 | |||
e700165eba | |||
8542ee59db | |||
76108671f6 | |||
8b0ce1cc00 | |||
0e88c73f68 | |||
ba0d73d102 | |||
d3ecd1d670 | |||
f9ae5938d0 | |||
a8ced184dc | |||
e7a2c6ecef | |||
a376bcc654 | |||
8e1ac9fb0c | |||
bc61357a44 | |||
f6d92eb737 | |||
48cadcd2fc | |||
bd63a840c7 | |||
aaf597f020 | |||
72bd3064a2 | |||
a1c316b940 | |||
02f84b225c | |||
6551c20005 | |||
a1e94154be | |||
4938e82795 | |||
7a94f63058 | |||
db0edf154c | |||
a1cd94a61d | |||
df48738ac9 | |||
d8f5cfdee4 | |||
95e5345cc3 | |||
ba5d0cc2f9 | |||
1d8ded3293 | |||
2487a8bede | |||
f1c0563c40 | |||
139c4b5633 | |||
645bf4a764 | |||
88a4a3b1ba | |||
6fabaae736 | |||
1b2cfd63e5 | |||
ff2b219abd | |||
33c3af752b | |||
f73a1d2d56 | |||
470ad39d0d | |||
5ad120208f | |||
b48a70db2e | |||
cd050b3423 | |||
eddbc7e757 | |||
8a62ba07e5 | |||
b3298a8f57 | |||
e5284771e4 | |||
5f611dad51 | |||
1c5fdb8a0a | |||
de4b9e9a16 | |||
57b5a33fbb | |||
3f4f7145a3 | |||
b959148447 | |||
855361b5b8 | |||
91c9f4cb20 | |||
e4896b257f | |||
592cac5815 | |||
4244cca48c | |||
179ab5220a | |||
d6bb1b72c3 | |||
3d9a5a4f91 | |||
683ba79ff0 | |||
0c69fc719f | |||
03b48a4ad4 | |||
aa71292265 | |||
d72eee6cf7 | |||
6bb19e7947 | |||
3d2518f799 | |||
5268909075 | |||
c62141fd98 | |||
ae303ee902 | |||
cfe0d0971f | |||
c5c8facc2d | |||
f78d6a8a93 | |||
78ef2c5f16 | |||
ec8e1178e5 | |||
4f3f471b4c | |||
e10325e133 | |||
ef46d3c97d | |||
a9c08c5975 | |||
c467c3b7e4 | |||
cdc0eaec3a | |||
a7cb738175 | |||
d1bb22a583 | |||
553d972de5 | |||
cc883cc3d8 | |||
c6a39ed927 | |||
df30255542 | |||
d5102539dd | |||
e3feaf3f5d | |||
25dc596397 | |||
0daff26fba | |||
94ba5b3fbe | |||
002f9bb105 | |||
e86b1146a6 | |||
d44fb3a2f6 | |||
1ef3069a7e | |||
f99b62c48d | |||
0fd45a640b | |||
0b0d03dbe2 | |||
533baf921f | |||
8e9767f3c6 | |||
27d4bedd73 | |||
c1c26ec73a | |||
8f592ff6e8 | |||
37629aaf87 | |||
d09d193715 | |||
010d0a7d56 | |||
902807ea50 | |||
d0224b3623 | |||
0f3148bda2 | |||
e3b1fc2ac0 | |||
6194d2af3d | |||
db87d95c1d | |||
47166c9614 | |||
ecacdf27a9 | |||
aad6f79efa | |||
0c00b83702 | |||
7320e26730 | |||
1520534660 | |||
6d6719da27 | |||
20085cd15b | |||
9b001823f6 | |||
ed4f84cc57 | |||
c8e66a2b45 | |||
6eb2e3ffa9 | |||
748ad8a978 | |||
d2f897f8de | |||
4b511d80a1 | |||
a74e9e1dd3 | |||
9c1a9f984b | |||
04c7adea07 | |||
5249ce8fb4 | |||
ebd865dbda | |||
d377ef01af | |||
393aa3c527 | |||
d7b6de57c5 | |||
05d4b0cd94 | |||
5dbafc2eeb | |||
a97918f812 | |||
22f86df606 | |||
712e8e828b | |||
7d3846bc49 | |||
9980526aaf | |||
1d2cb867b2 | |||
3859533e73 | |||
7ea7e1898a | |||
5e6a4e5f5e | |||
66dfc33de9 | |||
d56f740dc6 | |||
a109d341ef | |||
87b53d67c5 | |||
a577b8d381 | |||
136fddc7f1 | |||
ce0c87f8ff | |||
d79585d44d | |||
592b628523 | |||
39f886ad88 | |||
1d39be61b2 | |||
2bf9145ae6 | |||
127bcb02ff | |||
4430fc47c6 | |||
2b10a982e9 | |||
31bece7fa0 | |||
4436824faf | |||
dd92f1d03d | |||
b6f87565a9 | |||
0b909997b8 | |||
9d7ff26f25 | |||
06c866ceb4 | |||
fe19ad328c | |||
010dbc8b2b | |||
72653e54f9 | |||
93ec86a26e | |||
10185e92fa | |||
33b94e8478 | |||
2ee53b0e75 | |||
fb00f0f94c | |||
b679ebde3b | |||
f3ca08b0f1 | |||
946e413997 | |||
b475bf4a21 | |||
54fa73844c | |||
32f5a0ab18 | |||
e4135ffb35 | |||
b5b335a6f8 | |||
57ef31d51c | |||
61b413b57f | |||
d2c0203dc9 | |||
afba19e01c | |||
b989c03416 | |||
3361b4030b | |||
bdadd50251 | |||
d01f31197a | |||
8b82f1c609 | |||
de7e8a1ca4 | |||
aa2ee3f7be | |||
af4e79735c | |||
969e09210d | |||
cd7b571da0 | |||
0052877d2f | |||
23bb44f2d6 | |||
16f11e91d1 | |||
4b11566505 | |||
9ae49b5b85 | |||
c95bae2d73 | |||
e4b6611201 | |||
e6840a1863 | |||
78d5f1a803 | |||
42f28bce52 | |||
9a6c3e05ad | |||
cdc289fa9c | |||
672f17c6e9 | |||
723a9a6e9a | |||
59ba7c8bf5 | |||
78d548458b | |||
ac3e883c05 | |||
9ddc2a4331 | |||
435e4c4695 | |||
21f4a97c35 | |||
e0d63c50db | |||
803f74634a | |||
f85a630a64 | |||
43182f8f57 | |||
594cb1fad8 | |||
5eab6c2e5d | |||
3587aa1ea7 | |||
beb642faa5 | |||
31db768e4d | |||
d9e4ba1280 | |||
dcb1233b0d | |||
8a2ff0b31e | |||
be2881ae8d | |||
88cba48f45 | |||
9284e4edfe | |||
62a705af1c | |||
29ec7bf3a2 | |||
fc3f4fb988 | |||
60ff280dcb | |||
b378f5dcd7 | |||
e778d45128 | |||
5e11cf6378 | |||
5dbebc513a | |||
6d5a3cd2e2 | |||
f9ad80aa13 | |||
ed31cb76d6 | |||
eebd271bb1 | |||
ff74ec2482 | |||
49e31ca647 | |||
471108f2e4 | |||
2ceb162df0 | |||
915206405c | |||
5fa1d9796c | |||
77a1dd4737 | |||
9e7c778cc8 | |||
1d775af34a | |||
9f7919f71f | |||
0b3b994241 | |||
bc218f9414 | |||
f102fd7f92 | |||
64774d0d4f | |||
b88f573733 | |||
b211e61671 | |||
871cacf040 | |||
7c3984413e | |||
967ce78a57 | |||
923d3f1fe8 | |||
e11f42a089 | |||
9b8d9b7042 | |||
902e03bccc | |||
ec0e8a9a43 | |||
9e488ce322 | |||
c111bf3080 | |||
8f2a42d1ad | |||
9a475eeff9 | |||
91a37ec639 | |||
db1e2aae41 | |||
4a7c76a11b | |||
f1ed57c62d | |||
3b0969e3a5 | |||
35174a8766 | |||
d79f792e6f | |||
7b231b38b0 | |||
13263b8401 | |||
a604294b1b | |||
89d74cd293 | |||
56e5b34934 | |||
f43365e4ba | |||
4d071081bb | |||
b67b370dba | |||
0995c1dcaa | |||
7612bf3302 | |||
ba158d8dc6 | |||
a90f2249e8 | |||
d8f36db5dd | |||
fd460d93c4 | |||
989cbb4d8d | |||
e9007b1f56 | |||
0fb3d1d582 | |||
81910c1d92 | |||
d150f9b2bd | |||
1346e31a8e | |||
54f25b14ee | |||
0e4d3244b2 | |||
87e3b5f076 | |||
f8e18f2098 | |||
f81c67c0f0 | |||
4f4dd3446c | |||
f149dd9401 | |||
3a730c4a5c | |||
b03247ec3c | |||
8ebb49e972 | |||
84bfec8329 | |||
e1727d6297 | |||
e7bab66d29 | |||
ab25c96821 | |||
c6b0b07605 | |||
b5b583c397 | |||
56d969c709 | |||
3fedf16f35 | |||
5da56776d6 | |||
d58870a92d | |||
15ed7423ac | |||
d7e7ad4f88 | |||
823a1963f6 | |||
6513b21426 | |||
d4321cdd41 | |||
d301540d92 | |||
af5a3376f3 | |||
4aa52ffc77 | |||
47b62ece18 | |||
2aab26a08e | |||
565842b5ec | |||
a064e19b8a | |||
6fb49f68fc | |||
ef7faa7291 | |||
d5528e4e9a | |||
f730f65aaf | |||
dbd577c6b0 | |||
7ebb207005 | |||
e41d71cd19 | |||
0f6c53589e | |||
e2b1a7157e | |||
aaf69d1aff | |||
203b7e17de | |||
18c9dc8a06 | |||
ba07d1f91d | |||
9a2310395d | |||
218ace51a7 | |||
f09eedbd7a | |||
546e8a3b44 | |||
9a2b766aad | |||
24017659df | |||
c175a5fcd7 | |||
5ec8465374 | |||
6b5d6efe6c | |||
5bff70194b | |||
d94d04d7d5 | |||
bf2b9e3692 | |||
c8554504f3 | |||
0d066e3b08 | |||
6b12d86209 | |||
fe530548bb | |||
2eaff6d484 | |||
a54c2b438c | |||
890f6f0d35 | |||
bad4b72f82 | |||
4702c5b4ee | |||
4459d5ad54 | |||
39fb4b1b42 | |||
3864a2e111 | |||
697520f1f5 | |||
244f37179c | |||
4b3a47849d | |||
56faf774ff | |||
fa2bb91ae5 | |||
32478845b2 | |||
44f0e3097e | |||
289917e2b3 | |||
14fcb5867f | |||
cf59362c4a | |||
8472918559 | |||
ae8f51d608 | |||
4a7ee5472d | |||
8718b33a66 | |||
27f1155f1b | |||
84732fcb12 | |||
c6c578ce1d | |||
3c5e28a27d | |||
a39f6e9b4c | |||
adb7a88836 | |||
9892f7bb47 | |||
42ba70e79e | |||
cbaef66e82 | |||
97d915b06c | |||
3a3a23db34 | |||
d159e5ca44 | |||
d3bd10952e | |||
40078a99de | |||
0142c0d339 | |||
2e5de46584 | |||
1be55d6182 | |||
8ebcd44405 | |||
ccdd4ffda7 | |||
a6ed711492 | |||
3fb224cb22 | |||
5ca5af619d | |||
f61c5836b2 | |||
535b33b46e | |||
a8847de910 | |||
2231e878d5 | |||
299a7cab20 | |||
e48d6880c9 | |||
673c0c811e | |||
6e1da35c12 | |||
25f9c294dc | |||
2ea9f516e1 | |||
dbe1461886 | |||
7bea709747 | |||
6536474b94 | |||
ab4021dd0e | |||
1fcbb1fbed | |||
39333c9e8e | |||
1615ef1114 | |||
bf8d71e82c | |||
a4c2740852 | |||
afa1b8cb2d | |||
5447c01e1f | |||
b4bacd50a1 | |||
3c248ec61a | |||
78a8ceda0e | |||
14bf326de2 | |||
dc549b7f3c | |||
456c7ca661 | |||
bab75186f5 | |||
07b2a3818c | |||
15c6e2ec70 | |||
5bd8968eb8 | |||
4ad942522b | |||
b6c99ba3ef | |||
ee5bd57d40 | |||
6445337a32 | |||
f20c7303e8 | |||
c4c8ea62e2 | |||
71aadcbecb | |||
fd71ceeab5 | |||
e26bee45fb | |||
1b10d3413a | |||
f0fcd222a1 | |||
298e4a9f14 | |||
12d32b9311 | |||
226123ca08 | |||
5ebf5077f5 | |||
e1c930f1b7 | |||
c61ca1dea2 | |||
eea712a1ae | |||
1ebfca666d | |||
005b5aacaf | |||
7cf3d2caa1 | |||
e1f9f7b6dc | |||
6b0543ba27 | |||
3d948a930e | |||
6f3595bfd2 | |||
4524899e4d | |||
54206fd44d | |||
6d8c8f9fd1 | |||
00e1b0ed10 | |||
4f8feaa530 | |||
0324e6ca3d | |||
d773ab2806 | |||
8e76363ccf | |||
360c84e035 | |||
4868d21526 | |||
c802811ad2 | |||
5f63d5039b | |||
a454a37a6e | |||
a78d7311a6 | |||
08ff666e99 | |||
0d108d37f6 | |||
cae9041c2a | |||
330a07a554 | |||
7729cbe313 | |||
3e865067be | |||
b03c7b2f30 | |||
1ab9c43135 | |||
efcc24a76b | |||
4762311977 | |||
ab2ccb094a | |||
3c00cd0f88 | |||
a7718bae39 | |||
8ffae313fd | |||
8cced06a2d | |||
965399ba0c | |||
231cc11a62 | |||
1afa9e992c | |||
be543c4039 | |||
7e7462b39e | |||
d2ee37a3e0 | |||
1fcedb8d16 | |||
5c476391da | |||
6cb23e7069 | |||
c976b87ac7 | |||
af2bdfc421 | |||
b01c551197 | |||
df6d3ca66b | |||
5be7374f56 | |||
7300005398 | |||
6cd36edf45 | |||
604a0b1fe6 | |||
046d5bb9ff | |||
0e8442064e | |||
ea1f2762cf | |||
0f3095f130 | |||
7b7ec13349 | |||
7025c7090b | |||
7c12991f57 | |||
f444da80bc | |||
ed58467d12 | |||
c44c3b0530 | |||
46e9c1195c | |||
4730111492 | |||
a813e29491 | |||
344a25c133 | |||
772599a6fc | |||
3a3fe272bb | |||
88e3fe699c | |||
27d997a2e5 | |||
8809c6d122 | |||
6469aa9df9 | |||
ce6b5bc6f5 | |||
4f3775bb86 | |||
2cb760e0ac | |||
8850a8610a | |||
2d6a4e5974 | |||
93b4ac5cb2 | |||
e2509af163 | |||
3f4c166861 | |||
e53f63ca87 | |||
6a50291aa2 | |||
e59ed3e68f | |||
45c4ccb153 | |||
adeb7e7da0 | |||
f1c8706485 | |||
d5f4d381d0 | |||
69c5976775 | |||
988049f39b | |||
6651b8310e | |||
0843ed62fa | |||
d817039f79 | |||
f0794e09b7 | |||
9eaa3756f8 | |||
1eeebba2f7 | |||
2fc3d12fb6 | |||
4fe9a4fe83 | |||
01129d02b3 | |||
e1fbf7b34c | |||
7e90ab3534 | |||
5ee1ccd659 | |||
0b44919ba2 | |||
9f550292fe | |||
5ba7ca91c0 | |||
cc4bacc199 | |||
15c07c58b6 | |||
236fdb450c | |||
7e4b6b594b | |||
eac3667ec1 | |||
e35bca2c3c | |||
46049a1ef6 | |||
1f74dd4589 | |||
40d3993ceb | |||
0564bb3b35 | |||
29711e123f | |||
d3524f3609 | |||
d87f0293e3 | |||
5fadd8bdd2 | |||
3366b53247 | |||
68e549233d | |||
24fce0be86 | |||
740b34124f | |||
15402933bc | |||
8d0b2b781e | |||
83abc00aae | |||
5b6d27e659 | |||
ced8dfc639 | |||
8ef0e4bbaf | |||
0da9a9a3e0 | |||
cba37c6107 | |||
ea1da3321a | |||
34b146f28b | |||
fb46a546db | |||
debc4c45ee | |||
ab9afbc749 | |||
ef87069957 | |||
0d4109a9f1 | |||
16df2c3363 | |||
5ed5b22525 | |||
dccca7df1a | |||
1f6b13b7fd | |||
d23ade879b | |||
8afdb0aa65 | |||
daf8a66ced | |||
20278bb9e4 | |||
c7a4da3dd3 | |||
1908aa55f5 | |||
1c08f5e857 | |||
c9ee8612e4 | |||
a7d988745b | |||
a9f404aac3 | |||
ff9f8b1c2b | |||
b5c86b6ba4 | |||
407ad659ea | |||
f2d2df2b11 | |||
48a374c82c | |||
deee39343e | |||
8a2e8bd585 | |||
43780742b0 | |||
68a966fa55 | |||
43b3ec4b1a | |||
dcf1f70868 | |||
598ca48ed6 | |||
3790ebe77a | |||
d7f2287ce9 | |||
9f717e79ea | |||
26d43c9b06 | |||
8682c90c7d | |||
d063f583ee | |||
eebcf08084 | |||
01aa469591 | |||
4992ac2d9f | |||
412979ba8f | |||
4f8253dcdb | |||
4931e44998 | |||
d1101441b3 | |||
e8f6b4b5d3 | |||
94263ffcc1 | |||
a3bdae9735 | |||
d5e6f59004 | |||
22271f2a49 | |||
8b6d23b9f6 | |||
25056de5d3 | |||
994b25af4e | |||
74afef8eb1 | |||
54489a7f61 | |||
8e3004591b | |||
2ff2a8fd9a | |||
c2a01f6db4 | |||
7a00036954 | |||
914c42537c | |||
cb63babac4 | |||
ac1c127b68 | |||
cb82193333 | |||
f0636ffd4a | |||
51a420671f | |||
77c2bf3ad9 | |||
7223685b96 | |||
e7dff1c785 | |||
a5383d83d8 | |||
a3c7627acf | |||
297b1b4258 | |||
35ac995d05 | |||
6bd5aba4fa | |||
fb5217761b | |||
90f3e94565 | |||
ded5a53a6c | |||
d637988ccf | |||
858e8c5217 | |||
df1ce856c9 | |||
b5e0d014ab | |||
5eaf397a94 | |||
1814016eb7 | |||
6ecb42b031 | |||
584228b2b5 | |||
cd3683f2ba | |||
347ebcd899 | |||
e52c2c41ec | |||
95ff057e04 | |||
60bc291414 | |||
c476285bd6 | |||
63e8ad4cc3 | |||
2cdda38dc4 | |||
ccea3d04d6 | |||
90bd3e07a0 | |||
8e3463d47a | |||
8d594f8b53 | |||
5f4df0c6a9 | |||
0ee4d3554a | |||
0a7a33ef8f | |||
32fa061700 | |||
7036831203 | |||
68b4ca9b31 | |||
0dfc08b317 | |||
77f7dcf40a | |||
9a3c652a51 | |||
6db47de25e | |||
b0d888d235 | |||
af53e63ae2 | |||
35d5ed9c2b | |||
9827b8991d | |||
4dce71879f | |||
727fb197d8 | |||
c2f10a52de | |||
cf2ec0797e | |||
6443049f86 | |||
44bee4e3ff | |||
212a5af9a5 | |||
1cadbfb4d1 | |||
4729fec2eb | |||
f119c4a456 | |||
3e261fb999 | |||
0fd3afe2c8 | |||
9dc507c9ae | |||
5d37eabb59 | |||
169664ffc2 | |||
4c0a7c0fb2 | |||
faa9a06bf5 | |||
183434d30e | |||
c84ce76c59 | |||
1833c61556 | |||
ba78676ace | |||
0d37b7b665 | |||
1254dece5b | |||
b7ebf6edbf | |||
b72847d504 | |||
168b86fdcd | |||
a13f4d8353 | |||
cc808cc2dd | |||
ce001198d8 | |||
c0639ccd37 | |||
58701c1ca8 | |||
402d99ea8d | |||
b08ca49580 | |||
bd15262e54 | |||
3cb2e1197f | |||
7762cd680b | |||
c30f74987f | |||
628ef14d80 | |||
bc48a097f8 | |||
dd21c8a577 | |||
7d906df805 | |||
d166b494ee | |||
81959f14af | |||
2300f3c92b | |||
73fd934fec | |||
a7b635a980 | |||
91b8d6f34f | |||
c9d7845fea | |||
0b0cda2be4 | |||
e1310a764a | |||
dbf3e6c3c9 | |||
dee7f75f7e | |||
774c7e0ea5 | |||
4d498b3765 | |||
bcd05fbdfa | |||
2ba9343607 | |||
8ae07fb9c9 | |||
13682bd919 | |||
b5cab8afaa | |||
c15c9775bd | |||
51cf49a24f | |||
00fd9c3a15 | |||
8007ca56aa | |||
8d7f851b4e | |||
5b13b282ed | |||
d965768004 | |||
a91187e60e | |||
179324e44a | |||
c6dba50e35 | |||
b51d68a419 | |||
a0db48571d | |||
4d7f625aa1 | |||
e2f783ebbd | |||
7a12d8193b | |||
4d9b74b171 | |||
37d139177d | |||
8a7753cfe3 | |||
331382cf2f | |||
98152d974a | |||
56febbf2ba | |||
5cf410490e | |||
404a0bbddd | |||
f057bb63cd | |||
7e6e56e2bc | |||
67cb03742e | |||
a08246ce5d | |||
f54d5e9e8f | |||
91940cbcf5 | |||
77bd8aacd1 | |||
ecc1324bb0 | |||
d3b0081447 | |||
22e44c762b | |||
78e5a00a68 | |||
b9a4d138fc | |||
36a9aff283 | |||
e1755e569e | |||
ae374a78fc | |||
62befe006d | |||
1e6e112806 | |||
830250759c | |||
13100b245c | |||
4929be08f7 | |||
088bbd1c08 | |||
7404eb46c4 | |||
eaf6d6c938 | |||
02d288e9d4 | |||
6f15c4a561 | |||
ae491c277e | |||
ebe7e15475 | |||
dced40361b | |||
faf864b8a2 | |||
8a23d764de | |||
f21af60a13 | |||
10564d8e14 | |||
095aef5f30 | |||
145ac31c8a | |||
b7a5f783ba | |||
3d25a2ea02 | |||
76b785c90f | |||
b3073f44a2 | |||
bcdd158ad8 | |||
693ac4e86c | |||
6320879fe1 | |||
2afe3d89d0 | |||
8a15b42dab | |||
4b9e84f42f | |||
ba87640e4c | |||
a5400e0162 | |||
1a89694980 | |||
0e6065e3d5 | |||
a156fec25a | |||
fe725f9995 | |||
58207b30d1 | |||
f4192d7b9e | |||
e747692727 | |||
d786c5265f | |||
ba0a45365c | |||
decb4261d4 | |||
b0971e3a01 | |||
583cd25506 | |||
1beacc8c32 | |||
9f880d07ab | |||
3fc11e2278 | |||
1756e8b0f2 | |||
d57e343245 | |||
7e17a2072c | |||
9c94d6527a | |||
5da4fd2aef | |||
e621058cfd | |||
f2e2632ae7 | |||
35d1736c97 | |||
3c534abc99 | |||
c3deedd6fd | |||
b256111a17 | |||
b5a90a437b | |||
6d114b7480 | |||
c8f85ffec9 | |||
bae0060552 | |||
c8750e5812 | |||
89cb0e260a | |||
2c1a8524f0 | |||
b085329bca | |||
188f8021f8 | |||
975bcb8aff | |||
51e74f8d4f | |||
b4f3dfc347 | |||
41328eef94 | |||
59cf2ea341 | |||
67d472424d | |||
1d27adb102 | |||
940c0f2b93 | |||
d5620288d5 | |||
da30d2898e | |||
40198d6c13 | |||
4653ebc97f | |||
acd6978a30 | |||
ccbd6f97cd | |||
b4a8057994 | |||
225c2b095b | |||
0582338015 |
75
.clang-format
Normal file
75
.clang-format
Normal file
@ -0,0 +1,75 @@
|
||||
---
|
||||
BasedOnStyle: LLVM
|
||||
BreakBeforeBraces: Stroustrup
|
||||
IndentWidth: 4
|
||||
TabWidth: 4
|
||||
AlignAfterOpenBracket: AlwaysBreak
|
||||
AlignConsecutiveMacros: 'true'
|
||||
AlignConsecutiveAssignments: 'false'
|
||||
AlignConsecutiveDeclarations: 'false'
|
||||
AlignEscapedNewlines: Right
|
||||
AlignOperands: 'true'
|
||||
AlignTrailingComments: 'true'
|
||||
AllowAllArgumentsOnNextLine: 'false'
|
||||
AllowAllConstructorInitializersOnNextLine: 'false'
|
||||
AllowAllParametersOfDeclarationOnNextLine: 'false'
|
||||
AllowShortBlocksOnASingleLine: 'true'
|
||||
AllowShortCaseLabelsOnASingleLine: 'false'
|
||||
AllowShortFunctionsOnASingleLine: None
|
||||
AllowShortIfStatementsOnASingleLine: Never
|
||||
AlwaysBreakAfterReturnType: None
|
||||
BinPackArguments: 'false'
|
||||
BinPackParameters: 'false'
|
||||
BreakBeforeBinaryOperators: NonAssignment
|
||||
BreakBeforeTernaryOperators: 'true'
|
||||
BreakConstructorInitializers: BeforeComma
|
||||
BreakInheritanceList: BeforeComma
|
||||
CompactNamespaces: 'false'
|
||||
ConstructorInitializerAllOnOneLineOrOnePerLine: 'true'
|
||||
ConstructorInitializerIndentWidth: '4'
|
||||
ContinuationIndentWidth: '4'
|
||||
Cpp11BracedListStyle: 'false'
|
||||
FixNamespaceComments: 'true'
|
||||
IncludeBlocks: Regroup
|
||||
IndentCaseLabels: 'true'
|
||||
IndentPPDirectives: None
|
||||
IndentWrappedFunctionNames: 'false'
|
||||
KeepEmptyLinesAtTheStartOfBlocks: 'false'
|
||||
MaxEmptyLinesToKeep: '1'
|
||||
NamespaceIndentation: None
|
||||
PointerAlignment: Left
|
||||
ReflowComments: 'true'
|
||||
SortIncludes: 'true'
|
||||
SortUsingDeclarations: 'true'
|
||||
SpaceAfterCStyleCast: 'false'
|
||||
SpaceAfterLogicalNot: 'true'
|
||||
SpaceAfterTemplateKeyword: 'true'
|
||||
SpaceBeforeAssignmentOperators: 'true'
|
||||
SpaceBeforeCpp11BracedList: 'true'
|
||||
SpaceBeforeCtorInitializerColon: 'true'
|
||||
SpaceBeforeInheritanceColon: 'true'
|
||||
SpaceBeforeParens: ControlStatements
|
||||
SpaceBeforeRangeBasedForLoopColon: 'true'
|
||||
SpaceInEmptyParentheses: 'false'
|
||||
SpacesBeforeTrailingComments: '3'
|
||||
SpacesInAngles: 'false'
|
||||
SpacesInCStyleCastParentheses: 'false'
|
||||
SpacesInContainerLiterals: 'true'
|
||||
SpacesInParentheses: 'false'
|
||||
SpacesInSquareBrackets: 'false'
|
||||
UseTab: 'Never'
|
||||
|
||||
---
|
||||
Language: Cpp
|
||||
Standard: Cpp03
|
||||
ColumnLimit: '240'
|
||||
---
|
||||
Language: ObjC
|
||||
ColumnLimit: '240'
|
||||
---
|
||||
Language: Java
|
||||
ColumnLimit: '240'
|
||||
---
|
||||
Language: CSharp
|
||||
ColumnLimit: '240'
|
||||
...
|
9
.clangd
Normal file
9
.clangd
Normal file
@ -0,0 +1,9 @@
|
||||
CompileFlags:
|
||||
Add:
|
||||
- "-std=c++17"
|
||||
- "-I../ext"
|
||||
- "-I../ext/prometheus-cpp-lite-1.0/core/include"
|
||||
- "-I../ext/prometheus-cpp-lite-1.0/simpleapi/include"
|
||||
- "-I./ext"
|
||||
- "-I./ext/prometheus-cpp-lite-1.0/core/include"
|
||||
- "-I./ext/prometheus-cpp-lite-1.0/simpleapi/include"
|
2
.dockerignore
Normal file
2
.dockerignore
Normal file
@ -0,0 +1,2 @@
|
||||
.git/
|
||||
workspace/
|
4
.gitattributes
vendored
Normal file
4
.gitattributes
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
ext/bin/tap-windows-ndis6/x64/zttap300.inf eol=crlf
|
||||
ext/bin/tap-windows-ndis6/x64.old/zttap300.inf eol=crlf
|
||||
ext/bin/tap-windows-ndis6/x86/zttap300.inf eol=crlf
|
||||
windows/TapDriver6/zttap300.inf eol=crlf
|
31
.github/ISSUE_TEMPLATE/bugs-and-issues.md
vendored
Normal file
31
.github/ISSUE_TEMPLATE/bugs-and-issues.md
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
---
|
||||
name: Bugs and Issues
|
||||
about: Create a report to help us improve
|
||||
title: ''
|
||||
labels: NEEDS TRIAGE
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
# Before filing a Bug Report
|
||||
|
||||
_Using these will ensure you get quicker support, and make this space available for code-related issues. Thank you!_
|
||||
|
||||
- [Docs Site](https://docs.zerotier.com/zerotier/troubleshooting) => Troubleshooting, quickstarts, and more advanced topics.
|
||||
- [Discuss Forum](https://discuss.zerotier.com/) => Our discussion forum for users and support to mutually resolve issues & suggest ideas.
|
||||
- [Reddit](https://www.reddit.com/r/zerotier/) => Our subreddit, which we monitor regularly and is fairly active.
|
||||
- [Knowledge Base](https://zerotier.atlassian.net/wiki/spaces/SD/overview) => Older wiki.
|
||||
|
||||
If you are having a connection issue, it's much easier to diagnose through the discussion forum or the ticket system.
|
||||
|
||||
|
||||
# If you still want to file a Bug Report
|
||||
|
||||
## Please let us know
|
||||
|
||||
- What you expect to be happening.
|
||||
- What is actually happening?
|
||||
- Any steps to reproduce the error.
|
||||
- Any relevant console output or screenshots.
|
||||
- What operating system and ZeroTier version. Please try the latest ZeroTier release.
|
||||
|
13
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
13
.github/ISSUE_TEMPLATE/feature_request.md
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: "[Feature Request] "
|
||||
labels: suggestion
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
If there is something you'd like to have added to ZeroTier, to go to https://discuss.zerotier.com/c/feature-requests/ instead. Issues there can be voted on and discussed in-depth.
|
||||
|
||||
|
||||
Thank you!
|
15
.github/ISSUE_TEMPLATE/game-connection-issue.md
vendored
Normal file
15
.github/ISSUE_TEMPLATE/game-connection-issue.md
vendored
Normal file
@ -0,0 +1,15 @@
|
||||
---
|
||||
name: Game Connection Issue
|
||||
about: Game issues are better served by forum posts
|
||||
title: Please go to our Discuss or Reddit for game-related issues. Thanks!
|
||||
labels: wontfix
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
Are you having trouble connecting to a game on your virtual network after installing ZeroTier?
|
||||
|
||||
- [ ] Yes
|
||||
- [ ] No
|
||||
|
||||
If you answered yes, then it is very likely that your question would be better answered on our [Community Forums](https://discuss.zerotier.com) or [Reddit](https://www.reddit.com/r/zerotier/) community; we monitor both regularly. We also have extensive documentation on our [Knowledge Base](https://zerotier.atlassian.net/wiki/spaces/SD/overview). Thank you!
|
123
.github/workflows/build.yml
vendored
Normal file
123
.github/workflows/build.yml
vendored
Normal file
@ -0,0 +1,123 @@
|
||||
on: [ push ]
|
||||
|
||||
jobs:
|
||||
build_ubuntu:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: gitconfig
|
||||
run: |
|
||||
git config --global core.autocrlf input
|
||||
# git config --global core.eol lf
|
||||
- name: checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Install Rust
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
with:
|
||||
toolchain: stable
|
||||
targets: x86_64-unknown-linux-gnu
|
||||
components: rustfmt, clippy
|
||||
|
||||
- name: Set up cargo cache
|
||||
uses: Swatinem/rust-cache@v2
|
||||
continue-on-error: false
|
||||
with:
|
||||
key: ${{ runner.os }}-cargo-${{ hashFiles('rustybits//Cargo.lock') }}
|
||||
shared-key: ${{ runner.os }}-cargo-
|
||||
workspaces: |
|
||||
rustybits/
|
||||
|
||||
- name: make
|
||||
run: make
|
||||
- name: selftest
|
||||
run: |
|
||||
make selftest
|
||||
./zerotier-selftest
|
||||
- name: 'Tar files' # keeps permissions (execute)
|
||||
run: tar -cvf zerotier-one.tar zerotier-one
|
||||
- name: Archive production artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: zerotier-one-ubuntu-x64
|
||||
path: zerotier-one.tar
|
||||
retention-days: 7
|
||||
|
||||
build_macos:
|
||||
runs-on: macos-latest
|
||||
steps:
|
||||
- name: gitconfig
|
||||
run: |
|
||||
git config --global core.autocrlf input
|
||||
# git config --global core.eol lf
|
||||
- name: checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Install Rust aarch64
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
with:
|
||||
toolchain: stable
|
||||
target: aarch64-apple-darwin
|
||||
components: rustfmt, clippy
|
||||
- name: Install Rust x86_64
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
with:
|
||||
toolchain: stable
|
||||
target: x86_64-apple-darwin
|
||||
components: rustfmt, clippy
|
||||
- name: Set up cargo cache
|
||||
uses: Swatinem/rust-cache@v2
|
||||
continue-on-error: false
|
||||
with:
|
||||
key: ${{ runner.os }}-cargo-${{ hashFiles('rustybits//Cargo.lock') }}
|
||||
shared-key: ${{ runner.os }}-cargo-
|
||||
workspaces: |
|
||||
rustybits/
|
||||
- name: make
|
||||
run: make
|
||||
- name: selftest
|
||||
run: |
|
||||
make selftest
|
||||
./zerotier-selftest
|
||||
- name: 'Tar files' # keeps permissions (execute)
|
||||
run: tar -cvf zerotier-one.tar zerotier-one
|
||||
- name: Archive production artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: zerotier-one-mac
|
||||
path: zerotier-one.tar
|
||||
retention-days: 7
|
||||
|
||||
|
||||
build_windows:
|
||||
runs-on: windows-latest
|
||||
steps:
|
||||
- name: gitconfig
|
||||
run: |
|
||||
git config --global core.autocrlf true
|
||||
# git config --global core.eol lf
|
||||
- name: checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Install Rust
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
with:
|
||||
toolchain: stable
|
||||
target: aarch64-apple-darwin
|
||||
components: rustfmt, clippy
|
||||
- name: Set up cargo cache
|
||||
uses: Swatinem/rust-cache@v2
|
||||
continue-on-error: false
|
||||
with:
|
||||
key: ${{ runner.os }}-cargo-${{ hashFiles('rustybits//Cargo.lock') }}
|
||||
shared-key: ${{ runner.os }}-cargo-
|
||||
workspaces: |
|
||||
rustybits/
|
||||
|
||||
- name: setup msbuild
|
||||
uses: microsoft/setup-msbuild@v2
|
||||
- name: msbuild
|
||||
run: |
|
||||
msbuild windows\ZeroTierOne.sln /m /p:Configuration=Release /property:Platform=x64 /t:ZeroTierOne
|
||||
- name: Archive production artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: zerotier-one-windows
|
||||
path: windows/Build
|
||||
retention-days: 7
|
497
.github/workflows/validate-linux.sh
vendored
Executable file
497
.github/workflows/validate-linux.sh
vendored
Executable file
@ -0,0 +1,497 @@
|
||||
#!/bin/bash
|
||||
|
||||
# This test script joins Earth and pokes some stuff
|
||||
|
||||
TEST_NETWORK=8056c2e21c000001
|
||||
RUN_LENGTH=30
|
||||
TEST_FINISHED=false
|
||||
ZTO_VER=$(git describe --tags $(git rev-list --tags --max-count=1))
|
||||
ZTO_COMMIT=$(git rev-parse HEAD)
|
||||
ZTO_COMMIT_SHORT=$(git rev-parse --short HEAD)
|
||||
TEST_DIR_PREFIX="$ZTO_VER-$ZTO_COMMIT_SHORT-test-results"
|
||||
|
||||
TEST_OK=0
|
||||
TEST_FAIL=1
|
||||
|
||||
echo "Performing test on: $ZTO_VER-$ZTO_COMMIT_SHORT"
|
||||
TEST_FILEPATH_PREFIX="$TEST_DIR_PREFIX/$ZTO_COMMIT_SHORT"
|
||||
mkdir $TEST_DIR_PREFIX
|
||||
|
||||
# How long we will wait for ZT to come online before considering it a failure
|
||||
MAX_WAIT_SECS=30
|
||||
|
||||
ZT_PORT_NODE_1=9996
|
||||
ZT_PORT_NODE_2=9997
|
||||
|
||||
################################################################################
|
||||
# Multi-node connectivity and performance test #
|
||||
################################################################################
|
||||
|
||||
test() {
|
||||
|
||||
echo -e "\nPerforming pre-flight checks"
|
||||
|
||||
check_exit_on_invalid_identity
|
||||
|
||||
echo -e "\nRunning test for $RUN_LENGTH seconds"
|
||||
|
||||
export NS1="ip netns exec ns1"
|
||||
export NS2="ip netns exec ns2"
|
||||
|
||||
export ZT1="$NS1 ./zerotier-cli -p9996 -D$(pwd)/node1"
|
||||
# Specify custom port on one node to ensure that feature works
|
||||
export ZT2="$NS2 ./zerotier-cli -p9997 -D$(pwd)/node2"
|
||||
|
||||
echo -e "\nSetting up network namespaces..."
|
||||
echo "Setting up ns1"
|
||||
|
||||
ip netns add ns1
|
||||
$NS1 ip link set dev lo up
|
||||
ip link add veth0 type veth peer name veth1
|
||||
ip link set veth1 netns ns1
|
||||
ip addr add 192.168.0.1/24 dev veth0
|
||||
ip link set dev veth0 up
|
||||
|
||||
$NS1 ip addr add 192.168.0.2/24 dev veth1
|
||||
$NS1 ip link set dev veth1 up
|
||||
|
||||
# Add default route
|
||||
$NS1 ip route add default via 192.168.0.1
|
||||
|
||||
iptables -t nat -A POSTROUTING -s 192.168.0.0/255.255.255.0 \
|
||||
-o eth0 -j MASQUERADE
|
||||
iptables -A FORWARD -i eth0 -o veth0 -j ACCEPT
|
||||
iptables -A FORWARD -o eth0 -i veth0 -j ACCEPT
|
||||
|
||||
echo "Setting up ns2"
|
||||
ip netns add ns2
|
||||
$NS2 ip link set dev lo up
|
||||
ip link add veth2 type veth peer name veth3
|
||||
ip link set veth3 netns ns2
|
||||
ip addr add 192.168.1.1/24 dev veth2
|
||||
ip link set dev veth2 up
|
||||
|
||||
$NS2 ip addr add 192.168.1.2/24 dev veth3
|
||||
$NS2 ip link set dev veth3 up
|
||||
$NS2 ip route add default via 192.168.1.1
|
||||
|
||||
iptables -t nat -A POSTROUTING -s 192.168.1.0/255.255.255.0 \
|
||||
-o eth0 -j MASQUERADE
|
||||
iptables -A FORWARD -i eth0 -o veth2 -j ACCEPT
|
||||
iptables -A FORWARD -o eth0 -i veth2 -j ACCEPT
|
||||
|
||||
# Allow forwarding
|
||||
sysctl -w net.ipv4.ip_forward=1
|
||||
|
||||
################################################################################
|
||||
# Memory Leak Check #
|
||||
################################################################################
|
||||
|
||||
export FILENAME_MEMORY_LOG="$TEST_FILEPATH_PREFIX-memory.log"
|
||||
|
||||
echo -e "\nStarting a ZeroTier instance in each namespace..."
|
||||
|
||||
export time_test_start=$(date +%s)
|
||||
|
||||
# Spam the CLI as ZeroTier is starting
|
||||
spam_cli 100
|
||||
|
||||
echo "Starting memory leak check"
|
||||
$NS1 sudo valgrind --demangle=yes --exit-on-first-error=yes \
|
||||
--error-exitcode=1 \
|
||||
--xml=yes \
|
||||
--xml-file=$FILENAME_MEMORY_LOG \
|
||||
--leak-check=full \
|
||||
./zerotier-one node1 -p$ZT_PORT_NODE_1 -U >>node_1.log 2>&1 &
|
||||
|
||||
# Second instance, not run in memory profiler
|
||||
# Don't set up internet access until _after_ zerotier is running
|
||||
# This has been a source of stuckness in the past.
|
||||
$NS2 ip addr del 192.168.1.2/24 dev veth3
|
||||
$NS2 sudo ./zerotier-one node2 -U -p$ZT_PORT_NODE_2 >>node_2.log 2>&1 &
|
||||
|
||||
sleep 10; # New HTTP control plane is a bit sluggish, so we delay here
|
||||
|
||||
check_bind_to_correct_ports $ZT_PORT_NODE_1
|
||||
check_bind_to_correct_ports $ZT_PORT_NODE_2
|
||||
|
||||
$NS2 ip addr add 192.168.1.2/24 dev veth3
|
||||
$NS2 ip route add default via 192.168.1.1
|
||||
|
||||
echo -e "\nPing from host to namespaces"
|
||||
|
||||
ping -c 3 192.168.0.1
|
||||
ping -c 3 192.168.1.1
|
||||
|
||||
echo -e "\nPing from namespace to host"
|
||||
|
||||
$NS1 ping -c 3 192.168.0.1
|
||||
$NS1 ping -c 3 192.168.0.1
|
||||
$NS2 ping -c 3 192.168.0.2
|
||||
$NS2 ping -c 3 192.168.0.2
|
||||
|
||||
echo -e "\nPing from ns1 to ns2"
|
||||
|
||||
$NS1 ping -c 3 192.168.0.1
|
||||
|
||||
echo -e "\nPing from ns2 to ns1"
|
||||
|
||||
$NS2 ping -c 3 192.168.0.1
|
||||
|
||||
################################################################################
|
||||
# Online Check #
|
||||
################################################################################
|
||||
|
||||
echo "Waiting for ZeroTier to come online before attempting test..."
|
||||
node1_online=false
|
||||
node2_online=false
|
||||
both_instances_online=false
|
||||
time_zt_node1_start=$(date +%s)
|
||||
time_zt_node2_start=$(date +%s)
|
||||
|
||||
for ((s = 0; s <= $MAX_WAIT_SECS; s++)); do
|
||||
node1_online="$($ZT1 -j info | jq '.online' 2>/dev/null)"
|
||||
node2_online="$($ZT2 -j info | jq '.online' 2>/dev/null)"
|
||||
echo "Checking for online status: try #$s, node1:$node1_online, node2:$node2_online"
|
||||
if [[ "$node2_online" == "true" && "$node1_online" == "true" ]]; then
|
||||
export both_instances_online=true
|
||||
export time_to_both_nodes_online=$(date +%s)
|
||||
break
|
||||
fi
|
||||
sleep 1
|
||||
done
|
||||
|
||||
echo -e "\n\nContents of ZeroTier home paths:"
|
||||
|
||||
ls -lga node1
|
||||
tree node1
|
||||
ls -lga node2
|
||||
tree node2
|
||||
|
||||
echo -e "\n\nRunning ZeroTier processes:"
|
||||
echo -e "\nNode 1:\n"
|
||||
$NS1 ps aux | grep zerotier-one
|
||||
echo -e "\nNode 2:\n"
|
||||
$NS2 ps aux | grep zerotier-one
|
||||
|
||||
echo -e "\n\nStatus of each instance:"
|
||||
|
||||
echo -e "\n\nNode 1:\n"
|
||||
$ZT1 status
|
||||
echo -e "\n\nNode 2:\n"
|
||||
$ZT2 status
|
||||
|
||||
if [[ "$both_instances_online" != "true" ]]; then
|
||||
exit_test_and_generate_report $TEST_FAIL "one or more nodes failed to come online"
|
||||
fi
|
||||
|
||||
echo -e "\nJoining networks"
|
||||
|
||||
$ZT1 join $TEST_NETWORK
|
||||
$ZT2 join $TEST_NETWORK
|
||||
|
||||
sleep 10
|
||||
|
||||
node1_ip4=$($ZT1 get $TEST_NETWORK ip4)
|
||||
node2_ip4=$($ZT2 get $TEST_NETWORK ip4)
|
||||
|
||||
echo "node1_ip4=$node1_ip4"
|
||||
echo "node2_ip4=$node2_ip4"
|
||||
|
||||
echo -e "\nPinging each node"
|
||||
|
||||
PING12_FILENAME="$TEST_FILEPATH_PREFIX-ping-1-to-2.txt"
|
||||
PING21_FILENAME="$TEST_FILEPATH_PREFIX-ping-2-to-1.txt"
|
||||
|
||||
$NS1 ping -c 16 $node2_ip4 >$PING12_FILENAME
|
||||
$NS2 ping -c 16 $node1_ip4 >$PING21_FILENAME
|
||||
|
||||
ping_loss_percent_1_to_2=$(cat $PING12_FILENAME |
|
||||
grep "packet loss" | awk '{print $6}' | sed 's/%//')
|
||||
ping_loss_percent_2_to_1=$(cat $PING21_FILENAME |
|
||||
grep "packet loss" | awk '{print $6}' | sed 's/%//')
|
||||
|
||||
# Normalize loss value
|
||||
export ping_loss_percent_1_to_2=$(echo "scale=2; $ping_loss_percent_1_to_2/100.0" | bc)
|
||||
export ping_loss_percent_2_to_1=$(echo "scale=2; $ping_loss_percent_2_to_1/100.0" | bc)
|
||||
|
||||
################################################################################
|
||||
# CLI Check #
|
||||
################################################################################
|
||||
|
||||
echo "Testing basic CLI functionality..."
|
||||
|
||||
spam_cli 10
|
||||
|
||||
$ZT1 join $TEST_NETWORK
|
||||
|
||||
$ZT1 -h
|
||||
$ZT1 -v
|
||||
$ZT1 status
|
||||
$ZT1 info
|
||||
$ZT1 listnetworks
|
||||
$ZT1 peers
|
||||
$ZT1 listpeers
|
||||
|
||||
$ZT1 -j status
|
||||
$ZT1 -j info
|
||||
$ZT1 -j listnetworks
|
||||
$ZT1 -j peers
|
||||
$ZT1 -j listpeers
|
||||
|
||||
$ZT1 dump
|
||||
|
||||
$ZT1 get $TEST_NETWORK allowDNS
|
||||
$ZT1 get $TEST_NETWORK allowDefault
|
||||
$ZT1 get $TEST_NETWORK allowGlobal
|
||||
$ZT1 get $TEST_NETWORK allowManaged
|
||||
$ZT1 get $TEST_NETWORK bridge
|
||||
$ZT1 get $TEST_NETWORK broadcastEnabled
|
||||
$ZT1 get $TEST_NETWORK dhcp
|
||||
$ZT1 get $TEST_NETWORK id
|
||||
$ZT1 get $TEST_NETWORK mac
|
||||
$ZT1 get $TEST_NETWORK mtu
|
||||
$ZT1 get $TEST_NETWORK name
|
||||
$ZT1 get $TEST_NETWORK netconfRevision
|
||||
$ZT1 get $TEST_NETWORK nwid
|
||||
$ZT1 get $TEST_NETWORK portDeviceName
|
||||
$ZT1 get $TEST_NETWORK portError
|
||||
$ZT1 get $TEST_NETWORK status
|
||||
$ZT1 get $TEST_NETWORK type
|
||||
|
||||
# Test an invalid command
|
||||
$ZT1 get $TEST_NETWORK derpderp
|
||||
|
||||
# TODO: Validate JSON
|
||||
|
||||
# Performance Test
|
||||
|
||||
export FILENAME_PERF_JSON="$TEST_FILEPATH_PREFIX-iperf.json"
|
||||
|
||||
echo -e "\nBeginning performance test:"
|
||||
|
||||
echo -e "\nStarting server:"
|
||||
|
||||
echo "$NS1 iperf3 -s &"
|
||||
sleep 1
|
||||
|
||||
echo -e "\nStarting client:"
|
||||
sleep 1
|
||||
|
||||
echo "$NS2 iperf3 --json -c $node1_ip4 > $FILENAME_PERF_JSON"
|
||||
|
||||
cat $FILENAME_PERF_JSON
|
||||
|
||||
# Let ZeroTier idle long enough for various timers
|
||||
|
||||
echo -e "\nIdling ZeroTier for $RUN_LENGTH seconds..."
|
||||
sleep $RUN_LENGTH
|
||||
|
||||
echo -e "\nLeaving networks"
|
||||
|
||||
$ZT1 leave $TEST_NETWORK
|
||||
$ZT2 leave $TEST_NETWORK
|
||||
|
||||
sleep 5
|
||||
|
||||
exit_test_and_generate_report $TEST_OK "completed test"
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Generate report #
|
||||
################################################################################
|
||||
|
||||
exit_test_and_generate_report() {
|
||||
|
||||
echo -e "\nStopping memory check..."
|
||||
sudo pkill -15 -f valgrind
|
||||
sleep 10
|
||||
|
||||
time_test_end=$(date +%s)
|
||||
|
||||
echo "Exiting test with reason: $2 ($1)"
|
||||
|
||||
# Collect ZeroTier dump files
|
||||
|
||||
echo -e "\nCollecting ZeroTier dump files"
|
||||
|
||||
node1_id=$($ZT1 -j status | jq -r .address)
|
||||
node2_id=$($ZT2 -j status | jq -r .address)
|
||||
|
||||
$ZT1 dump
|
||||
mv zerotier_dump.txt "$TEST_FILEPATH_PREFIX-node-dump-$node1_id.txt"
|
||||
|
||||
$ZT2 dump
|
||||
mv zerotier_dump.txt "$TEST_FILEPATH_PREFIX-node-dump-$node2_id.txt"
|
||||
|
||||
# Copy ZeroTier stdout/stderr logs
|
||||
|
||||
cp node_1.log "$TEST_FILEPATH_PREFIX-node-log-$node1_id.txt"
|
||||
cp node_2.log "$TEST_FILEPATH_PREFIX-node-log-$node2_id.txt"
|
||||
|
||||
# Generate report
|
||||
|
||||
cat $FILENAME_MEMORY_LOG
|
||||
|
||||
DEFINITELY_LOST=$(xmlstarlet sel -t -v '/valgrindoutput/error/xwhat' \
|
||||
$FILENAME_MEMORY_LOG | grep "definitely" | awk '{print $1;}')
|
||||
POSSIBLY_LOST=$(xmlstarlet sel -t -v '/valgrindoutput/error/xwhat' \
|
||||
$FILENAME_MEMORY_LOG | grep "possibly" | awk '{print $1;}')
|
||||
|
||||
# Generate coverage report artifact and summary
|
||||
|
||||
FILENAME_COVERAGE_JSON="$TEST_FILEPATH_PREFIX-coverage.json"
|
||||
FILENAME_COVERAGE_HTML="$TEST_FILEPATH_PREFIX-coverage.html"
|
||||
|
||||
echo -e "\nGenerating coverage test report..."
|
||||
|
||||
gcovr -r . --exclude ext --json-summary $FILENAME_COVERAGE_JSON \
|
||||
--html >$FILENAME_COVERAGE_HTML
|
||||
|
||||
cat $FILENAME_COVERAGE_JSON
|
||||
|
||||
COVERAGE_LINE_COVERED=$(cat $FILENAME_COVERAGE_JSON | jq .line_covered)
|
||||
COVERAGE_LINE_TOTAL=$(cat $FILENAME_COVERAGE_JSON | jq .line_total)
|
||||
COVERAGE_LINE_PERCENT=$(cat $FILENAME_COVERAGE_JSON | jq .line_percent)
|
||||
|
||||
COVERAGE_LINE_COVERED="${COVERAGE_LINE_COVERED:-0}"
|
||||
COVERAGE_LINE_TOTAL="${COVERAGE_LINE_TOTAL:-0}"
|
||||
COVERAGE_LINE_PERCENT="${COVERAGE_LINE_PERCENT:-0}"
|
||||
|
||||
# Default values
|
||||
|
||||
DEFINITELY_LOST="${DEFINITELY_LOST:-0}"
|
||||
POSSIBLY_LOST="${POSSIBLY_LOST:-0}"
|
||||
ping_loss_percent_1_to_2="${ping_loss_percent_1_to_2:-100.0}"
|
||||
ping_loss_percent_2_to_1="${ping_loss_percent_2_to_1:-100.0}"
|
||||
time_to_both_nodes_online="${time_to_both_nodes_online:--1}"
|
||||
|
||||
# Summarize and emit json for trend reporting
|
||||
|
||||
FILENAME_SUMMARY="$TEST_FILEPATH_PREFIX-summary.json"
|
||||
|
||||
time_length_test=$((time_test_end - time_test_start))
|
||||
if [[ $time_to_both_nodes_online != -1 ]];
|
||||
then
|
||||
time_to_both_nodes_online=$((time_to_both_nodes_online - time_test_start))
|
||||
fi
|
||||
#time_length_zt_join=$((time_zt_join_end-time_zt_join_start))
|
||||
#time_length_zt_leave=$((time_zt_leave_end-time_zt_leave_start))
|
||||
#time_length_zt_can_still_ping=$((time_zt_can_still_ping-time_zt_leave_start))
|
||||
|
||||
summary=$(
|
||||
cat <<EOF
|
||||
{
|
||||
"version":"$ZTO_VER",
|
||||
"commit":"$ZTO_COMMIT",
|
||||
"arch_m":"$(uname -m)",
|
||||
"arch_a":"$(uname -a)",
|
||||
"binary_size":"$(stat -c %s zerotier-one)",
|
||||
"time_length_test":$time_length_test,
|
||||
"time_to_both_nodes_online":$time_to_both_nodes_online,
|
||||
"num_possible_bytes_lost": $POSSIBLY_LOST,
|
||||
"num_definite_bytes_lost": $DEFINITELY_LOST,
|
||||
"num_bad_formattings": $POSSIBLY_LOST,
|
||||
"coverage_lines_covered": $COVERAGE_LINE_COVERED,
|
||||
"coverage_lines_total": $COVERAGE_LINE_TOTAL,
|
||||
"coverage_lines_percent": $COVERAGE_LINE_PERCENT,
|
||||
"ping_loss_percent_1_to_2": $ping_loss_percent_1_to_2,
|
||||
"ping_loss_percent_2_to_1": $ping_loss_percent_2_to_1,
|
||||
"test_exit_code": $1,
|
||||
"test_exit_reason":"$2"
|
||||
}
|
||||
EOF
|
||||
)
|
||||
|
||||
echo $summary >$FILENAME_SUMMARY
|
||||
cat $FILENAME_SUMMARY
|
||||
|
||||
exit 0
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# CLI Check #
|
||||
################################################################################
|
||||
|
||||
spam_cli() {
|
||||
echo "Spamming CLI..."
|
||||
# Rapidly spam the CLI with joins/leaves
|
||||
|
||||
MAX_TRIES="${1:-10}"
|
||||
|
||||
for ((s = 0; s <= MAX_TRIES; s++)); do
|
||||
$ZT1 status
|
||||
$ZT2 status
|
||||
sleep 0.1
|
||||
done
|
||||
|
||||
SPAM_TRIES=128
|
||||
|
||||
for ((s = 0; s <= SPAM_TRIES; s++)); do
|
||||
$ZT1 join $TEST_NETWORK
|
||||
done
|
||||
|
||||
for ((s = 0; s <= SPAM_TRIES; s++)); do
|
||||
$ZT1 leave $TEST_NETWORK
|
||||
done
|
||||
|
||||
for ((s = 0; s <= SPAM_TRIES; s++)); do
|
||||
$ZT1 leave $TEST_NETWORK
|
||||
$ZT1 join $TEST_NETWORK
|
||||
done
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Check for proper exit on load of invalid identity #
|
||||
################################################################################
|
||||
|
||||
check_exit_on_invalid_identity() {
|
||||
echo "Checking ZeroTier exits on invalid identity..."
|
||||
mkdir -p $(pwd)/exit_test
|
||||
ZT1="sudo ./zerotier-one -p9999 $(pwd)/exit_test"
|
||||
echo "asdfasdfasdfasdf" > $(pwd)/exit_test/identity.secret
|
||||
echo "asdfasdfasdfasdf" > $(pwd)/exit_test/authtoken.secret
|
||||
|
||||
echo "Launch ZeroTier with an invalid identity"
|
||||
$ZT1 &
|
||||
my_pid=$!
|
||||
|
||||
echo "Waiting 5 seconds"
|
||||
sleep 5
|
||||
|
||||
# check if process is running
|
||||
kill -0 $my_pid
|
||||
if [ $? -eq 0 ]; then
|
||||
exit_test_and_generate_report $TEST_FAIL "Exit test FAILED: Process still running after being fed an invalid identity"
|
||||
fi
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# Check that we're binding to the primary port for TCP/TCP6/UDP #
|
||||
################################################################################
|
||||
|
||||
check_bind_to_correct_ports() {
|
||||
PORT_NUMBER=$1
|
||||
echo "Checking bound ports:"
|
||||
sudo netstat -anp | grep "$PORT_NUMBER" | grep "zerotier"
|
||||
if [[ $(sudo netstat -anp | grep "$PORT_NUMBER" | grep "zerotier" | grep "tcp") ]];
|
||||
then
|
||||
:
|
||||
else
|
||||
exit_test_and_generate_report $TEST_FAIL "ZeroTier did not bind to tcp/$1"
|
||||
fi
|
||||
if [[ $(sudo netstat -anp | grep "$PORT_NUMBER" | grep "zerotier" | grep "tcp6") ]];
|
||||
then
|
||||
:
|
||||
else
|
||||
exit_test_and_generate_report $TEST_FAIL "ZeroTier did not bind to tcp6/$1"
|
||||
fi
|
||||
if [[ $(sudo netstat -anp | grep "$PORT_NUMBER" | grep "zerotier" | grep "udp") ]];
|
||||
then
|
||||
:
|
||||
else
|
||||
exit_test_and_generate_report $TEST_FAIL "ZeroTier did not bind to udp/$1"
|
||||
fi
|
||||
}
|
||||
|
||||
test "$@"
|
24
.github/workflows/validate-report.sh
vendored
Executable file
24
.github/workflows/validate-report.sh
vendored
Executable file
@ -0,0 +1,24 @@
|
||||
#!/bin/bash
|
||||
|
||||
################################################################################
|
||||
# Set exit code depending on tool reports #
|
||||
################################################################################
|
||||
|
||||
DEFINITELY_LOST=$(cat *test-results/*summary.json | jq .num_definite_bytes_lost)
|
||||
EXIT_CODE=$(cat *test-results/*summary.json | jq .exit_code)
|
||||
EXIT_REASON=$(cat *test-results/*summary.json | jq .exit_reason)
|
||||
|
||||
cat *test-results/*summary.json
|
||||
|
||||
echo -e "\nBytes of memory definitely lost: $DEFINITELY_LOST"
|
||||
|
||||
if [[ "$DEFINITELY_LOST" -gt 0 ]]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Catch-all for other non-zero exit codes
|
||||
|
||||
if [[ "$EXIT_CODE" -gt 0 ]]; then
|
||||
echo "Test failed: $EXIT_REASON"
|
||||
exit 1
|
||||
fi
|
56
.github/workflows/validate.yml
vendored
Normal file
56
.github/workflows/validate.yml
vendored
Normal file
@ -0,0 +1,56 @@
|
||||
on:
|
||||
push:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
build_ubuntu:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: gitconfig
|
||||
run: |
|
||||
git config --global core.autocrlf input
|
||||
|
||||
- name: checkout
|
||||
uses: actions/checkout@v3
|
||||
with:
|
||||
fetch-depth: 0
|
||||
|
||||
- name: Install Rust
|
||||
uses: actions-rs/toolchain@v1
|
||||
with:
|
||||
toolchain: stable
|
||||
target: x86_64-unknown-linux-gnu
|
||||
override: true
|
||||
components: rustfmt, clippy
|
||||
|
||||
- name: Set up cargo cache
|
||||
uses: Swatinem/rust-cache@v2
|
||||
continue-on-error: false
|
||||
with:
|
||||
key: ${{ runner.os }}-cargo-${{ hashFiles('zeroidc//Cargo.lock') }}
|
||||
shared-key: ${{ runner.os }}-cargo-
|
||||
workspaces: |
|
||||
zeroidc/
|
||||
|
||||
- name: validate-1m-linux
|
||||
env:
|
||||
CC: 'gcc'
|
||||
CXX: 'g++'
|
||||
BRANCH: ${{ github.ref_name }}
|
||||
run: |
|
||||
sudo apt install -y valgrind xmlstarlet gcovr iperf3 tree
|
||||
make one ZT_COVERAGE=1 ZT_TRACE=1
|
||||
sudo chmod +x ./.github/workflows/validate-linux.sh
|
||||
sudo ./.github/workflows/validate-linux.sh
|
||||
|
||||
- name: Archive test results
|
||||
uses: actions/upload-artifact@v3
|
||||
with:
|
||||
name: ${{github.sha}}-test-results
|
||||
path: "*test-results*"
|
||||
|
||||
- name: final-report
|
||||
run: |
|
||||
sudo chmod +x ./.github/workflows/validate-report.sh
|
||||
sudo ./.github/workflows/validate-report.sh
|
||||
|
70
.gitignore
vendored
70
.gitignore
vendored
@ -4,11 +4,19 @@
|
||||
/zerotier-cli
|
||||
/zerotier-selftest
|
||||
/zerotier
|
||||
/nltest
|
||||
|
||||
# IDE stuff
|
||||
/.idea
|
||||
/.nova
|
||||
/compile_commands.json
|
||||
|
||||
# OS-created garbage files from various platforms
|
||||
.DS_Store
|
||||
.Apple*
|
||||
Thumbs.db
|
||||
@eaDir
|
||||
._*
|
||||
|
||||
# Windows build droppings
|
||||
/windows/ZeroTierOne.sdf
|
||||
@ -25,10 +33,19 @@ Thumbs.db
|
||||
/windows/Release
|
||||
/windows/WebUIWrapper/bin
|
||||
/windows/WebUIWrapper/obj
|
||||
/windows/lib
|
||||
/ext/installfiles/windows/ZeroTier One-SetupFiles
|
||||
/ext/installfiles/windows/Prerequisites
|
||||
/ext/installfiles/windows/*-cache
|
||||
/ZeroTier One.msi
|
||||
*.vcxproj.backup
|
||||
/windows/TapDriver6/Win7Debug
|
||||
/windows/TapDriver6/win7Release
|
||||
/windows/*.db
|
||||
/windows/*.opendb
|
||||
enc_temp_folder
|
||||
/windows/copyutil/bin
|
||||
/windows/copyutil/obj
|
||||
.vs/
|
||||
|
||||
# *nix/Mac build droppings
|
||||
/build-*
|
||||
@ -38,18 +55,18 @@ Thumbs.db
|
||||
/world/mkworld
|
||||
/world/*.c25519
|
||||
zt1-src.tar.gz
|
||||
/MacEthernetTapAgent
|
||||
|
||||
# Miscellaneous temporaries, build files, etc.
|
||||
*.log
|
||||
*.opensdf
|
||||
*.user
|
||||
*.cache
|
||||
*.obj
|
||||
*.tlog
|
||||
*.pid
|
||||
*.pkg
|
||||
*.o
|
||||
*.a
|
||||
/*.a
|
||||
*.dylib
|
||||
*.so
|
||||
*.so.*
|
||||
@ -59,16 +76,15 @@ zt1-src.tar.gz
|
||||
*.rpm
|
||||
*.autosave
|
||||
*.tmp
|
||||
doc/*.1
|
||||
doc/*.2
|
||||
doc/*.8
|
||||
.depend
|
||||
node_modules
|
||||
zt1_update_*
|
||||
debian/files
|
||||
debian/zerotier-one
|
||||
debian/zerotier-one*.debhelper
|
||||
debian/*.log
|
||||
debian/zerotier-one.substvars
|
||||
root-watcher/config.json
|
||||
|
||||
# Java/Android/JNI build droppings
|
||||
java/obj/
|
||||
@ -82,3 +98,45 @@ java/build_win32/
|
||||
windows/WinUI/obj/
|
||||
windows/WinUI/bin/
|
||||
windows/ZeroTierOne/Debug/
|
||||
/ext/installfiles/windows/chocolatey/zerotier-one/*.nupkg
|
||||
|
||||
# Miscellaneous mac/Xcode droppings
|
||||
.DS_Store
|
||||
.Trashes
|
||||
*.swp
|
||||
*~.nib
|
||||
DerivedData/
|
||||
*.pbxuser
|
||||
*.mode1v3
|
||||
*.mode2v3
|
||||
*.perspectivev3
|
||||
!default.pbxuser
|
||||
!default.mode1v3
|
||||
!default.mode2v3
|
||||
!default.perspectivev3
|
||||
*.xccheckout
|
||||
xcuserdata/
|
||||
.vscode
|
||||
__pycache__
|
||||
*~
|
||||
attic/world/*.c25519
|
||||
attic/world/mkworld
|
||||
workspace/
|
||||
workspace2/
|
||||
zeroidc/target/
|
||||
tcp-proxy/target
|
||||
|
||||
#snapcraft specifics
|
||||
/parts/
|
||||
/stage/
|
||||
/prime/
|
||||
|
||||
*.snap
|
||||
|
||||
.snapcraft
|
||||
__pycache__
|
||||
*.pyc
|
||||
*_source.tar.bz2
|
||||
snap/.snapcraft
|
||||
tcp-proxy/tcp-proxy
|
||||
rustybits/target
|
||||
|
80
AUTHORS.md
80
AUTHORS.md
@ -1,80 +0,0 @@
|
||||
## Primary Authors
|
||||
|
||||
* ZeroTier Core and ZeroTier One virtual networking service<br>
|
||||
Adam Ierymenko / adam.ierymenko@zerotier.com
|
||||
|
||||
* Java JNI Interface to enable Android application development, and Android app itself (code for that is elsewhere)<br>
|
||||
Grant Limberg / glimberg@gmail.com
|
||||
|
||||
* ZeroTier SDK (formerly known as Network Containers)<br>
|
||||
Joseph Henry / joseph.henry@zerotier.com
|
||||
|
||||
## Third Party Contributors
|
||||
|
||||
* A number of fixes and improvements to the new controller, other stuff.<br>
|
||||
Kees Bos / https://github.com/keesbos/
|
||||
|
||||
* Debugging and testing, OpenWRT support fixes.<br>
|
||||
Moritz Warning / moritzwarning@web.de
|
||||
|
||||
* Debian GNU/Linux packaging, manual pages, and license compliance edits.<br>
|
||||
Ben Finney <ben+zerotier@benfinney.id.au>
|
||||
|
||||
* Several others made smaller contributions, which GitHub tracks here:<br>
|
||||
https://github.com/zerotier/ZeroTierOne/graphs/contributors/
|
||||
|
||||
## Third-Party Code
|
||||
|
||||
These are included in ext/ for platforms that do not have them available in common repositories. Otherwise they may be linked and the package may ship with them as dependencies.
|
||||
|
||||
* LZ4 compression algorithm by Yann Collet
|
||||
|
||||
* Files: ext/lz4/*
|
||||
* Home page: http://code.google.com/p/lz4/
|
||||
* License grant: BSD attribution
|
||||
|
||||
* http-parser by Joyent, Inc. (many authors)
|
||||
|
||||
* Files: ext/http-parser/*
|
||||
* Home page: https://github.com/joyent/http-parser/
|
||||
* License grant: MIT/Expat
|
||||
|
||||
* json-parser by James McLaughlin
|
||||
|
||||
* Files: ext/json-parser/*
|
||||
* Home page: https://github.com/udp/json-parser/
|
||||
* License grant: BSD attribution
|
||||
|
||||
* TunTapOSX by Mattias Nissler
|
||||
|
||||
* Files: ext/tap-mac/tuntap/*
|
||||
* Home page: http://tuntaposx.sourceforge.net/
|
||||
* License grant: BSD attribution no-endorsement
|
||||
* ZeroTier Modifications: change interface name to zt#, increase max MTU, increase max devices
|
||||
|
||||
* tap-windows6 by the OpenVPN project
|
||||
|
||||
* Files: windows/TapDriver6/*
|
||||
* Home page:
|
||||
https://github.com/OpenVPN/tap-windows6/
|
||||
* License grant: GNU GPL v2
|
||||
* ZeroTier Modifications: change name of driver to ZeroTier, add ioctl() to get L2 multicast memberships (source is in ext/ and modifications inherit GPL)
|
||||
|
||||
* Salsa20 stream cipher, Curve25519 elliptic curve cipher, Ed25519
|
||||
digital signature algorithm, and Poly1305 MAC algorithm, all by
|
||||
Daniel J. Bernstein
|
||||
|
||||
* Files:
|
||||
node/Salsa20.hpp
|
||||
node/C25519.hpp
|
||||
node/Poly1305.hpp
|
||||
* Home page: http://cr.yp.to/
|
||||
* License grant: public domain
|
||||
|
||||
* MiniUPNPC and libnatpmp by Thomas Bernard
|
||||
|
||||
* Files:
|
||||
ext/libnatpmp/*
|
||||
ext/miniupnpc/*
|
||||
* Home page: http://miniupnp.free.fr/
|
||||
* License grant: BSD attribution no-endorsement
|
12
CMakeLists.txt
Normal file
12
CMakeLists.txt
Normal file
@ -0,0 +1,12 @@
|
||||
# CMake build script for libzerotiercore.a
|
||||
|
||||
cmake_minimum_required (VERSION 2.8)
|
||||
project (zerotiercore)
|
||||
|
||||
set (PROJ_DIR ${PROJECT_SOURCE_DIR})
|
||||
set (ZT_DEFS -std=c++11)
|
||||
|
||||
file(GLOB core_src_glob ${PROJ_DIR}/node/*.cpp)
|
||||
add_library(zerotiercore STATIC ${core_src_glob})
|
||||
|
||||
target_compile_options(zerotiercore PRIVATE ${ZT_DEFS})
|
11
COPYING
11
COPYING
@ -1,13 +1,8 @@
|
||||
ZeroTier One, an endpoint server for the ZeroTier virtual network layer.
|
||||
Copyright © 2011–2016 ZeroTier, Inc.
|
||||
Copyright © 2011–2019 ZeroTier, Inc.
|
||||
|
||||
ZeroTier One is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 3 of the License, or (at
|
||||
your option) any later version.
|
||||
|
||||
See the file ‘LICENSE.GPL-3’ for the text of the GNU GPL version 3.
|
||||
If that file is not present, see <http://www.gnu.org/licenses/>.
|
||||
ZeroTier is released under the terms of the BUSL version 1.1. See the
|
||||
file LICENSE.txt for details.
|
||||
|
||||
..
|
||||
Local variables:
|
||||
|
28
Dockerfile.ci
Normal file
28
Dockerfile.ci
Normal file
@ -0,0 +1,28 @@
|
||||
# vim: ft=dockerfile
|
||||
|
||||
FROM ubuntu:21.04 as stage
|
||||
|
||||
RUN apt-get update -qq && apt-get -qq install make clang
|
||||
COPY . .
|
||||
RUN /usr/bin/make
|
||||
RUN echo $PWD
|
||||
RUN cp zerotier-one /usr/sbin
|
||||
|
||||
FROM ubuntu:21.04
|
||||
|
||||
COPY --from=stage /zerotier-one /usr/sbin
|
||||
RUN ln -sf /usr/sbin/zerotier-one /usr/sbin/zerotier-idtool
|
||||
RUN ln -sf /usr/sbin/zerotier-one /usr/sbin/zerotier-cli
|
||||
|
||||
RUN echo "${VERSION}" > /etc/zerotier-version
|
||||
RUN rm -rf /var/lib/zerotier-one
|
||||
|
||||
|
||||
RUN apt-get -qq update
|
||||
RUN apt-get -qq install iproute2 net-tools fping 2ping iputils-ping iputils-arping
|
||||
|
||||
COPY entrypoint.sh.release /entrypoint.sh
|
||||
RUN chmod 755 /entrypoint.sh
|
||||
|
||||
CMD []
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
23
Dockerfile.release
Normal file
23
Dockerfile.release
Normal file
@ -0,0 +1,23 @@
|
||||
# vim: ft=dockerfile
|
||||
|
||||
FROM debian:bullseye
|
||||
|
||||
ARG VERSION
|
||||
|
||||
RUN apt-get update -qq && apt-get install curl gpg -y
|
||||
RUN mkdir -p /usr/share/zerotier && \
|
||||
curl -o /usr/share/zerotier/tmp.asc "https://download.zerotier.com/contact%40zerotier.com.gpg" && \
|
||||
gpg --no-default-keyring --keyring /usr/share/zerotier/zerotier.gpg --import /usr/share/zerotier/tmp.asc && \
|
||||
rm -f /usr/share/zerotier/tmp.asc && \
|
||||
echo "deb [signed-by=/usr/share/zerotier/zerotier.gpg] http://download.zerotier.com/debian/bullseye bullseye main" > /etc/apt/sources.list.d/zerotier.list
|
||||
|
||||
RUN apt-get update -qq && apt-get install zerotier-one=${VERSION} curl iproute2 net-tools iputils-ping openssl libssl1.1 -y
|
||||
RUN rm -rf /var/lib/zerotier-one
|
||||
|
||||
COPY entrypoint.sh.release /entrypoint.sh
|
||||
RUN chmod 755 /entrypoint.sh
|
||||
|
||||
HEALTHCHECK --interval=1s CMD bash /healthcheck.sh
|
||||
|
||||
CMD []
|
||||
ENTRYPOINT ["/entrypoint.sh"]
|
339
LICENSE.GPL-2
339
LICENSE.GPL-2
@ -1,339 +0,0 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Lesser General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License along
|
||||
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License.
|
149
LICENSE.txt
Normal file
149
LICENSE.txt
Normal file
@ -0,0 +1,149 @@
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
Business Source License 1.1
|
||||
|
||||
License text copyright (c) 2017 MariaDB Corporation Ab, All Rights Reserved.
|
||||
"Business Source License" is a trademark of MariaDB Corporation Ab.
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
Parameters
|
||||
|
||||
Licensor: ZeroTier, Inc.
|
||||
Licensed Work: ZeroTier Network Virtualization Engine 1.4.4
|
||||
The Licensed Work is (c)2019 ZeroTier, Inc.
|
||||
Additional Use Grant: You may make use of the Licensed Work, provided you
|
||||
do not use it in any of the following ways:
|
||||
|
||||
* Sell hosted ZeroTier services as a "SaaS" Product
|
||||
|
||||
(1) Operate or sell access to ZeroTier root servers,
|
||||
network controllers, or authorization key or certificate
|
||||
generation components of the Licensed Work as a
|
||||
for-profit service, regardless of whether the use of
|
||||
these components is sold alone or is bundled with other
|
||||
services. Note that this does not apply to the use of
|
||||
ZeroTier behind the scenes to operate a service not
|
||||
related to ZeroTier network administration.
|
||||
|
||||
* Create Non-Open-Source Commercial Derivative Works
|
||||
|
||||
(2) Link or directly include the Licensed Work in a
|
||||
commercial or for-profit application or other product
|
||||
not distributed under an Open Source Initiative (OSI)
|
||||
compliant license. See: https://opensource.org/licenses
|
||||
|
||||
(3) Remove the name, logo, copyright, or other branding
|
||||
material from the Licensed Work to create a "rebranded"
|
||||
or "white labeled" version to distribute as part of
|
||||
any commercial or for-profit product or service.
|
||||
|
||||
* Certain Government Uses
|
||||
|
||||
(4) Use or deploy the Licensed Work in a government
|
||||
setting in support of any active government function
|
||||
or operation with the exception of the following:
|
||||
physical or mental health care, family and social
|
||||
services, social welfare, senior care, child care, and
|
||||
the care of persons with disabilities.
|
||||
|
||||
Change Date: 2026-01-01
|
||||
|
||||
Change License: Apache License version 2.0 as published by the Apache
|
||||
Software Foundation
|
||||
https://www.apache.org/licenses/
|
||||
|
||||
Alternative Licensing
|
||||
|
||||
If you would like to use the Licensed Work in any way that conflicts with
|
||||
the stipulations of the Additional Use Grant, contact ZeroTier, Inc. to
|
||||
obtain an alternative commercial license.
|
||||
|
||||
Visit us on the web at: https://www.zerotier.com/
|
||||
|
||||
Notice
|
||||
|
||||
The Business Source License (this document, or the "License") is not an Open
|
||||
Source license. However, the Licensed Work will eventually be made available
|
||||
under an Open Source License, as stated in this License.
|
||||
|
||||
For more information on the use of the Business Source License for ZeroTier
|
||||
products, please visit our pricing page which contains license details and
|
||||
and license FAQ: https://zerotier.com/pricing
|
||||
|
||||
For more information on the use of the Business Source License generally,
|
||||
please visit the Adopting and Developing Business Source License FAQ at
|
||||
https://mariadb.com/bsl-faq-adopting.
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
Business Source License 1.1
|
||||
|
||||
Terms
|
||||
|
||||
The Licensor hereby grants you the right to copy, modify, create derivative
|
||||
works, redistribute, and make non-production use of the Licensed Work. The
|
||||
Licensor may make an Additional Use Grant, above, permitting limited
|
||||
production use.
|
||||
|
||||
Effective on the Change Date, or the fourth anniversary of the first publicly
|
||||
available distribution of a specific version of the Licensed Work under this
|
||||
License, whichever comes first, the Licensor hereby grants you rights under
|
||||
the terms of the Change License, and the rights granted in the paragraph
|
||||
above terminate.
|
||||
|
||||
If your use of the Licensed Work does not comply with the requirements
|
||||
currently in effect as described in this License, you must purchase a
|
||||
commercial license from the Licensor, its affiliated entities, or authorized
|
||||
resellers, or you must refrain from using the Licensed Work.
|
||||
|
||||
All copies of the original and modified Licensed Work, and derivative works
|
||||
of the Licensed Work, are subject to this License. This License applies
|
||||
separately for each version of the Licensed Work and the Change Date may vary
|
||||
for each version of the Licensed Work released by Licensor.
|
||||
|
||||
You must conspicuously display this License on each original or modified copy
|
||||
of the Licensed Work. If you receive the Licensed Work in original or
|
||||
modified form from a third party, the terms and conditions set forth in this
|
||||
License apply to your use of that work.
|
||||
|
||||
Any use of the Licensed Work in violation of this License will automatically
|
||||
terminate your rights under this License for the current and all other
|
||||
versions of the Licensed Work.
|
||||
|
||||
This License does not grant you any right in any trademark or logo of
|
||||
Licensor or its affiliates (provided that you may use a trademark or logo of
|
||||
Licensor as expressly required by this License).
|
||||
|
||||
TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
|
||||
AN "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
|
||||
EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
|
||||
TITLE.
|
||||
|
||||
-----------------------------------------------------------------------------
|
||||
|
||||
MariaDB hereby grants you permission to use this License’s text to license
|
||||
your works, and to refer to it using the trademark "Business Source License",
|
||||
as long as you comply with the Covenants of Licensor below.
|
||||
|
||||
Covenants of Licensor
|
||||
|
||||
In consideration of the right to use this License’s text and the "Business
|
||||
Source License" name and trademark, Licensor covenants to MariaDB, and to all
|
||||
other recipients of the licensed work to be provided by Licensor:
|
||||
|
||||
1. To specify as the Change License the GPL Version 2.0 or any later version,
|
||||
or a license that is compatible with GPL Version 2.0 or a later version,
|
||||
where "compatible" means that software provided under the Change License can
|
||||
be included in a program with software provided under GPL Version 2.0 or a
|
||||
later version. Licensor may specify additional Change Licenses without
|
||||
limitation.
|
||||
|
||||
2. To either: (a) specify an additional grant of rights to use that does not
|
||||
impose any additional restriction on the right granted in this License, as
|
||||
the Additional Use Grant; or (b) insert the text "None".
|
||||
|
||||
3. To specify a Change Date.
|
||||
|
||||
4. Not to modify this License in any other way.
|
19
Makefile
19
Makefile
@ -11,8 +11,23 @@ ifeq ($(OSTYPE),Linux)
|
||||
endif
|
||||
|
||||
ifeq ($(OSTYPE),FreeBSD)
|
||||
include make-freebsd.mk
|
||||
CC=clang
|
||||
CXX=clang++
|
||||
ZT_BUILD_PLATFORM=7
|
||||
include make-bsd.mk
|
||||
endif
|
||||
ifeq ($(OSTYPE),OpenBSD)
|
||||
include make-freebsd.mk
|
||||
CC=clang
|
||||
CXX=clang++
|
||||
ZT_BUILD_PLATFORM=9
|
||||
include make-bsd.mk
|
||||
endif
|
||||
|
||||
ifeq ($(OSTYPE),NetBSD)
|
||||
include make-netbsd.mk
|
||||
endif
|
||||
|
||||
drone:
|
||||
@echo "rendering .drone.yaml from .drone.jsonnet"
|
||||
drone jsonnet --format --stream
|
||||
drone sign zerotier/ZeroTierOne --save
|
||||
|
33
OFFICIAL-RELEASE-STEPS.md
Normal file
33
OFFICIAL-RELEASE-STEPS.md
Normal file
@ -0,0 +1,33 @@
|
||||
ZeroTier Official Release Steps
|
||||
======
|
||||
|
||||
This is mostly for ZeroTier internal use, but others who want to do builds might find it helpful.
|
||||
|
||||
Note: Many of these steps will require GPG and other signing keys that are kept in cold storage and must be mounted.
|
||||
|
||||
# Bumping the Version and Preparing Installers
|
||||
|
||||
The version must be incremented in all of the following files:
|
||||
|
||||
/version.h
|
||||
/zerotier-one.spec
|
||||
/debian/changelog
|
||||
/ext/installfiles/mac/ZeroTier One.pkgproj
|
||||
/ext/installfiles/windows/ZeroTier One.aip
|
||||
../DesktopUI/mac-app-template/ZeroTier.app/Contents/Info.plist
|
||||
|
||||
The final .AIP file can only be edited on Windows with [Advanced Installer Enterprise](http://www.advancedinstaller.com/). In addition to incrementing the version be sure that a new product code is generated. (The "upgrade code" GUID on the other hand must never change.)
|
||||
|
||||
# Building for Supported Platforms
|
||||
|
||||
## Macintosh
|
||||
|
||||
Mac's easy. Just type:
|
||||
|
||||
make official
|
||||
|
||||
You will need [Packages](http://s.sudre.free.fr/Software/Packages/about.html) and our release signing key in the keychain.
|
||||
|
||||
## Windows
|
||||
|
||||
First load the Visual Studio solution and rebuild the UI and ZeroTier One in both x64, i386, and arm64 `Release` mode. Then load [Advanced Installer Enterprise](http://www.advancedinstaller.com/), check that the version is correct, and build. The build will fail if any build artifacts are missing, and Windows must have our product singing key (from DigiCert) available to sign the resulting MSI file. The MSI must then be tested on at least a few different CLEAN Windows VMs to ensure that the installer is valid and properly signed.
|
72
README.docker.md
Normal file
72
README.docker.md
Normal file
@ -0,0 +1,72 @@
|
||||
# ZeroTier One in a container!
|
||||
|
||||
**NOTE:** _Most of this information pertains to the docker image only. For more information about ZeroTier, check out the repository_: [here](https://github.com/zerotier/ZeroTierOne) or the [commercial website](https://www.zerotier.com).
|
||||
|
||||
[ZeroTier](https://www.zerotier.com) is a smart programmable Ethernet switch for planet Earth. It allows all networked devices, VMs, containers, and applications to communicate as if they all reside in the same physical data center or cloud region.
|
||||
|
||||
This is accomplished by combining a cryptographically addressed and secure peer to peer network (termed VL1) with an Ethernet emulation layer somewhat similar to VXLAN (termed VL2). Our VL2 Ethernet virtualization layer includes advanced enterprise SDN features like fine grained access control rules for network micro-segmentation and security monitoring.
|
||||
|
||||
All ZeroTier traffic is encrypted end-to-end using secret keys that only you control. Most traffic flows peer to peer, though we offer free (but slow) relaying for users who cannot establish peer to peer connections.
|
||||
|
||||
The goals and design principles of ZeroTier are inspired by among other things the original [Google BeyondCorp](https://static.googleusercontent.com/media/research.google.com/en//pubs/archive/43231.pdf) paper and the [Jericho Forum](https://en.wikipedia.org/wiki/Jericho_Forum) with its notion of "deperimeterization."
|
||||
|
||||
Visit [ZeroTier's site](https://www.zerotier.com/) for more information and [pre-built binary packages](https://www.zerotier.com/download/). Apps for Android and iOS are available for free in the Google Play and Apple app stores.
|
||||
|
||||
ZeroTier is licensed under the [BSL version 1.1](https://mariadb.com/bsl11/). See [LICENSE.txt](https://github.com/zerotier/ZeroTierOne/blob/master/LICENSE.txt) and the [ZeroTier pricing page](https://www.zerotier.com/pricing) for details. ZeroTier is free to use internally in businesses and academic institutions and for non-commercial purposes. Certain types of commercial use such as building closed-source apps and devices based on ZeroTier or offering ZeroTier network controllers and network management as a SaaS service require a commercial license.
|
||||
|
||||
A small amount of third party code is also included in ZeroTier and is not subject to our BSL license. See [AUTHORS.md](https://github.com/zerotier/ZeroTierOne/blob/master/AUTHORS.md) for a list of third party code, where it is included, and the licenses that apply to it. All of the third party code in ZeroTier is liberally licensed (MIT, BSD, Apache, public domain, etc.).
|
||||
|
||||
## Building the docker image
|
||||
|
||||
Due to the network being a substrate for most applications and not an application unto itself, it makes sense that many people would want to build their own image based on our formula.
|
||||
|
||||
The image is based on `debian:buster`.
|
||||
|
||||
The `Dockerfile.release` file contains build instructions for building the described image in the rest of the README. The build is multi-arch and multi-release capable.
|
||||
|
||||
These build arguments power the build:
|
||||
|
||||
- `PACKAGE_BASEURL`: The base URL of the package repository to fetch from. (default: `https://download.zerotier.com/debian/buster/pool/main/z/zerotier-one/`)
|
||||
- `ARCH`: The architecture of the package, in debian format. Must match your image arch. (default: `amd64`)
|
||||
- `VERSION`: **REQUIRED** the version of ZeroTier to fetch.
|
||||
|
||||
You can build this image like so:
|
||||
|
||||
```
|
||||
docker build -f Dockerfile.release -t mybuild --build-arg VERSION=1.6.5 .
|
||||
```
|
||||
|
||||
## Using the docker image
|
||||
|
||||
The `entrypoint.sh` in the docker image is a little different; zerotier will be spawned in the background and the "main process" is actually just a sleeping shell script. This allows `zerotier-one` to gracefully terminate in some situations largely unique to docker.
|
||||
|
||||
The `zerotier/zerotier` image requires the `CAP_NET_ADMIN` capability and the `/dev/net/tun` device must be forwarded to it.
|
||||
|
||||
To join a network, simply supply it on the command-line; you can supply multiple networks.
|
||||
|
||||
```
|
||||
docker run --name myzerotier --rm --cap-add NET_ADMIN --device /dev/net/tun zerotier/zerotier:latest abcdefdeadbeef00
|
||||
```
|
||||
|
||||
Once joining all the networks you have provided, it will sleep until terminated. Note that in ZeroTier, joining a network does not necessarily mean you have an IP or can do anything, really. You will want to probe the control socket:
|
||||
|
||||
```
|
||||
docker exec myzerotier zerotier-cli listnetworks
|
||||
```
|
||||
|
||||
To ensure you have a network available before trying to listen on it. Without pre-configuring the identity, this usually means going to the central admin panel and clicking the checkmark against your zerotier identity.
|
||||
|
||||
### Environment Variables
|
||||
|
||||
You can control a few settings including the identity used and the authtoken used to interact with the control socket (which you can forward and access through `localhost:9993`).
|
||||
|
||||
- `ZEROTIER_JOIN_NETWORKS`: additional way to set networks to join.
|
||||
- `ZEROTIER_API_SECRET`: replaces the `authtoken.secret` before booting and allows you to manage the control socket's authentication key.
|
||||
- `ZEROTIER_IDENTITY_PUBLIC`: the `identity.public` file for zerotier-one. Use `zerotier-idtool` to generate one of these for you.
|
||||
- `ZEROTIER_IDENTITY_SECRET`: the `identity.secret` file for zerotier-one. Use `zerotier-idtool` to generate one of these for you.
|
||||
|
||||
### Tips
|
||||
|
||||
- Forwarding port `<dockerip>:9993` to somewhere outside is probably a good idea for highly trafficked services.
|
||||
- Forwarding `localhost:9993` to a control network where you can drive it remotely might be a good idea, just be sure to set your authtoken properly through environment variables.
|
||||
- Pre-generating your identities could be much simpler to do via our [terraform plugin](https://github.com/zerotier/terraform-provider-zerotier)
|
194
README.md
194
README.md
@ -1,101 +1,197 @@
|
||||
ZeroTier - A Planetary Ethernet Switch
|
||||
ZeroTier - Global Area Networking
|
||||
======
|
||||
|
||||
ZeroTier is a software-based managed Ethernet switch for planet Earth.
|
||||
*This document is written for a software developer audience. For information on using ZeroTier, see the: [Website](https://www.zerotier.com), [Documentation Site](https://docs.zerotier.com), and [Discussion Forum](https://discuss.zerotier.com).*
|
||||
|
||||
It erases the LAN/WAN distinction and makes VPNs, tunnels, proxies, and other kludges arising from the inflexible nature of physical networks obsolete. Everything is encrypted end-to-end and traffic takes the most direct (peer to peer) path available.
|
||||
ZeroTier is a smart programmable Ethernet switch for planet Earth. It allows all networked devices, VMs, containers, and applications to communicate as if they all reside in the same physical data center or cloud region.
|
||||
|
||||
This repository contains ZeroTier One, a service that provides ZeroTier network connectivity to devices running Windows, Mac, Linux, iOS, Android, and FreeBSD and makes joining virtual networks as easy as joining IRC or Slack channels. It also contains the OS-independent core ZeroTier protocol implementation in [node/](node/).
|
||||
This is accomplished by combining a cryptographically addressed and secure peer to peer network (termed VL1) with an Ethernet emulation layer somewhat similar to VXLAN (termed VL2). Our VL2 Ethernet virtualization layer includes advanced enterprise SDN features like fine grained access control rules for network micro-segmentation and security monitoring.
|
||||
|
||||
Visit [ZeroTier's site](https://www.zerotier.com/) for more information and [pre-built binary packages](https://www.zerotier.com/download.shtml). Apps for Android and iOS are available for free in the Google Play and Apple app stores.
|
||||
All ZeroTier traffic is encrypted end-to-end using secret keys that only you control. Most traffic flows peer to peer, though we offer free (but slow) relaying for users who cannot establish peer to peer connections.
|
||||
|
||||
The goals and design principles of ZeroTier are inspired by among other things the original [Google BeyondCorp](https://static.googleusercontent.com/media/research.google.com/en//pubs/archive/43231.pdf) paper and the [Jericho Forum](https://en.wikipedia.org/wiki/Jericho_Forum) with its notion of "deperimeterization."
|
||||
|
||||
Visit [ZeroTier's site](https://www.zerotier.com/) for more information and [pre-built binary packages](https://www.zerotier.com/download/). Apps for Android and iOS are available for free in the Google Play and Apple app stores.
|
||||
|
||||
ZeroTier is licensed under the [BSL version 1.1](https://mariadb.com/bsl11/). See [LICENSE.txt](LICENSE.txt) and the [ZeroTier pricing page](https://www.zerotier.com/pricing) for details. ZeroTier is free to use internally in businesses and academic institutions and for non-commercial purposes. Certain types of commercial use such as building closed-source apps and devices based on ZeroTier or offering ZeroTier network controllers and network management as a SaaS service require a commercial license.
|
||||
|
||||
A small amount of third party code is also included in ZeroTier and is not subject to our BSL license. See [AUTHORS.md](AUTHORS.md) for a list of third party code, where it is included, and the licenses that apply to it. All of the third party code in ZeroTier is liberally licensed (MIT, BSD, Apache, public domain, etc.).
|
||||
|
||||
### Getting Started
|
||||
|
||||
ZeroTier's basic operation is easy to understand. Devices have 10-digit *ZeroTier addresses* like `89e92ceee5` and networks have 16-digit network IDs like `8056c2e21c000001`. All it takes for a device to join a network is its 16-digit ID, and all it takes for a network to authorize a device is its 10-digit address. Everything else is automatic.
|
||||
Everything in the ZeroTier world is controlled by two types of identifier: 40-bit/10-digit *ZeroTier addresses* and 64-bit/16-digit *network IDs*. These identifiers are easily distinguished by their length. A ZeroTier address identifies a node or "device" (laptop, phone, server, VM, app, etc.) while a network ID identifies a virtual Ethernet network that can be joined by devices.
|
||||
|
||||
A "device" can be anything really: desktops, laptops, phones, servers, VMs/VPSes, containers, and even (soon) apps.
|
||||
ZeroTier addresses can be thought of as port numbers on an enormous planet-wide enterprise Ethernet smart switch supporting VLANs. Network IDs are VLAN IDs to which these ports may be assigned. A single port can be assigned to more than one VLAN.
|
||||
|
||||
For testing we provide a public virtual network called *Earth* with network ID `8056c2e21c000001`. On Linux and Mac you can do this with:
|
||||
A ZeroTier address looks like `8056c2e21c` and a network ID looks like `8056c2e21c000001`. Network IDs are composed of the ZeroTier address of that network's primary controller and an arbitrary 24-bit ID that identifies the network on this controller. Network controllers are roughly analogous to SDN controllers in SDN protocols like [OpenFlow](https://en.wikipedia.org/wiki/OpenFlow), though as with the analogy between VXLAN and VL2 this should not be read to imply that the protocols or design are the same. You can use our convenient and inexpensive SaaS hosted controllers at [my.zerotier.com](https://my.zerotier.com/) or [run your own controller](controller/) if you don't mind messing around with JSON configuration files or writing scripts to do so.
|
||||
|
||||
sudo zerotier-cli join 8056c2e21c000001
|
||||
### Project Layout
|
||||
|
||||
Now wait about 30 seconds and check your system with `ip addr list` or `ifconfig`. You'll see a new interface whose name starts with *zt* and it should quickly get an IPv4 and an IPv6 address. Once you see it get an IP, try pinging `earth.zerotier.net` at `29.209.112.93`. If you've joined Earth from more than one system, try pinging your other machine.
|
||||
The base path contains the ZeroTier One service main entry point (`one.cpp`), self test code, makefiles, etc.
|
||||
|
||||
*(IPv4 addresses for Earth are assigned from the block 28.0.0.0/7, which is not a part of the public Internet but is non-standard for private networks. It's used to avoid IP conflicts during testing. Your networks can run any IP addressing scheme you want.)*
|
||||
- `artwork/`: icons, logos, etc.
|
||||
- `attic/`: old stuff and experimental code that we want to keep around for reference.
|
||||
- `controller/`: the reference network controller implementation, which is built and included by default on desktop and server build targets.
|
||||
- `debian/`: files for building Debian packages on Linux.
|
||||
- `doc/`: manual pages and other documentation.
|
||||
- `ext/`: third party libraries, binaries that we ship for convenience on some platforms (Mac and Windows), and installation support files.
|
||||
- `include/`: include files for the ZeroTier core.
|
||||
- `java/`: a JNI wrapper used with our Android mobile app. (The whole Android app is not open source but may be made so in the future.)
|
||||
- `node/`: the ZeroTier virtual Ethernet switch core, which is designed to be entirely separate from the rest of the code and able to be built as a stand-alone OS-independent library. Note to developers: do not use C++11 features in here, since we want this to build on old embedded platforms that lack C++11 support. C++11 can be used elsewhere.
|
||||
- `osdep/`: code to support and integrate with OSes, including platform-specific stuff only built for certain targets.
|
||||
- `rule-compiler/`: JavaScript rules language compiler for defining network-level rules.
|
||||
- `service/`: the ZeroTier One service, which wraps the ZeroTier core and provides VPN-like connectivity to virtual networks for desktops, laptops, servers, VMs, and containers.
|
||||
- `windows/`: Visual Studio solution files, Windows service code, and the Windows task bar app UI.
|
||||
- `zeroidc/`: OIDC implementation used by ZeroTier service to log into SSO-enabled networks. (This part is written in Rust, and more Rust will be appearing in this repository in the future.)
|
||||
|
||||
If you don't want to belong to a giant Ethernet party line anymore, just type:
|
||||
### Contributing
|
||||
|
||||
sudo zerotier-cli leave 8056c2e21c000001
|
||||
Please do pull requests off of the `dev` branch.
|
||||
|
||||
The *zt* interface will disappear. You're no longer on the network.
|
||||
Releases are done by merging `dev` into `main` and then tagging and doing builds.
|
||||
|
||||
To create networks of your own you'll need a network controller. You can use [our hosted controller at my.zerotier.com](https://my.zerotier.com) which is free for up to 100 devices on an unlimited number of networks, or you can build your own controller and run it through its local JSON API. See [README.md in controller/](controller/) for more information.
|
||||
### Build and Platform Notes
|
||||
|
||||
### Building from Source
|
||||
To build on Mac and Linux just type `make`. On FreeBSD and OpenBSD `gmake` (GNU make) is required and can be installed from packages or ports. For Windows there is a Visual Studio solution in `windows/`.
|
||||
|
||||
For Mac, Linux, and BSD, just type "make" (or "gmake" on BSD). You won't need much installed; here are the requirements for various platforms:
|
||||
|
||||
* **Mac**: Xcode command line tools. It should build on OSX 10.7 or newer.
|
||||
* **Linux**: gcc/g++ (4.9 or newer recommended) or clang/clang++ (3.4 or newer recommended) Makefile will use clang by default if available. The Linux build will auto-detect the presence of development headers for *json-parser*, *http-parser*, *li8bnatpmp*, and *libminiupnpc* and will link against the system libraries for these if they are present and recent enough. Otherwise the bundled versions in [ext/](ext/) will be used. Type `make install` to install the binaries and other files on the system, though this will not create init.d or systemd links.
|
||||
* **FreeBSD**: C++ compiler (G++ usually) and GNU make (gmake).
|
||||
|
||||
Each supported platform has its own *make-XXX.mk* file that contains the actual make rules for the platform. The right .mk file is included by the main Makefile based on the GNU make *OSTYPE* variable. Take a look at the .mk file for your platform for other targets, debug build rules, etc.
|
||||
- **Mac**
|
||||
- Xcode command line tools for macOS 10.13 or newer are required.
|
||||
- Rust for x86_64 and ARM64 targets *if SSO is enabled in the build*.
|
||||
- **Linux**
|
||||
- The minimum compiler versions required are GCC/G++ 8.x or CLANG/CLANG++ 5.x.
|
||||
- Linux makefiles automatically detect and prefer clang/clang++ if present as it produces smaller and slightly faster binaries in most cases. You can override by supplying CC and CXX variables on the make command line.
|
||||
- Rust for x86_64 and ARM64 targets *if SSO is enabled in the build*.
|
||||
- **Windows**
|
||||
- Visual Studio 2022 on Windows 10 or newer.
|
||||
- Rust for x86_64 and ARM64 targets *if SSO is enabled in the build*.
|
||||
- **FreeBSD**
|
||||
- GNU make is required. Type `gmake` to build.
|
||||
- `binutils` is required. Type `pkg install binutils` to install.
|
||||
- Rust for x86_64 and ARM64 targets *if SSO is enabled in the build*.
|
||||
- **OpenBSD**
|
||||
- There is a limit of four network memberships on OpenBSD as there are only four tap devices (`/dev/tap0` through `/dev/tap3`).
|
||||
- GNU make is required. Type `gmake` to build.
|
||||
- Rust for x86_64 and ARM64 targets *if SSO is enabled in the build*.
|
||||
|
||||
Typing `make selftest` will build a *zerotier-selftest* binary which unit tests various internals and reports on a few aspects of the build environment. It's a good idea to try this on novel platforms or architectures.
|
||||
|
||||
Windows, of course, is special. We build for Windows with Microsoft Visual Studio 2012 on Windows 7. A solution file is located in the *windows/* subfolder. Newer versions of Visual Studio (and Windows) may work but haven't been tested. Older versions almost certainly will not, since they lack things like *stdint.h* and certain STL features. MinGW or other ports of gcc/clang to Windows should also work but haven't been tested.
|
||||
|
||||
32 and 64 bit X86 and ARM (e.g. Raspberry Pi, Android) are officially supported. Community members have built for MIPS and Sparc without issues.
|
||||
|
||||
### Running
|
||||
|
||||
Running *zerotier-one* with -h will show help.
|
||||
Running *zerotier-one* with `-h` option will show help.
|
||||
|
||||
On Linux and BSD you can start the service with:
|
||||
On Linux and BSD, if you built from source, you can start the service with:
|
||||
|
||||
sudo ./zerotier-one -d
|
||||
|
||||
On most distributions, macOS, and Windows, the installer will start the service and set it up to start on boot.
|
||||
|
||||
A home folder for your system will automatically be created.
|
||||
|
||||
The service is controlled via the JSON API, which by default is available at 127.0.0.1 port 9993. We include a *zerotier-cli* command line utility to make API calls for standard things like joining and leaving networks. The *authtoken.secret* file in the home folder contains the secret token for accessing this API. See README.md in [service/](service/) for API documentation.
|
||||
The service is controlled via the JSON API, which by default is available at `127.0.0.1:9993`. It also listens on `0.0.0.0:9993` which is only usable if `allowManagementFrom` is properly configured in `local.conf`. We include a *zerotier-cli* command line utility to make API calls for standard things like joining and leaving networks. The *authtoken.secret* file in the home folder contains the secret token for accessing this API. See [service/README.md](service/README.md) for API documentation.
|
||||
|
||||
Here's where home folders live (by default) on each OS:
|
||||
|
||||
* **Linux**: `/var/lib/zerotier-one`
|
||||
* **FreeBSD**: `/var/db/zerotier-one`
|
||||
* **FreeBSD** / **OpenBSD**: `/var/db/zerotier-one`
|
||||
* **Mac**: `/Library/Application Support/ZeroTier/One`
|
||||
* **Windows**: `\ProgramData\ZeroTier\One` (That's for Windows 7. The base 'shared app data' folder might be different on different Windows versions.)
|
||||
* **Windows**: `\ProgramData\ZeroTier\One` (That's the default. The base 'shared app data' folder might be different if Windows is installed with a non-standard drive letter assignment or layout.)
|
||||
|
||||
Running ZeroTier One on a Mac is the same, but OSX requires a kernel extension. We ship a signed binary build of the ZeroTier tap device driver, which can be installed on Mac with:
|
||||
|
||||
sudo make install-mac-tap
|
||||
|
||||
This will create the home folder for Mac, place *tap.kext* there, and set its modes correctly to enable ZeroTier One to manage it with *kextload* and *kextunload*.
|
||||
|
||||
### Troubleshooting
|
||||
### Basic Troubleshooting
|
||||
|
||||
For most users, it just works.
|
||||
|
||||
If you are running a local system firewall, we recommend adding a rule permitting UDP port 9993 inbound and outbound. If you installed binaries for Windows this should be done automatically. Other platforms might require manual editing of local firewall rules depending on your configuration.
|
||||
If you are running a local system firewall, we recommend adding a rules permitting zerotier. If you installed binaries for Windows this should be done automatically. Other platforms might require manual editing of local firewall rules depending on your configuration.
|
||||
|
||||
The Mac firewall can be found under "Security" in System Preferences. Linux has a variety of firewall configuration systems and tools. If you're using Ubuntu's *ufw*, you can do this:
|
||||
See the [documentation site](https://docs.zerotier.com/zerotier/troubleshooting) for more information.
|
||||
|
||||
sudo ufw allow 9993/udp
|
||||
The Mac firewall can be found under "Security" in System Preferences. Linux has a variety of firewall configuration systems and tools.
|
||||
|
||||
On CentOS check `/etc/sysconfig/iptables` for IPTables rules. For other distributions consult your distribution's documentation. You'll also have to check the UIs or documentation for commercial third party firewall applications like Little Snitch (Mac), McAfee Firewall Enterprise (Windows), etc. if you are running any of those. Some corporate environments might have centrally managed firewall software, so you might also have to contact IT.
|
||||
|
||||
ZeroTier One peers will automatically locate each other and communicate directly over a local wired LAN *if UDP port 9993 inbound is open*. If that port is filtered, they won't be able to see each others' LAN announcement packets. If you're experiencing poor performance between devices on the same physical network, check their firewall settings. Without LAN auto-location peers must attempt "loopback" NAT traversal, which sometimes fails and in any case requires that every packet traverse your external router twice.
|
||||
|
||||
Users behind certain types of firewalls and "symmetric" NAT devices may not able able to connect to external peers directly at all. ZeroTier has limited support for port prediction and will *attempt* to traverse symmetric NATs, but this doesn't always work. If P2P connectivity fails you'll be bouncing UDP packets off our relay servers resulting in slower performance. Some NAT router(s) have a configurable NAT mode, and setting this to "full cone" will eliminate this problem. If you do this you may also see a magical improvement for things like VoIP phones, Skype, BitTorrent, WebRTC, certain games, etc., since all of these use NAT traversal techniques similar to ours.
|
||||
|
||||
If you're interested, there's a [technical deep dive about NAT traversal on our blog](https://www.zerotier.com/blog/?p=226). A troubleshooting tool to help you diagnose NAT issues is planned for the future as are uPnP/IGD/NAT-PMP and IPv6 transport.
|
||||
Users behind certain types of firewalls and "symmetric" NAT devices may not be able to connect to external peers directly at all. ZeroTier has limited support for port prediction and will *attempt* to traverse symmetric NATs, but this doesn't always work. If P2P connectivity fails you'll be bouncing UDP packets off our relay servers resulting in slower performance. Some NAT router(s) have a configurable NAT mode, and setting this to "full cone" will eliminate this problem. If you do this you may also see a magical improvement for things like VoIP phones, Skype, BitTorrent, WebRTC, certain games, etc., since all of these use NAT traversal techniques similar to ours.
|
||||
|
||||
If a firewall between you and the Internet blocks ZeroTier's UDP traffic, you will fall back to last-resort TCP tunneling to rootservers over port 443 (https impersonation). This will work almost anywhere but is *very slow* compared to UDP or direct peer to peer connectivity.
|
||||
|
||||
### Contributing
|
||||
Additional help can be found in our [knowledge base](https://zerotier.atlassian.net/wiki/spaces/SD/overview).
|
||||
|
||||
Please make pull requests against the `dev` branch. The `master` branch is release, and `edge` is for unstable and work in progress changes and is not likely to work.
|
||||
### Prometheus Metrics
|
||||
|
||||
### License
|
||||
Prometheus Metrics are available at the `/metrics` API endpoint. This endpoint is protected by an API key stored in `metricstoken.secret` to prevent unwanted information leakage. Information that could be gleaned from the metrics include joined networks and peers your instance is talking to.
|
||||
|
||||
The ZeroTier source code is open source and is licensed under the GNU GPL v3 (not LGPL). If you'd like to embed it in a closed-source commercial product or appliance, please e-mail [contact@zerotier.com](mailto:contact@zerotier.com) to discuss commercial licensing. Otherwise it can be used for free.
|
||||
Access control is via the ZeroTier control interface itself and `metricstoken.secret`. This can be sent as a bearer auth token, via the `X-ZT1-Auth` HTTP header field, or appended to the URL as `?auth=<token>`. You can see the current metrics via `cURL` with the following command:
|
||||
|
||||
// Linux
|
||||
curl -H "X-ZT1-Auth: $(sudo cat /var/lib/zerotier-one/metricstoken.secret)" http://localhost:9993/metrics
|
||||
|
||||
// macOS
|
||||
curl -H "X-ZT1-Auth: $(sudo cat /Library/Application\ Support/ZeroTier/One/metricstoken.secret)" http://localhost:9993/metrics
|
||||
|
||||
// Windows PowerShell (Admin)
|
||||
Invoke-RestMethod -Headers @{'X-ZT1-Auth' = "$(Get-Content C:\ProgramData\ZeroTier\One\metricstoken.secret)"; } -Uri http://localhost:9993/metrics
|
||||
|
||||
To configure a scrape job in Prometheus on the machine ZeroTier is running on, add this to your Prometheus `scrape_config`:
|
||||
|
||||
- job_name: zerotier-one
|
||||
honor_labels: true
|
||||
scrape_interval: 15s
|
||||
metrics_path: /metrics
|
||||
static_configs:
|
||||
- targets:
|
||||
- 127.0.0.1:9993
|
||||
labels:
|
||||
group: zerotier-one
|
||||
node_id: $YOUR_10_CHARACTER_NODE_ID
|
||||
authorization:
|
||||
credentials: $YOUR_METRICS_TOKEN_SECRET
|
||||
|
||||
If neither of these methods are desirable, it is probably possible to distribute metrics via [Prometheus Proxy](https://github.com/pambrose/prometheus-proxy) or some other tool. Note: We have not tested this internally, but will probably work with the correct configuration.
|
||||
|
||||
Metrics are also available on disk in ZeroTier's working directory:
|
||||
|
||||
// Linux
|
||||
/var/lib/zerotier-one/metrics.prom
|
||||
|
||||
// macOS
|
||||
/Library/Application\ Support/ZeroTier/One/metrics.prom
|
||||
|
||||
//Windows
|
||||
C:\ProgramData\ZeroTier\One\metrics.prom
|
||||
|
||||
#### Available Metrics
|
||||
|
||||
| Metric Name | Labels | Metric Type | Description |
|
||||
| --- | --- | --- | --- |
|
||||
| zt_packet | packet_type, direction | Counter | ZeroTier packet type counts |
|
||||
| zt_packet_error | error_type, direction | Counter | ZeroTier packet errors|
|
||||
| zt_data | protocol, direction | Counter | number of bytes ZeroTier has transmitted or received |
|
||||
| zt_num_networks | | Gauge | number of networks this instance is joined to |
|
||||
| zt_network_multicast_groups_subscribed | network_id | Gauge | number of multicast groups networks are subscribed to |
|
||||
| zt_network_packets | network_id, direction | Counter | number of incoming/outgoing packets per network |
|
||||
| zt_peer_latency | node_id | Histogram | peer latency (ms) |
|
||||
| zt_peer_path_count | node_id, status | Gauge | number of paths to peer |
|
||||
| zt_peer_packets | node_id, direction | Counter | number of packets to/from a peer |
|
||||
| zt_peer_packet_errors | node_id | Counter | number of incoming packet errors from a peer |
|
||||
|
||||
If there are other metrics you'd like to see tracked, ask us in an Issue or send us a Pull Request!
|
||||
|
||||
### HTTP / App server
|
||||
|
||||
There is a static http file server suitable for hosting Single Page Apps at http://localhost:9993/app/<app-path>
|
||||
|
||||
Use `zerotier-cli info -j` to find your zerotier-one service's homeDir
|
||||
|
||||
``` sh
|
||||
cd $ZT_HOME
|
||||
sudo mkdir -p app/app1
|
||||
sudo mkdir -p app/appB
|
||||
echo '<html><meta charset=utf-8><title>appA</title><body><h1>hello world A' | sudo tee app/appA/index.html
|
||||
echo '<html><meta charset=utf-8><title>app2</title><body><h1>hello world 2' | sudo tee app/app2/index.html
|
||||
curl -sL http://localhost:9993/app/appA http://localhost:9993/app/app2
|
||||
```
|
||||
|
||||
Then visit [http://localhost:9993/app/app1/](http://localhost:9993/app/app1/) and [http://localhost:9993/app/appB/](http://localhost:9993/app/appB/)
|
||||
|
||||
Requests to paths don't exist return the app root index.html, as is customary for SPAs.
|
||||
If you want, you can write some javascript that talks to the service or controller [api](https://docs.zerotier.com/service/v1).
|
||||
|
499
RELEASE-NOTES.md
Normal file
499
RELEASE-NOTES.md
Normal file
@ -0,0 +1,499 @@
|
||||
ZeroTier Release Notes
|
||||
======
|
||||
|
||||
# 2024-09-12 -- Version 1.14.1
|
||||
|
||||
* Multithreaded packet I/O support! Currently this is just for Linux and must
|
||||
be enabled in local.conf. It will likely make the largest difference on small
|
||||
multi-core devices where CPU is a bottleneck and high throughput is desired.
|
||||
It may be enabled by default in the future but we want it to be thoroughly
|
||||
tested. It's a little harder than it seems at first glance due to the need
|
||||
to keep packets in sequence and balance load.
|
||||
* Several multipath bug fixes.
|
||||
* Updated the versions on a number of libraries related to OIDC support and HTTP.
|
||||
* MacOS .app now shows the correct version in its Info.plist manifest.
|
||||
* Sanitize MAC addresses in JSON format rules parser.
|
||||
* Some basic information about the platform (OS, CPU architecture) is now reported
|
||||
to network controllers when networks are joined so it can be displayed to
|
||||
network admins and in the future used in policy checking and inventory operations.
|
||||
|
||||
# 2024-05-02 -- Version 1.14.0
|
||||
|
||||
* Linux I/O performance improvements under heavy load
|
||||
* Improvements to multipath
|
||||
* Fix for port rebinding "coma" bug after periods offline (some laptop users)
|
||||
* Fixed a rules engine quirk/ambiguity (GitHub Issue #2200)
|
||||
* Controller API enhancements: node names and other node meta-data
|
||||
* Other bug fixes
|
||||
|
||||
# 2023-09-12 -- Version 1.12.2
|
||||
|
||||
* More improvements to macOS full tunnel mode.
|
||||
* Faster recovery after changes to physical network settings.
|
||||
|
||||
# 2023-08-25 -- Version 1.12.1
|
||||
|
||||
* Minor release to fix a port binding issue in Linux.
|
||||
* Update Debian dependencies.
|
||||
* No changes for other platforms.
|
||||
|
||||
# 2023-08-23 -- Version 1.12.0
|
||||
|
||||
* Experimental Windows ARM64 support
|
||||
* Fix numerous sleep/wake issues on macOS and other platforms
|
||||
* Faster recovery after changes to physical network settings
|
||||
* Prometheus compatible metrics support!
|
||||
* Fix full tunnel mode on recent macOS versions
|
||||
* Numerous macOS DNS fixes
|
||||
* 10-30% speed improvement on Linux
|
||||
|
||||
# 2023-03-23 -- Version 1.10.6
|
||||
|
||||
* Prevent binding temporary ipv6 addresses on macos (#1910)
|
||||
* Prevent path-learning loops (#1914)
|
||||
* Prevent infinite loop of UAC prompts in tray app
|
||||
|
||||
# 2023-03-10 -- Version 1.10.5
|
||||
|
||||
* Fix for high CPU usage bug on Windows
|
||||
|
||||
# 2023-03-07 -- Version 1.10.4
|
||||
|
||||
* SECURITY FIX (Windows): this version fixes a file permission problem on
|
||||
Windows that could allow non-privileged users on a Windows system to read
|
||||
privileged files in the ZeroTier service's working directory. This could
|
||||
allow an unprivileged local Windows user to administrate the local ZeroTier
|
||||
instance without appropriate local permissions. This issue is not remotely
|
||||
exploitable unless a remote user can read arbitrary local files, and does
|
||||
not impact other operating systems.
|
||||
|
||||
* Fix a bug in the handling of multiple IP address assignments to virtual
|
||||
interfaces on macOS.
|
||||
|
||||
# 2023-02-15 -- Version 1.10.3
|
||||
|
||||
* Fix for duplicate paths in client. Could cause connectivity issues. Affects all platforms.
|
||||
* Fix for Ethernet Tap MTU setting, would not properly apply on Linux.
|
||||
* Fix default route bugs (macOS.)
|
||||
* Enable Ping automatically for ZeroTier Adapters (Windows.)
|
||||
* SSO updates and minor bugfixes.
|
||||
* Add low-bandwidth mode.
|
||||
* Add forceTcpRelay mode (optionally enabled.)
|
||||
* Fix bug that prevented setting of custom TCP relay address.
|
||||
* Build script improvements and bug fixes.
|
||||
|
||||
# 2022-11-01 -- Version 1.10.2
|
||||
|
||||
* Fix another SSO "stuck client" issue in zeroidc.
|
||||
* Expose root-reported external IP/port information via the local JSON API for better diagnostics.
|
||||
* Multipath: CLI output improvement for inspecting bonds
|
||||
* Multipath: balance-aware mode
|
||||
* Multipath: Custom policies
|
||||
* Multipath: Link quality measurement improvements
|
||||
|
||||
Note that releases are coming few and far between because most of our dev effort is going into version 2.
|
||||
|
||||
# 2022-06-27 -- Version 1.10.1
|
||||
|
||||
* Fix an issue that could cause SSO clients to get "stuck" on stale auth URLs.
|
||||
* A few other SSO related bug fixes.
|
||||
|
||||
# 2022-06-07 -- Version 1.10.0
|
||||
|
||||
* Fix formatting problem in `zerotier-cli` when using SSO networks.
|
||||
* Fix a few other minor bugs in SSO signin to prepare for general availability.
|
||||
* Remove requirement for webview in desktop UI and instead just make everything available via the tray pulldown/menu. Use [libui-ng](https://github.com/libui-ng/libui-ng) for minor prompt dialogs. Saves space and eliminates installation headaches on Windows.
|
||||
* Fix SSO "spam" bug in desktop UI.
|
||||
* Use system default browser for SSO login so all your plugins, MFA devices, password managers, etc. will work as you have them configured.
|
||||
* Minor fix for bonding/multipath.
|
||||
|
||||
# 2022-05-10 -- Version 1.8.10
|
||||
|
||||
* Fixed a bug preventing SSO sign-on on Windows.
|
||||
|
||||
# 2022-04-25 -- Version 1.8.9
|
||||
|
||||
* Fixed a long-standing and strange bug that was causing sporadic "phantom" packet authentication failures. Not a security problem but could be behind sporadic reports of link failures under some conditions.
|
||||
* Fixed a memory leak in SSO/OIDC support.
|
||||
* Fixed SSO/OIDC display error on CLI.
|
||||
* Fixed a bug causing nodes to sometimes fail to push certs to each other (primarily affects SSO/OIDC use cases).
|
||||
* Fixed a deadlock bug on leaving SSO/OIDC managed networks.
|
||||
* Added some new Linux distributions to the build subsystem.
|
||||
|
||||
# 2022-04-11 -- Version 1.8.8
|
||||
|
||||
* Fix a local privilege escalation bug in the Windows installer.
|
||||
* Dependency fix for some Ubuntu versions.
|
||||
* No changes for other platforms. Windows upgrade recommended, everyone else optional.
|
||||
|
||||
# 2022-03-30 -- Version 1.8.7
|
||||
|
||||
* Fix for dependency installations in Windows MSI package.
|
||||
* Fix for desktop UI setup when run by a non-super-user.
|
||||
* Bug fix in local OIDC / SSO support for auth0 and other providers.
|
||||
* Other minor fixes for e.g. old Linux distributions.
|
||||
|
||||
# 2022-03-04 -- Version 1.8.6
|
||||
|
||||
* Fixed an issue that could cause the UI to be non-responsive if not joined to any networks.
|
||||
* Fix dependency issues in Debian and RedHat packages for some distributions (Fedora, Mint).
|
||||
* Bumped the peer cache serialization version to prevent "coma" issues on upgrade due to changes in path logic behaving badly with old values.
|
||||
|
||||
# 2022-02-22 -- Version 1.8.5
|
||||
|
||||
* Plumbing under the hood for endpoint device SSO support.
|
||||
* Fix in LinuxEthernetTap to tap device support on very old (2.6) Linux kernels.
|
||||
* Fix an issue that could cause self-hosted roots ("moons") to fail to assist peers in making direct links. (GitHub issue #1512)
|
||||
* Merge a series of changes by Joseph Henry (of ZeroTier) that should fix some edge cases where ZeroTier would "forget" valid paths.
|
||||
* Minor multipath improvements for automatic path negotiation.
|
||||
|
||||
# 2021-11-30 -- Version 1.8.4
|
||||
|
||||
* Fixed an ugly font problem on some older macOS versions.
|
||||
* Fixed a bug that could cause the desktop tray app control panel to stop opening after a while on Windows.
|
||||
* Fixed a possible double "release" in macOS tray app code that crashed on older macOS versions.
|
||||
* Fixed installation on 32-bit Windows 10.
|
||||
* Fixed a build flags issue that could cause ZeroTier to crash on older ARM32 CPUs.
|
||||
|
||||
# 2021-11-15 -- Version 1.8.3
|
||||
|
||||
* Remove problematic spinlock, which was only used on x86_64 anyway. Just use pthread always.
|
||||
* Fix fd leak on MacOS that caused non-responsiveness after some time.
|
||||
* Fix Debian install scripts to set /usr/sbin/nologin as shell on service user.
|
||||
* Fix regression that could prevent managed routes from being deleted.
|
||||
* DesktopUI: Remove NSDate:now() call, now works on MacOS 10.13 or newer!
|
||||
|
||||
# 2021-11-08 -- Version 1.8.2
|
||||
|
||||
* Fix multicast on linux.
|
||||
* Fix a bug that could cause the tap adapter to have the wrong MAC on Linux.
|
||||
* Update build flags to possibly support MacOS older than 10.14, but more work needs to be done. It may not work yet.
|
||||
* Fix path variable setting on Windows.
|
||||
|
||||
# 2021-10-28 -- Version 1.8.1
|
||||
|
||||
* Fix numerous UI issues from 1.8.0 (never fully released).
|
||||
* Remove support for REALLY ancient 1.1.6 or earlier network controllers.
|
||||
* MacOS IPv6 no longer binds to temporary addresses as these can cause interruptions if they expire.
|
||||
* Added additional hardening against address impersonation on networks (also in 1.6.6).
|
||||
* Fix an issue that could cause clobbering of MacOS IP route settings on restart.
|
||||
|
||||
* NOTE: Windows 7 is no longer supported! Windows 7 users will have to use version 1.6.5 or earlier.
|
||||
|
||||
# 2021-09-15 -- Version 1.8.0 (preview release only)
|
||||
|
||||
* A *completely* rewritten desktop UI for Mac and Windows!
|
||||
* Implement a workaround for one potential source of a "coma" bug, which can occur if buggy NATs/routers stop allowing the service to communicate on a given port. ZeroTier now reassigns a new secondary port if it's offline for a while unless a secondary port is manually specified in local.conf. Working around crummy buggy routers is an ongoing effort.
|
||||
* Fix for MacOS MTU capping issue on feth devices
|
||||
* Fix for mistakenly using v6 source addresses for v4 routes on some platforms
|
||||
* Stop binding to temporary IPv6 addresses
|
||||
* Set MAC address before bringing up Linux TAP link
|
||||
* Check if DNS servers need to be applied on macOS
|
||||
* Upgrade json.hpp dependency to version 3.10.2
|
||||
|
||||
# 2021-09-21 -- Version 1.6.6
|
||||
|
||||
* Backport COM hash check mitigation against network member impersonation.
|
||||
|
||||
# 2021-04-13 -- Version 1.6.5
|
||||
|
||||
* Fix a bug in potential network path filtering that could in some circumstances lead to "software laser" effects.
|
||||
* Fix a printf overflow in zerotier-cli (not exploitable or a security risk)
|
||||
* Windows now looks up the name of ZeroTier devices instead of relying on them having "ZeroTier" in them.
|
||||
|
||||
# 2021-02-15 -- Version 1.6.4
|
||||
|
||||
* The groundhog saw his shadow, which meant that the "connection coma" bug still wasn't gone. We think we found it this time.
|
||||
|
||||
# 2021-02-02 -- Version 1.6.3
|
||||
|
||||
* Likely fix for GitHub issue #1334, an issue that could cause ZeroTier to
|
||||
go into a "coma" on some networks.
|
||||
* Also groundhog day
|
||||
|
||||
# 2020-11-30 -- Version 1.6.2
|
||||
|
||||
* Fix an ARM hardware AES crypto issue (not an exploitable vulnerability).
|
||||
* Fix a Linux network leave hang due to a mutex deadlock.
|
||||
|
||||
# 2020-11-24 -- Version 1.6.1
|
||||
|
||||
This release fixes some minor bugs and other issues in 1.6.0.
|
||||
|
||||
* Fixed a bug that caused IP addresses in the 203.0.0.0/8 block to be miscategorized as not being in global scope.
|
||||
* Changed Linux builds to (hopefully) fix LXC and SELinux issues.
|
||||
* Fixed unaligned memory access that caused crash on FreeBSD systems on the ARM architecture.
|
||||
* Merged CLI options for controlling bonded devices into the beta multipath code.
|
||||
* Updated Windows driver with Microsoft cross-signing to fix issues on some Windows systems.
|
||||
|
||||
# 2020-11-19 -- Version 1.6.0
|
||||
|
||||
Version 1.6.0 is a major release that incorporates back-ported features from the 2.0 branch, which is still under development. It also fixes a number of issues.
|
||||
|
||||
New features and improvements (including those listed under 1.5.0):
|
||||
|
||||
* **Apple Silicon** (MacOS ARM64) native support via universal binary. ZeroTier now requires the very latest Xcode to build.
|
||||
* **Linux performance improvements** for up to 25% faster tun/tap I/O performance on multi-core systems.
|
||||
* **Multipath support** with modes modeled after the Linux kernel's bonding driver. This includes active-passive and active-active modes with fast failover and load balancing. See section 2.1.5 of the manual.
|
||||
* **DNS configuration** push from network controllers to end nodes, with locally configurable permissions for whether or not push is allowed.
|
||||
* **AES-GMAC-SIV** encryption mode, which is both somewhat more secure and significantly faster than the old Salsa20/12-Poly1305 mode on hardware that supports AES acceleration. This includes virtually all X86-64 chips and most ARM64. This mode is based on AES-SIV and has been audited by Trail of Bits to ensure that it is equivalent security-wise.
|
||||
|
||||
Bug fixes:
|
||||
|
||||
* **Managed route assignment fixes** to eliminate missing routes on Linux and what we believe to be the source of sporadic high CPU usage on MacOS.
|
||||
* **Hang on shutdown** issues should be fixed.
|
||||
* **Sporadic multicast outages** should be fixed.
|
||||
|
||||
Known remaining issues:
|
||||
|
||||
* AES hardware acceleration is not yet supported on 32-bit ARM, PowerPC (32 or 64), or MIPS (32 or 64) systems. Currently supported are X86-64 and ARM64/AARCH64 with crypto extensions.
|
||||
|
||||
# 2020-10-05 -- Version 1.5.0 (actually 1.6.0-beta1)
|
||||
|
||||
Version 1.6.0 (1.5.0 is a beta!) is a significant release that incorporates a number of back-ported fixes and features from the ZeroTier 2.0 tree.
|
||||
|
||||
Major new features are:
|
||||
|
||||
* **Multipath support** with modes modeled after the Linux kernel's bonding driver. This includes active-passive and active-active modes with fast failover and load balancing. See section 2.1.5 of the manual.
|
||||
* **DNS configuration** push from network controllers to end nodes, with locally configurable permissions for whether or not push is allowed.
|
||||
* **AES-GMAC-SIV** encryption mode, which is both somewhat more secure and significantly faster than the old Salsa20/12-Poly1305 mode on hardware that supports AES acceleration. This includes virtually all X86-64 chips and most ARM64. This mode is based on AES-SIV and has been audited by Trail of Bits to ensure that it is equivalent security-wise.
|
||||
|
||||
Known issues that are not yet fixed in this beta:
|
||||
|
||||
* Some Mac users have reported periods of 100% CPU in kernel_task and connection instability after leaving networks that have been joined for a period of time, or needing to kill ZeroTier and restart it to finish leaving a network. This doesn't appear to affect all users and we haven't diagnosed the root cause yet.
|
||||
* The service sometimes hangs on shutdown requiring a kill -9. This also does not affect all systems or users.
|
||||
* AES hardware acceleration is not yet supported on 32-bit ARM, PowerPC (32 or 64), or MIPS (32 or 64) systems. Currently supported are X86-64 and ARM64/AARCH64 with crypto extensions.
|
||||
* Some users have reported multicast/broadcast outages on networks lasting up to 30 seconds. Still investigating.
|
||||
|
||||
We're trying to fix all these issues before the 1.6.0 release. Stay tuned.
|
||||
|
||||
# 2019-08-30 -- Version 1.4.6
|
||||
|
||||
* Update default root list to latest
|
||||
* ARM32 platform build and flag fixes
|
||||
* Add a clarification line to LICENSE.txt
|
||||
* Fix license message in CLI
|
||||
* Windows service now looks for service command line arguments
|
||||
* Fixed a bug that could cause excessive queued multicasts
|
||||
|
||||
# 2019-08-23 -- Version 1.4.4
|
||||
|
||||
* Change license from GPL3 to BSL 1.1, see LICENSE.txt
|
||||
* Fix an issue with the "ipauth" rule and auto-generated unforgeable IPv6 addresses
|
||||
* Fix socket/bind errors setting IPs and routes on Linux
|
||||
|
||||
# 2019-08-12 -- Version 1.4.2
|
||||
|
||||
* Fix high CPU use bug on some platforms
|
||||
* Fix issues with PostgreSQL controller DB (only affects Central)
|
||||
* Restore backward compatibility with MacOS versions prior to 10.13
|
||||
|
||||
# 2019-07-29 -- Version 1.4.0
|
||||
|
||||
### Major Changes
|
||||
|
||||
* Mac version no longer requires a kernel extension, instead making use of the [feth interfaces](https://apple.stackexchange.com/questions/337715/fake-ethernet-interfaces-feth-if-fake-anyone-ever-seen-this).
|
||||
* Added support for concurrent multipath (multiple paths at once) with traffic weighting by link quality and faster recovery from lost links.
|
||||
* Added under-the-hood support for QoS (not yet exposed) that will eventually be configurable via our rules engine.
|
||||
|
||||
### Minor Changes and Bug Fixes
|
||||
|
||||
* Experimental controller DB driver for [LF](https://github.com/zerotier/lf) to store network controller data (LFDB.cpp / LFDB.hpp).
|
||||
* Modified credential push and direct path push timings and algorithms to somewhat reduce "chattiness" of the protocol when idle. More radical background overhead reductions will have to wait for the 2.x line.
|
||||
* Removed our beta/half-baked integration of Central with the Windows UI. We're going to do a whole new UI of some kind in the future at least for Windows and Mac.
|
||||
* Fixed stack overflow issues on Linux versions using musl libc.
|
||||
* Fixed some alignment problems reported on ARM and ARM64, but some reports we could not reproduce so please report any issues with exact chip, OS/distro, and ZeroTier version in use.
|
||||
* Fixed numerous other small issues and bugs such as ARM alignment issues causing crashes on some devices.
|
||||
* Windows now sets the adapter name such that it is consistent in both the Windows UI and command line utilities.
|
||||
|
||||
# 2018-07-27 -- Version 1.2.12
|
||||
|
||||
* Fixed a bug that caused exits to take a long time on Mac due to huge numbers of redundant attempts to delete managed routes.
|
||||
* Fixed a socket limit problem on Windows that caused the ZeroTier service to run out of sockets, causing the UI and CLI to be unable to access the API.
|
||||
* Fixed a threading bug in the ZeroTier Core, albeit one that never manifested on the regular ZeroTier One service/client.
|
||||
* Fixed a bug that could cause the service to crash if an authorized local client accessed an invalid URL via the control API. (Not exploitable since you needed admin access anyway.)
|
||||
|
||||
# 2018-05-08 -- Version 1.2.10
|
||||
|
||||
* Fix bug loading `moons.d/` files for federated root operation.
|
||||
* Fix compile problem with ZT_DEBUG on some versions of `clang`
|
||||
* Fix slow network startup bug related to loading of `networks.d/` cache files
|
||||
|
||||
# 2018-04-27 -- Version 1.2.8
|
||||
|
||||
* Linux version once again builds with PIE (position independent executable) flags
|
||||
* Fixed bug in zerotier-idtool file sign and verify
|
||||
* Fixed minor OSX app typo
|
||||
* Merged alpha NetBSD support (mostly untested, so YMMV)
|
||||
* Merged several minor typo and one-liner bug fixes
|
||||
|
||||
# 2018-04-17 -- Version 1.2.6
|
||||
|
||||
* Features and Core Improvements
|
||||
* Path selection has been overhauled to improve path stability, simplify code, and prepare for multi-path and trunking in the next major release.
|
||||
* This version introduces remote tracing for remote diagnostics. Network controllers can set a node (usually the controller itself) to receive remote tracing events from all members of the network or from select members. Events are only sent if they pertain to a given network for security reasons.
|
||||
* Multicast replication can now be done by designated multicast replicators on a network (flagged as such at the controller) rather than by the sender. Most users won't want this, but it's useful for specialized use cases on hub-and-spoke networks and for low-power devices.
|
||||
* Cryptographic performance improvements on several platforms.
|
||||
* Multithreaded performance improvements throughout the code base, including the use of an inline lightweight spinlock for low-contention resources.
|
||||
* Bugs fixed
|
||||
* Disappearing routes on Mac (GitHub issue #600)
|
||||
* Route flapping and path instability in some dual-stack V4/V6 networks
|
||||
* Blacklist (in local.conf) doesn't work reliably (GitHub issue #656)
|
||||
* Connection instabilities due to unsigned integer overflows in timing comparisons (use int64_t instead of uint64_t)
|
||||
* Binaries don't run on some older or lower-end 32-bit ARM chips (build problem)
|
||||
* ARM NEON crypto code crashes (build problem)
|
||||
* Fixed some lock ordering issues revealed by "valgrind" tool
|
||||
* The "zerotier-idtool" command could not be accessed from "zerotier-one" via command line switch
|
||||
* Leaking sockets on some platforms when uPnP/NAT-PMP is enabled
|
||||
* Fixed two very rare multithreading issues that were only observed on certain systems
|
||||
* Platform-Specific Changes
|
||||
* MacOS
|
||||
* Installer now loads the kernel extension right away so that High Sierra users will see the prompt to authorize it. This is done in the "Security & Privacy" preference pane and must be done directly on the console (not via remote desktop). On High Sierra and newer kexts must be authorized at the console via security settings system preferences pane.
|
||||
* Windows
|
||||
* The Windows installer should now install the driver without requiring a special prompt in most cases. This should make it easier for our packages to be accepted into and updated in the Chocolatey repository and should make it easier to perform remote installs across groups of machines using IT management and provisioning tools.
|
||||
* The Windows official packages are now signed with an EV certificate (with hardware key).
|
||||
* The Windows UI can now log into ZeroTier Central and join networks via the Central API.
|
||||
* The `zerotier-idtool` command should now work on Windows without ugly hacks.
|
||||
* Upgraded the installer version.
|
||||
* Made a few changes to hopefully fix sporadic "will not uninstall" problems, though we cannot duplicate these issues ourselves.
|
||||
* Linux
|
||||
* Device names are now generated deterministically based on network IDs for all newly joined networks.
|
||||
* Android
|
||||
* Multicast now works on Android in most cases! Android apps can send and receive multicast and subscribe to multicast group IPs. Note that in some cases the app must bind to the specific correct interface for this to work.
|
||||
* IPv6 can be disabled in UI for cases where it causes problems.
|
||||
|
||||
# 2017-04-20 -- Version 1.2.4
|
||||
|
||||
* Managed routes are now only bifurcated for the default route. This is a change in behavior, though few people will probably notice. Bifurcating all managed routes was causing more trouble than it was worth for most users.
|
||||
* Up to 2X crypto speedup on x86-64 (except Windows, which will take some porting) and 32-bit ARM platforms due to integration of fast assembly language implementations of Salsa20/12 from the [supercop](http://bench.cr.yp.to/supercop.html) code base. These were written by Daniel J. Bernstein and are in the public domain. My MacBook Pro (Core i5 2.8ghz) now does almost 1.5GiB/sec Salsa20/12 per core and a Raspberry Pi got a 2X boost. 64-bit ARM support and Windows support will take some work but should not be too hard.
|
||||
* Refactored code that manages credentials to greatly reduce memory use in most cases. This may also result in a small performance improvement.
|
||||
* Reworked and simplified path selection and priority logic to fix path instability and dead path persistence edge cases. There have been some sporadic reports of persistent path instabilities and dead paths hanging around that take minutes to resolve. These have proven difficult to reproduce in house, but hopefully this will fix them. In any case it seems to speed up path establishment in our tests and it makes the code simpler and more readable.
|
||||
* Eliminated some unused cruft from the code around path management and in the peer class.
|
||||
* Fixed an issue causing build problems on some MIPS architecture systems.
|
||||
* Fixed Windows forgetting routes on sleep/wake or in some other circumstances. (GitHub issue #465)
|
||||
|
||||
# 2017-03-17 -- Version 1.2.2
|
||||
|
||||
* A bug causing unreliable multicast propagation (GitHub issue #461).
|
||||
* A crash in ARM binaries due to a build chain and flags problem.
|
||||
* A bug in the network controller preventing members from being listed (GitHub issue #460).
|
||||
|
||||
# 2017-03-14 -- Version 1.2.0
|
||||
|
||||
Version 1.2.0 is a major milestone release representing almost nine months of work. It includes our rules engine for distributed network packet filtering and security monitoring, federated roots, and many other architectural and UI improvements and bug fixes.
|
||||
|
||||
## New Features in 1.2.0
|
||||
|
||||
### The ZeroTier Rules Engine
|
||||
|
||||
The largest new feature in 1.2.0, and the product of many months of work, is our advanced network rules engine. With this release we achieve traffic control, security monitoring, and micro-segmentation capability on par with many enterprise SDN solutions designed for use in advanced data centers and corporate networks.
|
||||
|
||||
Rules allow you to filter packets on your network and vector traffic to security observers. Security observation can be performed in-band using REDIRECT or out of band using TEE.
|
||||
|
||||
Tags and capabilities provide advanced methods for implementing fine grained permission structures and micro-segmentation schemes without bloating the size and complexity of your rules table.
|
||||
|
||||
See the [rules engine announcement blog post](https://www.zerotier.com/blog/?p=927) for an in-depth discussion of theory and implementation. The [manual](https://www.zerotier.com/manual.shtml) contains detailed information on rule, tag, and capability use, and the `rule-compiler/` subfolder of the ZeroTier source tree contains a JavaScript function to compile rules in our human-readable rule definition language into rules suitable for import into a network controller. (ZeroTier Central uses this same script to compile rules on [my.zerotier.com](https://my.zerotier.com/).)
|
||||
|
||||
### Root Server Federation
|
||||
|
||||
It's now possible to create your own root servers and add them to the root server pool on your nodes. This is done by creating what's called a "moon," which is a signed enumeration of root servers and their stable points on the network. Refer to the [manual](https://www.zerotier.com/manual.shtml) for instructions.
|
||||
|
||||
Federated roots achieve a number of things:
|
||||
|
||||
* You can deploy your own infrastructure to reduce dependency on ours.
|
||||
* You can deploy roots *inside your LAN* to ensure that network connectivity inside your facility still works if the Internet goes down. This is the first step toward making ZeroTier viable as an in-house SDN solution.
|
||||
* Roots can be deployed inside national boundaries for countries with data residency laws or "great firewalls." (As of 1.2.0 there is still no way to force all traffic to use these roots, but that will be easy to do in a later version.)
|
||||
* Last but not least this makes ZeroTier somewhat less centralized by eliminating any hard dependency on ZeroTier, Inc.'s infrastructure.
|
||||
|
||||
Our roots will of course remain and continue to provide zero-configuration instant-on deployment, a secure global authority for identities, and free traffic relaying for those who can't establish peer to peer connections.
|
||||
|
||||
### Local Configuration
|
||||
|
||||
An element of our design philosophy is "features are bugs." This isn't an absolute dogma but more of a guiding principle. We try as hard as we can to avoid adding features, especially "knobs" that must be tweaked by a user.
|
||||
|
||||
As of 1.2.0 we've decided that certain knobs are unavoidable, and so there is now a `local.conf` file that can be used to configure them. See the ZeroTier One documentation for these. They include:
|
||||
|
||||
* Blacklisting interfaces you want to make sure ZeroTier doesn't use for network traffic, such as VPNs, slow links, or backplanes designated for only certain kinds of traffic.
|
||||
* Turning uPnP/NAT-PMP on or off.
|
||||
* Configuring software updates on Windows and Mac platforms.
|
||||
* Defining trusted paths (the old trusted paths file is now deprecated)
|
||||
* Setting the ZeroTier main port so it doesn't have to be changed on the command line, which is very inconvenient in many cases.
|
||||
|
||||
### Improved In-Band Software Updates
|
||||
|
||||
A good software update system for Windows and Mac clients has been a missing feature in previous versions. It does exist but we've been shy about using it so far due to its fragility in some environments.
|
||||
|
||||
We've greatly improved this mechanism in 1.2.0. Not only does it now do a better job of actually invoking the update, but it also transfers updates in-band using the ZeroTier protocol. This means it can work in environments that do not allows http/https traffic or that force it through proxies. There's also now an update channel setting: `beta` or `release` (the default).
|
||||
|
||||
Software updates are authenticated three ways:
|
||||
|
||||
1. ZeroTier's own signing key is used to sign all updates and this signature is checked prior to installation. ZeroTier, Inc.'s signatures are performed on an air-gapped machine.
|
||||
|
||||
2. Updates for Mac and Windows are signed using Apple and Microsoft (DigiCert EV) keys and will not install unless these signatures are also valid.
|
||||
|
||||
3. The new in-band update mechanism also authenticates the source of the update via ZeroTier's built-in security features. This provides transport security, while 1 and 2 provide security of the update at rest.
|
||||
|
||||
Updates are now configurable via `local.conf`. There are three options: `disable`, `download`, and `apply`. The third (apply) is the default for official builds on Windows and Mac, making updates happen silently and automatically as they do for popular browsers like Chrome and Firefox. Updates are disabled by default on Linux and other Unix-type systems as these are typically updated through package managers.
|
||||
|
||||
### Path Link Quality Awareness
|
||||
|
||||
Version 1.2.0 is now aware of the link quality of direct paths with other 1.2.0 nodes. This information isn't used yet but is visible through the JSON API. (Quality always shows as 100% with pre-1.2.0 nodes.) Quality is measured passively with no additional overhead using a counter based packet loss detection algorithm.
|
||||
|
||||
This information is visible from the command line via `listpeers`:
|
||||
|
||||
200 listpeers XXXXXXXXXX 199.XXX.XXX.XXX/9993;10574;15250;1.00 48 1.2.0 LEAF
|
||||
200 listpeers XXXXXXXXXX 195.XXX.XXX.XXX/45584;467;7608;0.44 290 1.2.0 LEAF
|
||||
|
||||
The first peer's path is at 100% (1.00), while the second peer's path is suffering quite a bit of packet loss (0.44).
|
||||
|
||||
Link quality awareness is a precursor to intelligent multi-path and QoS support, which will in future versions bring us to feature parity with SD-WAN products like Cisco iWAN.
|
||||
|
||||
### Security Improvements
|
||||
|
||||
Version 1.2.0 adds anti-DOS (denial of service) rate limits and other hardening for improved resiliency against a number of denial of service attack scenarios.
|
||||
|
||||
It also adds a mechanism for instantaneous credential revocation. This can be used to revoke certificates of membership instantly to kick a node off a network (for private networks) and also to revoke capabilities and tags. The new controller sends revocations by default when a peer is de-authorized.
|
||||
|
||||
Revocations propagate using a "rumor mill" peer to peer algorithm. This means that a controller need only successfully send a revocation to at least one member of a network with connections to other active members. At this point the revocation will flood through the network peer to peer very quickly. This helps make revocations more robust in the face of poor connectivity with the controller or attempts to incapacitate the controller with denial of service attacks, as well as making revocations faster on huge networks.
|
||||
|
||||
### Windows and Macintosh UI Improvements (ZeroTier One)
|
||||
|
||||
The Mac has a whole new UI built natively in Objective-C. It provides a pulldown similar in appearance and operation to the Mac WiFi task bar menu.
|
||||
|
||||
The Windows UI has also been improved and now provides a task bar icon that can be right-clicked to manage networks. Both now expose managed route and IP permissions, allowing nodes to easily opt in to full tunnel operation if you have a router configured on your network.
|
||||
|
||||
### Ad-Hoc Networks
|
||||
|
||||
A special kind of public network called an ad-hoc network may be accessed by joining a network ID with the format:
|
||||
|
||||
ffSSSSEEEE000000
|
||||
| | | |
|
||||
| | | Reserved for future use, must be 0
|
||||
| | End of port range (hex)
|
||||
| Start of port range (hex)
|
||||
Reserved ZeroTier address prefix indicating a controller-less network
|
||||
|
||||
Ad-hoc networks are public (no access control) networks that have no network controller. Instead their configuration and other credentials are generated locally. Ad-hoc networks permit only IPv6 UDP and TCP unicast traffic (no multicast or broadcast) using 6plane format NDP-emulated IPv6 addresses. In addition an ad-hoc network ID encodes an IP port range. UDP packets and TCP SYN (connection open) packets are only allowed to destination ports within the encoded range.
|
||||
|
||||
For example `ff00160016000000` is an ad-hoc network allowing only SSH, while `ff0000ffff000000` is an ad-hoc network allowing any UDP or TCP port.
|
||||
|
||||
Keep in mind that these networks are public and anyone in the entire world can join them. Care must be taken to avoid exposing vulnerable services or sharing unwanted files or other resources.
|
||||
|
||||
### Network Controller (Partial) Rewrite
|
||||
|
||||
The network controller has been largely rewritten to use a simple in-filesystem JSON data store in place of SQLite, and it is now included by default in all Windows, Mac, Linux, and BSD builds. This means any desktop or server node running ZeroTier One can now be a controller with no recompilation needed.
|
||||
|
||||
If you have data in an old SQLite3 controller we've included a NodeJS script in `controller/migrate-sqlite` to migrate data to the new format. If you don't migrate, members will start getting `NOT_FOUND` when they attempt to query for updates.
|
||||
|
||||
## Major Bug Fixes in 1.2.0
|
||||
|
||||
* **The Windows HyperV 100% CPU bug is FINALLY DEAD**: This long-running problem turns out to have been an issue with Windows itself, but one we were triggering by placing invalid data into the Windows registry. Microsoft is aware of the issue but we've also fixed the triggering problem on our side. ZeroTier should now co-exist quite well with HyperV and should now be able to be bridged with a HyperV virtual switch.
|
||||
* **Segmentation faults on musl-libc based Linux systems**: Alpine Linux and some embedded Linux systems that use musl libc (a minimal libc) experienced segmentation faults. These were due to a smaller default stack size. A work-around that sets the stack size for new threads has been added.
|
||||
* **Windows firewall blocks local JSON API**: On some Windows systems the firewall likes to block 127.0.0.1:9993 for mysterious reasons. This is now fixed in the installer via the addition of another firewall exemption rule.
|
||||
* **UI crash on embedded Windows due to missing fonts**: The MSI installer now ships fonts and will install them if they are not present, so this should be fixed.
|
||||
|
||||
## Other Improvements in 1.2.0
|
||||
|
||||
* **Improved dead path detection**: ZeroTier is now more aggressive about expiring paths that do not seem to be active. If a path seems marginal it is re-confirmed before re-use.
|
||||
* **Minor performance improvements**: We've reduced unnecessary memcpy's and made a few other performance improvements in the core.
|
||||
* **Linux static binaries**: For our official packages (the ones in the download.zerotier.com apt and yum repositories) we now build Linux binaries with static linking. Hopefully this will stop all the bug reports relating to library inconsistencies, as well as allowing our deb packages to run on a wider variety of Debian-based distributions. (There are far too many of these to support officially!) The overhead for this is very small, especially since we built our static versions against musl-libc. Distribution maintainers are of course free to build dynamically linked versions for inclusion into distributions; this only affects our official binaries.
|
93
SECURITY.md
Normal file
93
SECURITY.md
Normal file
@ -0,0 +1,93 @@
|
||||
# Security
|
||||
|
||||
ZeroTier takes the security of our software products and services seriously, which
|
||||
includes all source code repositories managed through our GitHub organization.
|
||||
|
||||
## Supported Versions
|
||||
|
||||
The following versions of ZeroTier One receive security updates
|
||||
|
||||
| Version | Supported |
|
||||
| -------- | ------------------ |
|
||||
| 1.14.x | :white_check_mark: |
|
||||
| 1.12.x | :white_check_mark: |
|
||||
| < 1.12.0 | :x: |
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
**Please do not report security issues through public GitHub issues**
|
||||
|
||||
Instead, please report vulnerabilities via email to security@zerotier.com. If possible,
|
||||
please encrypt with our PGP key (see below).
|
||||
|
||||
Please include the following information, or as much as you can provide to help us
|
||||
understand the nature and scope of the issue:
|
||||
|
||||
* Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.)
|
||||
* Full paths of source file(s) related to the manifestation of the issue
|
||||
* The location of the affected source code (tag/branch/commit or direct URL)
|
||||
* Any special configuration required to reproduce the issue
|
||||
* Step-by-step instructions to reproduce the issue
|
||||
* Proof-of-concept or exploit code (if possible)
|
||||
* Impact of the issue, including how an attacker might exploit the issue
|
||||
|
||||
## Preferred Languages
|
||||
|
||||
We prefer all communications to be in English.
|
||||
|
||||
## security@zerotier.com PGP key
|
||||
|
||||
```
|
||||
-----BEGIN PGP PUBLIC KEY BLOCK-----
|
||||
|
||||
mQINBGQGOVIBEACalXTnNqaiSOVLFEiqHpDMg8N/OI5D5850Xy1ZEvx3B3rz7cbn
|
||||
k30ozHtJKbh+vqpyItE7DjyQAuF19gP5Q64Yh0Y+MmLHq60q/GwOwAYz7cI+UzA3
|
||||
5x8YqcmTp32LAM1xJn+iMlMLBuAmJl4kULKmOXPlpqPiyTFs5saizvm7fgRmfgJJ
|
||||
HpsnIrTkaDFJhAR+jvMJohVYwmhuydeI0DsHu7KGpG1ddcHDrUjOPNqXnnAPSPwx
|
||||
llw4yfKlQb8GYErsv/G5QVyzd5+SxEuiI4MARRnrk8LlMQ33CR6pzIQ/Bk5AAmye
|
||||
mHqfEAknkiOf++urYhRs9BL3Kz3MdV0cg92zr9EFOg0u56jxf5OnAiTOhGUUA0hn
|
||||
dS7peVGl46R9Oy2JYIazNDGi+4NIsYDFXsnsss9xOQVygPyeQd71zFHfix0jct9w
|
||||
j3o/kj7Egsnm9nc13354bYT6bbalqXiRWwGH1eAFpjueNWiVFwZS6NZUP3WeNDiY
|
||||
BlPo1LodvolbXiJcTILTCyEkERJPCK2zoE2nTdVfvTLWsuehw1M6Yd2/q74TVYy/
|
||||
RY+KjHkrChEBQ9PqXsXRHj6opKbT8JLfZkvU5k+3IiqqxOpB+QXFI/whj493CxWW
|
||||
so7QAmzOCyJq8GDVPxzkwUac22YIkXdiOmb8i/HWq+kLY/HjQE259Gx6KwARAQAB
|
||||
tClaZXJvVGllciBTZWN1cml0eSA8c2VjdXJpdHlAemVyb3RpZXIuY29tPokCTAQT
|
||||
AQoANhYhBH1HQGb+4jzl6mnFqf09m6uqADkABQJkBjlSAhsDBAsJCAcEFQoJCAUW
|
||||
AgMBAAIeAQIXgAAKCRD9PZurqgA5ACqPD/sFt6SG6Tu0HwTY2ofJtYsa2GBLL0pf
|
||||
dYlX4cWSs1PVB5+m5Oj18y+GB2umA9GnsVtmvaSfp3XEngt2zNWX27uUsVfL35b2
|
||||
/5TVVe8RjzOedqMN+lQWMvO+f/C1zmWYXjjpC+iGjgMMaRRrofkkn+7uL4N9y6gY
|
||||
rcXtpACT1rYFC+i1AKnZfUO8Vr5ji7odq0f7bDkN/N38rB0kRRwEmO8wqdpQK6gK
|
||||
nxf9vgJl5ggimDk5Xtz1sfd3y28bf5N4hdOCkXUbd10nUFY3wDNTM4VxozxTGJeG
|
||||
imdcc19Wuw/1fGUZ5SIjgPanCdPLGYwSTr+M6Fuern9uTtlC1GOby3BUtmVGP6EU
|
||||
1pSAJSRpmoBPHKKOYtSMwV8PCboXru9P1ab8y8STKM3SKyghUJrl17gdc0LaksZa
|
||||
E54pJudGPIQMFRqZjMdV6jgMuaLTozjZ4mW8EThf4mkX4xDkO8l7cOn0225ZYJZC
|
||||
lZKpdnwzk9owkJA80u4KBNJxTtB4ZAPzjBsD5hFzCZQTLNQp/psU3EjZsau28eXT
|
||||
E/C1QjEQHgy4ohkgQlCm1H1+clKssCWcdmsVGXuS1u8gh4K6X9b0Z6LeCGRaQvH2
|
||||
+DB8oTAdqp9nUZv9rP4pbo+sR4fF67CFLriVuxjedAiFkbM4uHMFcL4tc/X9+DRo
|
||||
YN5X7oEkZvO507kCDQRkBjlSARAAz58UMF7K1qKyQjzKTcutaYZ5SaIGky9lCLZn
|
||||
/2vjpFCoBogkxS/6IKQcwZk8b4S9QstaaQZDFEkxqNeKC0GiFTAMAb6SmYcK495h
|
||||
EZnHl0NA5Nc2dBlZk5E/ENzTCz2bXaxCcVESc2z+xCzu07brbhGrqvliKiwOUzt9
|
||||
JzqEsar6I95OutBcZvkFCs44/Uf9bS1qf1w4klE8w3vdMtGH23umrET4tFZ+sh6o
|
||||
ZFtQx0u2eKjsRdn/RMtsxLNaJlcE1DdIAqBpQrcmuwMC8v5wUGfCGZjhClzmyQlq
|
||||
akUkayir7UtbHbFT/mgO+YI77YGXWk5QrwPscqqT2l8KB/YMujNDmaWa/0KV1lIY
|
||||
zr5s4dzVeiwqFLR9ANFIhzFwzf3JLi6XSx123Qix0TxZoYPZCHl7yoi9qi6qybz5
|
||||
0Od2LSz3jbApeKYymZ+zjE+YV5y9DI6Wzy1j2M1FogNvTO9fMk+6dLt4HhTdSNvH
|
||||
cKya462YCcy+tnZTkhmh+FTebbJlV6D4wG7skE5KCdBhjm53xLwp6XW9L6n2CrkL
|
||||
W1IDBcCz0oPd1sMkXbO3wnxdXprV2XurCfsg/R2nszSNzvdJ8/xj3cr9hpoJ714R
|
||||
qqyoEDRZ1Ss9kGL166o5MpN5qb/EewdkqGgWP7YFXbhsdHQiW7Z7dAqzjoaybD4O
|
||||
nakkwyUAEQEAAYkCNgQYAQoAIBYhBH1HQGb+4jzl6mnFqf09m6uqADkABQJkBjlS
|
||||
AhsMAAoJEP09m6uqADkAax0P/Rh8EZYRqW6dPYTl1YQusAK10rAcRNq3ekjofXGk
|
||||
oXK1S7HWGoFgl5++5nfSfNgFJ5VLcgIM56wtIf49zFjWe5oC6fw8k+ghh4d2chMP
|
||||
hdDILx6e0c30Iq1+EvovGR9hWa0wJ4cKTdzlwhY9ZC09q0ia+bl2mwpie1JQDR0c
|
||||
zXCjt+PldLeeK9z1/XT0Q7KowYC+U18oR+KFm+EaRV4QT85JVequnIeGkmaHJrHB
|
||||
lH4T5A5ib7y8edon1c0Zx3GsaxJUojkEJ0SX7ffVDu6ztUZfkHfCVpMW4VzUeGA/
|
||||
m+CtFO9ciLRGZEkRa+zhIGoBvwEXU0GiwiF4nZ0F2C8UioeW0YIEV9zl3nXJctYE
|
||||
ZKc2whSENQRTGgaYHVoVZhznt71LKWgFLshwBo81UCXVkzwAjMW1ActDnmPw5M7q
|
||||
xR5Qp5G49Z1GmfSozazha0HVFPKNV5i3RlTzs4yLUnZyH0yC9IvtOefMHcLjG96L
|
||||
N5miEV97gvJJjrn8rhRvpUwAWgmT/9IuYjBNQTtNN40arto5HxezR76WCjdKYxdL
|
||||
p3dM1iiBDShHNm7LdyZlLFhTOMU0tNBxJJ7B09ar5gakeZjD+2aB1ODX9VuFtozL
|
||||
onBjI2gIkry0UIkuznHfFw05lZAZAiqHEVgVi/WTk4C/bklDZNgE0lx+IWzEz2iS
|
||||
L455
|
||||
=lheL
|
||||
-----END PGP PUBLIC KEY BLOCK-----
|
||||
```
|
BIN
artwork/AppIcon_1024x1024.png
Normal file
BIN
artwork/AppIcon_1024x1024.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 47 KiB |
BIN
artwork/AppIcon_20x20.png
Normal file
BIN
artwork/AppIcon_20x20.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 621 B |
BIN
artwork/AppIcon_60x60.png
Normal file
BIN
artwork/AppIcon_60x60.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
BIN
artwork/AppIcon_90x90.png
Normal file
BIN
artwork/AppIcon_90x90.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.6 KiB |
BIN
artwork/ZeroTierIcon32x32.png
Normal file
BIN
artwork/ZeroTierIcon32x32.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.0 KiB |
408
attic/Filter.cpp
408
attic/Filter.cpp
@ -1,408 +0,0 @@
|
||||
/*
|
||||
* ZeroTier One - Network Virtualization Everywhere
|
||||
* Copyright (C) 2011-2015 ZeroTier, Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* --
|
||||
*
|
||||
* ZeroTier may be used and distributed under the terms of the GPLv3, which
|
||||
* are available at: http://www.gnu.org/licenses/gpl-3.0.html
|
||||
*
|
||||
* If you would like to embed ZeroTier into a commercial application or
|
||||
* redistribute it in a modified binary form, please contact ZeroTier Networks
|
||||
* LLC. Start here: http://www.zerotier.com/
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
#include "RuntimeEnvironment.hpp"
|
||||
#include "Logger.hpp"
|
||||
#include "Filter.hpp"
|
||||
#include "Utils.hpp"
|
||||
|
||||
namespace ZeroTier {
|
||||
|
||||
const char *const Filter::UNKNOWN_NAME = "(unknown)";
|
||||
const Range<unsigned int> Filter::ANY;
|
||||
|
||||
static inline Range<unsigned int> __parseRange(char *r)
|
||||
throw(std::invalid_argument)
|
||||
{
|
||||
char *saveptr = (char *)0;
|
||||
unsigned int a = 0;
|
||||
unsigned int b = 0;
|
||||
unsigned int fn = 0;
|
||||
for(char *f=Utils::stok(r,"-",&saveptr);(f);f=Utils::stok((char *)0,"-",&saveptr)) {
|
||||
if (*f) {
|
||||
switch(fn++) {
|
||||
case 0:
|
||||
if (*f != '*')
|
||||
a = b = (unsigned int)strtoul(f,(char **)0,10);
|
||||
break;
|
||||
case 1:
|
||||
if (*f != '*')
|
||||
b = (unsigned int)strtoul(f,(char **)0,10);
|
||||
break;
|
||||
default:
|
||||
throw std::invalid_argument("rule range must be <int>, <int>-<int>, or *");
|
||||
}
|
||||
}
|
||||
}
|
||||
return Range<unsigned int>(a,b);
|
||||
}
|
||||
|
||||
Filter::Rule::Rule(const char *s)
|
||||
throw(std::invalid_argument)
|
||||
{
|
||||
char *saveptr = (char *)0;
|
||||
char tmp[256];
|
||||
if (!Utils::scopy(tmp,sizeof(tmp),s))
|
||||
throw std::invalid_argument("rule string too long");
|
||||
unsigned int fn = 0;
|
||||
for(char *f=Utils::stok(tmp,";",&saveptr);(f);f=Utils::stok((char *)0,";",&saveptr)) {
|
||||
if (*f) {
|
||||
switch(fn++) {
|
||||
case 0:
|
||||
_etherType = __parseRange(f);
|
||||
break;
|
||||
case 1:
|
||||
_protocol = __parseRange(f);
|
||||
break;
|
||||
case 2:
|
||||
_port = __parseRange(f);
|
||||
break;
|
||||
default:
|
||||
throw std::invalid_argument("rule string has unknown extra fields");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (fn != 3)
|
||||
throw std::invalid_argument("rule string must contain 3 fields");
|
||||
}
|
||||
|
||||
bool Filter::Rule::operator()(unsigned int etype,const void *data,unsigned int len) const
|
||||
throw(std::invalid_argument)
|
||||
{
|
||||
if ((!_etherType)||(_etherType(etype))) { // ethertype is ANY, or matches
|
||||
// Ethertype determines meaning of protocol and port
|
||||
switch(etype) {
|
||||
case ZT_ETHERTYPE_IPV4:
|
||||
if (len > 20) {
|
||||
if ((!_protocol)||(_protocol(((const uint8_t *)data)[9]))) { // protocol is ANY or match
|
||||
if (!_port) // port is ANY
|
||||
return true;
|
||||
|
||||
// Don't match on fragments beyond fragment 0. If we've blocked
|
||||
// fragment 0, further fragments will fall on deaf ears anyway.
|
||||
if ((Utils::ntoh(((const uint16_t *)data)[3]) & 0x1fff))
|
||||
return false;
|
||||
|
||||
// Internet header length determines where data begins, in multiples of 32 bits
|
||||
unsigned int ihl = 4 * (((const uint8_t *)data)[0] & 0x0f);
|
||||
|
||||
switch(((const uint8_t *)data)[9]) { // port's meaning depends on IP protocol
|
||||
case ZT_IPPROTO_ICMP:
|
||||
// For ICMP, port is ICMP type
|
||||
return _port(((const uint8_t *)data)[ihl]);
|
||||
case ZT_IPPROTO_TCP:
|
||||
case ZT_IPPROTO_UDP:
|
||||
case ZT_IPPROTO_SCTP:
|
||||
case ZT_IPPROTO_UDPLITE:
|
||||
// For these, port is destination port. Protocol designers were
|
||||
// nice enough to put the field in the same place.
|
||||
return _port(((const uint16_t *)data)[(ihl / 2) + 1]);
|
||||
default:
|
||||
// port has no meaning for other IP types, so ignore it
|
||||
return true;
|
||||
}
|
||||
|
||||
return false; // no match on port
|
||||
}
|
||||
} else throw std::invalid_argument("undersized IPv4 packet");
|
||||
break;
|
||||
|
||||
case ZT_ETHERTYPE_IPV6:
|
||||
if (len > 40) {
|
||||
int nextHeader = ((const uint8_t *)data)[6];
|
||||
unsigned int pos = 40;
|
||||
while ((pos < len)&&(nextHeader >= 0)&&(nextHeader != 59)) { // 59 == no next header
|
||||
fprintf(stderr,"[rule] V6: start header parse, header %.2x pos %d\n",nextHeader,pos);
|
||||
|
||||
switch(nextHeader) {
|
||||
case 0: // hop-by-hop options
|
||||
case 60: // destination options
|
||||
case 43: // routing
|
||||
case 135: // mobility (mobile IPv6 options)
|
||||
if (_protocol((unsigned int)nextHeader))
|
||||
return true; // match if our goal was to match any of these
|
||||
nextHeader = ((const uint8_t *)data)[pos];
|
||||
pos += 8 + (8 * ((const uint8_t *)data)[pos + 1]);
|
||||
break;
|
||||
case 44: // fragment
|
||||
if (_protocol(44))
|
||||
return true; // match if our goal was to match fragments
|
||||
nextHeader = ((const uint8_t *)data)[pos];
|
||||
pos += 8;
|
||||
break;
|
||||
case ZT_IPPROTO_AH: // AH
|
||||
return _protocol(ZT_IPPROTO_AH); // true if AH is matched protocol, otherwise false since packet will be IPsec
|
||||
case ZT_IPPROTO_ESP: // ESP
|
||||
return _protocol(ZT_IPPROTO_ESP); // true if ESP is matched protocol, otherwise false since packet will be IPsec
|
||||
case ZT_IPPROTO_ICMPV6:
|
||||
// Only match ICMPv6 if we've selected it specifically
|
||||
if (_protocol(ZT_IPPROTO_ICMPV6)) {
|
||||
// Port is interpreted as ICMPv6 type
|
||||
if ((!_port)||(_port(((const uint8_t *)data)[pos])))
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case ZT_IPPROTO_TCP:
|
||||
case ZT_IPPROTO_UDP:
|
||||
case ZT_IPPROTO_SCTP:
|
||||
case ZT_IPPROTO_UDPLITE:
|
||||
// If we encounter any of these, match if protocol matches or is wildcard as
|
||||
// we'll consider these the "real payload" if present.
|
||||
if ((!_protocol)||(_protocol(nextHeader))) {
|
||||
if ((!_port)||(_port(((const uint16_t *)data)[(pos / 2) + 1])))
|
||||
return true; // protocol matches or is ANY, port is ANY or matches
|
||||
}
|
||||
break;
|
||||
default: {
|
||||
char foo[128];
|
||||
Utils::snprintf(foo,sizeof(foo),"unrecognized IPv6 header type %d",(int)nextHeader);
|
||||
throw std::invalid_argument(foo);
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(stderr,"[rule] V6: end header parse, next header %.2x, new pos %d\n",nextHeader,pos);
|
||||
}
|
||||
} else throw std::invalid_argument("undersized IPv6 packet");
|
||||
break;
|
||||
|
||||
default:
|
||||
// For other ethertypes, protocol and port are ignored. What would they mean?
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
std::string Filter::Rule::toString() const
|
||||
{
|
||||
char buf[128];
|
||||
std::string s;
|
||||
|
||||
switch(_etherType.magnitude()) {
|
||||
case 0:
|
||||
s.push_back('*');
|
||||
break;
|
||||
case 1:
|
||||
Utils::snprintf(buf,sizeof(buf),"%u",_etherType.start);
|
||||
s.append(buf);
|
||||
break;
|
||||
default:
|
||||
Utils::snprintf(buf,sizeof(buf),"%u-%u",_etherType.start,_etherType.end);
|
||||
s.append(buf);
|
||||
break;
|
||||
}
|
||||
s.push_back(';');
|
||||
switch(_protocol.magnitude()) {
|
||||
case 0:
|
||||
s.push_back('*');
|
||||
break;
|
||||
case 1:
|
||||
Utils::snprintf(buf,sizeof(buf),"%u",_protocol.start);
|
||||
s.append(buf);
|
||||
break;
|
||||
default:
|
||||
Utils::snprintf(buf,sizeof(buf),"%u-%u",_protocol.start,_protocol.end);
|
||||
s.append(buf);
|
||||
break;
|
||||
}
|
||||
s.push_back(';');
|
||||
switch(_port.magnitude()) {
|
||||
case 0:
|
||||
s.push_back('*');
|
||||
break;
|
||||
case 1:
|
||||
Utils::snprintf(buf,sizeof(buf),"%u",_port.start);
|
||||
s.append(buf);
|
||||
break;
|
||||
default:
|
||||
Utils::snprintf(buf,sizeof(buf),"%u-%u",_port.start,_port.end);
|
||||
s.append(buf);
|
||||
break;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
Filter::Filter(const char *s)
|
||||
throw(std::invalid_argument)
|
||||
{
|
||||
char tmp[16384];
|
||||
if (!Utils::scopy(tmp,sizeof(tmp),s))
|
||||
throw std::invalid_argument("filter string too long");
|
||||
char *saveptr = (char *)0;
|
||||
unsigned int fn = 0;
|
||||
for(char *f=Utils::stok(tmp,",",&saveptr);(f);f=Utils::stok((char *)0,",",&saveptr)) {
|
||||
try {
|
||||
_rules.push_back(Rule(f));
|
||||
++fn;
|
||||
} catch (std::invalid_argument &exc) {
|
||||
char tmp[256];
|
||||
Utils::snprintf(tmp,sizeof(tmp),"invalid rule at index %u: %s",fn,exc.what());
|
||||
throw std::invalid_argument(tmp);
|
||||
}
|
||||
}
|
||||
std::sort(_rules.begin(),_rules.end());
|
||||
}
|
||||
|
||||
std::string Filter::toString() const
|
||||
{
|
||||
std::string s;
|
||||
|
||||
for(std::vector<Rule>::const_iterator r(_rules.begin());r!=_rules.end();++r) {
|
||||
if (s.length() > 0)
|
||||
s.push_back(',');
|
||||
s.append(r->toString());
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
void Filter::add(const Rule &r)
|
||||
{
|
||||
for(std::vector<Rule>::iterator rr(_rules.begin());rr!=_rules.end();++rr) {
|
||||
if (r == *rr)
|
||||
return;
|
||||
}
|
||||
_rules.push_back(r);
|
||||
std::sort(_rules.begin(),_rules.end());
|
||||
}
|
||||
|
||||
const char *Filter::etherTypeName(const unsigned int etherType)
|
||||
throw()
|
||||
{
|
||||
switch(etherType) {
|
||||
case ZT_ETHERTYPE_IPV4: return "ETHERTYPE_IPV4";
|
||||
case ZT_ETHERTYPE_ARP: return "ETHERTYPE_ARP";
|
||||
case ZT_ETHERTYPE_RARP: return "ETHERTYPE_RARP";
|
||||
case ZT_ETHERTYPE_ATALK: return "ETHERTYPE_ATALK";
|
||||
case ZT_ETHERTYPE_AARP: return "ETHERTYPE_AARP";
|
||||
case ZT_ETHERTYPE_IPX_A: return "ETHERTYPE_IPX_A";
|
||||
case ZT_ETHERTYPE_IPX_B: return "ETHERTYPE_IPX_B";
|
||||
case ZT_ETHERTYPE_IPV6: return "ETHERTYPE_IPV6";
|
||||
}
|
||||
return UNKNOWN_NAME;
|
||||
}
|
||||
|
||||
const char *Filter::ipProtocolName(const unsigned int ipp)
|
||||
throw()
|
||||
{
|
||||
switch(ipp) {
|
||||
case ZT_IPPROTO_ICMP: return "IPPROTO_ICMP";
|
||||
case ZT_IPPROTO_IGMP: return "IPPROTO_IGMP";
|
||||
case ZT_IPPROTO_TCP: return "IPPROTO_TCP";
|
||||
case ZT_IPPROTO_UDP: return "IPPROTO_UDP";
|
||||
case ZT_IPPROTO_GRE: return "IPPROTO_GRE";
|
||||
case ZT_IPPROTO_ESP: return "IPPROTO_ESP";
|
||||
case ZT_IPPROTO_AH: return "IPPROTO_AH";
|
||||
case ZT_IPPROTO_ICMPV6: return "IPPROTO_ICMPV6";
|
||||
case ZT_IPPROTO_OSPF: return "IPPROTO_OSPF";
|
||||
case ZT_IPPROTO_IPIP: return "IPPROTO_IPIP";
|
||||
case ZT_IPPROTO_IPCOMP: return "IPPROTO_IPCOMP";
|
||||
case ZT_IPPROTO_L2TP: return "IPPROTO_L2TP";
|
||||
case ZT_IPPROTO_SCTP: return "IPPROTO_SCTP";
|
||||
case ZT_IPPROTO_FC: return "IPPROTO_FC";
|
||||
case ZT_IPPROTO_UDPLITE: return "IPPROTO_UDPLITE";
|
||||
case ZT_IPPROTO_HIP: return "IPPROTO_HIP";
|
||||
}
|
||||
return UNKNOWN_NAME;
|
||||
}
|
||||
|
||||
const char *Filter::icmpTypeName(const unsigned int icmpType)
|
||||
throw()
|
||||
{
|
||||
switch(icmpType) {
|
||||
case ZT_ICMP_ECHO_REPLY: return "ICMP_ECHO_REPLY";
|
||||
case ZT_ICMP_DESTINATION_UNREACHABLE: return "ICMP_DESTINATION_UNREACHABLE";
|
||||
case ZT_ICMP_SOURCE_QUENCH: return "ICMP_SOURCE_QUENCH";
|
||||
case ZT_ICMP_REDIRECT: return "ICMP_REDIRECT";
|
||||
case ZT_ICMP_ALTERNATE_HOST_ADDRESS: return "ICMP_ALTERNATE_HOST_ADDRESS";
|
||||
case ZT_ICMP_ECHO_REQUEST: return "ICMP_ECHO_REQUEST";
|
||||
case ZT_ICMP_ROUTER_ADVERTISEMENT: return "ICMP_ROUTER_ADVERTISEMENT";
|
||||
case ZT_ICMP_ROUTER_SOLICITATION: return "ICMP_ROUTER_SOLICITATION";
|
||||
case ZT_ICMP_TIME_EXCEEDED: return "ICMP_TIME_EXCEEDED";
|
||||
case ZT_ICMP_BAD_IP_HEADER: return "ICMP_BAD_IP_HEADER";
|
||||
case ZT_ICMP_TIMESTAMP: return "ICMP_TIMESTAMP";
|
||||
case ZT_ICMP_TIMESTAMP_REPLY: return "ICMP_TIMESTAMP_REPLY";
|
||||
case ZT_ICMP_INFORMATION_REQUEST: return "ICMP_INFORMATION_REQUEST";
|
||||
case ZT_ICMP_INFORMATION_REPLY: return "ICMP_INFORMATION_REPLY";
|
||||
case ZT_ICMP_ADDRESS_MASK_REQUEST: return "ICMP_ADDRESS_MASK_REQUEST";
|
||||
case ZT_ICMP_ADDRESS_MASK_REPLY: return "ICMP_ADDRESS_MASK_REPLY";
|
||||
case ZT_ICMP_TRACEROUTE: return "ICMP_TRACEROUTE";
|
||||
case ZT_ICMP_MOBILE_HOST_REDIRECT: return "ICMP_MOBILE_HOST_REDIRECT";
|
||||
case ZT_ICMP_MOBILE_REGISTRATION_REQUEST: return "ICMP_MOBILE_REGISTRATION_REQUEST";
|
||||
case ZT_ICMP_MOBILE_REGISTRATION_REPLY: return "ICMP_MOBILE_REGISTRATION_REPLY";
|
||||
}
|
||||
return UNKNOWN_NAME;
|
||||
}
|
||||
|
||||
const char *Filter::icmp6TypeName(const unsigned int icmp6Type)
|
||||
throw()
|
||||
{
|
||||
switch(icmp6Type) {
|
||||
case ZT_ICMP6_DESTINATION_UNREACHABLE: return "ICMP6_DESTINATION_UNREACHABLE";
|
||||
case ZT_ICMP6_PACKET_TOO_BIG: return "ICMP6_PACKET_TOO_BIG";
|
||||
case ZT_ICMP6_TIME_EXCEEDED: return "ICMP6_TIME_EXCEEDED";
|
||||
case ZT_ICMP6_PARAMETER_PROBLEM: return "ICMP6_PARAMETER_PROBLEM";
|
||||
case ZT_ICMP6_ECHO_REQUEST: return "ICMP6_ECHO_REQUEST";
|
||||
case ZT_ICMP6_ECHO_REPLY: return "ICMP6_ECHO_REPLY";
|
||||
case ZT_ICMP6_MULTICAST_LISTENER_QUERY: return "ICMP6_MULTICAST_LISTENER_QUERY";
|
||||
case ZT_ICMP6_MULTICAST_LISTENER_REPORT: return "ICMP6_MULTICAST_LISTENER_REPORT";
|
||||
case ZT_ICMP6_MULTICAST_LISTENER_DONE: return "ICMP6_MULTICAST_LISTENER_DONE";
|
||||
case ZT_ICMP6_ROUTER_SOLICITATION: return "ICMP6_ROUTER_SOLICITATION";
|
||||
case ZT_ICMP6_ROUTER_ADVERTISEMENT: return "ICMP6_ROUTER_ADVERTISEMENT";
|
||||
case ZT_ICMP6_NEIGHBOR_SOLICITATION: return "ICMP6_NEIGHBOR_SOLICITATION";
|
||||
case ZT_ICMP6_NEIGHBOR_ADVERTISEMENT: return "ICMP6_NEIGHBOR_ADVERTISEMENT";
|
||||
case ZT_ICMP6_REDIRECT_MESSAGE: return "ICMP6_REDIRECT_MESSAGE";
|
||||
case ZT_ICMP6_ROUTER_RENUMBERING: return "ICMP6_ROUTER_RENUMBERING";
|
||||
case ZT_ICMP6_NODE_INFORMATION_QUERY: return "ICMP6_NODE_INFORMATION_QUERY";
|
||||
case ZT_ICMP6_NODE_INFORMATION_RESPONSE: return "ICMP6_NODE_INFORMATION_RESPONSE";
|
||||
case ZT_ICMP6_INV_NEIGHBOR_SOLICITATION: return "ICMP6_INV_NEIGHBOR_SOLICITATION";
|
||||
case ZT_ICMP6_INV_NEIGHBOR_ADVERTISEMENT: return "ICMP6_INV_NEIGHBOR_ADVERTISEMENT";
|
||||
case ZT_ICMP6_MLDV2: return "ICMP6_MLDV2";
|
||||
case ZT_ICMP6_HOME_AGENT_ADDRESS_DISCOVERY_REQUEST: return "ICMP6_HOME_AGENT_ADDRESS_DISCOVERY_REQUEST";
|
||||
case ZT_ICMP6_HOME_AGENT_ADDRESS_DISCOVERY_REPLY: return "ICMP6_HOME_AGENT_ADDRESS_DISCOVERY_REPLY";
|
||||
case ZT_ICMP6_MOBILE_PREFIX_SOLICITATION: return "ICMP6_MOBILE_PREFIX_SOLICITATION";
|
||||
case ZT_ICMP6_MOBILE_PREFIX_ADVERTISEMENT: return "ICMP6_MOBILE_PREFIX_ADVERTISEMENT";
|
||||
case ZT_ICMP6_CERTIFICATION_PATH_SOLICITATION: return "ICMP6_CERTIFICATION_PATH_SOLICITATION";
|
||||
case ZT_ICMP6_CERTIFICATION_PATH_ADVERTISEMENT: return "ICMP6_CERTIFICATION_PATH_ADVERTISEMENT";
|
||||
case ZT_ICMP6_MULTICAST_ROUTER_ADVERTISEMENT: return "ICMP6_MULTICAST_ROUTER_ADVERTISEMENT";
|
||||
case ZT_ICMP6_MULTICAST_ROUTER_SOLICITATION: return "ICMP6_MULTICAST_ROUTER_SOLICITATION";
|
||||
case ZT_ICMP6_MULTICAST_ROUTER_TERMINATION: return "ICMP6_MULTICAST_ROUTER_TERMINATION";
|
||||
case ZT_ICMP6_RPL_CONTROL_MESSAGE: return "ICMP6_RPL_CONTROL_MESSAGE";
|
||||
}
|
||||
return UNKNOWN_NAME;
|
||||
}
|
||||
|
||||
} // namespace ZeroTier
|
284
attic/Filter.hpp
284
attic/Filter.hpp
@ -1,284 +0,0 @@
|
||||
/*
|
||||
* ZeroTier One - Network Virtualization Everywhere
|
||||
* Copyright (C) 2011-2015 ZeroTier, Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* --
|
||||
*
|
||||
* ZeroTier may be used and distributed under the terms of the GPLv3, which
|
||||
* are available at: http://www.gnu.org/licenses/gpl-3.0.html
|
||||
*
|
||||
* If you would like to embed ZeroTier into a commercial application or
|
||||
* redistribute it in a modified binary form, please contact ZeroTier Networks
|
||||
* LLC. Start here: http://www.zerotier.com/
|
||||
*/
|
||||
|
||||
#ifndef _ZT_FILTER_HPP
|
||||
#define _ZT_FILTER_HPP
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
#include <stdexcept>
|
||||
|
||||
#include "Range.hpp"
|
||||
|
||||
/* Ethernet frame types that might be relevant to us */
|
||||
#define ZT_ETHERTYPE_IPV4 0x0800
|
||||
#define ZT_ETHERTYPE_ARP 0x0806
|
||||
#define ZT_ETHERTYPE_RARP 0x8035
|
||||
#define ZT_ETHERTYPE_ATALK 0x809b
|
||||
#define ZT_ETHERTYPE_AARP 0x80f3
|
||||
#define ZT_ETHERTYPE_IPX_A 0x8137
|
||||
#define ZT_ETHERTYPE_IPX_B 0x8138
|
||||
#define ZT_ETHERTYPE_IPV6 0x86dd
|
||||
|
||||
/* IP protocols we might care about */
|
||||
#define ZT_IPPROTO_ICMP 0x01
|
||||
#define ZT_IPPROTO_IGMP 0x02
|
||||
#define ZT_IPPROTO_TCP 0x06
|
||||
#define ZT_IPPROTO_UDP 0x11
|
||||
#define ZT_IPPROTO_GRE 0x2f
|
||||
#define ZT_IPPROTO_ESP 0x32
|
||||
#define ZT_IPPROTO_AH 0x33
|
||||
#define ZT_IPPROTO_ICMPV6 0x3a
|
||||
#define ZT_IPPROTO_OSPF 0x59
|
||||
#define ZT_IPPROTO_IPIP 0x5e
|
||||
#define ZT_IPPROTO_IPCOMP 0x6c
|
||||
#define ZT_IPPROTO_L2TP 0x73
|
||||
#define ZT_IPPROTO_SCTP 0x84
|
||||
#define ZT_IPPROTO_FC 0x85
|
||||
#define ZT_IPPROTO_UDPLITE 0x88
|
||||
#define ZT_IPPROTO_HIP 0x8b
|
||||
|
||||
/* IPv4 ICMP types */
|
||||
#define ZT_ICMP_ECHO_REPLY 0
|
||||
#define ZT_ICMP_DESTINATION_UNREACHABLE 3
|
||||
#define ZT_ICMP_SOURCE_QUENCH 4
|
||||
#define ZT_ICMP_REDIRECT 5
|
||||
#define ZT_ICMP_ALTERNATE_HOST_ADDRESS 6
|
||||
#define ZT_ICMP_ECHO_REQUEST 8
|
||||
#define ZT_ICMP_ROUTER_ADVERTISEMENT 9
|
||||
#define ZT_ICMP_ROUTER_SOLICITATION 10
|
||||
#define ZT_ICMP_TIME_EXCEEDED 11
|
||||
#define ZT_ICMP_BAD_IP_HEADER 12
|
||||
#define ZT_ICMP_TIMESTAMP 13
|
||||
#define ZT_ICMP_TIMESTAMP_REPLY 14
|
||||
#define ZT_ICMP_INFORMATION_REQUEST 15
|
||||
#define ZT_ICMP_INFORMATION_REPLY 16
|
||||
#define ZT_ICMP_ADDRESS_MASK_REQUEST 17
|
||||
#define ZT_ICMP_ADDRESS_MASK_REPLY 18
|
||||
#define ZT_ICMP_TRACEROUTE 30
|
||||
#define ZT_ICMP_MOBILE_HOST_REDIRECT 32
|
||||
#define ZT_ICMP_MOBILE_REGISTRATION_REQUEST 35
|
||||
#define ZT_ICMP_MOBILE_REGISTRATION_REPLY 36
|
||||
|
||||
/* IPv6 ICMP types */
|
||||
#define ZT_ICMP6_DESTINATION_UNREACHABLE 1
|
||||
#define ZT_ICMP6_PACKET_TOO_BIG 2
|
||||
#define ZT_ICMP6_TIME_EXCEEDED 3
|
||||
#define ZT_ICMP6_PARAMETER_PROBLEM 4
|
||||
#define ZT_ICMP6_ECHO_REQUEST 128
|
||||
#define ZT_ICMP6_ECHO_REPLY 129
|
||||
#define ZT_ICMP6_MULTICAST_LISTENER_QUERY 130
|
||||
#define ZT_ICMP6_MULTICAST_LISTENER_REPORT 131
|
||||
#define ZT_ICMP6_MULTICAST_LISTENER_DONE 132
|
||||
#define ZT_ICMP6_ROUTER_SOLICITATION 133
|
||||
#define ZT_ICMP6_ROUTER_ADVERTISEMENT 134
|
||||
#define ZT_ICMP6_NEIGHBOR_SOLICITATION 135
|
||||
#define ZT_ICMP6_NEIGHBOR_ADVERTISEMENT 136
|
||||
#define ZT_ICMP6_REDIRECT_MESSAGE 137
|
||||
#define ZT_ICMP6_ROUTER_RENUMBERING 138
|
||||
#define ZT_ICMP6_NODE_INFORMATION_QUERY 139
|
||||
#define ZT_ICMP6_NODE_INFORMATION_RESPONSE 140
|
||||
#define ZT_ICMP6_INV_NEIGHBOR_SOLICITATION 141
|
||||
#define ZT_ICMP6_INV_NEIGHBOR_ADVERTISEMENT 142
|
||||
#define ZT_ICMP6_MLDV2 143
|
||||
#define ZT_ICMP6_HOME_AGENT_ADDRESS_DISCOVERY_REQUEST 144
|
||||
#define ZT_ICMP6_HOME_AGENT_ADDRESS_DISCOVERY_REPLY 145
|
||||
#define ZT_ICMP6_MOBILE_PREFIX_SOLICITATION 146
|
||||
#define ZT_ICMP6_MOBILE_PREFIX_ADVERTISEMENT 147
|
||||
#define ZT_ICMP6_CERTIFICATION_PATH_SOLICITATION 148
|
||||
#define ZT_ICMP6_CERTIFICATION_PATH_ADVERTISEMENT 149
|
||||
#define ZT_ICMP6_MULTICAST_ROUTER_ADVERTISEMENT 151
|
||||
#define ZT_ICMP6_MULTICAST_ROUTER_SOLICITATION 152
|
||||
#define ZT_ICMP6_MULTICAST_ROUTER_TERMINATION 153
|
||||
#define ZT_ICMP6_RPL_CONTROL_MESSAGE 155
|
||||
|
||||
namespace ZeroTier {
|
||||
|
||||
class RuntimeEnvironment;
|
||||
|
||||
/**
|
||||
* A simple Ethernet frame level filter
|
||||
*
|
||||
* This doesn't specify actions, since it's used as a deny filter. The rule
|
||||
* in ZT1 is "that which is not explicitly prohibited is allowed." (Except for
|
||||
* ethertypes, which are handled by a whitelist.)
|
||||
*/
|
||||
class Filter
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Value returned by etherTypeName, etc. on unknown
|
||||
*
|
||||
* These static methods return precisely this, so a pointer equality
|
||||
* check will work.
|
||||
*/
|
||||
static const char *const UNKNOWN_NAME;
|
||||
|
||||
/**
|
||||
* An empty range as a more idiomatic way of specifying a wildcard match
|
||||
*/
|
||||
static const Range<unsigned int> ANY;
|
||||
|
||||
/**
|
||||
* A filter rule
|
||||
*/
|
||||
class Rule
|
||||
{
|
||||
public:
|
||||
Rule()
|
||||
throw() :
|
||||
_etherType(),
|
||||
_protocol(),
|
||||
_port()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a rule from a string-serialized value
|
||||
*
|
||||
* @param s String formatted rule, such as returned by toString()
|
||||
* @throws std::invalid_argument String formatted rule is not valid
|
||||
*/
|
||||
Rule(const char *s)
|
||||
throw(std::invalid_argument);
|
||||
|
||||
/**
|
||||
* Construct a new rule
|
||||
*
|
||||
* @param etype Ethernet type or empty range for ANY
|
||||
* @param prot Protocol or empty range for ANY (meaning depends on ethertype, e.g. IP protocol numbers)
|
||||
* @param prt Port or empty range for ANY (only applies to some protocols)
|
||||
*/
|
||||
Rule(const Range<unsigned int> &etype,const Range<unsigned int> &prot,const Range<unsigned int> &prt)
|
||||
throw() :
|
||||
_etherType(etype),
|
||||
_protocol(prot),
|
||||
_port(prt)
|
||||
{
|
||||
}
|
||||
|
||||
inline const Range<unsigned int> ðerType() const throw() { return _etherType; }
|
||||
inline const Range<unsigned int> &protocol() const throw() { return _protocol; }
|
||||
inline const Range<unsigned int> &port() const throw() { return _port; }
|
||||
|
||||
/**
|
||||
* Test this rule against a frame
|
||||
*
|
||||
* @param etype Type of ethernet frame
|
||||
* @param data Ethernet frame data
|
||||
* @param len Length of ethernet frame
|
||||
* @return True if rule matches
|
||||
* @throws std::invalid_argument Frame invalid or not parseable
|
||||
*/
|
||||
bool operator()(unsigned int etype,const void *data,unsigned int len) const
|
||||
throw(std::invalid_argument);
|
||||
|
||||
/**
|
||||
* Serialize rule as string
|
||||
*
|
||||
* @return Human readable representation of rule
|
||||
*/
|
||||
std::string toString() const;
|
||||
|
||||
inline bool operator==(const Rule &r) const throw() { return ((_etherType == r._etherType)&&(_protocol == r._protocol)&&(_port == r._port)); }
|
||||
inline bool operator!=(const Rule &r) const throw() { return !(*this == r); }
|
||||
inline bool operator<(const Rule &r) const
|
||||
throw()
|
||||
{
|
||||
if (_etherType < r._etherType)
|
||||
return true;
|
||||
else if (_etherType == r._etherType) {
|
||||
if (_protocol < r._protocol)
|
||||
return true;
|
||||
else if (_protocol == r._protocol) {
|
||||
if (_port < r._port)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
inline bool operator>(const Rule &r) const throw() { return (r < *this); }
|
||||
inline bool operator<=(const Rule &r) const throw() { return !(r < *this); }
|
||||
inline bool operator>=(const Rule &r) const throw() { return !(*this < r); }
|
||||
|
||||
private:
|
||||
Range<unsigned int> _etherType;
|
||||
Range<unsigned int> _protocol;
|
||||
Range<unsigned int> _port;
|
||||
};
|
||||
|
||||
Filter() {}
|
||||
|
||||
/**
|
||||
* @param s String-serialized filter representation
|
||||
*/
|
||||
Filter(const char *s)
|
||||
throw(std::invalid_argument);
|
||||
|
||||
/**
|
||||
* @return Comma-delimited list of string-format rules
|
||||
*/
|
||||
std::string toString() const;
|
||||
|
||||
/**
|
||||
* Add a rule to this filter
|
||||
*
|
||||
* @param r Rule to add to filter
|
||||
*/
|
||||
void add(const Rule &r);
|
||||
|
||||
inline bool operator()(unsigned int etype,const void *data,unsigned int len) const
|
||||
throw(std::invalid_argument)
|
||||
{
|
||||
for(std::vector<Rule>::const_iterator r(_rules.begin());r!=_rules.end();++r) {
|
||||
if ((*r)(etype,data,len))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static const char *etherTypeName(const unsigned int etherType)
|
||||
throw();
|
||||
static const char *ipProtocolName(const unsigned int ipp)
|
||||
throw();
|
||||
static const char *icmpTypeName(const unsigned int icmpType)
|
||||
throw();
|
||||
static const char *icmp6TypeName(const unsigned int icmp6Type)
|
||||
throw();
|
||||
|
||||
private:
|
||||
std::vector<Rule> _rules;
|
||||
};
|
||||
|
||||
} // namespace ZeroTier
|
||||
|
||||
#endif
|
@ -1,651 +0,0 @@
|
||||
/*
|
||||
* ZeroTier One - Network Virtualization Everywhere
|
||||
* Copyright (C) 2011-2015 ZeroTier, Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* --
|
||||
*
|
||||
* ZeroTier may be used and distributed under the terms of the GPLv3, which
|
||||
* are available at: http://www.gnu.org/licenses/gpl-3.0.html
|
||||
*
|
||||
* If you would like to embed ZeroTier into a commercial application or
|
||||
* redistribute it in a modified binary form, please contact ZeroTier Networks
|
||||
* LLC. Start here: http://www.zerotier.com/
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <net/route.h>
|
||||
#include <net/if.h>
|
||||
#include <net/if_arp.h>
|
||||
#include <net/if_dl.h>
|
||||
#include <net/if_media.h>
|
||||
#include <netinet6/in6_var.h>
|
||||
#include <netinet/in_var.h>
|
||||
#include <netinet/icmp6.h>
|
||||
|
||||
#include <pcap/pcap.h>
|
||||
|
||||
// OSX compile fix... in6_var defines this in a struct which namespaces it for C++ ... why?!?
|
||||
struct prf_ra {
|
||||
u_char onlink : 1;
|
||||
u_char autonomous : 1;
|
||||
u_char reserved : 6;
|
||||
} prf_ra;
|
||||
|
||||
#include <netinet6/nd6.h>
|
||||
#include <ifaddrs.h>
|
||||
|
||||
// These are KERNEL_PRIVATE... why?
|
||||
#ifndef SIOCAUTOCONF_START
|
||||
#define SIOCAUTOCONF_START _IOWR('i', 132, struct in6_ifreq) /* accept rtadvd on this interface */
|
||||
#endif
|
||||
#ifndef SIOCAUTOCONF_STOP
|
||||
#define SIOCAUTOCONF_STOP _IOWR('i', 133, struct in6_ifreq) /* stop accepting rtadv for this interface */
|
||||
#endif
|
||||
|
||||
#ifndef ETH_ALEN
|
||||
#define ETH_ALEN 6
|
||||
#endif
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// --------------------------------------------------------------------------
|
||||
// This source is from:
|
||||
// http://www.opensource.apple.com/source/Libinfo/Libinfo-406.17/gen.subproj/getifmaddrs.c?txt
|
||||
// It's here because OSX 10.6 does not have this convenience function.
|
||||
|
||||
#define SALIGN (sizeof(uint32_t) - 1)
|
||||
#define SA_RLEN(sa) ((sa)->sa_len ? (((sa)->sa_len + SALIGN) & ~SALIGN) : \
|
||||
(SALIGN + 1))
|
||||
#define MAX_SYSCTL_TRY 5
|
||||
#define RTA_MASKS (RTA_GATEWAY | RTA_IFP | RTA_IFA)
|
||||
|
||||
/* FreeBSD uses NET_RT_IFMALIST and RTM_NEWMADDR from <sys/socket.h> */
|
||||
/* We can use NET_RT_IFLIST2 and RTM_NEWMADDR2 on Darwin */
|
||||
//#define DARWIN_COMPAT
|
||||
|
||||
//#ifdef DARWIN_COMPAT
|
||||
#define GIM_SYSCTL_MIB NET_RT_IFLIST2
|
||||
#define GIM_RTM_ADDR RTM_NEWMADDR2
|
||||
//#else
|
||||
//#define GIM_SYSCTL_MIB NET_RT_IFMALIST
|
||||
//#define GIM_RTM_ADDR RTM_NEWMADDR
|
||||
//#endif
|
||||
|
||||
// Not in 10.6 includes so use our own
|
||||
struct _intl_ifmaddrs {
|
||||
struct _intl_ifmaddrs *ifma_next;
|
||||
struct sockaddr *ifma_name;
|
||||
struct sockaddr *ifma_addr;
|
||||
struct sockaddr *ifma_lladdr;
|
||||
};
|
||||
|
||||
static inline int _intl_getifmaddrs(struct _intl_ifmaddrs **pif)
|
||||
{
|
||||
int icnt = 1;
|
||||
int dcnt = 0;
|
||||
int ntry = 0;
|
||||
size_t len;
|
||||
size_t needed;
|
||||
int mib[6];
|
||||
int i;
|
||||
char *buf;
|
||||
char *data;
|
||||
char *next;
|
||||
char *p;
|
||||
struct ifma_msghdr2 *ifmam;
|
||||
struct _intl_ifmaddrs *ifa, *ift;
|
||||
struct rt_msghdr *rtm;
|
||||
struct sockaddr *sa;
|
||||
|
||||
mib[0] = CTL_NET;
|
||||
mib[1] = PF_ROUTE;
|
||||
mib[2] = 0; /* protocol */
|
||||
mib[3] = 0; /* wildcard address family */
|
||||
mib[4] = GIM_SYSCTL_MIB;
|
||||
mib[5] = 0; /* no flags */
|
||||
do {
|
||||
if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
|
||||
return (-1);
|
||||
if ((buf = (char *)malloc(needed)) == NULL)
|
||||
return (-1);
|
||||
if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) {
|
||||
if (errno != ENOMEM || ++ntry >= MAX_SYSCTL_TRY) {
|
||||
free(buf);
|
||||
return (-1);
|
||||
}
|
||||
free(buf);
|
||||
buf = NULL;
|
||||
}
|
||||
} while (buf == NULL);
|
||||
|
||||
for (next = buf; next < buf + needed; next += rtm->rtm_msglen) {
|
||||
rtm = (struct rt_msghdr *)(void *)next;
|
||||
if (rtm->rtm_version != RTM_VERSION)
|
||||
continue;
|
||||
switch (rtm->rtm_type) {
|
||||
case GIM_RTM_ADDR:
|
||||
ifmam = (struct ifma_msghdr2 *)(void *)rtm;
|
||||
if ((ifmam->ifmam_addrs & RTA_IFA) == 0)
|
||||
break;
|
||||
icnt++;
|
||||
p = (char *)(ifmam + 1);
|
||||
for (i = 0; i < RTAX_MAX; i++) {
|
||||
if ((RTA_MASKS & ifmam->ifmam_addrs &
|
||||
(1 << i)) == 0)
|
||||
continue;
|
||||
sa = (struct sockaddr *)(void *)p;
|
||||
len = SA_RLEN(sa);
|
||||
dcnt += len;
|
||||
p += len;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
data = (char *)malloc(sizeof(struct _intl_ifmaddrs) * icnt + dcnt);
|
||||
if (data == NULL) {
|
||||
free(buf);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
ifa = (struct _intl_ifmaddrs *)(void *)data;
|
||||
data += sizeof(struct _intl_ifmaddrs) * icnt;
|
||||
|
||||
memset(ifa, 0, sizeof(struct _intl_ifmaddrs) * icnt);
|
||||
ift = ifa;
|
||||
|
||||
for (next = buf; next < buf + needed; next += rtm->rtm_msglen) {
|
||||
rtm = (struct rt_msghdr *)(void *)next;
|
||||
if (rtm->rtm_version != RTM_VERSION)
|
||||
continue;
|
||||
|
||||
switch (rtm->rtm_type) {
|
||||
case GIM_RTM_ADDR:
|
||||
ifmam = (struct ifma_msghdr2 *)(void *)rtm;
|
||||
if ((ifmam->ifmam_addrs & RTA_IFA) == 0)
|
||||
break;
|
||||
|
||||
p = (char *)(ifmam + 1);
|
||||
for (i = 0; i < RTAX_MAX; i++) {
|
||||
if ((RTA_MASKS & ifmam->ifmam_addrs &
|
||||
(1 << i)) == 0)
|
||||
continue;
|
||||
sa = (struct sockaddr *)(void *)p;
|
||||
len = SA_RLEN(sa);
|
||||
switch (i) {
|
||||
case RTAX_GATEWAY:
|
||||
ift->ifma_lladdr =
|
||||
(struct sockaddr *)(void *)data;
|
||||
memcpy(data, p, len);
|
||||
data += len;
|
||||
break;
|
||||
|
||||
case RTAX_IFP:
|
||||
ift->ifma_name =
|
||||
(struct sockaddr *)(void *)data;
|
||||
memcpy(data, p, len);
|
||||
data += len;
|
||||
break;
|
||||
|
||||
case RTAX_IFA:
|
||||
ift->ifma_addr =
|
||||
(struct sockaddr *)(void *)data;
|
||||
memcpy(data, p, len);
|
||||
data += len;
|
||||
break;
|
||||
|
||||
default:
|
||||
data += len;
|
||||
break;
|
||||
}
|
||||
p += len;
|
||||
}
|
||||
ift->ifma_next = ift + 1;
|
||||
ift = ift->ifma_next;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
free(buf);
|
||||
|
||||
if (ift > ifa) {
|
||||
ift--;
|
||||
ift->ifma_next = NULL;
|
||||
*pif = ifa;
|
||||
} else {
|
||||
*pif = NULL;
|
||||
free(ifa);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
static inline void _intl_freeifmaddrs(struct _intl_ifmaddrs *ifmp)
|
||||
{
|
||||
free(ifmp);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <algorithm>
|
||||
|
||||
#include "../node/Constants.hpp"
|
||||
#include "../node/Utils.hpp"
|
||||
#include "../node/Mutex.hpp"
|
||||
#include "../node/Dictionary.hpp"
|
||||
#include "OSUtils.hpp"
|
||||
#include "OSXEthernetTap.hpp"
|
||||
|
||||
// ff:ff:ff:ff:ff:ff with no ADI
|
||||
static const ZeroTier::MulticastGroup _blindWildcardMulticastGroup(ZeroTier::MAC(0xff),0);
|
||||
|
||||
static inline bool _setIpv6Stuff(const char *ifname,bool performNUD,bool acceptRouterAdverts)
|
||||
{
|
||||
struct in6_ndireq nd;
|
||||
struct in6_ifreq ifr;
|
||||
|
||||
int s = socket(AF_INET6,SOCK_DGRAM,0);
|
||||
if (s <= 0)
|
||||
return false;
|
||||
|
||||
memset(&nd,0,sizeof(nd));
|
||||
strncpy(nd.ifname,ifname,sizeof(nd.ifname));
|
||||
|
||||
if (ioctl(s,SIOCGIFINFO_IN6,&nd)) {
|
||||
close(s);
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned long oldFlags = (unsigned long)nd.ndi.flags;
|
||||
|
||||
if (performNUD)
|
||||
nd.ndi.flags |= ND6_IFF_PERFORMNUD;
|
||||
else nd.ndi.flags &= ~ND6_IFF_PERFORMNUD;
|
||||
|
||||
if (oldFlags != (unsigned long)nd.ndi.flags) {
|
||||
if (ioctl(s,SIOCSIFINFO_FLAGS,&nd)) {
|
||||
close(s);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
memset(&ifr,0,sizeof(ifr));
|
||||
strncpy(ifr.ifr_name,ifname,sizeof(ifr.ifr_name));
|
||||
if (ioctl(s,acceptRouterAdverts ? SIOCAUTOCONF_START : SIOCAUTOCONF_STOP,&ifr)) {
|
||||
close(s);
|
||||
return false;
|
||||
}
|
||||
|
||||
close(s);
|
||||
return true;
|
||||
}
|
||||
|
||||
namespace ZeroTier {
|
||||
|
||||
static std::set<std::string> globalDeviceNames;
|
||||
static Mutex globalTapCreateLock;
|
||||
|
||||
OSXEthernetTap::OSXEthernetTap(
|
||||
const char *homePath,
|
||||
const MAC &mac,
|
||||
unsigned int mtu,
|
||||
unsigned int metric,
|
||||
uint64_t nwid,
|
||||
const char *friendlyName,
|
||||
void (*handler)(void *,uint64_t,const MAC &,const MAC &,unsigned int,unsigned int,const void *data,unsigned int len),
|
||||
void *arg) :
|
||||
_handler(handler),
|
||||
_arg(arg),
|
||||
_pcap((void *)0),
|
||||
_nwid(nwid),
|
||||
_mac(mac),
|
||||
_homePath(homePath),
|
||||
_mtu(mtu),
|
||||
_metric(metric),
|
||||
_enabled(true)
|
||||
{
|
||||
char errbuf[PCAP_ERRBUF_SIZE];
|
||||
char devname[64],ethaddr[64],mtustr[32],metstr[32],nwids[32];
|
||||
|
||||
Utils::snprintf(nwids,sizeof(nwids),"%.16llx",nwid);
|
||||
|
||||
if (mtu > 2800)
|
||||
throw std::runtime_error("max tap MTU is 2800");
|
||||
|
||||
Mutex::Lock _gl(globalTapCreateLock);
|
||||
|
||||
std::string desiredDevice;
|
||||
Dictionary devmap;
|
||||
{
|
||||
std::string devmapbuf;
|
||||
if (OSUtils::readFile((_homePath + ZT_PATH_SEPARATOR_S + "devicemap").c_str(),devmapbuf)) {
|
||||
devmap.fromString(devmapbuf);
|
||||
desiredDevice = devmap.get(nwids,"");
|
||||
}
|
||||
}
|
||||
|
||||
if ((desiredDevice.length() >= 9)&&(desiredDevice.substr(0,6) == "bridge")) {
|
||||
// length() >= 9 matches bridge### or bridge####
|
||||
_dev = desiredDevice;
|
||||
} else {
|
||||
if (globalDeviceNames.size() >= (10000 - 128)) // sanity check... this would be nuts
|
||||
throw std::runtime_error("too many devices!");
|
||||
unsigned int pseudoBridgeNo = (unsigned int)((nwid ^ (nwid >> 32)) % (10000 - 128)) + 128; // range: bridge128 to bridge9999
|
||||
sprintf(devname,"bridge%u",pseudoBridgeNo);
|
||||
while (globalDeviceNames.count(std::string(devname)) > 0) {
|
||||
++pseudoBridgeNo;
|
||||
if (pseudoBridgeNo > 9999)
|
||||
pseudoBridgeNo = 64;
|
||||
sprintf(devname,"bridge%u",pseudoBridgeNo);
|
||||
}
|
||||
_dev = devname;
|
||||
}
|
||||
|
||||
// Configure MAC address and MTU, bring interface up
|
||||
long cpid = (long)vfork();
|
||||
if (cpid == 0) {
|
||||
::execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),"create",(const char *)0);
|
||||
::_exit(-1);
|
||||
} else if (cpid > 0) {
|
||||
int exitcode = -1;
|
||||
::waitpid(cpid,&exitcode,0);
|
||||
if (exitcode != 0)
|
||||
throw std::runtime_error("ifconfig failure setting link-layer address and activating tap interface");
|
||||
} else throw std::runtime_error("unable to fork()");
|
||||
Utils::snprintf(ethaddr,sizeof(ethaddr),"%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",(int)mac[0],(int)mac[1],(int)mac[2],(int)mac[3],(int)mac[4],(int)mac[5]);
|
||||
Utils::snprintf(mtustr,sizeof(mtustr),"%u",_mtu);
|
||||
Utils::snprintf(metstr,sizeof(metstr),"%u",_metric);
|
||||
cpid = (long)vfork();
|
||||
if (cpid == 0) {
|
||||
::execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),"lladdr",ethaddr,"mtu",mtustr,"metric",metstr,"up",(const char *)0);
|
||||
::_exit(-1);
|
||||
} else if (cpid > 0) {
|
||||
int exitcode = -1;
|
||||
::waitpid(cpid,&exitcode,0);
|
||||
if (exitcode != 0)
|
||||
throw std::runtime_error("ifconfig failure setting link-layer address and activating tap interface");
|
||||
} else throw std::runtime_error("unable to fork()");
|
||||
|
||||
_setIpv6Stuff(_dev.c_str(),true,false);
|
||||
|
||||
_pcap = (void *)pcap_create(_dev.c_str(),errbuf);
|
||||
if (!_pcap) {
|
||||
cpid = (long)vfork();
|
||||
if (cpid == 0) {
|
||||
::execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),"destroy",(const char *)0);
|
||||
::_exit(-1);
|
||||
} else if (cpid > 0) {
|
||||
int exitcode = -1;
|
||||
::waitpid(cpid,&exitcode,0);
|
||||
}
|
||||
throw std::runtime_error((std::string("pcap_create() on new bridge device failed: ") + errbuf).c_str());
|
||||
}
|
||||
pcap_set_promisc(reinterpret_cast<pcap_t *>(_pcap),1);
|
||||
pcap_set_timeout(reinterpret_cast<pcap_t *>(_pcap),120000);
|
||||
pcap_set_immediate_mode(reinterpret_cast<pcap_t *>(_pcap),1);
|
||||
if (pcap_set_buffer_size(reinterpret_cast<pcap_t *>(_pcap),1024 * 1024 * 16) != 0) // 16MB
|
||||
fprintf(stderr,"WARNING: pcap_set_buffer_size() failed!\n");
|
||||
if (pcap_set_snaplen(reinterpret_cast<pcap_t *>(_pcap),4096) != 0)
|
||||
fprintf(stderr,"WARNING: pcap_set_snaplen() failed!\n");
|
||||
if (pcap_activate(reinterpret_cast<pcap_t *>(_pcap)) != 0) {
|
||||
pcap_close(reinterpret_cast<pcap_t *>(_pcap));
|
||||
cpid = (long)vfork();
|
||||
if (cpid == 0) {
|
||||
::execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),"destroy",(const char *)0);
|
||||
::_exit(-1);
|
||||
} else if (cpid > 0) {
|
||||
int exitcode = -1;
|
||||
::waitpid(cpid,&exitcode,0);
|
||||
}
|
||||
throw std::runtime_error("pcap_activate() on new bridge device failed.");
|
||||
}
|
||||
|
||||
globalDeviceNames.insert(_dev);
|
||||
|
||||
devmap[nwids] = _dev;
|
||||
OSUtils::writeFile((_homePath + ZT_PATH_SEPARATOR_S + "devicemap").c_str(),devmap.toString());
|
||||
|
||||
_thread = Thread::start(this);
|
||||
}
|
||||
|
||||
OSXEthernetTap::~OSXEthernetTap()
|
||||
{
|
||||
_enabled = false;
|
||||
|
||||
Mutex::Lock _gl(globalTapCreateLock);
|
||||
globalDeviceNames.erase(_dev);
|
||||
|
||||
long cpid = (long)vfork();
|
||||
if (cpid == 0) {
|
||||
::execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),"destroy",(const char *)0);
|
||||
::_exit(-1);
|
||||
} else if (cpid > 0) {
|
||||
int exitcode = -1;
|
||||
::waitpid(cpid,&exitcode,0);
|
||||
if (exitcode == 0) {
|
||||
// Destroying the interface nukes pcap and terminates the thread.
|
||||
Thread::join(_thread);
|
||||
}
|
||||
}
|
||||
|
||||
pcap_close(reinterpret_cast<pcap_t *>(_pcap));
|
||||
}
|
||||
|
||||
static bool ___removeIp(const std::string &_dev,const InetAddress &ip)
|
||||
{
|
||||
long cpid = (long)vfork();
|
||||
if (cpid == 0) {
|
||||
execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),"inet",ip.toIpString().c_str(),"-alias",(const char *)0);
|
||||
_exit(-1);
|
||||
} else if (cpid > 0) {
|
||||
int exitcode = -1;
|
||||
waitpid(cpid,&exitcode,0);
|
||||
return (exitcode == 0);
|
||||
}
|
||||
return false; // never reached, make compiler shut up about return value
|
||||
}
|
||||
|
||||
bool OSXEthernetTap::addIp(const InetAddress &ip)
|
||||
{
|
||||
if (!ip)
|
||||
return false;
|
||||
|
||||
std::vector<InetAddress> allIps(ips());
|
||||
if (std::binary_search(allIps.begin(),allIps.end(),ip))
|
||||
return true;
|
||||
|
||||
// Remove and reconfigure if address is the same but netmask is different
|
||||
for(std::vector<InetAddress>::iterator i(allIps.begin());i!=allIps.end();++i) {
|
||||
if ((i->ipsEqual(ip))&&(i->netmaskBits() != ip.netmaskBits())) {
|
||||
if (___removeIp(_dev,*i))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
long cpid = (long)vfork();
|
||||
if (cpid == 0) {
|
||||
::execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),ip.isV4() ? "inet" : "inet6",ip.toString().c_str(),"alias",(const char *)0);
|
||||
::_exit(-1);
|
||||
} else if (cpid > 0) {
|
||||
int exitcode = -1;
|
||||
::waitpid(cpid,&exitcode,0);
|
||||
return (exitcode == 0);
|
||||
} // else return false...
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool OSXEthernetTap::removeIp(const InetAddress &ip)
|
||||
{
|
||||
if (!ip)
|
||||
return true;
|
||||
std::vector<InetAddress> allIps(ips());
|
||||
if (!std::binary_search(allIps.begin(),allIps.end(),ip)) {
|
||||
if (___removeIp(_dev,ip))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<InetAddress> OSXEthernetTap::ips() const
|
||||
{
|
||||
struct ifaddrs *ifa = (struct ifaddrs *)0;
|
||||
if (getifaddrs(&ifa))
|
||||
return std::vector<InetAddress>();
|
||||
|
||||
std::vector<InetAddress> r;
|
||||
|
||||
struct ifaddrs *p = ifa;
|
||||
while (p) {
|
||||
if ((!strcmp(p->ifa_name,_dev.c_str()))&&(p->ifa_addr)&&(p->ifa_netmask)&&(p->ifa_addr->sa_family == p->ifa_netmask->sa_family)) {
|
||||
switch(p->ifa_addr->sa_family) {
|
||||
case AF_INET: {
|
||||
struct sockaddr_in *sin = (struct sockaddr_in *)p->ifa_addr;
|
||||
struct sockaddr_in *nm = (struct sockaddr_in *)p->ifa_netmask;
|
||||
r.push_back(InetAddress(&(sin->sin_addr.s_addr),4,Utils::countBits((uint32_t)nm->sin_addr.s_addr)));
|
||||
} break;
|
||||
case AF_INET6: {
|
||||
struct sockaddr_in6 *sin = (struct sockaddr_in6 *)p->ifa_addr;
|
||||
struct sockaddr_in6 *nm = (struct sockaddr_in6 *)p->ifa_netmask;
|
||||
uint32_t b[4];
|
||||
memcpy(b,nm->sin6_addr.s6_addr,sizeof(b));
|
||||
r.push_back(InetAddress(sin->sin6_addr.s6_addr,16,Utils::countBits(b[0]) + Utils::countBits(b[1]) + Utils::countBits(b[2]) + Utils::countBits(b[3])));
|
||||
} break;
|
||||
}
|
||||
}
|
||||
p = p->ifa_next;
|
||||
}
|
||||
|
||||
if (ifa)
|
||||
freeifaddrs(ifa);
|
||||
|
||||
std::sort(r.begin(),r.end());
|
||||
std::unique(r.begin(),r.end());
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
void OSXEthernetTap::put(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len)
|
||||
{
|
||||
char putBuf[4096];
|
||||
if ((len <= _mtu)&&(_enabled)) {
|
||||
to.copyTo(putBuf,6);
|
||||
from.copyTo(putBuf + 6,6);
|
||||
*((uint16_t *)(putBuf + 12)) = htons((uint16_t)etherType);
|
||||
memcpy(putBuf + 14,data,len);
|
||||
len += 14;
|
||||
int r = pcap_inject(reinterpret_cast<pcap_t *>(_pcap),putBuf,len);
|
||||
if (r <= 0) {
|
||||
printf("%s: pcap_inject() failed\n",_dev.c_str());
|
||||
return;
|
||||
}
|
||||
printf("%s: inject %s -> %s etherType==%u len=%u r==%d\n",_dev.c_str(),from.toString().c_str(),to.toString().c_str(),etherType,len,r);
|
||||
}
|
||||
}
|
||||
|
||||
std::string OSXEthernetTap::deviceName() const
|
||||
{
|
||||
return _dev;
|
||||
}
|
||||
|
||||
void OSXEthernetTap::setFriendlyName(const char *friendlyName)
|
||||
{
|
||||
}
|
||||
|
||||
void OSXEthernetTap::scanMulticastGroups(std::vector<MulticastGroup> &added,std::vector<MulticastGroup> &removed)
|
||||
{
|
||||
std::vector<MulticastGroup> newGroups;
|
||||
|
||||
struct _intl_ifmaddrs *ifmap = (struct _intl_ifmaddrs *)0;
|
||||
if (!_intl_getifmaddrs(&ifmap)) {
|
||||
struct _intl_ifmaddrs *p = ifmap;
|
||||
while (p) {
|
||||
if (p->ifma_addr->sa_family == AF_LINK) {
|
||||
struct sockaddr_dl *in = (struct sockaddr_dl *)p->ifma_name;
|
||||
struct sockaddr_dl *la = (struct sockaddr_dl *)p->ifma_addr;
|
||||
if ((la->sdl_alen == 6)&&(in->sdl_nlen <= _dev.length())&&(!memcmp(_dev.data(),in->sdl_data,in->sdl_nlen)))
|
||||
newGroups.push_back(MulticastGroup(MAC(la->sdl_data + la->sdl_nlen,6),0));
|
||||
}
|
||||
p = p->ifma_next;
|
||||
}
|
||||
_intl_freeifmaddrs(ifmap);
|
||||
}
|
||||
|
||||
std::vector<InetAddress> allIps(ips());
|
||||
for(std::vector<InetAddress>::iterator ip(allIps.begin());ip!=allIps.end();++ip)
|
||||
newGroups.push_back(MulticastGroup::deriveMulticastGroupForAddressResolution(*ip));
|
||||
|
||||
std::sort(newGroups.begin(),newGroups.end());
|
||||
std::unique(newGroups.begin(),newGroups.end());
|
||||
|
||||
for(std::vector<MulticastGroup>::iterator m(newGroups.begin());m!=newGroups.end();++m) {
|
||||
if (!std::binary_search(_multicastGroups.begin(),_multicastGroups.end(),*m))
|
||||
added.push_back(*m);
|
||||
}
|
||||
for(std::vector<MulticastGroup>::iterator m(_multicastGroups.begin());m!=_multicastGroups.end();++m) {
|
||||
if (!std::binary_search(newGroups.begin(),newGroups.end(),*m))
|
||||
removed.push_back(*m);
|
||||
}
|
||||
|
||||
_multicastGroups.swap(newGroups);
|
||||
}
|
||||
|
||||
static void _pcapHandler(u_char *ptr,const struct pcap_pkthdr *hdr,const u_char *data)
|
||||
{
|
||||
OSXEthernetTap *tap = reinterpret_cast<OSXEthernetTap *>(ptr);
|
||||
if (hdr->caplen > 14) {
|
||||
MAC to(data,6);
|
||||
MAC from(data + 6,6);
|
||||
if (from == tap->_mac) {
|
||||
unsigned int etherType = ntohs(((const uint16_t *)data)[6]);
|
||||
printf("%s: %s -> %s etherType==%u len==%u\n",tap->_dev.c_str(),from.toString().c_str(),to.toString().c_str(),etherType,(unsigned int)hdr->caplen);
|
||||
// TODO: VLAN support
|
||||
tap->_handler(tap->_arg,tap->_nwid,from,to,etherType,0,(const void *)(data + 14),hdr->len - 14);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OSXEthernetTap::threadMain()
|
||||
throw()
|
||||
{
|
||||
pcap_loop(reinterpret_cast<pcap_t *>(_pcap),-1,&_pcapHandler,reinterpret_cast<u_char *>(this));
|
||||
}
|
||||
|
||||
} // namespace ZeroTier
|
@ -1,832 +0,0 @@
|
||||
/*
|
||||
* ZeroTier One - Network Virtualization Everywhere
|
||||
* Copyright (C) 2011-2015 ZeroTier, Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* --
|
||||
*
|
||||
* ZeroTier may be used and distributed under the terms of the GPLv3, which
|
||||
* are available at: http://www.gnu.org/licenses/gpl-3.0.html
|
||||
*
|
||||
* If you would like to embed ZeroTier into a commercial application or
|
||||
* redistribute it in a modified binary form, please contact ZeroTier Networks
|
||||
* LLC. Start here: http://www.zerotier.com/
|
||||
*/
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/wait.h>
|
||||
#include <sys/select.h>
|
||||
#include <sys/cdefs.h>
|
||||
#include <sys/uio.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/sysctl.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/sys_domain.h>
|
||||
#include <sys/kern_control.h>
|
||||
#include <net/if_utun.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <net/route.h>
|
||||
#include <net/if.h>
|
||||
#include <net/if_arp.h>
|
||||
#include <net/if_dl.h>
|
||||
#include <net/if_media.h>
|
||||
#include <netinet6/in6_var.h>
|
||||
#include <netinet/in_var.h>
|
||||
#include <netinet/icmp6.h>
|
||||
|
||||
// OSX compile fix... in6_var defines this in a struct which namespaces it for C++ ... why?!?
|
||||
struct prf_ra {
|
||||
u_char onlink : 1;
|
||||
u_char autonomous : 1;
|
||||
u_char reserved : 6;
|
||||
} prf_ra;
|
||||
|
||||
#include <netinet6/nd6.h>
|
||||
#include <ifaddrs.h>
|
||||
|
||||
// These are KERNEL_PRIVATE... why?
|
||||
#ifndef SIOCAUTOCONF_START
|
||||
#define SIOCAUTOCONF_START _IOWR('i', 132, struct in6_ifreq) /* accept rtadvd on this interface */
|
||||
#endif
|
||||
#ifndef SIOCAUTOCONF_STOP
|
||||
#define SIOCAUTOCONF_STOP _IOWR('i', 133, struct in6_ifreq) /* stop accepting rtadv for this interface */
|
||||
#endif
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// --------------------------------------------------------------------------
|
||||
// This source is from:
|
||||
// http://www.opensource.apple.com/source/Libinfo/Libinfo-406.17/gen.subproj/getifmaddrs.c?txt
|
||||
// It's here because OSX 10.6 does not have this convenience function.
|
||||
|
||||
#define SALIGN (sizeof(uint32_t) - 1)
|
||||
#define SA_RLEN(sa) ((sa)->sa_len ? (((sa)->sa_len + SALIGN) & ~SALIGN) : \
|
||||
(SALIGN + 1))
|
||||
#define MAX_SYSCTL_TRY 5
|
||||
#define RTA_MASKS (RTA_GATEWAY | RTA_IFP | RTA_IFA)
|
||||
|
||||
/* FreeBSD uses NET_RT_IFMALIST and RTM_NEWMADDR from <sys/socket.h> */
|
||||
/* We can use NET_RT_IFLIST2 and RTM_NEWMADDR2 on Darwin */
|
||||
//#define DARWIN_COMPAT
|
||||
|
||||
//#ifdef DARWIN_COMPAT
|
||||
#define GIM_SYSCTL_MIB NET_RT_IFLIST2
|
||||
#define GIM_RTM_ADDR RTM_NEWMADDR2
|
||||
//#else
|
||||
//#define GIM_SYSCTL_MIB NET_RT_IFMALIST
|
||||
//#define GIM_RTM_ADDR RTM_NEWMADDR
|
||||
//#endif
|
||||
|
||||
// Not in 10.6 includes so use our own
|
||||
struct _intl_ifmaddrs {
|
||||
struct _intl_ifmaddrs *ifma_next;
|
||||
struct sockaddr *ifma_name;
|
||||
struct sockaddr *ifma_addr;
|
||||
struct sockaddr *ifma_lladdr;
|
||||
};
|
||||
|
||||
static inline int _intl_getifmaddrs(struct _intl_ifmaddrs **pif)
|
||||
{
|
||||
int icnt = 1;
|
||||
int dcnt = 0;
|
||||
int ntry = 0;
|
||||
size_t len;
|
||||
size_t needed;
|
||||
int mib[6];
|
||||
int i;
|
||||
char *buf;
|
||||
char *data;
|
||||
char *next;
|
||||
char *p;
|
||||
struct ifma_msghdr2 *ifmam;
|
||||
struct _intl_ifmaddrs *ifa, *ift;
|
||||
struct rt_msghdr *rtm;
|
||||
struct sockaddr *sa;
|
||||
|
||||
mib[0] = CTL_NET;
|
||||
mib[1] = PF_ROUTE;
|
||||
mib[2] = 0; /* protocol */
|
||||
mib[3] = 0; /* wildcard address family */
|
||||
mib[4] = GIM_SYSCTL_MIB;
|
||||
mib[5] = 0; /* no flags */
|
||||
do {
|
||||
if (sysctl(mib, 6, NULL, &needed, NULL, 0) < 0)
|
||||
return (-1);
|
||||
if ((buf = (char *)malloc(needed)) == NULL)
|
||||
return (-1);
|
||||
if (sysctl(mib, 6, buf, &needed, NULL, 0) < 0) {
|
||||
if (errno != ENOMEM || ++ntry >= MAX_SYSCTL_TRY) {
|
||||
free(buf);
|
||||
return (-1);
|
||||
}
|
||||
free(buf);
|
||||
buf = NULL;
|
||||
}
|
||||
} while (buf == NULL);
|
||||
|
||||
for (next = buf; next < buf + needed; next += rtm->rtm_msglen) {
|
||||
rtm = (struct rt_msghdr *)(void *)next;
|
||||
if (rtm->rtm_version != RTM_VERSION)
|
||||
continue;
|
||||
switch (rtm->rtm_type) {
|
||||
case GIM_RTM_ADDR:
|
||||
ifmam = (struct ifma_msghdr2 *)(void *)rtm;
|
||||
if ((ifmam->ifmam_addrs & RTA_IFA) == 0)
|
||||
break;
|
||||
icnt++;
|
||||
p = (char *)(ifmam + 1);
|
||||
for (i = 0; i < RTAX_MAX; i++) {
|
||||
if ((RTA_MASKS & ifmam->ifmam_addrs &
|
||||
(1 << i)) == 0)
|
||||
continue;
|
||||
sa = (struct sockaddr *)(void *)p;
|
||||
len = SA_RLEN(sa);
|
||||
dcnt += len;
|
||||
p += len;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
data = (char *)malloc(sizeof(struct _intl_ifmaddrs) * icnt + dcnt);
|
||||
if (data == NULL) {
|
||||
free(buf);
|
||||
return (-1);
|
||||
}
|
||||
|
||||
ifa = (struct _intl_ifmaddrs *)(void *)data;
|
||||
data += sizeof(struct _intl_ifmaddrs) * icnt;
|
||||
|
||||
memset(ifa, 0, sizeof(struct _intl_ifmaddrs) * icnt);
|
||||
ift = ifa;
|
||||
|
||||
for (next = buf; next < buf + needed; next += rtm->rtm_msglen) {
|
||||
rtm = (struct rt_msghdr *)(void *)next;
|
||||
if (rtm->rtm_version != RTM_VERSION)
|
||||
continue;
|
||||
|
||||
switch (rtm->rtm_type) {
|
||||
case GIM_RTM_ADDR:
|
||||
ifmam = (struct ifma_msghdr2 *)(void *)rtm;
|
||||
if ((ifmam->ifmam_addrs & RTA_IFA) == 0)
|
||||
break;
|
||||
|
||||
p = (char *)(ifmam + 1);
|
||||
for (i = 0; i < RTAX_MAX; i++) {
|
||||
if ((RTA_MASKS & ifmam->ifmam_addrs &
|
||||
(1 << i)) == 0)
|
||||
continue;
|
||||
sa = (struct sockaddr *)(void *)p;
|
||||
len = SA_RLEN(sa);
|
||||
switch (i) {
|
||||
case RTAX_GATEWAY:
|
||||
ift->ifma_lladdr =
|
||||
(struct sockaddr *)(void *)data;
|
||||
memcpy(data, p, len);
|
||||
data += len;
|
||||
break;
|
||||
|
||||
case RTAX_IFP:
|
||||
ift->ifma_name =
|
||||
(struct sockaddr *)(void *)data;
|
||||
memcpy(data, p, len);
|
||||
data += len;
|
||||
break;
|
||||
|
||||
case RTAX_IFA:
|
||||
ift->ifma_addr =
|
||||
(struct sockaddr *)(void *)data;
|
||||
memcpy(data, p, len);
|
||||
data += len;
|
||||
break;
|
||||
|
||||
default:
|
||||
data += len;
|
||||
break;
|
||||
}
|
||||
p += len;
|
||||
}
|
||||
ift->ifma_next = ift + 1;
|
||||
ift = ift->ifma_next;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
free(buf);
|
||||
|
||||
if (ift > ifa) {
|
||||
ift--;
|
||||
ift->ifma_next = NULL;
|
||||
*pif = ifa;
|
||||
} else {
|
||||
*pif = NULL;
|
||||
free(ifa);
|
||||
}
|
||||
return (0);
|
||||
}
|
||||
|
||||
static inline void _intl_freeifmaddrs(struct _intl_ifmaddrs *ifmp)
|
||||
{
|
||||
free(ifmp);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
#include <string>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <algorithm>
|
||||
|
||||
#include "../node/Constants.hpp"
|
||||
#include "../node/Utils.hpp"
|
||||
#include "../node/Mutex.hpp"
|
||||
#include "../node/Dictionary.hpp"
|
||||
#include "Arp.hpp"
|
||||
#include "OSUtils.hpp"
|
||||
#include "OSXEthernetTap.hpp"
|
||||
|
||||
// ff:ff:ff:ff:ff:ff with no ADI
|
||||
static const ZeroTier::MulticastGroup _blindWildcardMulticastGroup(ZeroTier::MAC(0xff),0);
|
||||
|
||||
static inline bool _setIpv6Stuff(const char *ifname,bool performNUD,bool acceptRouterAdverts)
|
||||
{
|
||||
struct in6_ndireq nd;
|
||||
struct in6_ifreq ifr;
|
||||
|
||||
int s = socket(AF_INET6,SOCK_DGRAM,0);
|
||||
if (s <= 0)
|
||||
return false;
|
||||
|
||||
memset(&nd,0,sizeof(nd));
|
||||
strncpy(nd.ifname,ifname,sizeof(nd.ifname));
|
||||
|
||||
if (ioctl(s,SIOCGIFINFO_IN6,&nd)) {
|
||||
close(s);
|
||||
return false;
|
||||
}
|
||||
|
||||
unsigned long oldFlags = (unsigned long)nd.ndi.flags;
|
||||
|
||||
if (performNUD)
|
||||
nd.ndi.flags |= ND6_IFF_PERFORMNUD;
|
||||
else nd.ndi.flags &= ~ND6_IFF_PERFORMNUD;
|
||||
|
||||
if (oldFlags != (unsigned long)nd.ndi.flags) {
|
||||
if (ioctl(s,SIOCSIFINFO_FLAGS,&nd)) {
|
||||
close(s);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
memset(&ifr,0,sizeof(ifr));
|
||||
strncpy(ifr.ifr_name,ifname,sizeof(ifr.ifr_name));
|
||||
if (ioctl(s,acceptRouterAdverts ? SIOCAUTOCONF_START : SIOCAUTOCONF_STOP,&ifr)) {
|
||||
close(s);
|
||||
return false;
|
||||
}
|
||||
|
||||
close(s);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Create an OSX-native utun device (utun# where # is desiredNumber)
|
||||
// Adapted from public domain utun example code by Jonathan Levin
|
||||
static int _make_utun(int desiredNumber)
|
||||
{
|
||||
struct sockaddr_ctl sc;
|
||||
struct ctl_info ctlInfo;
|
||||
struct ifreq ifr;
|
||||
|
||||
memset(&ctlInfo, 0, sizeof(ctlInfo));
|
||||
if (strlcpy(ctlInfo.ctl_name, UTUN_CONTROL_NAME, sizeof(ctlInfo.ctl_name)) >= sizeof(ctlInfo.ctl_name)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
int fd = socket(PF_SYSTEM, SOCK_DGRAM, SYSPROTO_CONTROL);
|
||||
if (fd == -1)
|
||||
return -1;
|
||||
if (ioctl(fd, CTLIOCGINFO, &ctlInfo) == -1) {
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
sc.sc_id = ctlInfo.ctl_id;
|
||||
sc.sc_len = sizeof(sc);
|
||||
sc.sc_family = AF_SYSTEM;
|
||||
sc.ss_sysaddr = AF_SYS_CONTROL;
|
||||
sc.sc_unit = desiredNumber + 1;
|
||||
|
||||
if (connect(fd, (struct sockaddr *)&sc, sizeof(sc)) == -1) {
|
||||
close(fd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
memset(&ifr,0,sizeof(ifr));
|
||||
sprintf(ifr.ifr_name,"utun%d",desiredNumber);
|
||||
if (ioctl(fd,SIOCGIFFLAGS,(void *)&ifr) < 0) {
|
||||
printf("SIOCGIFFLAGS failed\n");
|
||||
}
|
||||
ifr.ifr_flags &= ~IFF_POINTOPOINT;
|
||||
if (ioctl(fd,SIOCSIFFLAGS,(void *)&ifr) < 0) {
|
||||
printf("clear IFF_POINTOPOINT failed\n");
|
||||
}
|
||||
|
||||
return fd;
|
||||
}
|
||||
|
||||
namespace ZeroTier {
|
||||
|
||||
static long globalTapsRunning = 0;
|
||||
static Mutex globalTapCreateLock;
|
||||
|
||||
OSXEthernetTap::OSXEthernetTap(
|
||||
const char *homePath,
|
||||
const MAC &mac,
|
||||
unsigned int mtu,
|
||||
unsigned int metric,
|
||||
uint64_t nwid,
|
||||
const char *friendlyName,
|
||||
void (*handler)(void *,uint64_t,const MAC &,const MAC &,unsigned int,unsigned int,const void *data,unsigned int len),
|
||||
void *arg) :
|
||||
_handler(handler),
|
||||
_arg(arg),
|
||||
_arp((Arp *)0),
|
||||
_nwid(nwid),
|
||||
_homePath(homePath),
|
||||
_mtu(mtu),
|
||||
_metric(metric),
|
||||
_fd(0),
|
||||
_utun(false),
|
||||
_enabled(true)
|
||||
{
|
||||
char devpath[64],ethaddr[64],mtustr[32],metstr[32],nwids[32];
|
||||
struct stat stattmp;
|
||||
|
||||
Utils::snprintf(nwids,sizeof(nwids),"%.16llx",nwid);
|
||||
|
||||
if (mtu > 2800)
|
||||
throw std::runtime_error("max tap MTU is 2800");
|
||||
|
||||
Mutex::Lock _gl(globalTapCreateLock);
|
||||
|
||||
// Read remembered previous device name, if any -- we'll try to reuse
|
||||
Dictionary devmap;
|
||||
std::string desiredDevice;
|
||||
{
|
||||
std::string devmapbuf;
|
||||
if (OSUtils::readFile((_homePath + ZT_PATH_SEPARATOR_S + "devicemap").c_str(),devmapbuf)) {
|
||||
devmap.fromString(devmapbuf);
|
||||
desiredDevice = devmap.get(nwids,"");
|
||||
}
|
||||
}
|
||||
|
||||
if (::stat((_homePath + ZT_PATH_SEPARATOR_S + "tap.kext").c_str(),&stattmp) == 0) {
|
||||
// Try to init kext if it's there, otherwise revert to utun mode
|
||||
|
||||
if (::stat("/dev/zt0",&stattmp)) {
|
||||
long kextpid = (long)vfork();
|
||||
if (kextpid == 0) {
|
||||
::chdir(homePath);
|
||||
OSUtils::redirectUnixOutputs("/dev/null",(const char *)0);
|
||||
::execl("/sbin/kextload","/sbin/kextload","-q","-repository",homePath,"tap.kext",(const char *)0);
|
||||
::_exit(-1);
|
||||
} else if (kextpid > 0) {
|
||||
int exitcode = -1;
|
||||
::waitpid(kextpid,&exitcode,0);
|
||||
}
|
||||
::usleep(500); // give tap device driver time to start up and try again
|
||||
if (::stat("/dev/zt0",&stattmp))
|
||||
_utun = true;
|
||||
}
|
||||
|
||||
if (!_utun) {
|
||||
// See if we can re-use the last device we had.
|
||||
bool recalledDevice = false;
|
||||
if (desiredDevice.length() > 2) {
|
||||
Utils::snprintf(devpath,sizeof(devpath),"/dev/%s",desiredDevice.c_str());
|
||||
if (stat(devpath,&stattmp) == 0) {
|
||||
_fd = ::open(devpath,O_RDWR);
|
||||
if (_fd > 0) {
|
||||
_dev = desiredDevice;
|
||||
recalledDevice = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Open the first unused tap device if we didn't recall a previous one.
|
||||
if (!recalledDevice) {
|
||||
for(int i=0;i<64;++i) {
|
||||
Utils::snprintf(devpath,sizeof(devpath),"/dev/zt%d",i);
|
||||
if (stat(devpath,&stattmp)) {
|
||||
_utun = true;
|
||||
break;
|
||||
}
|
||||
_fd = ::open(devpath,O_RDWR);
|
||||
if (_fd > 0) {
|
||||
char foo[16];
|
||||
Utils::snprintf(foo,sizeof(foo),"zt%d",i);
|
||||
_dev = foo;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (_fd <= 0)
|
||||
_utun = true;
|
||||
}
|
||||
} else {
|
||||
_utun = true;
|
||||
}
|
||||
|
||||
if (_utun) {
|
||||
// Use OSX built-in utun device if kext is not available or doesn't work
|
||||
|
||||
int utunNo = 0;
|
||||
|
||||
if ((desiredDevice.length() > 4)&&(desiredDevice.substr(0,4) == "utun")) {
|
||||
utunNo = Utils::strToInt(desiredDevice.substr(4).c_str());
|
||||
if (utunNo >= 0)
|
||||
_fd = _make_utun(utunNo);
|
||||
}
|
||||
|
||||
if (_fd <= 0) {
|
||||
// Start at utun8 to leave lower utuns unused since other stuff might
|
||||
// want them -- OpenVPN, cjdns, etc. I'm not sure if those are smart
|
||||
// enough to scan upward like this.
|
||||
for(utunNo=8;utunNo<=256;++utunNo) {
|
||||
if ((_fd = _make_utun(utunNo)) > 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (_fd <= 0)
|
||||
throw std::runtime_error("unable to find/load ZeroTier tap driver OR use built-in utun driver in OSX; permission or system problem or too many open devices?");
|
||||
|
||||
Utils::snprintf(devpath,sizeof(devpath),"utun%d",utunNo);
|
||||
_dev = devpath;
|
||||
|
||||
// Configure address and bring it up
|
||||
Utils::snprintf(mtustr,sizeof(mtustr),"%u",_mtu);
|
||||
Utils::snprintf(metstr,sizeof(metstr),"%u",_metric);
|
||||
long cpid = (long)vfork();
|
||||
if (cpid == 0) {
|
||||
::execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),"mtu",mtustr,"metric",metstr,"up",(const char *)0);
|
||||
::_exit(-1);
|
||||
} else if (cpid > 0) {
|
||||
int exitcode = -1;
|
||||
::waitpid(cpid,&exitcode,0);
|
||||
if (exitcode) {
|
||||
::close(_fd);
|
||||
throw std::runtime_error("ifconfig failure activating utun interface");
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
// Use our ZeroTier OSX tun/tap driver for zt# Ethernet tap device
|
||||
|
||||
if (fcntl(_fd,F_SETFL,fcntl(_fd,F_GETFL) & ~O_NONBLOCK) == -1) {
|
||||
::close(_fd);
|
||||
throw std::runtime_error("unable to set flags on file descriptor for TAP device");
|
||||
}
|
||||
|
||||
// Configure MAC address and MTU, bring interface up
|
||||
Utils::snprintf(ethaddr,sizeof(ethaddr),"%.2x:%.2x:%.2x:%.2x:%.2x:%.2x",(int)mac[0],(int)mac[1],(int)mac[2],(int)mac[3],(int)mac[4],(int)mac[5]);
|
||||
Utils::snprintf(mtustr,sizeof(mtustr),"%u",_mtu);
|
||||
Utils::snprintf(metstr,sizeof(metstr),"%u",_metric);
|
||||
long cpid = (long)vfork();
|
||||
if (cpid == 0) {
|
||||
::execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),"lladdr",ethaddr,"mtu",mtustr,"metric",metstr,"up",(const char *)0);
|
||||
::_exit(-1);
|
||||
} else if (cpid > 0) {
|
||||
int exitcode = -1;
|
||||
::waitpid(cpid,&exitcode,0);
|
||||
if (exitcode) {
|
||||
::close(_fd);
|
||||
throw std::runtime_error("ifconfig failure setting link-layer address and activating tap interface");
|
||||
}
|
||||
}
|
||||
|
||||
_setIpv6Stuff(_dev.c_str(),true,false);
|
||||
}
|
||||
|
||||
// Set close-on-exec so that devices cannot persist if we fork/exec for update
|
||||
fcntl(_fd,F_SETFD,fcntl(_fd,F_GETFD) | FD_CLOEXEC);
|
||||
|
||||
::pipe(_shutdownSignalPipe);
|
||||
|
||||
++globalTapsRunning;
|
||||
|
||||
devmap[nwids] = _dev;
|
||||
OSUtils::writeFile((_homePath + ZT_PATH_SEPARATOR_S + "devicemap").c_str(),devmap.toString());
|
||||
|
||||
_thread = Thread::start(this);
|
||||
}
|
||||
|
||||
OSXEthernetTap::~OSXEthernetTap()
|
||||
{
|
||||
Mutex::Lock _gl(globalTapCreateLock);
|
||||
|
||||
::write(_shutdownSignalPipe[1],(const void *)this,1); // writing a byte causes thread to exit
|
||||
Thread::join(_thread);
|
||||
|
||||
::close(_fd);
|
||||
::close(_shutdownSignalPipe[0]);
|
||||
::close(_shutdownSignalPipe[1]);
|
||||
|
||||
if (_utun) {
|
||||
delete _arp;
|
||||
} else {
|
||||
if (--globalTapsRunning <= 0) {
|
||||
globalTapsRunning = 0; // sanity check -- should not be possible
|
||||
|
||||
char tmp[16384];
|
||||
sprintf(tmp,"%s/%s",_homePath.c_str(),"tap.kext");
|
||||
long kextpid = (long)vfork();
|
||||
if (kextpid == 0) {
|
||||
OSUtils::redirectUnixOutputs("/dev/null",(const char *)0);
|
||||
::execl("/sbin/kextunload","/sbin/kextunload",tmp,(const char *)0);
|
||||
::_exit(-1);
|
||||
} else if (kextpid > 0) {
|
||||
int exitcode = -1;
|
||||
::waitpid(kextpid,&exitcode,0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void OSXEthernetTap::setEnabled(bool en)
|
||||
{
|
||||
_enabled = en;
|
||||
// TODO: interface status change
|
||||
}
|
||||
|
||||
bool OSXEthernetTap::enabled() const
|
||||
{
|
||||
return _enabled;
|
||||
}
|
||||
|
||||
static bool ___removeIp(const std::string &_dev,const InetAddress &ip)
|
||||
{
|
||||
long cpid = (long)vfork();
|
||||
if (cpid == 0) {
|
||||
execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),"inet",ip.toIpString().c_str(),"-alias",(const char *)0);
|
||||
_exit(-1);
|
||||
} else if (cpid > 0) {
|
||||
int exitcode = -1;
|
||||
waitpid(cpid,&exitcode,0);
|
||||
return (exitcode == 0);
|
||||
}
|
||||
return false; // never reached, make compiler shut up about return value
|
||||
}
|
||||
|
||||
bool OSXEthernetTap::addIp(const InetAddress &ip)
|
||||
{
|
||||
if (!ip)
|
||||
return false;
|
||||
|
||||
std::vector<InetAddress> allIps(ips());
|
||||
if (std::binary_search(allIps.begin(),allIps.end(),ip))
|
||||
return true;
|
||||
|
||||
// Remove and reconfigure if address is the same but netmask is different
|
||||
for(std::vector<InetAddress>::iterator i(allIps.begin());i!=allIps.end();++i) {
|
||||
if ((i->ipsEqual(ip))&&(i->netmaskBits() != ip.netmaskBits())) {
|
||||
if (___removeIp(_dev,*i))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (_utun) {
|
||||
long cpid = (long)vfork();
|
||||
if (cpid == 0) {
|
||||
if (ip.ss_family == AF_INET6) {
|
||||
::execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),"inet6",ip.toString().c_str(),"alias",(const char *)0);
|
||||
} else {
|
||||
::execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),ip.toString().c_str(),ip.toIpString().c_str(),"alias",(const char *)0);
|
||||
}
|
||||
::_exit(-1);
|
||||
} else if (cpid > 0) {
|
||||
int exitcode = -1;
|
||||
::waitpid(cpid,&exitcode,0);
|
||||
|
||||
if (exitcode == 0) {
|
||||
if (ip.ss_family == AF_INET) {
|
||||
// Add route to network over tun for IPv4 -- otherwise it behaves
|
||||
// as a simple point to point tunnel instead of a true route.
|
||||
cpid = (long)vfork();
|
||||
if (cpid == 0) {
|
||||
::close(STDERR_FILENO);
|
||||
::close(STDOUT_FILENO);
|
||||
::execl("/sbin/route","/sbin/route","add",ip.network().toString().c_str(),ip.toIpString().c_str(),(const char *)0);
|
||||
::exit(-1);
|
||||
} else if (cpid > 0) {
|
||||
int exitcode = -1;
|
||||
::waitpid(cpid,&exitcode,0);
|
||||
return (exitcode == 0);
|
||||
}
|
||||
} else return true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
long cpid = (long)vfork();
|
||||
if (cpid == 0) {
|
||||
::execl("/sbin/ifconfig","/sbin/ifconfig",_dev.c_str(),ip.isV4() ? "inet" : "inet6",ip.toString().c_str(),"alias",(const char *)0);
|
||||
::_exit(-1);
|
||||
} else if (cpid > 0) {
|
||||
int exitcode = -1;
|
||||
::waitpid(cpid,&exitcode,0);
|
||||
return (exitcode == 0);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool OSXEthernetTap::removeIp(const InetAddress &ip)
|
||||
{
|
||||
if (!ip)
|
||||
return true;
|
||||
std::vector<InetAddress> allIps(ips());
|
||||
if (!std::binary_search(allIps.begin(),allIps.end(),ip)) {
|
||||
if (___removeIp(_dev,ip))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
std::vector<InetAddress> OSXEthernetTap::ips() const
|
||||
{
|
||||
struct ifaddrs *ifa = (struct ifaddrs *)0;
|
||||
if (getifaddrs(&ifa))
|
||||
return std::vector<InetAddress>();
|
||||
|
||||
std::vector<InetAddress> r;
|
||||
|
||||
struct ifaddrs *p = ifa;
|
||||
while (p) {
|
||||
if ((!strcmp(p->ifa_name,_dev.c_str()))&&(p->ifa_addr)&&(p->ifa_netmask)&&(p->ifa_addr->sa_family == p->ifa_netmask->sa_family)) {
|
||||
switch(p->ifa_addr->sa_family) {
|
||||
case AF_INET: {
|
||||
struct sockaddr_in *sin = (struct sockaddr_in *)p->ifa_addr;
|
||||
struct sockaddr_in *nm = (struct sockaddr_in *)p->ifa_netmask;
|
||||
r.push_back(InetAddress(&(sin->sin_addr.s_addr),4,Utils::countBits((uint32_t)nm->sin_addr.s_addr)));
|
||||
} break;
|
||||
case AF_INET6: {
|
||||
struct sockaddr_in6 *sin = (struct sockaddr_in6 *)p->ifa_addr;
|
||||
struct sockaddr_in6 *nm = (struct sockaddr_in6 *)p->ifa_netmask;
|
||||
uint32_t b[4];
|
||||
memcpy(b,nm->sin6_addr.s6_addr,sizeof(b));
|
||||
r.push_back(InetAddress(sin->sin6_addr.s6_addr,16,Utils::countBits(b[0]) + Utils::countBits(b[1]) + Utils::countBits(b[2]) + Utils::countBits(b[3])));
|
||||
} break;
|
||||
}
|
||||
}
|
||||
p = p->ifa_next;
|
||||
}
|
||||
|
||||
if (ifa)
|
||||
freeifaddrs(ifa);
|
||||
|
||||
std::sort(r.begin(),r.end());
|
||||
std::unique(r.begin(),r.end());
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
void OSXEthernetTap::put(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len)
|
||||
{
|
||||
char putBuf[4096];
|
||||
if ((_fd > 0)&&(len <= _mtu)&&(_enabled)) {
|
||||
to.copyTo(putBuf,6);
|
||||
from.copyTo(putBuf + 6,6);
|
||||
*((uint16_t *)(putBuf + 12)) = htons((uint16_t)etherType);
|
||||
memcpy(putBuf + 14,data,len);
|
||||
len += 14;
|
||||
::write(_fd,putBuf,len);
|
||||
}
|
||||
}
|
||||
|
||||
std::string OSXEthernetTap::deviceName() const
|
||||
{
|
||||
return _dev;
|
||||
}
|
||||
|
||||
void OSXEthernetTap::setFriendlyName(const char *friendlyName)
|
||||
{
|
||||
}
|
||||
|
||||
void OSXEthernetTap::scanMulticastGroups(std::vector<MulticastGroup> &added,std::vector<MulticastGroup> &removed)
|
||||
{
|
||||
std::vector<MulticastGroup> newGroups;
|
||||
|
||||
struct _intl_ifmaddrs *ifmap = (struct _intl_ifmaddrs *)0;
|
||||
if (!_intl_getifmaddrs(&ifmap)) {
|
||||
struct _intl_ifmaddrs *p = ifmap;
|
||||
while (p) {
|
||||
if (p->ifma_addr->sa_family == AF_LINK) {
|
||||
struct sockaddr_dl *in = (struct sockaddr_dl *)p->ifma_name;
|
||||
struct sockaddr_dl *la = (struct sockaddr_dl *)p->ifma_addr;
|
||||
if ((la->sdl_alen == 6)&&(in->sdl_nlen <= _dev.length())&&(!memcmp(_dev.data(),in->sdl_data,in->sdl_nlen)))
|
||||
newGroups.push_back(MulticastGroup(MAC(la->sdl_data + la->sdl_nlen,6),0));
|
||||
}
|
||||
p = p->ifma_next;
|
||||
}
|
||||
_intl_freeifmaddrs(ifmap);
|
||||
}
|
||||
|
||||
std::vector<InetAddress> allIps(ips());
|
||||
for(std::vector<InetAddress>::iterator ip(allIps.begin());ip!=allIps.end();++ip)
|
||||
newGroups.push_back(MulticastGroup::deriveMulticastGroupForAddressResolution(*ip));
|
||||
|
||||
std::sort(newGroups.begin(),newGroups.end());
|
||||
std::unique(newGroups.begin(),newGroups.end());
|
||||
|
||||
for(std::vector<MulticastGroup>::iterator m(newGroups.begin());m!=newGroups.end();++m) {
|
||||
if (!std::binary_search(_multicastGroups.begin(),_multicastGroups.end(),*m))
|
||||
added.push_back(*m);
|
||||
}
|
||||
for(std::vector<MulticastGroup>::iterator m(_multicastGroups.begin());m!=_multicastGroups.end();++m) {
|
||||
if (!std::binary_search(newGroups.begin(),newGroups.end(),*m))
|
||||
removed.push_back(*m);
|
||||
}
|
||||
|
||||
_multicastGroups.swap(newGroups);
|
||||
}
|
||||
|
||||
void OSXEthernetTap::threadMain()
|
||||
throw()
|
||||
{
|
||||
fd_set readfds,nullfds;
|
||||
MAC to,from;
|
||||
int n,nfds,r;
|
||||
char getBuf[8194];
|
||||
|
||||
Thread::sleep(500);
|
||||
|
||||
FD_ZERO(&readfds);
|
||||
FD_ZERO(&nullfds);
|
||||
nfds = (int)std::max(_shutdownSignalPipe[0],_fd) + 1;
|
||||
|
||||
r = 0;
|
||||
for(;;) {
|
||||
FD_SET(_shutdownSignalPipe[0],&readfds);
|
||||
FD_SET(_fd,&readfds);
|
||||
select(nfds,&readfds,&nullfds,&nullfds,(struct timeval *)0);
|
||||
|
||||
if (FD_ISSET(_shutdownSignalPipe[0],&readfds)) // writes to shutdown pipe terminate thread
|
||||
break;
|
||||
|
||||
if (FD_ISSET(_fd,&readfds)) {
|
||||
n = (int)::read(_fd,getBuf + r,sizeof(getBuf) - r);
|
||||
if (n < 0) {
|
||||
if ((errno != EINTR)&&(errno != ETIMEDOUT))
|
||||
break;
|
||||
} else {
|
||||
// Some tap drivers like to send the ethernet frame and the
|
||||
// payload in two chunks, so handle that by accumulating
|
||||
// data until we have at least a frame.
|
||||
r += n;
|
||||
if (r > 14) {
|
||||
if (r > ((int)_mtu + 14)) // sanity check for weird TAP behavior on some platforms
|
||||
r = _mtu + 14;
|
||||
|
||||
if (_enabled) {
|
||||
to.setTo(getBuf,6);
|
||||
from.setTo(getBuf + 6,6);
|
||||
unsigned int etherType = ntohs(((const uint16_t *)getBuf)[6]);
|
||||
// TODO: VLAN support
|
||||
_handler(_arg,_nwid,from,to,etherType,0,(const void *)(getBuf + 14),r - 14);
|
||||
}
|
||||
|
||||
r = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace ZeroTier
|
@ -1,96 +0,0 @@
|
||||
/*
|
||||
* ZeroTier One - Network Virtualization Everywhere
|
||||
* Copyright (C) 2011-2015 ZeroTier, Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* --
|
||||
*
|
||||
* ZeroTier may be used and distributed under the terms of the GPLv3, which
|
||||
* are available at: http://www.gnu.org/licenses/gpl-3.0.html
|
||||
*
|
||||
* If you would like to embed ZeroTier into a commercial application or
|
||||
* redistribute it in a modified binary form, please contact ZeroTier Networks
|
||||
* LLC. Start here: http://www.zerotier.com/
|
||||
*/
|
||||
|
||||
#ifndef ZT_OSXETHERNETTAP_HPP
|
||||
#define ZT_OSXETHERNETTAP_HPP
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "../node/Constants.hpp"
|
||||
#include "../node/MAC.hpp"
|
||||
#include "../node/InetAddress.hpp"
|
||||
#include "../node/MulticastGroup.hpp"
|
||||
|
||||
#include "Thread.hpp"
|
||||
|
||||
namespace ZeroTier {
|
||||
|
||||
/**
|
||||
* OSX Ethernet tap using ZeroTier kernel extension zt# devices
|
||||
*/
|
||||
class OSXEthernetTap
|
||||
{
|
||||
public:
|
||||
OSXEthernetTap(
|
||||
const char *homePath,
|
||||
const MAC &mac,
|
||||
unsigned int mtu,
|
||||
unsigned int metric,
|
||||
uint64_t nwid,
|
||||
const char *friendlyName,
|
||||
void (*handler)(void *,uint64_t,const MAC &,const MAC &,unsigned int,unsigned int,const void *,unsigned int),
|
||||
void *arg);
|
||||
|
||||
~OSXEthernetTap();
|
||||
|
||||
inline void setEnabled(bool en) { _enabled = en; }
|
||||
inline bool enabled() const { return _enabled; }
|
||||
bool addIp(const InetAddress &ip);
|
||||
bool removeIp(const InetAddress &ip);
|
||||
std::vector<InetAddress> ips() const;
|
||||
void put(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len);
|
||||
std::string deviceName() const;
|
||||
void setFriendlyName(const char *friendlyName);
|
||||
void scanMulticastGroups(std::vector<MulticastGroup> &added,std::vector<MulticastGroup> &removed);
|
||||
|
||||
void threadMain()
|
||||
throw();
|
||||
|
||||
// Private members of OSXEthernetTap have public visibility to be accessable
|
||||
// from an internal bounce function; don't modify directly.
|
||||
void (*_handler)(void *,uint64_t,const MAC &,const MAC &,unsigned int,unsigned int,const void *,unsigned int);
|
||||
void *_arg;
|
||||
void *_pcap; // pcap_t *
|
||||
uint64_t _nwid;
|
||||
MAC _mac;
|
||||
Thread _thread;
|
||||
std::string _homePath;
|
||||
std::string _dev;
|
||||
std::vector<MulticastGroup> _multicastGroups;
|
||||
unsigned int _mtu;
|
||||
unsigned int _metric;
|
||||
volatile bool _enabled;
|
||||
};
|
||||
|
||||
} // namespace ZeroTier
|
||||
|
||||
#endif
|
@ -1,101 +0,0 @@
|
||||
/*
|
||||
* ZeroTier One - Network Virtualization Everywhere
|
||||
* Copyright (C) 2011-2015 ZeroTier, Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* --
|
||||
*
|
||||
* ZeroTier may be used and distributed under the terms of the GPLv3, which
|
||||
* are available at: http://www.gnu.org/licenses/gpl-3.0.html
|
||||
*
|
||||
* If you would like to embed ZeroTier into a commercial application or
|
||||
* redistribute it in a modified binary form, please contact ZeroTier Networks
|
||||
* LLC. Start here: http://www.zerotier.com/
|
||||
*/
|
||||
|
||||
#ifndef ZT_OSXETHERNETTAP_HPP
|
||||
#define ZT_OSXETHERNETTAP_HPP
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "../node/Constants.hpp"
|
||||
#include "../node/MAC.hpp"
|
||||
#include "../node/InetAddress.hpp"
|
||||
#include "../node/MulticastGroup.hpp"
|
||||
|
||||
#include "Thread.hpp"
|
||||
|
||||
namespace ZeroTier {
|
||||
|
||||
class Arp;
|
||||
|
||||
/**
|
||||
* OSX Ethernet tap supporting either ZeroTier tun/tap kext or OSX-native utun
|
||||
*/
|
||||
class OSXEthernetTap
|
||||
{
|
||||
public:
|
||||
OSXEthernetTap(
|
||||
const char *homePath,
|
||||
const MAC &mac,
|
||||
unsigned int mtu,
|
||||
unsigned int metric,
|
||||
uint64_t nwid,
|
||||
const char *friendlyName,
|
||||
void (*handler)(void *,uint64_t,const MAC &,const MAC &,unsigned int,unsigned int,const void *,unsigned int),
|
||||
void *arg);
|
||||
|
||||
~OSXEthernetTap();
|
||||
|
||||
void setEnabled(bool en);
|
||||
bool enabled() const;
|
||||
bool addIp(const InetAddress &ip);
|
||||
bool removeIp(const InetAddress &ip);
|
||||
std::vector<InetAddress> ips() const;
|
||||
void put(const MAC &from,const MAC &to,unsigned int etherType,const void *data,unsigned int len);
|
||||
std::string deviceName() const;
|
||||
void setFriendlyName(const char *friendlyName);
|
||||
void scanMulticastGroups(std::vector<MulticastGroup> &added,std::vector<MulticastGroup> &removed);
|
||||
|
||||
inline bool isNativeUtun() const { return _utun; }
|
||||
|
||||
void threadMain()
|
||||
throw();
|
||||
|
||||
private:
|
||||
void (*_handler)(void *,uint64_t,const MAC &,const MAC &,unsigned int,unsigned int,const void *,unsigned int);
|
||||
void *_arg;
|
||||
Arp *_arp; // created and used if utun is enabled
|
||||
uint64_t _nwid;
|
||||
Thread _thread;
|
||||
std::string _homePath;
|
||||
std::string _dev;
|
||||
std::vector<MulticastGroup> _multicastGroups;
|
||||
unsigned int _mtu;
|
||||
unsigned int _metric;
|
||||
int _fd;
|
||||
int _shutdownSignalPipe[2];
|
||||
bool _utun;
|
||||
volatile bool _enabled;
|
||||
};
|
||||
|
||||
} // namespace ZeroTier
|
||||
|
||||
#endif
|
@ -1,4 +0,0 @@
|
||||
Retired Code and Miscellaneous Junk
|
||||
======
|
||||
|
||||
This directory is for old code that isn't used but we don't want to lose track of, and for anything else random like debug scripts.
|
@ -1,84 +0,0 @@
|
||||
ZeroTier Security
|
||||
======
|
||||
|
||||
## Summary
|
||||
|
||||
|
||||
## Using ZeroTier Securely
|
||||
|
||||
### Overall Recommendations
|
||||
|
||||
*TL;DR: same as anything else: defense in depth defense in depth defense in depth.*
|
||||
|
||||
We encourage our users to treat private ZeroTier networks as being rougly equivalent in security to WPA2-enterprise securied WiFi or on-premise wired Ethernet. (Public networks on the other hand are open by design.) That means they're networks with perimeters, but like all networks the compromise of any participating device or network controller allows an attacker to breach this perimeter.
|
||||
|
||||
**Never trust the network.** Many modern security professionals discourage reliance on network perimeters as major components in any security strategy, and we strongly agree regardless of whether your network is physical or virtual.
|
||||
|
||||
As part of a defense in depth approach **we specifically encourage the use of other secure protocols and authentication systems over ZeroTier networks**. While the use of secure encrypted protocols like SSH and SSL over ZeroTier adds a bit more overhead, it greatly reduces the chance of total compromise.
|
||||
|
||||
Imagine that the per-day probability of a major "0-day" security flaw in ZeroTier and OpenSSH are both roughly 0.001 or one per thousand days. Using both at the same time gives you a cumulative 0-day risk of roughly 0.000001 or one per one million days.
|
||||
|
||||
Those are made-up numbers. In reality these probabilities can't be known ahead of time. History shows that a 0-day could be found in anything tomorrow, next week, or never. But layers of security give you an overall posture that is the product -- more than the sum -- of its parts. That's how defense in depth works.
|
||||
|
||||
### ZeroTier Specifics
|
||||
|
||||
#### Protect Your Identity
|
||||
|
||||
Each ZeroTier device has an identity. The secret portion of this identity is stored in a file called "identity.secret." *Protect this file.* If it's stolen your device's identity (as represented by its 10-digit ZeroTier address) can easily be stolen or impersonated and your traffic can be decrypted or man-in-the-middle'd.
|
||||
|
||||
#### Protect Your Controller
|
||||
|
||||
The second major component of ZeroTier network security is the network controller. It's responsible for issuing certificates and configuration information to all network members. That makes it a certificate authority. Compromise of the controller allows an attacker to join or disrupt any network the controller controls. It does *not*, however, allow an attacker to decrypt peer to peer unicast traffic.
|
||||
|
||||
If you are using our controller-as-a-service at [my.zerotier.com](https://my.zerotier.com), you are delegating this responsibility to us.
|
||||
|
||||
## Security Priorities
|
||||
|
||||
These are our security "must-haves." If the system fails in any of these objectives it is broken.
|
||||
|
||||
* ZeroTier must be secure against remote vulnerabilities. This includes things like unauthorized remote control, remote penetration of the device using ZeroTier as a vector, or remote injection of malware.
|
||||
|
||||
* The content (but not meta-data) of communication must be secure against eavesdropping on the wire by any known means. (We can't warrant against secret vulnerabilities against ciphers, etc., or anything else we don't know about.)
|
||||
|
||||
* Communication must be secure against man-in-the-middle attacks and remote device impersonation.
|
||||
|
||||
## Security Non-Priorities
|
||||
|
||||
There are a few aspects of security we knowingly do not address, since doing so would be beyond scope or would conflict too greatly with other priorities.
|
||||
|
||||
* ZeroTier makes no effort to conceal communication meta-data such as source and destination addresses and the amount of information transferred between peers. To do this more or less requires onion routing or other "heavy" approaches to anonymity, and this is beyond scope.
|
||||
|
||||
* ZeroTier does not implement complex certificate chains, X.509, or other feature-rich (some would say feature-laden) cryptographic stuff. We only implement the crypto we need to get the job done.
|
||||
|
||||
* We don't take extraordinary measures to preserve security under conditions in which an endpoint device has been penetrated by other means (e.g. "rooted" by third party malware) or physicall compromised. If someone steals your keys they've stolen your keys, and if they've "pwned" your device they can easily eavesdrop on everything directly.
|
||||
|
||||
## Insecurities and Areas for Improvement
|
||||
|
||||
The only perfectly secure system is one that is off. All real world systems have potential security weaknesses. If possible, we like to know what these are and acknowledge their existence.
|
||||
|
||||
In some cases we plan to improve these. In other cases we have deliberately decided to "punt" on them in favor of some other priority (see philosophy). We may or may not revisit this decision in the future.
|
||||
|
||||
* We don't implement forward secrecy / ephemeral keys. A [discussion of this can be found at the closed GitHub issue for this feature](https://github.com/zerotier/ZeroTierOne/issues/204). In short: we've decided to "punt" on this feature because it introduces complexity and state negotiation. One of the design goals of ZeroTier is "reliability convergence" -- the reliability of ZeroTier virtual networks should rapidly converge with that of the underlying physical wire. Any state that must be negotiated prior to communication multiplies the probability of delay or failure due to packet loss. We *may* revisit this decision at a later date.
|
||||
|
||||
## Secure Coding Practices
|
||||
|
||||
The first line of defense employed against remote vulnerabilities and other major security flaws is the use of secure coding practices. These are, in no particular order:
|
||||
|
||||
* All parsing of remote messages is performed via higher level safe bounds-checked data structures and interfaces. See node/Buffer.hpp for one of the core elements of this.
|
||||
|
||||
* C++ exceptions are used to ensure that any unhandled failure or error condition (such as a bounds checking violation) results in the safe and complete termination of message processing. Invalid messages are dropped and ignored.
|
||||
|
||||
* Minimalism is a secure coding practice. There is an exponential relationship between complexity and the probability of bugs, and complex designs are much harder to audit and reason about.
|
||||
|
||||
* Our build scripts try to enable any OS and compiler level security features such as ASLR and "stack canaries" on non-debug builds.
|
||||
|
||||
## Cryptographic Security Practices
|
||||
|
||||
* We use [boring crypto](https://cr.yp.to/talks/2015.10.05/slides-djb-20151005-a4.pdf). A single symmetric algorithm (Salsa20/12), a single asymmetric algorithm (Curve25519 ECDH-256), and a single MAC (Poly1305). The way these algorithms are used is identical to how they're used in the NaCl reference implementation. The protocol supports selection of alternative algorithms but only for "future proofing" in the case that a serious flaw is discovered in any of these. Avoding algorithm bloat and cryptographic state negotiation helps guard against down-grade, "oracle," and other protocol level attacks.
|
||||
|
||||
* Authenticated encryption is employed with authentication being performed prior to any other operations on received messages. See also: [the cryptographic doom principle](https://moxie.org/blog/the-cryptographic-doom-principle/).
|
||||
|
||||
* "Never branch on anything secret" -- deterministic-time comparisons and other operations are used in cryptographic operations. See Utils::secureEq() in node/Utils.hpp.
|
||||
|
||||
* OS-derived crypographic random numbers (/dev/urandom or Windows CryptGenRandom) are further randomized using encryption by a secondary key with a secondary source of entropy to guard against CSPRNG bugs. Such OS-level CSPRNG bugs have been found in the past. See Utils::getSecureRandom() in node/Utils.hpp.
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,24 +0,0 @@
|
||||
FROM centos:latest
|
||||
|
||||
MAINTAINER https://www.zerotier.com/
|
||||
|
||||
EXPOSE 9993/udp
|
||||
|
||||
ADD nodesource-el.repo /etc/yum.repos.d/nodesource-el.repo
|
||||
RUN yum -y update && yum install -y nodejs && yum clean all
|
||||
|
||||
RUN mkdir -p /var/lib/zerotier-one
|
||||
RUN mkdir -p /var/lib/zerotier-one/networks.d
|
||||
RUN touch /var/lib/zerotier-one/networks.d/ffffffffffffffff.conf
|
||||
|
||||
ADD package.json /
|
||||
RUN npm install
|
||||
|
||||
ADD zerotier-one /
|
||||
RUN chmod a+x /zerotier-one
|
||||
|
||||
ADD agent.js /
|
||||
ADD docker-main.sh /
|
||||
RUN chmod a+x /docker-main.sh
|
||||
|
||||
CMD ["./docker-main.sh"]
|
@ -1,12 +0,0 @@
|
||||
HTTP one-to-all test
|
||||
======
|
||||
|
||||
*This is really internal use code. You're free to test it out but expect to do some editing/tweaking to make it work. We used this to run some massive scale tests of our new geo-cluster-based root server infrastructure prior to taking it live.*
|
||||
|
||||
Before using this code you will want to edit agent.js to change SERVER_HOST to the IP address of where you will run server.js. This should typically be an open Internet IP, since this makes reporting not dependent upon the thing being tested. Also note that this thing does no security of any kind. It's designed for one-off tests run over a short period of time, not to be anything that runs permanently. You will also want to edit the Dockerfile if you want to build containers and change the network ID to the network you want to run tests over.
|
||||
|
||||
This code can be deployed across a large number of VMs or containers to test and benchmark HTTP traffic within a virtual network at scale. The agent acts as a server and can query other agents, while the server collects agent data and tells agents about each other. It's designed to use RFC4193-based ZeroTier IPv6 addresses within the cluster, which allows the easy provisioning of a large cluster without IP conflicts.
|
||||
|
||||
The Dockerfile builds an image that launches the agent. The image must be "docker run" with "--device=/dev/net/tun --privileged" to permit it to open a tun/tap device within the container. (Unfortunately CAP_NET_ADMIN may not work due to a bug in Docker and/or Linux.) You can run a bunch with a command like:
|
||||
|
||||
for ((n=0;n<10;n++)); do docker run --device=/dev/net/tun --privileged -d zerotier/http-test; done
|
@ -1,196 +0,0 @@
|
||||
// ZeroTier distributed HTTP test agent
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Customizable parameters:
|
||||
|
||||
// Time between startup and first test attempt
|
||||
var TEST_STARTUP_LAG = 10000;
|
||||
|
||||
// Maximum interval between test attempts (actual timing is random % this)
|
||||
var TEST_INTERVAL_MAX = (60000 * 10);
|
||||
|
||||
// Test timeout in ms
|
||||
var TEST_TIMEOUT = 30000;
|
||||
|
||||
// Where should I get other agents' IDs and POST results?
|
||||
var SERVER_HOST = '52.26.196.147';
|
||||
var SERVER_PORT = 18080;
|
||||
|
||||
// Which port do agents use to serve up test data to each other?
|
||||
var AGENT_PORT = 18888;
|
||||
|
||||
// Payload size in bytes
|
||||
var PAYLOAD_SIZE = 5000;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
var ipaddr = require('ipaddr.js');
|
||||
var os = require('os');
|
||||
var http = require('http');
|
||||
var async = require('async');
|
||||
|
||||
var express = require('express');
|
||||
var app = express();
|
||||
|
||||
// Find our ZeroTier-assigned RFC4193 IPv6 address
|
||||
var thisAgentId = null;
|
||||
var interfaces = os.networkInterfaces();
|
||||
if (!interfaces) {
|
||||
console.error('FATAL: os.networkInterfaces() failed.');
|
||||
process.exit(1);
|
||||
}
|
||||
for(var ifname in interfaces) {
|
||||
var ifaddrs = interfaces[ifname];
|
||||
if (Array.isArray(ifaddrs)) {
|
||||
for(var i=0;i<ifaddrs.length;++i) {
|
||||
if (ifaddrs[i].family == 'IPv6') {
|
||||
try {
|
||||
var ipbytes = ipaddr.parse(ifaddrs[i].address).toByteArray();
|
||||
if ((ipbytes.length === 16)&&(ipbytes[0] == 0xfd)&&(ipbytes[9] == 0x99)&&(ipbytes[10] == 0x93)) {
|
||||
thisAgentId = '';
|
||||
for(var j=0;j<16;++j) {
|
||||
var tmp = ipbytes[j].toString(16);
|
||||
if (tmp.length === 1)
|
||||
thisAgentId += '0';
|
||||
thisAgentId += tmp;
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (thisAgentId === null) {
|
||||
console.error('FATAL: no ZeroTier-assigned RFC4193 IPv6 addresses found on any local interface!');
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
//console.log(thisAgentId);
|
||||
|
||||
// Create a random (and therefore not very compressable) payload
|
||||
var payload = new Buffer(PAYLOAD_SIZE);
|
||||
for(var xx=0;xx<PAYLOAD_SIZE;++xx) {
|
||||
payload.writeUInt8(Math.round(Math.random() * 255.0),xx);
|
||||
}
|
||||
|
||||
function agentIdToIp(agentId)
|
||||
{
|
||||
var ip = '';
|
||||
ip += agentId.substr(0,4);
|
||||
ip += ':';
|
||||
ip += agentId.substr(4,4);
|
||||
ip += ':';
|
||||
ip += agentId.substr(8,4);
|
||||
ip += ':';
|
||||
ip += agentId.substr(12,4);
|
||||
ip += ':';
|
||||
ip += agentId.substr(16,4);
|
||||
ip += ':';
|
||||
ip += agentId.substr(20,4);
|
||||
ip += ':';
|
||||
ip += agentId.substr(24,4);
|
||||
ip += ':';
|
||||
ip += agentId.substr(28,4);
|
||||
return ip;
|
||||
};
|
||||
|
||||
var lastTestResult = null;
|
||||
var allOtherAgents = {};
|
||||
|
||||
function doTest()
|
||||
{
|
||||
var submit = http.request({
|
||||
host: SERVER_HOST,
|
||||
port: SERVER_PORT,
|
||||
path: '/'+thisAgentId,
|
||||
method: 'POST'
|
||||
},function(res) {
|
||||
var body = '';
|
||||
res.on('data',function(chunk) { body += chunk.toString(); });
|
||||
res.on('end',function() {
|
||||
|
||||
if (body) {
|
||||
try {
|
||||
var peers = JSON.parse(body);
|
||||
if (Array.isArray(peers)) {
|
||||
for(var xx=0;xx<peers.length;++xx)
|
||||
allOtherAgents[peers[xx]] = true;
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
var agents = Object.keys(allOtherAgents);
|
||||
if (agents.length > 1) {
|
||||
|
||||
var target = agents[Math.floor(Math.random() * agents.length)];
|
||||
while (target === thisAgentId)
|
||||
target = agents[Math.floor(Math.random() * agents.length)];
|
||||
|
||||
var testRequest = null;
|
||||
var timeoutId = null;
|
||||
timeoutId = setTimeout(function() {
|
||||
if (testRequest !== null)
|
||||
testRequest.abort();
|
||||
timeoutId = null;
|
||||
},TEST_TIMEOUT);
|
||||
var startTime = Date.now();
|
||||
|
||||
testRequest = http.get({
|
||||
host: agentIdToIp(target),
|
||||
port: AGENT_PORT,
|
||||
path: '/'
|
||||
},function(res) {
|
||||
var bytes = 0;
|
||||
res.on('data',function(chunk) { bytes += chunk.length; });
|
||||
res.on('end',function() {
|
||||
lastTestResult = {
|
||||
source: thisAgentId,
|
||||
target: target,
|
||||
time: (Date.now() - startTime),
|
||||
bytes: bytes,
|
||||
timedOut: (timeoutId === null),
|
||||
error: null
|
||||
};
|
||||
if (timeoutId !== null)
|
||||
clearTimeout(timeoutId);
|
||||
return setTimeout(doTest,Math.round(Math.random() * TEST_INTERVAL_MAX) + 1);
|
||||
});
|
||||
}).on('error',function(e) {
|
||||
lastTestResult = {
|
||||
source: thisAgentId,
|
||||
target: target,
|
||||
time: (Date.now() - startTime),
|
||||
bytes: 0,
|
||||
timedOut: (timeoutId === null),
|
||||
error: e.toString()
|
||||
};
|
||||
if (timeoutId !== null)
|
||||
clearTimeout(timeoutId);
|
||||
return setTimeout(doTest,Math.round(Math.random() * TEST_INTERVAL_MAX) + 1);
|
||||
});
|
||||
|
||||
} else {
|
||||
return setTimeout(doTest,1000);
|
||||
}
|
||||
|
||||
});
|
||||
}).on('error',function(e) {
|
||||
console.log('POST failed: '+e.toString());
|
||||
return setTimeout(doTest,1000);
|
||||
});
|
||||
if (lastTestResult !== null) {
|
||||
submit.write(JSON.stringify(lastTestResult));
|
||||
lastTestResult = null;
|
||||
}
|
||||
submit.end();
|
||||
};
|
||||
|
||||
// Agents just serve up a test payload
|
||||
app.get('/',function(req,res) { return res.status(200).send(payload); });
|
||||
|
||||
var expressServer = app.listen(AGENT_PORT,function () {
|
||||
// Start timeout-based loop
|
||||
setTimeout(doTest(),TEST_STARTUP_LAG);
|
||||
});
|
@ -1,9 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# Kills all running Docker containers on all big-test-hosts
|
||||
|
||||
export PATH=/bin:/usr/bin:/usr/local/bin:/usr/sbin:/sbin
|
||||
|
||||
pssh -h big-test-hosts -x '-t -t' -i -OUserKnownHostsFile=/dev/null -OStrictHostKeyChecking=no -t 0 -p 256 "sudo docker ps -aq | xargs -r sudo docker rm -f"
|
||||
|
||||
exit 0
|
@ -1,13 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
# More than 500 container seems to result in a lot of sporadic failures, probably due to Linux kernel scaling issues with virtual network ports
|
||||
# 250 with a 16GB RAM VM like Amazon m4.xlarge seems good
|
||||
NUM_CONTAINERS=250
|
||||
CONTAINER_IMAGE=zerotier/http-test
|
||||
SCALE_UP_DELAY=10
|
||||
|
||||
export PATH=/bin:/usr/bin:/usr/local/bin:/usr/sbin:/sbin
|
||||
|
||||
pssh -h big-test-hosts -x '-t -t' -i -OUserKnownHostsFile=/dev/null -OStrictHostKeyChecking=no -t 0 -p 256 "sudo sysctl -w net.netfilter.nf_conntrack_max=262144 ; for ((n=0;n<$NUM_CONTAINERS;n++)); do sudo docker run --device=/dev/net/tun --privileged -d $CONTAINER_IMAGE; sleep $SCALE_UP_DELAY; done"
|
||||
|
||||
exit 0
|
@ -1,65 +0,0 @@
|
||||
//
|
||||
// Pipe the output of server.js into this to convert raw test results into bracketed statistics
|
||||
// suitable for graphing.
|
||||
//
|
||||
|
||||
// Time duration per statistical bracket
|
||||
var BRACKET_SIZE = 10000;
|
||||
|
||||
// Number of bytes expected from each test
|
||||
var EXPECTED_BYTES = 5000;
|
||||
|
||||
var readline = require('readline');
|
||||
var rl = readline.createInterface({
|
||||
input: process.stdin,
|
||||
output: process.stdout,
|
||||
terminal: false
|
||||
});
|
||||
|
||||
var count = 0.0;
|
||||
var overallCount = 0.0;
|
||||
var totalFailures = 0.0;
|
||||
var totalOverallFailures = 0.0;
|
||||
var totalMs = 0;
|
||||
var totalData = 0;
|
||||
var devices = {};
|
||||
var lastBracketTs = 0;
|
||||
|
||||
rl.on('line',function(line) {
|
||||
line = line.trim();
|
||||
var ls = line.split(',');
|
||||
if (ls.length == 7) {
|
||||
var ts = parseInt(ls[0]);
|
||||
var fromId = ls[1];
|
||||
var toId = ls[2];
|
||||
var ms = parseFloat(ls[3]);
|
||||
var bytes = parseInt(ls[4]);
|
||||
var timedOut = (ls[5] == 'true') ? true : false;
|
||||
var errMsg = ls[6];
|
||||
|
||||
count += 1.0;
|
||||
overallCount += 1.0;
|
||||
if ((bytes !== EXPECTED_BYTES)||(timedOut)) {
|
||||
totalFailures += 1.0;
|
||||
totalOverallFailures += 1.0;
|
||||
}
|
||||
totalMs += ms;
|
||||
totalData += bytes;
|
||||
|
||||
devices[fromId] = true;
|
||||
devices[toId] = true;
|
||||
|
||||
if (lastBracketTs === 0)
|
||||
lastBracketTs = ts;
|
||||
|
||||
if (((ts - lastBracketTs) >= BRACKET_SIZE)&&(count > 0.0)) {
|
||||
console.log(count.toString()+','+overallCount.toString()+','+(totalMs / count)+','+(totalFailures / count)+','+(totalOverallFailures / overallCount)+','+totalData+','+Object.keys(devices).length);
|
||||
|
||||
count = 0.0;
|
||||
totalFailures = 0.0;
|
||||
totalMs = 0;
|
||||
totalData = 0;
|
||||
lastBracketTs = ts;
|
||||
}
|
||||
} // else ignore junk
|
||||
});
|
@ -1,16 +0,0 @@
|
||||
#!/bin/bash
|
||||
|
||||
export PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin
|
||||
|
||||
/zerotier-one -d >>zerotier-one.out 2>&1
|
||||
|
||||
# Wait for ZeroTier to start and join the network
|
||||
while [ ! -d "/proc/sys/net/ipv6/conf/zt0" ]; do
|
||||
sleep 0.25
|
||||
done
|
||||
|
||||
# Wait just a bit longer for stuff to settle
|
||||
sleep 5
|
||||
|
||||
exec node --harmony /agent.js >>agent.out 2>&1
|
||||
#exec node --harmony /agent.js
|
@ -1,6 +0,0 @@
|
||||
[nodesource]
|
||||
name=Node.js Packages for Enterprise Linux 7 - $basearch
|
||||
baseurl=https://rpm.nodesource.com/pub_4.x/el/7/$basearch
|
||||
failovermethod=priority
|
||||
enabled=1
|
||||
gpgcheck=0
|
@ -1,16 +0,0 @@
|
||||
{
|
||||
"name": "zerotier-test-http",
|
||||
"version": "1.0.0",
|
||||
"description": "ZeroTier in-network HTTP test",
|
||||
"main": "agent.js",
|
||||
"scripts": {
|
||||
"test": "echo \"Error: no test specified\" && exit 1"
|
||||
},
|
||||
"author": "ZeroTier, Inc.",
|
||||
"license": "GPL-3.0",
|
||||
"dependencies": {
|
||||
"async": "^1.5.0",
|
||||
"express": "^4.13.3",
|
||||
"ipaddr.js": "^1.0.3"
|
||||
}
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
// ZeroTier distributed HTTP test coordinator and result-reporting server
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// Customizable parameters:
|
||||
|
||||
var SERVER_PORT = 18080;
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
var fs = require('fs');
|
||||
|
||||
var express = require('express');
|
||||
var app = express();
|
||||
|
||||
app.use(function(req,res,next) {
|
||||
req.rawBody = '';
|
||||
req.on('data', function(chunk) { req.rawBody += chunk.toString(); });
|
||||
req.on('end', function() { return next(); });
|
||||
});
|
||||
|
||||
var knownAgents = {};
|
||||
|
||||
app.post('/:agentId',function(req,res) {
|
||||
var agentId = req.params.agentId;
|
||||
if ((!agentId)||(agentId.length !== 32))
|
||||
return res.status(404).send('');
|
||||
|
||||
if (req.rawBody) {
|
||||
var receiveTime = Date.now();
|
||||
var resultData = null;
|
||||
try {
|
||||
resultData = JSON.parse(req.rawBody);
|
||||
console.log(Date.now().toString()+','+resultData.source+','+resultData.target+','+resultData.time+','+resultData.bytes+','+resultData.timedOut+',"'+((resultData.error) ? resultData.error : '')+'"');
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
knownAgents[agentId] = true;
|
||||
var thisUpdate = [];
|
||||
var agents = Object.keys(knownAgents);
|
||||
if (agents.length < 100)
|
||||
thisUpdate = agents;
|
||||
else {
|
||||
for(var xx=0;xx<100;++xx)
|
||||
thisUpdate.push(agents[Math.floor(Math.random() * agents.length)]);
|
||||
}
|
||||
|
||||
return res.status(200).send(JSON.stringify(thisUpdate));
|
||||
});
|
||||
|
||||
var expressServer = app.listen(SERVER_PORT,function () {
|
||||
console.log('LISTENING ON '+SERVER_PORT);
|
||||
console.log('');
|
||||
});
|
17
attic/historic/anode/config.mk.Darwin
Normal file
17
attic/historic/anode/config.mk.Darwin
Normal file
@ -0,0 +1,17 @@
|
||||
CC=gcc
|
||||
CXX=g++
|
||||
|
||||
#ARCH_FLAGS=-arch x86_64 -arch i386 -arch ppc
|
||||
|
||||
DEFS=-DHAS_DEV_URANDOM
|
||||
CXXDEFS=-DBOOST_DISABLE_ASSERTS -DBOOST_NO_TYPEID -DNDEBUG
|
||||
|
||||
CFLAGS=-mmacosx-version-min=10.4 -std=c99 -O6 -ftree-vectorize -Wall $(DEFS) $(ARCH_FLAGS)
|
||||
CXXFLAGS=-mmacosx-version-min=10.4 -Drestrict=__restrict__ -O6 -ftree-vectorize -Wall $(DEFS) $(CXXDEFS) $(ARCH_FLAGS)
|
||||
|
||||
LDFLAGS=-mmacosx-version-min=10.4 $(ARCH_FLAGS)
|
||||
DLLFLAGS=$(ARCH_FLAGS) -shared
|
||||
DLLEXT=dylib
|
||||
|
||||
LIBANODE_LIBS=-lcrypto -lpthread -lresolv
|
||||
LIBSPARK_LIBS=-lz
|
17
attic/historic/anode/config.mk.Linux
Normal file
17
attic/historic/anode/config.mk.Linux
Normal file
@ -0,0 +1,17 @@
|
||||
CC=gcc
|
||||
CXX=g++
|
||||
|
||||
DEFS=-DHAS_DEV_URANDOM
|
||||
|
||||
CFLAGS=-std=c99 -O6 -fPIC -Wall $(DEFS)
|
||||
CXXFLAGS=-Drestrict=__restrict__ -O6 -Wall $(DEFS) -I..
|
||||
|
||||
#CFLAGS=-g -Wall $(DEFS)
|
||||
#CXXFLAGS=-g -Wall $(DEFS)
|
||||
|
||||
LDFLAGS=
|
||||
DLLFLAGS=-shared
|
||||
DLLEXT=so
|
||||
|
||||
LIBANODE_LIBS=-lcrypto -lresolv -pthread
|
||||
LIBSPARK_LIBS=-lz
|
764
attic/historic/anode/docs/anode_protocol.txt
Normal file
764
attic/historic/anode/docs/anode_protocol.txt
Normal file
@ -0,0 +1,764 @@
|
||||
*****************************************************************************
|
||||
Anode Protocol Specification Draft
|
||||
Version 0.8
|
||||
|
||||
(c)2009-2010 Adam Ierymenko
|
||||
*****************************************************************************
|
||||
|
||||
Table of Contents
|
||||
|
||||
*****************************************************************************
|
||||
|
||||
1. Introduction
|
||||
|
||||
Anode provides three components that work together to provide a global,
|
||||
secure, and mobile addressing system for computer networks:
|
||||
|
||||
1) An addressing system based on public key cryptography enabling network
|
||||
devices or applications to assign themselves secure, unique, and globally
|
||||
reachable network addresses in a flat address space.
|
||||
|
||||
2) A system enabling network participants holding global addresses to locate
|
||||
one another on local or global networks with "zero configuration."
|
||||
|
||||
3) A communications protocol for communication between addressed network
|
||||
participants that requires no special operating system support and no
|
||||
changes to existing network infrastructure.
|
||||
|
||||
Using Anode, both fixed and mobile applications and devices can communicate
|
||||
directly as if they were all connected to the same VPN. Anode restores the
|
||||
original vision of the Internet as a "flat" network where anything can talk
|
||||
to anything, and adds the added benefits of address mobility and strong
|
||||
protection against address spoofing and other protocol level attacks.
|
||||
|
||||
1.1. Design Philosophy
|
||||
|
||||
Anode's design philosophy is the classical "KISS" principle: "Keep It Simple
|
||||
Stupid." Anode's design principles are:
|
||||
|
||||
#1: Do not try to solve too many problems at once, and stay in scope.
|
||||
|
||||
Anode does not attempt to solve too many problems at once. It attempts to
|
||||
solve the problems of mobile addressing, address portability, and "flat"
|
||||
addressing in the presence of NAT or other barriers.
|
||||
|
||||
It does not attempt to duplicate the full functionality of SSL, X.509, SSH,
|
||||
XMPP, an enterprise service bus, a pub/sub architecture, BitTorrent, etc. All
|
||||
of those protocols and services can be used over Anode if their functionality
|
||||
is desired.
|
||||
|
||||
#2: Avoid state management.
|
||||
|
||||
State multiplies the complexity and failure modes of network protocols. State
|
||||
also tends to get in the way of the achievement of new features implicitly
|
||||
(see principle #4). Avoid state whenever possible.
|
||||
|
||||
#3: Avoid algorithm and dependency bloat.
|
||||
|
||||
Anode uses only elliptic curve Diffie-Hellman (EC-DH) and AES-256. No other
|
||||
cryptographic algorithms or hash functions are presently necessary. This
|
||||
yields implementations compact enough for embedded devices.
|
||||
|
||||
Anode also requires few or no dependencies, depending on whether the two
|
||||
needed cryptographic algorithms are obtained through a library or included.
|
||||
No other protocols or libraries are required in an implementation.
|
||||
|
||||
#4: Achieve features implicitly.
|
||||
|
||||
Use a simple stateless design that allows features to be achieved implicitly
|
||||
rather than specified explicitly. For example, Anode can do multi-homing and
|
||||
could be used to build a mesh network, but neither of these features is
|
||||
explicitly specified.
|
||||
|
||||
*****************************************************************************
|
||||
|
||||
2. Core Concepts and Algorithms
|
||||
|
||||
This section describes addresses, zones, common algorithms, and other core
|
||||
concepts.
|
||||
|
||||
2.1. Zones
|
||||
|
||||
A zone is a 32-bit integer encoded into every Anode address. Zones serve to
|
||||
assist in the location of peers by address on global IP networks. They are
|
||||
not presently significant for local communications, though they could be
|
||||
used to partition addresses into groups or link them with configuration
|
||||
options.
|
||||
|
||||
Each zone has a corresponding zone file which can be fetched in a number of
|
||||
ways (see below). A zone file is a flat text format dictionary of the format
|
||||
"key=value" separated by carriage returns. Line feeds are ignored, and any
|
||||
character may be escaped with a backslash (\) character. Blank lines are
|
||||
ignored.
|
||||
|
||||
The following entries must appear in a zone file:
|
||||
|
||||
n=<zone name>
|
||||
d=<zone description>
|
||||
c=<zone contact, e-mail address of zone administrator>
|
||||
r=<zone revision, monotonically increasing integer with each edit>
|
||||
ttl=<seconds before zone file should be re-checked for changes>
|
||||
|
||||
Additional fields may appear as well, including fields specific to special
|
||||
applications or protocols supported within the zone. Some of these are
|
||||
defined in this document.
|
||||
|
||||
Zone file fetching mechanisms are described below. Multiple mechanisms are
|
||||
specified to enable fallback in the event that one mechanism is not available.
|
||||
|
||||
2.1.1. Zone File Retrieval
|
||||
|
||||
Zone files are retrieved via HTTP, with the HTTP address being formed in one
|
||||
of two ways.
|
||||
|
||||
The preferred DNS method:
|
||||
|
||||
To fetch a zone file via DNS, use the zone ID to generate a host name and URI
|
||||
of the form:
|
||||
|
||||
http://a--XXXXXXXX.net/z
|
||||
|
||||
The XXXXXXXX field is the zone ID in hexadecimal.
|
||||
|
||||
The fallback IP method:
|
||||
|
||||
For fallback in the absence of DNS, the zone ID can be used directly as an
|
||||
IPv4 or IPv4-mapped-to-IPv6 IP address. A URI is generated of the form:
|
||||
|
||||
http://ip_address/z
|
||||
|
||||
Support for this method requires that a zone ID be chosen to correspond to a
|
||||
permanent IPv4 (preferably mappable to IPv6 space as well) IP address.
|
||||
|
||||
2.1.2. Zone ID Reservation
|
||||
|
||||
By convention, a zone ID is considered reserved when a domain of the form
|
||||
"a--XXXXXXXX.net" (where XXXXXXXX is the ID in hex) is registered.
|
||||
|
||||
It is recommended that this be done even for zone IDs not used for global
|
||||
address location in order to globally reserve them.
|
||||
|
||||
2.2. Addresses
|
||||
|
||||
Anode addresses are binary strings containing a 32-bit zone ID, a public key,
|
||||
and possibly other fields. Only one address type is presently defined:
|
||||
|
||||
|---------------------------------------------------------------------------|
|
||||
| Name | Type ID | Elliptic Curve Parameters | Total Length |
|
||||
|---------------------------------------------------------------------------|
|
||||
| ANODE-256-40 | 1 | NIST-P-256 | 40 |
|
||||
|---------------------------------------------------------------------------|
|
||||
|
||||
|---------------------------------------------------------------------------|
|
||||
| Name | Binary Layout |
|
||||
|---------------------------------------------------------------------------|
|
||||
| ANODE-256-40 | <type[1]><zone[4]><unused[2]><public key[33]> |
|
||||
|---------------------------------------------------------------------------|
|
||||
|
||||
The public key is a "compressed" form elliptic curve public key as described
|
||||
in RFC5480.
|
||||
|
||||
The unused section of the address must be zero. These bytes are reserved for
|
||||
future use.
|
||||
|
||||
2.2.1. ASCII Format For Addresses
|
||||
|
||||
Addresses are encoded in ASCII using base-32, which provides a quotable and
|
||||
printable encoding that is of manageable length and is case-insensitive. For
|
||||
example, an ANODE-256-40 address is 64 characters long in base-32 encoding.
|
||||
|
||||
2.3. Relaying
|
||||
|
||||
An Anode peer may optionally relay packets to any other reachable peer.
|
||||
Relaying is accomplished by sending a packet to a peer with the recipient set
|
||||
to the final recipient. The receiving peer will, if relaying is allowed and if
|
||||
it knows of or can reach the recipient, forward the packet.
|
||||
|
||||
No error is returned if relaying fails, so relay paths are treated as possible
|
||||
paths for communication until a return is received in the same way as direct
|
||||
paths.
|
||||
|
||||
Relaying can be used by peers to send messages indirectly, locate one
|
||||
another, and determine network location information to facilitate the
|
||||
establishment of direct communications.
|
||||
|
||||
Peers may refuse to relay or may limit the transmission rate at which packets
|
||||
can be relayed.
|
||||
|
||||
2.3.1. Zone Relays
|
||||
|
||||
If a zone's addresses are globally reachable on global IP networks, it must
|
||||
have one or more zone relays. These must have globally reachable public
|
||||
static IP addresses.
|
||||
|
||||
Zone relays are specified in the zone file in the following format:
|
||||
|
||||
zr.<address checksum>=<ip>[,<ip>]:<udp port>:<tcp port>:<anode addresses>
|
||||
|
||||
The address checksum is the sum of the bytes in the Anode address modulus
|
||||
the number of "zr" entries, in hexadecimal. For example, if a zone had four
|
||||
global relays its zone file could contain the lines:
|
||||
|
||||
zr.0=1.2.3.4:4343:4344:klj4j3...
|
||||
zr.1=2.3.4.5:4343:4344:00194j...
|
||||
zr.2=3.4.5.6:4343:4344:1j42zz...
|
||||
zr.3=4.5.6.7:4343:4344:z94j1q...
|
||||
|
||||
The relay would be chosen by taking the sum of the bytes in the address
|
||||
modulo 4. For example, if the bytes of an address sum to 5081 then relay
|
||||
zr.1 would be used to communicate with that address.
|
||||
|
||||
If more than one IP address is listed for a given relay, the peer must choose
|
||||
at random from among the addresses of the desired type (IPv4 or IPv6).
|
||||
|
||||
Each relay must have one Anode address for every address type supported within
|
||||
the zone. (At present there is only one address type defined.)
|
||||
|
||||
Peers should prefer UDP and fall back to TCP only if UDP is not available.
|
||||
|
||||
To make itself available, a peer must make itself known to its designated zone
|
||||
relay. This is accomplished by sending a PING message.
|
||||
|
||||
2.4. Key Agreement and Derivation
|
||||
|
||||
Key agreement is performed using elliptic curve Diffie-Hellman. This yields
|
||||
a raw key whose size depends on the elliptic curve parameters in use.
|
||||
|
||||
The following algorithm is used to derive a key of any length from a raw
|
||||
key generated through key agreement:
|
||||
|
||||
1) Zero the derived key buffer.
|
||||
2) Determine the largest of the original raw key or the derived key.
|
||||
3) Loop from 0 to the largest length determined in step 2, XOR each byte of
|
||||
the derived key buffer with the corresponding byte of the original key
|
||||
buffer with each index being modulus the length of the respective buffer.
|
||||
|
||||
2.5. Message Authentication
|
||||
|
||||
For message authentication, CMAC-AES (with AES-256) is used. This is also
|
||||
known in some literature as OMAC1-AES. The key is derived from key agreement
|
||||
between the key pair of the sending peer and the address of the recipient.
|
||||
|
||||
2.6. AES-DIGEST
|
||||
|
||||
To maintain cryptographic algorithm frugality, a cryptographic hash function
|
||||
is constructed from the AES-256 cipher. This hash function uses the common
|
||||
Davis-Meyer construction with Merkle-Damgård length padding.
|
||||
|
||||
It is described by the following pseudocode:
|
||||
|
||||
byte previous_digest[16]
|
||||
byte digest[16] = { 0,0,... }
|
||||
byte block[32] = { 0,0,... }
|
||||
integer block_counter = 0
|
||||
|
||||
; digest message
|
||||
for each byte b of message
|
||||
block[block_counter] = b
|
||||
block_counter = block_counter + 1
|
||||
if block_counter == 32 then
|
||||
block_counter = 0
|
||||
save digest[] in previous_digest[]
|
||||
encrypt digest[] with aes-256 using block[] as 256-bit aes-256 key
|
||||
xor digest[] with previous_digest[]
|
||||
end if
|
||||
next
|
||||
|
||||
; append end marker, do final block
|
||||
block[block_counter] = 0x80
|
||||
block_counter = block_counter + 1
|
||||
zero rest of block[] from block_counter to 15
|
||||
save digest[] in previous_digest[]
|
||||
encrypt digest[] with aes-256 using block[] as 256-bit aes-256 key
|
||||
xor digest[] with previous_digest[]
|
||||
|
||||
; Merkle-Damgård length padding
|
||||
zero first 8 bytes of block[]
|
||||
fill last 8 bytes of block[] w/64-bit length in big-endian order
|
||||
save digest[] in previous_digest[]
|
||||
encrypt digest[] with aes-256 using block[] as 256-bit aes-128 key
|
||||
xor digest[] with previous_digest[]
|
||||
|
||||
; digest[] now contains 128-bit message digest
|
||||
|
||||
2.7. Short Address Identifiers (Address IDs)
|
||||
|
||||
A short 8-byte version of the Anode address is used in the protocol to reduce
|
||||
transmission overhead when both sides are already aware of the other's full
|
||||
address.
|
||||
|
||||
The short address identifier is formed by computing the AES-DIGEST of the
|
||||
full address and then XORing the first 8 bytes of the digest with the last
|
||||
8 bytes to yield an 8-byte shortened digest.
|
||||
|
||||
2.8. DNS Resolution of Anode Addresses
|
||||
|
||||
Anode addresses can be saved in DNS TXT records in the following format:
|
||||
|
||||
anode:<address in base32 ASCII encoding>
|
||||
|
||||
This permits Anode addresses to be resolved from normal DNS host name.
|
||||
|
||||
2.9. Packet Transmission Mechanisms
|
||||
|
||||
2.9.1. UDP Transmission
|
||||
|
||||
The recommended method of sending Anode packets is UDP. Each packet is simply
|
||||
sent as a UDP packet.
|
||||
|
||||
2.9.2. TCP Transmission
|
||||
|
||||
To send packets over TCP, each packet is prefixed by its size as a 16-bit
|
||||
integer.
|
||||
|
||||
2.9.3. HTTP Transmission
|
||||
|
||||
Anode packets may be submitted in HTTP POST transactions for transport over
|
||||
networks where HTTP is the only available protocol.
|
||||
|
||||
Anode packets are simply prefixed with a 16-byte packet size and concatenated
|
||||
together just as they are in a TCP stream. One or more packets may be sent
|
||||
with each HTTP POST transaction for improved performance.
|
||||
|
||||
Since this method is intended for use in "hostile" or highly restricted
|
||||
circumstances, no additional details such as special headers or MIME types
|
||||
are specified to allow maximum flexibility. Peers should ignore anything
|
||||
other than the payload.
|
||||
|
||||
2.10. Endpoints
|
||||
|
||||
An endpoint indicates a place where Anode packets may be sent. The following
|
||||
endpoint types are specified:
|
||||
|
||||
|---------------------------------------------------------------------------|
|
||||
| Endpoint Type | Description | Address Format |
|
||||
|---------------------------------------------------------------------------|
|
||||
| 0x00 | Unspecified | (none) |
|
||||
| 0x01 | Ethernet | <mac[6]> |
|
||||
| 0x02 | UDP/IPv4 | <ip[4]><port[2]> |
|
||||
| 0x03 | TCP/IPv4 | <ip[4]><port[2]> |
|
||||
| 0x04 | UDP/IPv6 | <ip[16]><port[2]> |
|
||||
| 0x05 | TCP/IPv6 | <ip[16]><port[2]> |
|
||||
| 0x06 | HTTP | <null-terminated full URI> |
|
||||
|---------------------------------------------------------------------------|
|
||||
|
||||
Endpoints are encoded by beginning with a single byte indicating the endpoint
|
||||
type followed by the address information required for the given type.
|
||||
|
||||
Note that IP ports bear no relationship to Anode protocol ports.
|
||||
|
||||
2.11. Notes
|
||||
|
||||
All integers in the protocol are transmitted in network (big endian) byte
|
||||
order.
|
||||
|
||||
*****************************************************************************
|
||||
|
||||
3. Common Packet Format
|
||||
|
||||
A common header is used for all Anode packets:
|
||||
|
||||
|---------------------------------------------------------------------------|
|
||||
| Field | Length | Description |
|
||||
|---------------------------------------------------------------------------|
|
||||
| Hop Count | 1 | 8-bit hop count (not included in MAC) |
|
||||
| Flags | 1 | 8-bit flags |
|
||||
| MAC | 8 | 8 byte shortened CMAC-AES of packet |
|
||||
| Sender Address | ? | Full address or short ID of sender |
|
||||
| Recipient Address | ? | Full address or short ID of recipient |
|
||||
| Peer IDs | 1 | Two 4-bit peer IDs: sender, recipient |
|
||||
| Message Type | 1 | 8-bit message type |
|
||||
| Message | ? | Message payload |
|
||||
|---------------------------------------------------------------------------|
|
||||
|
||||
3.1. Hop Count
|
||||
|
||||
The hop count begins at zero and must be incremented by each peer that relays
|
||||
the packet to another peer. The hop count must not wrap to zero at 255.
|
||||
|
||||
Because the hop count is modified in transit, it is not included in MAC
|
||||
calculation or authentication.
|
||||
|
||||
The hop count is used to prioritize endpoints that are direct over endpoints
|
||||
that involve relaying, or to prioritize closer routes over more distant
|
||||
ones.
|
||||
|
||||
3.2. Flags and Flag Behavior
|
||||
|
||||
|---------------------------------------------------------------------------|
|
||||
| Flag | Description |
|
||||
|---------------------------------------------------------------------------|
|
||||
| 0x01 | Sender address fully specified |
|
||||
| 0x02 | Recipient address fully specified |
|
||||
| 0x04 | Authentication error response |
|
||||
|---------------------------------------------------------------------------|
|
||||
|
||||
If flag 0x01 is set, then the sender address will be the full address rather
|
||||
than a short address identifier. The length of the address can be determined
|
||||
from the first byte of the address, which always specifies the address type.
|
||||
Flag 0x02 has the same meaning for the recipient address.
|
||||
|
||||
A peer must send fully specified sender addresses until it receives a response
|
||||
from the recipient. At this point the sender may assume that the recipient
|
||||
knows its address and use short a short sender address instead. This
|
||||
assumption should time out, with a recommended timeout of 60 seconds.
|
||||
|
||||
There is presently no need to send fully specified recipient addresses, but
|
||||
the flag is present in case it is needed and must be honored.
|
||||
|
||||
Flag 0x04 indicates that this is an error response containing a failed
|
||||
authentication error. Since authentication failed, this packet may not have
|
||||
a valid MAC. Packets with this flag must never have any effect other than
|
||||
to inform of an error. This error, since it is unauthenticated, must never
|
||||
have any side effects such as terminating a connection.
|
||||
|
||||
3.3. MAC
|
||||
|
||||
The MAC is calculated as follows:
|
||||
|
||||
1) Temporarily set the 64-bit/8-byte MAC field in the packet to the packet's
|
||||
size as a 64-bit big-endian integer.
|
||||
2) Calculate the MAC for the entire packet (excluding the first byte) using
|
||||
the key agreed upon between the sender and the recipient, resulting in a
|
||||
16 byte full CMAC-AES MAC.
|
||||
3) Derive the 8 byte packet MAC by XORing the first 8 bytes of the full 16
|
||||
byte CMAC-AES MAC with the last 8 bytes. Place this into the packet's MAC
|
||||
field.
|
||||
|
||||
3.4. Peer IDs
|
||||
|
||||
Peer IDs provide a method for up to 15 different peers to share an address,
|
||||
each with a unique ID allowing packets to be routed to them individually.
|
||||
|
||||
A peer ID of zero indicates "any" or "unspecified." Real peers must have a
|
||||
nonzero peer ID. In the normal single peer per address case, any peer ID may
|
||||
be used. If multiple peers are to share an address, some implementation-
|
||||
dependent method must be used to ensure that each peer has a unique peer ID.
|
||||
|
||||
Relaying peers must follow these rules based on the recipient peer ID when
|
||||
relaying messages:
|
||||
|
||||
- IF the peer ID is zero or if the peer ID is not known, the message must
|
||||
be forwarded to a random endpoint for the given recipient address.
|
||||
- IF the peer ID is nonzero and matches one or more known endpoints for the
|
||||
given recipient address and peer ID, the message must only be sent to
|
||||
a matching endpoint.
|
||||
|
||||
A receiving peer should process any message that it receives regardless of
|
||||
whether its recipient peer ID is correct. The peer ID is primarily for relays.
|
||||
|
||||
Peers should typically send messages with a nonzero recipient peer ID when
|
||||
responding to or involved in a conversation with a specific peer (e.g. a
|
||||
streaming connection), and send zero recipient peer IDs otherwise.
|
||||
|
||||
3.5. Short Address Conflict Disambiguation
|
||||
|
||||
In the unlikely event of two Anode addresses with the same short identifier,
|
||||
the recipient should use MAC validation to disambiguate. The peer ID must not
|
||||
be relied upon for this purpose.
|
||||
|
||||
*****************************************************************************
|
||||
|
||||
4. Basic Signaling and Transport Protocol
|
||||
|
||||
4.1. Message Types
|
||||
|
||||
|---------------------------------------------------------------------------|
|
||||
| Type | ID | Description |
|
||||
|---------------------------------------------------------------------------|
|
||||
| ERROR | 0x00 | Error response |
|
||||
| PING | 0x01 | Echo request |
|
||||
| PONG | 0x02 | Echo response |
|
||||
| EPC_REQ | 0x03 | Endpoint check request |
|
||||
| EPC | 0x04 | Endpoint check response |
|
||||
| EPI | 0x05 | Endpoint information |
|
||||
| NAT_T | 0x06 | NAT traversal message |
|
||||
| NETID_REQ | 0x07 | Request network address identification and/or test |
|
||||
| NETID | 0x08 | Response to network address identification request |
|
||||
| DGRAM | 0x09 | Simple UDP-like datagram |
|
||||
|---------------------------------------------------------------------------|
|
||||
|
||||
4.2. Message Details
|
||||
|
||||
4.2.1. ERROR
|
||||
|
||||
|---------------------------------------------------------------------------|
|
||||
| Field | Length | Description |
|
||||
|---------------------------------------------------------------------------|
|
||||
| Error Code | 2 | 16-bit error code |
|
||||
| Error Arguments | ? | Error arguments, depending on error type |
|
||||
|---------------------------------------------------------------------------|
|
||||
|
||||
Error arguments are empty unless otherwise stated below.
|
||||
|
||||
Error codes:
|
||||
|
||||
|---------------------------------------------------------------------------|
|
||||
| Error Code | Description |
|
||||
|---------------------------------------------------------------------------|
|
||||
| 0x01 | Message not valid |
|
||||
| 0x02 | Message authentication or decryption failed |
|
||||
| 0x03 | Relaying and related features not authorized |
|
||||
| 0x04 | Relay recipient not reachable |
|
||||
|---------------------------------------------------------------------------|
|
||||
|
||||
Generation of errors is optional. A peer may choose to ignore invalid
|
||||
messages or to throttle the sending of errors.
|
||||
|
||||
4.2.2. PING
|
||||
|
||||
(Payload unspecified.)
|
||||
|
||||
Request echo of payload as PONG message.
|
||||
|
||||
4.2.3. PONG
|
||||
|
||||
(Payload unspecified.)
|
||||
|
||||
Echoed payload of received PING message.
|
||||
|
||||
4.2.4. EPC_REQ
|
||||
|
||||
|---------------------------------------------------------------------------|
|
||||
| Field | Length | Description |
|
||||
|---------------------------------------------------------------------------|
|
||||
| Request ID | 4 | 32-bit request ID |
|
||||
|---------------------------------------------------------------------------|
|
||||
|
||||
Request echo of request ID in EPC message, used to check and learn endpoints.
|
||||
|
||||
To learn a network endpoint for a peer, CHECK_REQ is sent. If CHECK is
|
||||
returned with a valid request ID, the endpoint is considered valid.
|
||||
|
||||
4.2.5. EPC
|
||||
|
||||
|---------------------------------------------------------------------------|
|
||||
| Field | Length | Description |
|
||||
|---------------------------------------------------------------------------|
|
||||
| Request ID | 4 | 32-bit request ID echoed back |
|
||||
|---------------------------------------------------------------------------|
|
||||
|
||||
Response to EPC_REQ containing request ID.
|
||||
|
||||
4.2.6. EPI
|
||||
|
||||
|---------------------------------------------------------------------------|
|
||||
| Field | Length | Description |
|
||||
|---------------------------------------------------------------------------|
|
||||
| Flags | 1 | 8-bit flags |
|
||||
| Endpoint | ? | Endpoint type and address |
|
||||
| NAT-T mode | 1 | 8-bit NAT traversal mode |
|
||||
| NAT-T options | ? | Options related to specified NAT-T mode |
|
||||
|---------------------------------------------------------------------------|
|
||||
|
||||
EPI stands for EndPoint Identification, and is sent to notify another peer of
|
||||
a network endpoint where the sending peer is reachable.
|
||||
|
||||
If the receiving peer is interested in communicating with the sending peer,
|
||||
the receiving peer must send EPC_REQ to the sending peer at the specified
|
||||
endpoint to check the validity of that endpoint. The endpoint is learned if a
|
||||
valid EPC is returned.
|
||||
|
||||
If the endpoint in EPI is unspecified, the actual source of the EPI message
|
||||
is the endpoint. This allows EPI messages to be broadcast on a local LAN
|
||||
segment to advertise the presence of an address on a local network. EPI
|
||||
broadcasts on local IP networks must be made to UDP port 8737.
|
||||
|
||||
Usually EPI is sent via relays (usually zone relays) to inform a peer of an
|
||||
endpoint for direct communication.
|
||||
|
||||
There are presently no flags, so flags must be zero.
|
||||
|
||||
4.2.7. NAT_T
|
||||
|
||||
|---------------------------------------------------------------------------|
|
||||
| Field | Length | Description |
|
||||
|---------------------------------------------------------------------------|
|
||||
| NAT-T mode | 1 | 8-bit NAT traversal mode |
|
||||
| NAT-T options | ? | Options related to specified NAT-T mode |
|
||||
|---------------------------------------------------------------------------|
|
||||
|
||||
NAT_T is used to send messages specific to certain NAT traversal modes.
|
||||
|
||||
4.2.8. NETID_REQ
|
||||
|
||||
|---------------------------------------------------------------------------|
|
||||
| Field | Length | Description |
|
||||
|---------------------------------------------------------------------------|
|
||||
| Request ID | 4 | 32-bit request ID |
|
||||
| Endpoint | ? | Endpoint type and address information |
|
||||
|---------------------------------------------------------------------------|
|
||||
|
||||
When a NETID_REQ message is received, the recipient attempts to echo it back
|
||||
as a NETID message to the specified endpoint address. If the endpoint is
|
||||
unspecified, the recipient must fill it in with the actual origin of the
|
||||
NETID_REQ message. This allows a peer to cooperate with another peer (usually
|
||||
a zone relay) to empirically determine its externally visible network
|
||||
address information.
|
||||
|
||||
A peer may ignore NETID_REQ or respond with an error if it does not allow
|
||||
relaying.
|
||||
|
||||
4.2.9. NETID
|
||||
|
||||
|---------------------------------------------------------------------------|
|
||||
| Field | Length | Description |
|
||||
|---------------------------------------------------------------------------|
|
||||
| Request ID | 4 | 32-bit request ID echoed back |
|
||||
| Endpoint Type | 1 | 8-bit endpoint type |
|
||||
| Endpoint Address | ? | Endpoint Address (size depends on type) |
|
||||
|---------------------------------------------------------------------------|
|
||||
|
||||
NETID is sent in response to NETID_REQ to the specified endpoint address. It
|
||||
always contains the endpoint address to which it was sent.
|
||||
|
||||
4.2.10. DGRAM
|
||||
|
||||
|---------------------------------------------------------------------------|
|
||||
| Field | Length | Description |
|
||||
|---------------------------------------------------------------------------|
|
||||
| Source Port | 2 | 16-bit source port |
|
||||
| Destination Port | 2 | 16-bit destination port |
|
||||
| Payload | ? | Datagram packet payload |
|
||||
|---------------------------------------------------------------------------|
|
||||
|
||||
A datagram is a UDP-like message without flow control or delivery assurance.
|
||||
|
||||
*****************************************************************************
|
||||
|
||||
5. Stream Protocol
|
||||
|
||||
The stream protocol is very similar to TCP, though it omits some features
|
||||
that are not required since they are taken care of by the encapsulating
|
||||
protocol. SCTP was also an inspiration in the design.
|
||||
|
||||
5.1. Message Types
|
||||
|
||||
|---------------------------------------------------------------------------|
|
||||
| Type | ID | Description |
|
||||
|---------------------------------------------------------------------------|
|
||||
| S_OPEN | 20 | Initiate a streaming connection (like TCP SYN) |
|
||||
| S_CLOSE | 21 | Terminate a streaming connection (like TCP RST/FIN) |
|
||||
| S_DATA | 22 | Data packet |
|
||||
| S_ACK | 23 | Acknowedge receipt of one or more data packets |
|
||||
| S_DACK | 24 | Combination of DATA and ACK |
|
||||
|---------------------------------------------------------------------------|
|
||||
|
||||
5.2. Message Details
|
||||
|
||||
5.2.1. S_OPEN
|
||||
|
||||
|---------------------------------------------------------------------------|
|
||||
| Field | Length | Description |
|
||||
|---------------------------------------------------------------------------|
|
||||
| Sender Link ID | 2 | 16-bit sender link ID |
|
||||
| Destination Port | 2 | 16-bit destination port |
|
||||
| Window Size | 2 | 16-bit window size in 1024-byte increments |
|
||||
| Init. Seq. Number | 4 | 32-bit initial sequence number |
|
||||
| Flags | 1 | 8-bit flags |
|
||||
|---------------------------------------------------------------------------|
|
||||
|
||||
The OPEN message corresponds to TCP SYN, and initiates a connection. It
|
||||
specifies the initial window size for the sender and the sender's initial
|
||||
sequence number, which should be randomly chosen to prevent replay attacks.
|
||||
|
||||
If OPEN is successful, the recipient sends its own OPEN to establish the
|
||||
connetion. If OPEN is unsuccessful, CLOSE is sent with its initial and current
|
||||
sequence numbers equal and an appropriate reason such as "connection refused."
|
||||
|
||||
The sender link ID must be unique for a given recipient.
|
||||
|
||||
If flag 01 is set, the sender link ID is actually a source port where the
|
||||
sender might be listening for connections as well. This exactly duplicates
|
||||
the behavior of standard TCP. Otherwise, the sender link ID is simply an
|
||||
arbitrary number that the sender uses to identify the connection with this
|
||||
recipient and there is no port of origin. Ports of origin are optional for
|
||||
Anode streaming connections to permit greater scalability.
|
||||
|
||||
5.2.2. S_CLOSE
|
||||
|
||||
|---------------------------------------------------------------------------|
|
||||
| Field | Length | Description |
|
||||
|---------------------------------------------------------------------------|
|
||||
| Sender Link ID | 2 | 16-bit sender link ID |
|
||||
| Destination Port | 2 | 16-bit destination port |
|
||||
| Flags | 1 | 8-bit flags |
|
||||
| Reason | 1 | 8-bit close reason |
|
||||
| Init. Seq. Number | 4 | 32-bit initial sequence number |
|
||||
| Sequence Number | 4 | 32-bit current sequence number |
|
||||
|---------------------------------------------------------------------------|
|
||||
|
||||
The CLOSE message serves a function similar to TCP FIN. The initial sequence
|
||||
number is the original starting sequence number sent with S_OPEN, while the
|
||||
current sequence number is the sequence number corresponding to the close
|
||||
and must be ACKed to complete the close operation. The use of the initial
|
||||
sequence number helps to serve as a key to prevent replay attacks.
|
||||
|
||||
CLOSE is also used to indicate a failed OPEN attempt. In this case the current
|
||||
sequence number will be equal to the initial sequence number and no ACK will
|
||||
be expected.
|
||||
|
||||
There are currently no flags, so flags must be zero.
|
||||
|
||||
The reason field describes the reason for the close:
|
||||
|
||||
|---------------------------------------------------------------------------|
|
||||
| Reason Code | Description |
|
||||
|---------------------------------------------------------------------------|
|
||||
| 00 | Application closed connection |
|
||||
| 01 | Connection refused |
|
||||
| 02 | Protocol error |
|
||||
| 03 | Timed out |
|
||||
|---------------------------------------------------------------------------|
|
||||
|
||||
Established connections will usually be closed with reason 00, while reason
|
||||
01 is usually provided if an OPEN is received but the port is not bound.
|
||||
|
||||
5.2.3. S_DATA
|
||||
|
||||
|---------------------------------------------------------------------------|
|
||||
| Field | Length | Description |
|
||||
|---------------------------------------------------------------------------|
|
||||
| Sender Link ID | 2 | 16-bit sender link ID |
|
||||
| Destination Port | 2 | 16-bit destination port |
|
||||
| Sequence Number | 4 | 32-bit sequence number |
|
||||
| Payload | ? | Data payload |
|
||||
|---------------------------------------------------------------------------|
|
||||
|
||||
The DATA message carries a packet of data, with the sequence number
|
||||
determining order. The sequence number is monotonically incremented with
|
||||
each data packet, and wraps at the maximum value of an unsigned 32-bit
|
||||
integer.
|
||||
|
||||
5.2.4. S_ACK
|
||||
|
||||
|---------------------------------------------------------------------------|
|
||||
| Field | Length | Description |
|
||||
|---------------------------------------------------------------------------|
|
||||
| Sender Link ID | 2 | 16-bit sender link ID |
|
||||
| Destination Port | 2 | 16-bit destination port |
|
||||
| Window Size | 2 | 16-bit window size in 1024-byte increments |
|
||||
| Acknowledgements | ? | One or more acknowledgements (see below) |
|
||||
|---------------------------------------------------------------------------|
|
||||
|
||||
Each acknowledgement is a 32-bit integer followed by an 8-bit integer (5 bytes
|
||||
total). The 32-bit integer is the first sequence number to acknowledge, and
|
||||
the 8-bit integer is the number of sequential following sequence numbers to
|
||||
acknowledge. For example "1, 4" would acknowledge sequence numbers 1, 2, 3,
|
||||
and 4.
|
||||
|
||||
5.2.5. S_DACK
|
||||
|
||||
|---------------------------------------------------------------------------|
|
||||
| Field | Length | Description |
|
||||
|---------------------------------------------------------------------------|
|
||||
| Sender Link ID | 2 | 16-bit sender link ID |
|
||||
| Destination Port | 2 | 16-bit destination port |
|
||||
| Window Size | 2 | 16-bit window size in 1024-byte increments |
|
||||
| Num. Acks | 1 | 8-bit number of acknowledgements |
|
||||
| Acknowledgements | ? | One or more acknowledgements |
|
||||
| Payload | ? | Data payload |
|
||||
|---------------------------------------------------------------------------|
|
||||
|
||||
The DACK message combines ACK and DATA, allowing two peers that are both
|
||||
transmitting data to efficiently ACK without a separate packet.
|
33
attic/historic/anode/libanode/Makefile
Normal file
33
attic/historic/anode/libanode/Makefile
Normal file
@ -0,0 +1,33 @@
|
||||
SYSNAME:=${shell uname}
|
||||
SYSNAME!=uname
|
||||
include ../config.mk.${SYSNAME}
|
||||
|
||||
LIBANODE_OBJS= \
|
||||
impl/aes.o \
|
||||
impl/dictionary.o \
|
||||
impl/dns_txt.o \
|
||||
impl/ec.o \
|
||||
impl/environment.o \
|
||||
impl/misc.o \
|
||||
impl/thread.o \
|
||||
address.o \
|
||||
aes_digest.o \
|
||||
errors.o \
|
||||
identity.o \
|
||||
network_address.o \
|
||||
secure_random.o \
|
||||
system_transport.o \
|
||||
uri.o
|
||||
# zone.o
|
||||
|
||||
all: $(LIBANODE_OBJS)
|
||||
ar rcs libanode.a $(LIBANODE_OBJS)
|
||||
ranlib libanode.a
|
||||
$(CC) $(CFLAGS) -o utils/anode-make-identity utils/anode-make-identity.c $(LIBANODE_OBJS) $(LIBANODE_LIBS)
|
||||
|
||||
clean: force
|
||||
rm -f $(LIBANODE_OBJS)
|
||||
rm -f libanode.$(DLLEXT) libanode.a
|
||||
rm -f utils/anode-make-identity
|
||||
|
||||
force: ;
|
98
attic/historic/anode/libanode/address.c
Normal file
98
attic/historic/anode/libanode/address.c
Normal file
@ -0,0 +1,98 @@
|
||||
/* libanode: the Anode C reference implementation
|
||||
* Copyright (C) 2009-2010 Adam Ierymenko <adam.ierymenko@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include "impl/aes.h"
|
||||
#include "impl/ec.h"
|
||||
#include "impl/misc.h"
|
||||
#include "impl/types.h"
|
||||
#include "anode.h"
|
||||
|
||||
int AnodeAddress_calc_short_id(
|
||||
const AnodeAddress *address,
|
||||
AnodeAddressId *short_address_id)
|
||||
{
|
||||
unsigned char digest[16];
|
||||
|
||||
switch(AnodeAddress_get_type(address)) {
|
||||
case ANODE_ADDRESS_ANODE_256_40:
|
||||
Anode_aes_digest(address->bits,ANODE_ADDRESS_LENGTH_ANODE_256_40,digest);
|
||||
break;
|
||||
default:
|
||||
return ANODE_ERR_ADDRESS_INVALID;
|
||||
}
|
||||
|
||||
*((uint64_t *)short_address_id->bits) = ((uint64_t *)digest)[0] ^ ((uint64_t *)digest)[1];
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int AnodeAddress_get_zone(const AnodeAddress *address,AnodeZone *zone)
|
||||
{
|
||||
switch(AnodeAddress_get_type(address)) {
|
||||
case ANODE_ADDRESS_ANODE_256_40:
|
||||
*((uint32_t *)&(zone->bits[0])) = *((uint32_t *)&(address->bits[1]));
|
||||
return 0;
|
||||
}
|
||||
return ANODE_ERR_ADDRESS_INVALID;
|
||||
}
|
||||
|
||||
int AnodeAddress_to_string(const AnodeAddress *address,char *buf,int len)
|
||||
{
|
||||
const unsigned char *inptr;
|
||||
char *outptr;
|
||||
unsigned int i;
|
||||
|
||||
switch(AnodeAddress_get_type(address)) {
|
||||
case ANODE_ADDRESS_ANODE_256_40:
|
||||
if (len < (((ANODE_ADDRESS_LENGTH_ANODE_256_40 / 5) * 8) + 1))
|
||||
return ANODE_ERR_BUFFER_TOO_SMALL;
|
||||
inptr = (const unsigned char *)address->bits;
|
||||
outptr = buf;
|
||||
for(i=0;i<(ANODE_ADDRESS_LENGTH_ANODE_256_40 / 5);++i) {
|
||||
Anode_base32_5_to_8(inptr,outptr);
|
||||
inptr += 5;
|
||||
outptr += 8;
|
||||
}
|
||||
*outptr = (char)0;
|
||||
return ((ANODE_ADDRESS_LENGTH_ANODE_256_40 / 5) * 8);
|
||||
}
|
||||
return ANODE_ERR_ADDRESS_INVALID;
|
||||
}
|
||||
|
||||
int AnodeAddress_from_string(const char *str,AnodeAddress *address)
|
||||
{
|
||||
const char *blk_start = str;
|
||||
const char *ptr = str;
|
||||
unsigned int address_len = 0;
|
||||
|
||||
while (*ptr) {
|
||||
if ((unsigned long)(ptr - blk_start) == 8) {
|
||||
if ((address_len + 5) > sizeof(address->bits))
|
||||
return ANODE_ERR_ADDRESS_INVALID;
|
||||
Anode_base32_8_to_5(blk_start,(unsigned char *)&(address->bits[address_len]));
|
||||
address_len += 5;
|
||||
blk_start = ptr;
|
||||
}
|
||||
++ptr;
|
||||
}
|
||||
|
||||
if (ptr != blk_start)
|
||||
return ANODE_ERR_ADDRESS_INVALID;
|
||||
if (AnodeAddress_get_type(address) != ANODE_ADDRESS_ANODE_256_40)
|
||||
return ANODE_ERR_ADDRESS_INVALID;
|
||||
|
||||
return 0;
|
||||
}
|
85
attic/historic/anode/libanode/aes_digest.c
Normal file
85
attic/historic/anode/libanode/aes_digest.c
Normal file
@ -0,0 +1,85 @@
|
||||
/* libanode: the Anode C reference implementation
|
||||
* Copyright (C) 2009-2010 Adam Ierymenko <adam.ierymenko@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include "anode.h"
|
||||
#include "impl/aes.h"
|
||||
#include "impl/misc.h"
|
||||
#include "impl/types.h"
|
||||
|
||||
void Anode_aes_digest(const void *const message,unsigned long message_len,void *const hash)
|
||||
{
|
||||
unsigned char previous_digest[16];
|
||||
unsigned char digest[16];
|
||||
unsigned char block[32];
|
||||
const unsigned char *in = (const unsigned char *)message;
|
||||
const unsigned char *end = in + message_len;
|
||||
unsigned long block_counter;
|
||||
AnodeAesExpandedKey expkey;
|
||||
|
||||
((uint64_t *)digest)[0] = 0ULL;
|
||||
((uint64_t *)digest)[1] = 0ULL;
|
||||
((uint64_t *)block)[0] = 0ULL;
|
||||
((uint64_t *)block)[1] = 0ULL;
|
||||
((uint64_t *)block)[2] = 0ULL;
|
||||
((uint64_t *)block)[3] = 0ULL;
|
||||
|
||||
/* Davis-Meyer hash function built from block cipher */
|
||||
block_counter = 0;
|
||||
while (in != end) {
|
||||
block[block_counter++] = *(in++);
|
||||
if (block_counter == 32) {
|
||||
block_counter = 0;
|
||||
((uint64_t *)previous_digest)[0] = ((uint64_t *)digest)[0];
|
||||
((uint64_t *)previous_digest)[1] = ((uint64_t *)digest)[1];
|
||||
Anode_aes256_expand_key(block,&expkey);
|
||||
Anode_aes256_encrypt(&expkey,digest,digest);
|
||||
((uint64_t *)digest)[0] ^= ((uint64_t *)previous_digest)[0];
|
||||
((uint64_t *)digest)[1] ^= ((uint64_t *)previous_digest)[1];
|
||||
}
|
||||
}
|
||||
|
||||
/* Davis-Meyer end marker */
|
||||
block[block_counter++] = 0x80;
|
||||
while (block_counter != 32) block[block_counter++] = 0;
|
||||
((uint64_t *)previous_digest)[0] = ((uint64_t *)digest)[0];
|
||||
((uint64_t *)previous_digest)[1] = ((uint64_t *)digest)[1];
|
||||
Anode_aes256_expand_key(block,&expkey);
|
||||
Anode_aes256_encrypt(&expkey,digest,digest);
|
||||
((uint64_t *)digest)[0] ^= ((uint64_t *)previous_digest)[0];
|
||||
((uint64_t *)digest)[1] ^= ((uint64_t *)previous_digest)[1];
|
||||
|
||||
/* Merkle-Damgård length padding */
|
||||
((uint64_t *)block)[0] = 0ULL;
|
||||
if (sizeof(message_len) >= 8) { /* 32/64 bit? this will get optimized out */
|
||||
block[8] = (uint8_t)((uint64_t)message_len >> 56);
|
||||
block[9] = (uint8_t)((uint64_t)message_len >> 48);
|
||||
block[10] = (uint8_t)((uint64_t)message_len >> 40);
|
||||
block[11] = (uint8_t)((uint64_t)message_len >> 32);
|
||||
} else ((uint32_t *)block)[2] = 0;
|
||||
block[12] = (uint8_t)(message_len >> 24);
|
||||
block[13] = (uint8_t)(message_len >> 16);
|
||||
block[14] = (uint8_t)(message_len >> 8);
|
||||
block[15] = (uint8_t)message_len;
|
||||
((uint64_t *)previous_digest)[0] = ((uint64_t *)digest)[0];
|
||||
((uint64_t *)previous_digest)[1] = ((uint64_t *)digest)[1];
|
||||
Anode_aes256_expand_key(block,&expkey);
|
||||
Anode_aes256_encrypt(&expkey,digest,digest);
|
||||
((uint64_t *)digest)[0] ^= ((uint64_t *)previous_digest)[0];
|
||||
((uint64_t *)digest)[1] ^= ((uint64_t *)previous_digest)[1];
|
||||
|
||||
((uint64_t *)hash)[0] = ((uint64_t *)digest)[0];
|
||||
((uint64_t *)hash)[1] = ((uint64_t *)digest)[1];
|
||||
}
|
795
attic/historic/anode/libanode/anode.h
Normal file
795
attic/historic/anode/libanode/anode.h
Normal file
@ -0,0 +1,795 @@
|
||||
/* libanode: the Anode C reference implementation
|
||||
* Copyright (C) 2009-2010 Adam Ierymenko <adam.ierymenko@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _ANODE_ANODE_H
|
||||
#define _ANODE_ANODE_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL ((void *)0)
|
||||
#endif
|
||||
|
||||
#define ANODE_ADDRESS_LENGTH_ANODE_256_40 40
|
||||
#define ANODE_ADDRESS_MAX_LENGTH 40
|
||||
#define ANODE_ADDRESS_SECRET_LENGTH_ANODE_256_40 32
|
||||
#define ANODE_ADDRESS_MAX_SECRET_LENGTH 32
|
||||
|
||||
#define ANODE_ADDRESS_ID_LENGTH 8
|
||||
#define ANODE_ZONE_LENGTH 4
|
||||
|
||||
#define ANODE_ERR_NONE 0
|
||||
#define ANODE_ERR_INVALID_ARGUMENT (-10000)
|
||||
#define ANODE_ERR_OUT_OF_MEMORY (-10001)
|
||||
#define ANODE_ERR_INVALID_URI (-10002)
|
||||
#define ANODE_ERR_BUFFER_TOO_SMALL (-10003)
|
||||
#define ANODE_ERR_ADDRESS_INVALID (-10010)
|
||||
#define ANODE_ERR_ADDRESS_TYPE_NOT_SUPPORTED (-10011)
|
||||
#define ANODE_ERR_CONNECTION_CLOSED (-10012)
|
||||
#define ANODE_ERR_CONNECTION_CLOSED_BY_REMOTE (-10013)
|
||||
#define ANODE_ERR_CONNECT_FAILED (-10014)
|
||||
#define ANODE_ERR_UNABLE_TO_BIND (-10015)
|
||||
#define ANODE_ERR_TOO_MANY_OPEN_SOCKETS (-10016)
|
||||
#define ANODE_ERR_DNS_NAME_NOT_FOUND_OR_TIMED_OUT (-10017)
|
||||
|
||||
/**
|
||||
* Get a human-readable error description for an error code
|
||||
*
|
||||
* The value of 'err' can be either negative or positive.
|
||||
*
|
||||
* @param err Error code
|
||||
* @return Human-readable description
|
||||
*/
|
||||
extern const char *Anode_strerror(int err);
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* Secure random source */
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Opaque secure random instance
|
||||
*/
|
||||
typedef void AnodeSecureRandom;
|
||||
|
||||
/**
|
||||
* Initialize a secure random source
|
||||
*
|
||||
* No cleanup/destructor is necessary.
|
||||
*
|
||||
* @param srng Random structure to initialize
|
||||
*/
|
||||
extern AnodeSecureRandom *AnodeSecureRandom_new();
|
||||
|
||||
/**
|
||||
* Generate random bytes
|
||||
*
|
||||
* @param srng Secure random source
|
||||
* @param buf Buffer to fill
|
||||
* @param count Number of bytes to generate
|
||||
*/
|
||||
extern void AnodeSecureRandom_gen_bytes(AnodeSecureRandom *srng,void *buf,long count);
|
||||
|
||||
/**
|
||||
* Destroy and free a secure random instance
|
||||
*
|
||||
* @param srng Secure random source
|
||||
*/
|
||||
extern void AnodeSecureRandom_delete(AnodeSecureRandom *srng);
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* AES-256 derived Davis-Meyer hash function */
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Digest a message using AES-DIGEST to yield a 16-byte hash code
|
||||
*
|
||||
* @param message Message to digest
|
||||
* @param message_len Length of message in bytes
|
||||
* @param hash Buffer to store 16 byte hash code
|
||||
*/
|
||||
extern void Anode_aes_digest(
|
||||
const void *const message,
|
||||
unsigned long message_len,
|
||||
void *const hash);
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* Address Types and Components */
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Anode address
|
||||
*
|
||||
* The first byte always identifies the address type, which right now can
|
||||
* only be type 1 (ANODE-256-40).
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
char bits[ANODE_ADDRESS_MAX_LENGTH];
|
||||
} AnodeAddress;
|
||||
|
||||
/**
|
||||
* 8-byte short Anode address ID
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
char bits[ANODE_ADDRESS_ID_LENGTH];
|
||||
} AnodeAddressId;
|
||||
|
||||
/**
|
||||
* 4-byte Anode zone ID
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
char bits[ANODE_ZONE_LENGTH];
|
||||
} AnodeZone;
|
||||
|
||||
/**
|
||||
* Anode address types
|
||||
*/
|
||||
enum AnodeAddressType
|
||||
{
|
||||
ANODE_ADDRESS_ANODE_256_40 = 1
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the type of an Anode address
|
||||
*
|
||||
* This is a shortcut macro for just looking at the first byte and casting
|
||||
* it to the AnodeAddressType enum.
|
||||
*
|
||||
* @param a Pointer to address
|
||||
* @return Type as enum AnodeAddressType
|
||||
*/
|
||||
#define AnodeAddress_get_type(a) ((enum AnodeAddressType)((a)->bits[0]))
|
||||
|
||||
/**
|
||||
* Calculate the short 8 byte address ID from an address
|
||||
*
|
||||
* @param address Binary address
|
||||
* @param short_address_id Buffer to store 8-byte short address ID
|
||||
* @return 0 on success or error code on failure
|
||||
*/
|
||||
extern int AnodeAddress_calc_short_id(
|
||||
const AnodeAddress *address,
|
||||
AnodeAddressId *short_address_id);
|
||||
|
||||
/**
|
||||
* Extract the zone from an anode address
|
||||
*
|
||||
* @param address Binary address
|
||||
* @param zone Zone value-result parameter to fill on success
|
||||
* @return 0 on success or error code on failure
|
||||
*/
|
||||
extern int AnodeAddress_get_zone(const AnodeAddress *address,AnodeZone *zone);
|
||||
|
||||
/**
|
||||
* Convert an address to an ASCII string
|
||||
*
|
||||
* Anode addresses are 64 characters in ASCII form, so the buffer should
|
||||
* have 65 bytes of space.
|
||||
*
|
||||
* @param address Address to convert
|
||||
* @param buf Buffer to receive address in string form (should have 65 bytes of space)
|
||||
* @param len Length of buffer
|
||||
* @return Length of resulting string or a negative error code on error
|
||||
*/
|
||||
extern int AnodeAddress_to_string(const AnodeAddress *address,char *buf,int len);
|
||||
|
||||
/**
|
||||
* Convert a string into an address
|
||||
*
|
||||
* @param str Address in string form
|
||||
* @param address Address buffer to receive result
|
||||
* @return Zero on sucess or error code on error
|
||||
*/
|
||||
extern int AnodeAddress_from_string(const char *str,AnodeAddress *address);
|
||||
|
||||
/**
|
||||
* Supported network address types
|
||||
*/
|
||||
enum AnodeNetworkAddressType
|
||||
{
|
||||
ANODE_NETWORK_ADDRESS_IPV4 = 0,
|
||||
ANODE_NETWORK_ADDRESS_IPV6 = 1,
|
||||
ANODE_NETWORK_ADDRESS_ETHERNET = 2, /* reserved but unused */
|
||||
ANODE_NETWORK_ADDRESS_USB = 3, /* reserved but unused */
|
||||
ANODE_NETWORK_ADDRESS_BLUETOOTH = 4, /* reserved but unused */
|
||||
ANODE_NETWORK_ADDRESS_IPC = 5, /* reserved but unused */
|
||||
ANODE_NETWORK_ADDRESS_80211S = 6, /* reserved but unused */
|
||||
ANODE_NETWORK_ADDRESS_SERIAL = 7, /* reserved but unused */
|
||||
ANODE_NETWORK_ADDRESS_ANODE_256_40 = 8
|
||||
};
|
||||
|
||||
/**
|
||||
* Anode network address
|
||||
*
|
||||
* This can contain an address of any type: IPv4, IPv6, or Anode, and is used
|
||||
* with the common transport API.
|
||||
*
|
||||
* The length of the address stored in bits[] is determined by the type.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
enum AnodeNetworkAddressType type;
|
||||
char bits[ANODE_ADDRESS_MAX_LENGTH];
|
||||
} AnodeNetworkAddress;
|
||||
|
||||
/**
|
||||
* An endpoint with an address and a port
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
AnodeNetworkAddress address;
|
||||
int port;
|
||||
} AnodeNetworkEndpoint;
|
||||
|
||||
/* Constants for binding to any address (v4 or v6) */
|
||||
extern const AnodeNetworkAddress AnodeNetworkAddress_IP_ANY_V4;
|
||||
extern const AnodeNetworkAddress AnodeNetworkAddress_IP_ANY_V6;
|
||||
|
||||
/* Local host address in v4 and v6 */
|
||||
extern const AnodeNetworkAddress AnodeNetworkAddress_IP_LOCAL_V4;
|
||||
extern const AnodeNetworkAddress AnodeNetworkAddress_IP_LOCAL_V6;
|
||||
|
||||
/**
|
||||
* Convert a network address to an ASCII string
|
||||
*
|
||||
* The buffer must have room for a 15 character string for IPv4, a 40 byte
|
||||
* string for IPv6, and a 64 byte string for Anode addresses. This does not
|
||||
* include the trailing null.
|
||||
*
|
||||
* @param address Address to convert
|
||||
* @param buf Buffer to receive address in string form
|
||||
* @param len Length of buffer
|
||||
* @return Length of resulting string or a negative error code on error
|
||||
*/
|
||||
extern int AnodeNetworkAddress_to_string(const AnodeNetworkAddress *address,char *buf,int len);
|
||||
|
||||
/**
|
||||
* Convert a string into a network address of the correct type
|
||||
*
|
||||
* @param str Address in string form
|
||||
* @param address Address buffer to receive result
|
||||
* @return Zero on sucess or error code on error
|
||||
*/
|
||||
extern int AnodeNetworkAddress_from_string(const char *str,AnodeNetworkAddress *address);
|
||||
|
||||
/**
|
||||
* Fill a network endpoint from a C-API sockaddr structure
|
||||
*
|
||||
* The argument must be struct sockaddr_in for IPv4 or sockaddr_in6 for IPv6.
|
||||
* The common sin_family field will be used to differentiate.
|
||||
*
|
||||
* @param sockaddr Pointer to proper sockaddr structure
|
||||
* @param endpoint Endpoint structure to fill
|
||||
* @return Zero on success or error on failure
|
||||
*/
|
||||
extern int AnodeNetworkEndpoint_from_sockaddr(const void *sockaddr,AnodeNetworkEndpoint *endpoint);
|
||||
|
||||
/**
|
||||
* Fill a sockaddr from a network endpoint
|
||||
*
|
||||
* To support either IPv4 or IPv6 addresses, there is a sockaddr_storage
|
||||
* structure in most C APIs. If you supply anything other than an IP address
|
||||
* such as an Anode address, this will return an error.
|
||||
*
|
||||
* @param endpoint Endpoint structure to convert
|
||||
* @param sockaddr Sockaddr structure storage
|
||||
* @param sockaddr_len Length of sockaddr structure storage in bytes
|
||||
* @return Zero on success or error on failure
|
||||
*/
|
||||
extern int AnodeNetworkEndpoint_to_sockaddr(const AnodeNetworkEndpoint *endpoint,void *sockaddr,int sockaddr_len);
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* Identity Generation and Management */
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Anode identity structure containing address and secret key
|
||||
*
|
||||
* This structure is memcpy-safe, and its members are accessible.
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
/* The public Anode address */
|
||||
AnodeAddress address;
|
||||
|
||||
/* Short address ID */
|
||||
AnodeAddressId address_id;
|
||||
|
||||
/* The secret key corresponding with the public address */
|
||||
/* Secret length is determined by address type */
|
||||
char secret[ANODE_ADDRESS_MAX_SECRET_LENGTH];
|
||||
} AnodeIdentity;
|
||||
|
||||
/**
|
||||
* Generate a new identity
|
||||
*
|
||||
* This generates a public/private key pair and from that generates an
|
||||
* identity containing an address and a secret key.
|
||||
*
|
||||
* @param identity Destination structure to store new identity
|
||||
* @param zone Zone ID
|
||||
* @param type Type of identity to generate
|
||||
* @return Zero on success, error on failure
|
||||
*/
|
||||
extern int AnodeIdentity_generate(
|
||||
AnodeIdentity *identity,
|
||||
const AnodeZone *zone,
|
||||
enum AnodeAddressType type);
|
||||
|
||||
/**
|
||||
* Convert an Anode identity to a string representation
|
||||
*
|
||||
* @param identity Identity to convert
|
||||
* @param dest String buffer
|
||||
* @param dest_len Length of string buffer
|
||||
* @return Length of string created or negative error code on failure
|
||||
*/
|
||||
extern int AnodeIdentity_to_string(
|
||||
const AnodeIdentity *identity,
|
||||
char *dest,
|
||||
int dest_len);
|
||||
|
||||
/**
|
||||
* Convert a string representation to an Anode identity structure
|
||||
*
|
||||
* @param identity Destination structure to fill
|
||||
* @param str C-string containing string representation
|
||||
* @return Zero on success or negative error code on failure
|
||||
*/
|
||||
extern int AnodeIdentity_from_string(
|
||||
AnodeIdentity *identity,
|
||||
const char *str);
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* Transport API */
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
struct _AnodeTransport;
|
||||
typedef struct _AnodeTransport AnodeTransport;
|
||||
struct _AnodeEvent;
|
||||
typedef struct _AnodeEvent AnodeEvent;
|
||||
|
||||
/**
|
||||
* Anode socket
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
/* Type of socket (read-only) */
|
||||
enum {
|
||||
ANODE_SOCKET_DATAGRAM = 1,
|
||||
ANODE_SOCKET_STREAM_LISTEN = 2,
|
||||
ANODE_SOCKET_STREAM_CONNECTION = 3
|
||||
} type;
|
||||
|
||||
/* Socket state */
|
||||
enum {
|
||||
ANODE_SOCKET_CLOSED = 0,
|
||||
ANODE_SOCKET_OPEN = 1,
|
||||
ANODE_SOCKET_CONNECTING = 2,
|
||||
} state;
|
||||
|
||||
/* Local address or remote address for stream connections (read-only) */
|
||||
AnodeNetworkEndpoint endpoint;
|
||||
|
||||
/* Name of owning class (read-only) */
|
||||
const char *class_name;
|
||||
|
||||
/* Pointers for end user use (writable) */
|
||||
void *user_ptr[2];
|
||||
|
||||
/* Special handler to receive events or null for default (writable) */
|
||||
void (*event_handler)(const AnodeEvent *event);
|
||||
} AnodeSocket;
|
||||
|
||||
/**
|
||||
* Anode transport I/O event
|
||||
*/
|
||||
struct _AnodeEvent
|
||||
{
|
||||
enum {
|
||||
ANODE_TRANSPORT_EVENT_DATAGRAM_RECEIVED = 1,
|
||||
ANODE_TRANSPORT_EVENT_STREAM_INCOMING_CONNECT = 2,
|
||||
ANODE_TRANSPORT_EVENT_STREAM_OUTGOING_CONNECT_ESTABLISHED = 3,
|
||||
ANODE_TRANSPORT_EVENT_STREAM_OUTGOING_CONNECT_FAILED = 4,
|
||||
ANODE_TRANSPORT_EVENT_STREAM_CLOSED = 5,
|
||||
ANODE_TRANSPORT_EVENT_STREAM_DATA_RECEIVED = 6,
|
||||
ANODE_TRANSPORT_EVENT_STREAM_AVAILABLE_FOR_WRITE = 7,
|
||||
ANODE_TRANSPORT_EVENT_DNS_RESULT = 8
|
||||
} type;
|
||||
|
||||
AnodeTransport *transport;
|
||||
|
||||
/* Anode socket corresponding to this event */
|
||||
AnodeSocket *sock;
|
||||
|
||||
/* Originating endpoint for incoming datagrams */
|
||||
AnodeNetworkEndpoint *datagram_from;
|
||||
|
||||
/* DNS lookup results */
|
||||
const char *dns_name;
|
||||
AnodeNetworkAddress *dns_addresses;
|
||||
int dns_address_count;
|
||||
|
||||
/* Error code or 0 for none */
|
||||
int error_code;
|
||||
|
||||
/* Data for incoming datagrams and stream received events */
|
||||
int data_length;
|
||||
char *data;
|
||||
};
|
||||
|
||||
/**
|
||||
* Enum used for dns_resolve method in transport to specify query rules
|
||||
*
|
||||
* This can be specified for ipv4, ipv6, and Anode address types to tell the
|
||||
* DNS resolver when to bother querying for addresses of the given type.
|
||||
* NEVER means to never query for this type, and ALWAYS means to always
|
||||
* query. IF_NO_PREVIOUS means to query for this type if no addresses were
|
||||
* found in previous queries. Addresses are queried in the order of ipv4,
|
||||
* ipv6, then Anode, so if you specify IF_NO_PREVIOUS for all three you will
|
||||
* get addresses in that order of priority.
|
||||
*/
|
||||
enum AnodeTransportDnsIncludeMode
|
||||
{
|
||||
ANODE_TRANSPORT_DNS_QUERY_NEVER = 0,
|
||||
ANODE_TRANSPORT_DNS_QUERY_ALWAYS = 1,
|
||||
ANODE_TRANSPORT_DNS_QUERY_IF_NO_PREVIOUS = 2
|
||||
};
|
||||
|
||||
struct _AnodeTransport
|
||||
{
|
||||
/**
|
||||
* Set the default event handler
|
||||
*
|
||||
* @param transport Transport engine
|
||||
* @param event_handler Default event handler
|
||||
*/
|
||||
void (*set_default_event_handler)(AnodeTransport *transport,
|
||||
void (*event_handler)(const AnodeEvent *event));
|
||||
|
||||
/**
|
||||
* Enqueue a function to be executed during a subsequent call to poll()
|
||||
*
|
||||
* This can be called from other threads, so it can be used to pass a
|
||||
* message to the I/O thread in multithreaded applications.
|
||||
*
|
||||
* If it is called from the same thread, the function is still queued to be
|
||||
* run later rather than being run instantly.
|
||||
*
|
||||
* The order in which invoked functions are called is undefined.
|
||||
*
|
||||
* @param transport Transport engine
|
||||
* @param ptr Arbitrary pointer to pass to function to be called
|
||||
* @param func Function to be called
|
||||
*/
|
||||
void (*invoke)(AnodeTransport *transport,
|
||||
void *ptr,
|
||||
void (*func)(void *));
|
||||
|
||||
/**
|
||||
* Initiate a forward DNS query
|
||||
*
|
||||
* @param transport Transport instance
|
||||
* @param name DNS name to query
|
||||
* @param event_handler Event handler or null for default event path
|
||||
* @param ipv4_include_mode Inclusion mode for IPv4 addresses
|
||||
* @param ipv6_include_mode Inclusion mode for IPv6 addresses
|
||||
* @param anode_include_mode Inclusion mode for Anode addresses
|
||||
*/
|
||||
void (*dns_resolve)(AnodeTransport *transport,
|
||||
const char *name,
|
||||
void (*event_handler)(const AnodeEvent *),
|
||||
enum AnodeTransportDnsIncludeMode ipv4_include_mode,
|
||||
enum AnodeTransportDnsIncludeMode ipv6_include_mode,
|
||||
enum AnodeTransportDnsIncludeMode anode_include_mode);
|
||||
|
||||
/**
|
||||
* Open a datagram socket
|
||||
*
|
||||
* @param transport Transport instance
|
||||
* @param local_address Local address to bind
|
||||
* @param local_port Local port to bind
|
||||
* @param error_code Value-result parameter to receive error code on error
|
||||
* @return Listen socket or null if error (check error_code in error case)
|
||||
*/
|
||||
AnodeSocket *(*datagram_listen)(AnodeTransport *transport,
|
||||
const AnodeNetworkAddress *local_address,
|
||||
int local_port,
|
||||
int *error_code);
|
||||
|
||||
/**
|
||||
* Open a socket to listen for incoming stream connections
|
||||
*
|
||||
* @param transport Transport instance
|
||||
* @param local_address Local address to bind
|
||||
* @param local_port Local port to bind
|
||||
* @param error_code Value-result parameter to receive error code on error
|
||||
* @return Listen socket or null if error (check error_code in error case)
|
||||
*/
|
||||
AnodeSocket *(*stream_listen)(AnodeTransport *transport,
|
||||
const AnodeNetworkAddress *local_address,
|
||||
int local_port,
|
||||
int *error_code);
|
||||
|
||||
/**
|
||||
* Send a datagram to a network endpoint
|
||||
*
|
||||
* @param transport Transport instance
|
||||
* @param socket Originating datagram socket
|
||||
* @param data Data to send
|
||||
* @param data_len Length of data to send
|
||||
* @param to_endpoint Destination endpoint
|
||||
* @return Zero on success or error code on error
|
||||
*/
|
||||
int (*datagram_send)(AnodeTransport *transport,
|
||||
AnodeSocket *sock,
|
||||
const void *data,
|
||||
int data_len,
|
||||
const AnodeNetworkEndpoint *to_endpoint);
|
||||
|
||||
/**
|
||||
* Initiate an outgoing stream connection attempt
|
||||
*
|
||||
* For IPv4 and IPv6 addresses, this will initiate a TCP connection. For
|
||||
* Anode addresses, Anode's internal streaming protocol will be used.
|
||||
*
|
||||
* @param transport Transport instance
|
||||
* @param to_endpoint Destination endpoint
|
||||
* @param error_code Error code value-result parameter, filled on error
|
||||
* @return Stream socket object or null on error (check error_code)
|
||||
*/
|
||||
AnodeSocket *(*stream_connect)(AnodeTransport *transport,
|
||||
const AnodeNetworkEndpoint *to_endpoint,
|
||||
int *error_code);
|
||||
|
||||
/**
|
||||
* Indicate that you are interested in writing to a stream
|
||||
*
|
||||
* This does nothing if the socket is not a stream connection or is not
|
||||
* connected.
|
||||
*
|
||||
* @param transport Transport instance
|
||||
* @param sock Stream connection
|
||||
*/
|
||||
void (*stream_start_writing)(AnodeTransport *transport,
|
||||
AnodeSocket *sock);
|
||||
|
||||
/**
|
||||
* Indicate that you are no longer interested in writing to a stream
|
||||
*
|
||||
* This does nothing if the socket is not a stream connection or is not
|
||||
* connected.
|
||||
*
|
||||
* @param transport Transport instance
|
||||
* @param sock Stream connection
|
||||
*/
|
||||
void (*stream_stop_writing)(AnodeTransport *transport,
|
||||
AnodeSocket *sock);
|
||||
|
||||
/**
|
||||
* Send data to a stream connection
|
||||
*
|
||||
* This must be called after a stream is indicated to be ready for writing.
|
||||
* It returns the number of bytes actually written, or a negative error
|
||||
* code on failure.
|
||||
*
|
||||
* A return value of zero can occur here, and simply indicates that nothing
|
||||
* was sent. This may occur with certain network stacks on certain
|
||||
* platforms.
|
||||
*
|
||||
* @param transport Transport engine
|
||||
* @param sock Stream socket
|
||||
* @param data Data to send
|
||||
* @param data_len Maximum data to send in bytes
|
||||
* @return Actual data sent or negative error code on error
|
||||
*/
|
||||
int (*stream_send)(AnodeTransport *transport,
|
||||
AnodeSocket *sock,
|
||||
const void *data,
|
||||
int data_len);
|
||||
|
||||
/**
|
||||
* Close a socket
|
||||
*
|
||||
* If the socket is a stream connection in the connected state, this
|
||||
* will generate a stream closed event with a zero error_code to indicate
|
||||
* a normal close.
|
||||
*
|
||||
* @param transport Transport engine
|
||||
* @param sock Socket object
|
||||
*/
|
||||
void (*close)(AnodeTransport *transport,
|
||||
AnodeSocket *sock);
|
||||
|
||||
/**
|
||||
* Run main polling loop
|
||||
*
|
||||
* This should be called repeatedly from the I/O thread of your main
|
||||
* process. It blocks until one or more events occur, and then returns
|
||||
* the number of events. Error returns here are fatal and indicate
|
||||
* serious problems such as build or platform issues or a lack of any
|
||||
* network interface.
|
||||
*
|
||||
* Functions queued with invoke() are also called inside here.
|
||||
*
|
||||
* @param transport Transport engine
|
||||
* @return Number of events handled or negative on (fatal) error
|
||||
*/
|
||||
int (*poll)(AnodeTransport *transport);
|
||||
|
||||
/**
|
||||
* Check whether transport supports an address type
|
||||
*
|
||||
* Inheriting classes should call their base if they do not natively
|
||||
* speak the specified type.
|
||||
*
|
||||
* @param transport Transport engine
|
||||
* @param at Address type
|
||||
* @return Nonzero if true
|
||||
*/
|
||||
int (*supports_address_type)(const AnodeTransport *transport,
|
||||
enum AnodeNetworkAddressType at);
|
||||
|
||||
/**
|
||||
* Get the instance of AnodeTransport under this one (if any)
|
||||
*
|
||||
* @param transport Transport engine
|
||||
* @return Base instance or null if none
|
||||
*/
|
||||
AnodeTransport *(*base_instance)(const AnodeTransport *transport);
|
||||
|
||||
/**
|
||||
* @param transport Transport engine
|
||||
* @return Class name of this instance
|
||||
*/
|
||||
const char *(*class_name)(AnodeTransport *transport);
|
||||
|
||||
/**
|
||||
* Delete this transport and its base transports
|
||||
*
|
||||
* The 'transport' pointer and any streams or sockets it owns are no longer
|
||||
* valid after this call.
|
||||
*
|
||||
* @param transport Transport engine
|
||||
*/
|
||||
void (*delete)(AnodeTransport *transport);
|
||||
};
|
||||
|
||||
/**
|
||||
* Construct a new system transport
|
||||
*
|
||||
* This is the default base for AnodeTransport, and it is constructed
|
||||
* automatically if 'base' is null in AnodeTransport_new(). However, it also
|
||||
* exposed to the user so that specialized transports (such as those that use
|
||||
* proxy servers) can be developed on top of it. These in turn can be supplied
|
||||
* as 'base' to AnodeTransport_new() to talk Anode over these transports.
|
||||
*
|
||||
* The system transport supports IP protocols and possibly others.
|
||||
*
|
||||
* @param base Base class or null for none (usually null)
|
||||
* @return Base transport engine instance
|
||||
*/
|
||||
extern AnodeTransport *AnodeSystemTransport_new(AnodeTransport *base);
|
||||
|
||||
/**
|
||||
* Construct a new Anode core transport
|
||||
*
|
||||
* This is the transport that talks Anode using the specified base transport.
|
||||
* Requests for other address types are passed through to the base. If the
|
||||
* base is null, an instance of AnodeSystemTransport is used.
|
||||
*
|
||||
* Since transport engines inherit their functionality, this transport
|
||||
* will also do standard IP and everything else that the system transport
|
||||
* supports. Most users will just want to construct this with a null base.
|
||||
*
|
||||
* @param base Base transport to use, or null to use SystemTransport
|
||||
* @return Anode transport engine or null on error
|
||||
*/
|
||||
extern AnodeTransport *AnodeCoreTransport_new(AnodeTransport *base);
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* URI Parser */
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* URI broken down by component
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
char scheme[8];
|
||||
char username[64];
|
||||
char password[64];
|
||||
char host[128];
|
||||
char path[256];
|
||||
char query[256];
|
||||
char fragment[64];
|
||||
int port;
|
||||
} AnodeURI;
|
||||
|
||||
/**
|
||||
* URI parser
|
||||
*
|
||||
* A buffer too small error will occur if any field is too large for the
|
||||
* AnodeURI structure.
|
||||
*
|
||||
* @param parsed_uri Structure to fill with parsed URI data
|
||||
* @param uri_string URI in string format
|
||||
* @return Zero on success or error on failure
|
||||
*/
|
||||
extern int AnodeURI_parse(AnodeURI *parsed_uri,const char *uri_string);
|
||||
|
||||
/**
|
||||
* Output a URI in string format
|
||||
*
|
||||
* @param uri URI to output as string
|
||||
* @param buf Buffer to store URI string
|
||||
* @param len Length of buffer
|
||||
* @return Buffer or null on error
|
||||
*/
|
||||
extern char *AnodeURI_to_string(const AnodeURI *uri,char *buf,int len);
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
/* Zone File Lookup and Dictionary */
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
/**
|
||||
* Zone file dictionary
|
||||
*/
|
||||
typedef void AnodeZoneFile;
|
||||
|
||||
/**
|
||||
* Start asynchronous zone fetch
|
||||
*
|
||||
* When the zone is retrieved, the lookup handler is called. If zone lookup
|
||||
* failed, the zone file argument to the handler will be null.
|
||||
*
|
||||
* @param transport Transport engine
|
||||
* @param zone Zone ID
|
||||
* @param user_ptr User pointer
|
||||
* @param zone_lookup_handler Handler for Anode zone lookup
|
||||
*/
|
||||
extern void AnodeZoneFile_lookup(
|
||||
AnodeTransport *transport,
|
||||
const AnodeZone *zone,
|
||||
void *ptr,
|
||||
void (*zone_lookup_handler)(const AnodeZone *,AnodeZoneFile *,void *));
|
||||
|
||||
/**
|
||||
* Look up a key in a zone file
|
||||
*
|
||||
* @param zone Zone file object
|
||||
* @param key Key to get in zone file
|
||||
*/
|
||||
extern const char *AnodeZoneFile_get(const AnodeZoneFile *zone,const char *key);
|
||||
|
||||
/**
|
||||
* Free a zone file
|
||||
*
|
||||
* @param zone Zone to free
|
||||
*/
|
||||
extern void AnodeZoneFile_free(AnodeZoneFile *zone);
|
||||
|
||||
/* ----------------------------------------------------------------------- */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
52
attic/historic/anode/libanode/errors.c
Normal file
52
attic/historic/anode/libanode/errors.c
Normal file
@ -0,0 +1,52 @@
|
||||
/* libanode: the Anode C reference implementation
|
||||
* Copyright (C) 2009-2010 Adam Ierymenko <adam.ierymenko@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include "anode.h"
|
||||
|
||||
struct AnodeErrDesc
|
||||
{
|
||||
int code;
|
||||
const char *desc;
|
||||
};
|
||||
|
||||
#define TOTAL_ERRORS 12
|
||||
static const struct AnodeErrDesc ANODE_ERRORS[TOTAL_ERRORS] = {
|
||||
{ ANODE_ERR_NONE, "No error (success)" },
|
||||
{ ANODE_ERR_INVALID_ARGUMENT, "Invalid argument" },
|
||||
{ ANODE_ERR_OUT_OF_MEMORY, "Out of memory" },
|
||||
{ ANODE_ERR_INVALID_URI, "Invalid URI" },
|
||||
{ ANODE_ERR_BUFFER_TOO_SMALL, "Supplied buffer too small" },
|
||||
{ ANODE_ERR_ADDRESS_INVALID, "Address invalid" },
|
||||
{ ANODE_ERR_ADDRESS_TYPE_NOT_SUPPORTED, "Address type not supported"},
|
||||
{ ANODE_ERR_CONNECTION_CLOSED, "Connection closed"},
|
||||
{ ANODE_ERR_CONNECT_FAILED, "Connect failed"},
|
||||
{ ANODE_ERR_UNABLE_TO_BIND, "Unable to bind to address"},
|
||||
{ ANODE_ERR_TOO_MANY_OPEN_SOCKETS, "Too many open sockets"},
|
||||
{ ANODE_ERR_DNS_NAME_NOT_FOUND_OR_TIMED_OUT, "DNS name not found or timed out"}
|
||||
};
|
||||
|
||||
extern const char *Anode_strerror(int err)
|
||||
{
|
||||
int i;
|
||||
int negerr = -err;
|
||||
|
||||
for(i=0;i<TOTAL_ERRORS;++i) {
|
||||
if ((ANODE_ERRORS[i].code == err)||(ANODE_ERRORS[i].code == negerr))
|
||||
return ANODE_ERRORS[i].desc;
|
||||
}
|
||||
|
||||
return "Unknown error";
|
||||
}
|
110
attic/historic/anode/libanode/identity.c
Normal file
110
attic/historic/anode/libanode/identity.c
Normal file
@ -0,0 +1,110 @@
|
||||
/* libanode: the Anode C reference implementation
|
||||
* Copyright (C) 2009-2010 Adam Ierymenko <adam.ierymenko@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "impl/types.h"
|
||||
#include "impl/ec.h"
|
||||
#include "impl/misc.h"
|
||||
#include "anode.h"
|
||||
|
||||
int AnodeIdentity_generate(AnodeIdentity *identity,const AnodeZone *zone,enum AnodeAddressType type)
|
||||
{
|
||||
struct AnodeECKeyPair kp;
|
||||
|
||||
switch(type) {
|
||||
case ANODE_ADDRESS_ANODE_256_40:
|
||||
if (!AnodeECKeyPair_generate(&kp))
|
||||
return ANODE_ERR_OUT_OF_MEMORY;
|
||||
|
||||
identity->address.bits[0] = (unsigned char)ANODE_ADDRESS_ANODE_256_40;
|
||||
|
||||
identity->address.bits[1] = zone->bits[0];
|
||||
identity->address.bits[2] = zone->bits[1];
|
||||
identity->address.bits[3] = zone->bits[2];
|
||||
identity->address.bits[4] = zone->bits[3];
|
||||
|
||||
identity->address.bits[5] = 0;
|
||||
identity->address.bits[6] = 0;
|
||||
|
||||
Anode_memcpy((void *)&(identity->address.bits[7]),(const void *)kp.pub.key,ANODE_EC_PUBLIC_KEY_BYTES);
|
||||
Anode_memcpy((void *)identity->secret,(const void *)kp.priv.key,kp.priv.bytes);
|
||||
|
||||
AnodeAddress_calc_short_id(&identity->address,&identity->address_id);
|
||||
|
||||
AnodeECKeyPair_destroy(&kp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ANODE_ERR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
int AnodeIdentity_to_string(const AnodeIdentity *identity,char *dest,int dest_len)
|
||||
{
|
||||
char hexbuf[128];
|
||||
char strbuf[128];
|
||||
int n;
|
||||
|
||||
if ((n = AnodeAddress_to_string(&identity->address,strbuf,sizeof(strbuf))) <= 0)
|
||||
return n;
|
||||
|
||||
switch(AnodeAddress_get_type(&identity->address)) {
|
||||
case ANODE_ADDRESS_ANODE_256_40:
|
||||
Anode_to_hex((const unsigned char *)identity->secret,ANODE_ADDRESS_SECRET_LENGTH_ANODE_256_40,hexbuf,sizeof(hexbuf));
|
||||
n = snprintf(dest,dest_len,"ANODE-256-40:%s:%s",strbuf,hexbuf);
|
||||
if (n >= dest_len)
|
||||
return ANODE_ERR_BUFFER_TOO_SMALL;
|
||||
return n;
|
||||
}
|
||||
|
||||
return ANODE_ERR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
int AnodeIdentity_from_string(AnodeIdentity *identity,const char *str)
|
||||
{
|
||||
char buf[1024];
|
||||
char *id_name;
|
||||
char *address;
|
||||
char *secret;
|
||||
int ec;
|
||||
|
||||
Anode_str_copy(buf,str,sizeof(buf));
|
||||
|
||||
id_name = buf;
|
||||
if (!id_name) return 0;
|
||||
if (!*id_name) return 0;
|
||||
address = (char *)Anode_strchr(id_name,':');
|
||||
if (!address) return 0;
|
||||
if (!*address) return 0;
|
||||
*(address++) = (char)0;
|
||||
secret = (char *)Anode_strchr(address,':');
|
||||
if (!secret) return 0;
|
||||
if (!*secret) return 0;
|
||||
*(secret++) = (char)0;
|
||||
|
||||
if (Anode_strcaseeq("ANODE-256-40",id_name)) {
|
||||
if ((ec = AnodeAddress_from_string(address,&identity->address)))
|
||||
return ec;
|
||||
if (Anode_strlen(secret) != (ANODE_ADDRESS_SECRET_LENGTH_ANODE_256_40 * 2))
|
||||
return ANODE_ERR_INVALID_ARGUMENT;
|
||||
Anode_from_hex(secret,(unsigned char *)identity->secret,sizeof(identity->secret));
|
||||
AnodeAddress_calc_short_id(&identity->address,&identity->address_id);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ANODE_ERR_INVALID_ARGUMENT;
|
||||
}
|
72
attic/historic/anode/libanode/impl/aes.c
Normal file
72
attic/historic/anode/libanode/impl/aes.c
Normal file
@ -0,0 +1,72 @@
|
||||
/* libanode: the Anode C reference implementation
|
||||
* Copyright (C) 2009-2010 Adam Ierymenko <adam.ierymenko@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include "aes.h"
|
||||
|
||||
void Anode_cmac_aes256(
|
||||
const AnodeAesExpandedKey *expkey,
|
||||
const unsigned char *restrict data,
|
||||
unsigned long data_len,
|
||||
unsigned char *restrict mac)
|
||||
{
|
||||
unsigned char cbc[16];
|
||||
unsigned char pad[16];
|
||||
const unsigned char *restrict pos = data;
|
||||
unsigned long i;
|
||||
unsigned long remaining = data_len;
|
||||
unsigned char c;
|
||||
|
||||
((uint64_t *)((void *)cbc))[0] = 0ULL;
|
||||
((uint64_t *)((void *)cbc))[1] = 0ULL;
|
||||
|
||||
while (remaining >= 16) {
|
||||
((uint64_t *)((void *)cbc))[0] ^= ((uint64_t *)((void *)pos))[0];
|
||||
((uint64_t *)((void *)cbc))[1] ^= ((uint64_t *)((void *)pos))[1];
|
||||
pos += 16;
|
||||
if (remaining > 16)
|
||||
Anode_aes256_encrypt(expkey,cbc,cbc);
|
||||
remaining -= 16;
|
||||
}
|
||||
|
||||
((uint64_t *)((void *)pad))[0] = 0ULL;
|
||||
((uint64_t *)((void *)pad))[1] = 0ULL;
|
||||
Anode_aes256_encrypt(expkey,pad,pad);
|
||||
|
||||
c = pad[0] & 0x80;
|
||||
for(i=0;i<15;++i)
|
||||
pad[i] = (pad[i] << 1) | (pad[i + 1] >> 7);
|
||||
pad[15] <<= 1;
|
||||
if (c)
|
||||
pad[15] ^= 0x87;
|
||||
|
||||
if (remaining||(!data_len)) {
|
||||
for(i=0;i<remaining;++i)
|
||||
cbc[i] ^= *(pos++);
|
||||
cbc[remaining] ^= 0x80;
|
||||
|
||||
c = pad[0] & 0x80;
|
||||
for(i=0;i<15;++i)
|
||||
pad[i] = (pad[i] << 1) | (pad[i + 1] >> 7);
|
||||
pad[15] <<= 1;
|
||||
if (c)
|
||||
pad[15] ^= 0x87;
|
||||
}
|
||||
|
||||
((uint64_t *)((void *)mac))[0] = ((uint64_t *)((void *)pad))[0] ^ ((uint64_t *)((void *)cbc))[0];
|
||||
((uint64_t *)((void *)mac))[1] = ((uint64_t *)((void *)pad))[1] ^ ((uint64_t *)((void *)cbc))[1];
|
||||
|
||||
Anode_aes256_encrypt(expkey,mac,mac);
|
||||
}
|
64
attic/historic/anode/libanode/impl/aes.h
Normal file
64
attic/historic/anode/libanode/impl/aes.h
Normal file
@ -0,0 +1,64 @@
|
||||
/* libanode: the Anode C reference implementation
|
||||
* Copyright (C) 2009 Adam Ierymenko <adam.ierymenko@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _ANODE_AES_H
|
||||
#define _ANODE_AES_H
|
||||
|
||||
#include <openssl/aes.h>
|
||||
#include "types.h"
|
||||
|
||||
/* This just glues us to OpenSSL's built-in AES-256 implementation */
|
||||
|
||||
#define ANODE_AES_BLOCK_SIZE 16
|
||||
#define ANODE_AES_KEY_SIZE 32
|
||||
|
||||
typedef AES_KEY AnodeAesExpandedKey;
|
||||
|
||||
#define Anode_aes256_expand_key(k,ek) AES_set_encrypt_key((const unsigned char *)(k),256,(AES_KEY *)(ek))
|
||||
|
||||
/* Note: in and out can be the same thing */
|
||||
#define Anode_aes256_encrypt(ek,in,out) AES_encrypt((const unsigned char *)(in),(unsigned char *)(out),(const AES_KEY *)(ek))
|
||||
|
||||
/* Note: iv is modified */
|
||||
static inline void Anode_aes256_cfb_encrypt(
|
||||
const AnodeAesExpandedKey *expkey,
|
||||
const unsigned char *in,
|
||||
unsigned char *out,
|
||||
unsigned char *iv,
|
||||
unsigned long len)
|
||||
{
|
||||
int tmp = 0;
|
||||
AES_cfb128_encrypt(in,out,len,(const AES_KEY *)expkey,iv,&tmp,AES_ENCRYPT);
|
||||
}
|
||||
static inline void Anode_aes256_cfb_decrypt(
|
||||
const AnodeAesExpandedKey *expkey,
|
||||
const unsigned char *in,
|
||||
unsigned char *out,
|
||||
unsigned char *iv,
|
||||
unsigned long len)
|
||||
{
|
||||
int tmp = 0;
|
||||
AES_cfb128_encrypt(in,out,len,(const AES_KEY *)expkey,iv,&tmp,AES_DECRYPT);
|
||||
}
|
||||
|
||||
/* CMAC message authentication code */
|
||||
void Anode_cmac_aes256(
|
||||
const AnodeAesExpandedKey *expkey,
|
||||
const unsigned char *restrict data,
|
||||
unsigned long data_len,
|
||||
unsigned char *restrict mac);
|
||||
|
||||
#endif
|
239
attic/historic/anode/libanode/impl/dictionary.c
Normal file
239
attic/historic/anode/libanode/impl/dictionary.c
Normal file
@ -0,0 +1,239 @@
|
||||
/* libanode: the Anode C reference implementation
|
||||
* Copyright (C) 2009-2010 Adam Ierymenko <adam.ierymenko@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "dictionary.h"
|
||||
|
||||
static const char *EMPTY_STR = "";
|
||||
|
||||
void AnodeDictionary_clear(struct AnodeDictionary *d)
|
||||
{
|
||||
struct AnodeDictionaryEntry *e,*ne;
|
||||
int oldcs;
|
||||
unsigned int i;
|
||||
|
||||
oldcs = d->case_sensitive;
|
||||
|
||||
for(i=0;i<ANODE_DICTIONARY_FIXED_HASH_TABLE_SIZE;++i) {
|
||||
e = d->ht[i];
|
||||
while (e) {
|
||||
ne = e->next;
|
||||
if ((e->key)&&(e->key != EMPTY_STR)) free((void *)e->key);
|
||||
if ((e->value)&&(e->value != EMPTY_STR)) free((void *)e->value);
|
||||
free((void *)e);
|
||||
e = ne;
|
||||
}
|
||||
}
|
||||
|
||||
Anode_zero((void *)d,sizeof(struct AnodeDictionary));
|
||||
|
||||
d->case_sensitive = oldcs;
|
||||
}
|
||||
|
||||
void AnodeDictionary_put(struct AnodeDictionary *d,const char *key,const char *value)
|
||||
{
|
||||
struct AnodeDictionaryEntry *e;
|
||||
char *p1;
|
||||
const char *p2;
|
||||
unsigned int bucket = (d->case_sensitive) ? AnodeDictionary__get_bucket(key) : AnodeDictionary__get_bucket_ci(key);
|
||||
unsigned int len,i;
|
||||
|
||||
e = d->ht[bucket];
|
||||
while (e) {
|
||||
if (((d->case_sensitive) ? Anode_streq(key,e->key) : Anode_strcaseeq(key,e->key))) {
|
||||
if (!d->case_sensitive) {
|
||||
p1 = e->key;
|
||||
p2 = key;
|
||||
while (*p2) *(p1++) = *(p2++);
|
||||
}
|
||||
|
||||
len = 0;
|
||||
while (value[len]) ++len;
|
||||
if (len) {
|
||||
if ((e->value)&&(e->value != EMPTY_STR))
|
||||
e->value = (char *)realloc((void *)e->value,len + 1);
|
||||
else e->value = (char *)malloc(len + 1);
|
||||
for(i=0;i<len;++i) e->value[i] = value[i];
|
||||
e->value[i] = (char)0;
|
||||
} else {
|
||||
if ((e->value)&&(e->value != EMPTY_STR)) free((void *)e->value);
|
||||
e->value = (char *)EMPTY_STR;
|
||||
}
|
||||
return;
|
||||
}
|
||||
e = e->next;
|
||||
}
|
||||
|
||||
e = (struct AnodeDictionaryEntry *)malloc(sizeof(struct AnodeDictionaryEntry));
|
||||
|
||||
len = 0;
|
||||
while (key[len]) ++len;
|
||||
if (len) {
|
||||
e->key = (char *)malloc(len + 1);
|
||||
for(i=0;i<len;++i) e->key[i] = key[i];
|
||||
e->key[i] = (char)0;
|
||||
} else e->key = (char *)EMPTY_STR;
|
||||
|
||||
len = 0;
|
||||
while (value[len]) ++len;
|
||||
if (len) {
|
||||
e->value = (char *)malloc(len + 1);
|
||||
for(i=0;i<len;++i) e->value[i] = value[i];
|
||||
e->value[i] = (char)0;
|
||||
} else e->value = (char *)EMPTY_STR;
|
||||
|
||||
e->next = d->ht[bucket];
|
||||
d->ht[bucket] = e;
|
||||
|
||||
++d->size;
|
||||
}
|
||||
|
||||
void AnodeDictionary_read(
|
||||
struct AnodeDictionary *d,
|
||||
char *in,
|
||||
const char *line_breaks,
|
||||
const char *kv_breaks,
|
||||
const char *comment_chars,
|
||||
char escape_char,
|
||||
int trim_whitespace_from_keys,
|
||||
int trim_whitespace_from_values)
|
||||
{
|
||||
char *line = in;
|
||||
char *key;
|
||||
char *value;
|
||||
char *p1,*p2,*p3;
|
||||
char last = ~escape_char;
|
||||
int eof_state = 0;
|
||||
|
||||
for(;;) {
|
||||
if ((!*in)||((Anode_strchr(line_breaks,*in))&&((last != escape_char)||(!escape_char)))) {
|
||||
if (!*in)
|
||||
eof_state = 1;
|
||||
else *in = (char)0;
|
||||
|
||||
if ((*line)&&((comment_chars)&&(!Anode_strchr(comment_chars,*line)))) {
|
||||
key = line;
|
||||
|
||||
while (*line) {
|
||||
if ((Anode_strchr(kv_breaks,*line))&&((last != escape_char)||(!escape_char))) {
|
||||
*(line++) = (char)0;
|
||||
break;
|
||||
} else last = *(line++);
|
||||
}
|
||||
while ((*line)&&(Anode_strchr(kv_breaks,*line))&&((last != escape_char)||(!escape_char)))
|
||||
last = *(line++);
|
||||
value = line;
|
||||
|
||||
if (escape_char) {
|
||||
p1 = key;
|
||||
while (*p1) {
|
||||
if (*p1 == escape_char) {
|
||||
p2 = p1;
|
||||
p3 = p1 + 1;
|
||||
while (*p3)
|
||||
*(p2++) = *(p3++);
|
||||
*p2 = (char)0;
|
||||
}
|
||||
++p1;
|
||||
}
|
||||
p1 = value;
|
||||
while (*p1) {
|
||||
if (*p1 == escape_char) {
|
||||
p2 = p1;
|
||||
p3 = p1 + 1;
|
||||
while (*p3)
|
||||
*(p2++) = *(p3++);
|
||||
*p2 = (char)0;
|
||||
}
|
||||
++p1;
|
||||
}
|
||||
}
|
||||
|
||||
if (trim_whitespace_from_keys)
|
||||
Anode_trim(key);
|
||||
if (trim_whitespace_from_values)
|
||||
Anode_trim(value);
|
||||
|
||||
AnodeDictionary_put(d,key,value);
|
||||
}
|
||||
|
||||
if (eof_state)
|
||||
break;
|
||||
else line = in + 1;
|
||||
}
|
||||
last = *(in++);
|
||||
}
|
||||
}
|
||||
|
||||
long AnodeDictionary_write(
|
||||
struct AnodeDictionary *d,
|
||||
char *out,
|
||||
long out_size,
|
||||
const char *line_break,
|
||||
const char *kv_break)
|
||||
{
|
||||
struct AnodeDictionaryEntry *e;
|
||||
const char *tmp;
|
||||
long ptr = 0;
|
||||
unsigned int bucket;
|
||||
|
||||
if (out_size <= 0)
|
||||
return -1;
|
||||
|
||||
for(bucket=0;bucket<ANODE_DICTIONARY_FIXED_HASH_TABLE_SIZE;++bucket) {
|
||||
e = d->ht[bucket];
|
||||
while (e) {
|
||||
tmp = e->key;
|
||||
if (tmp) {
|
||||
while (*tmp) {
|
||||
out[ptr++] = *tmp++;
|
||||
if (ptr >= (out_size - 1)) return -1;
|
||||
}
|
||||
}
|
||||
|
||||
tmp = kv_break;
|
||||
if (tmp) {
|
||||
while (*tmp) {
|
||||
out[ptr++] = *tmp++;
|
||||
if (ptr >= (out_size - 1)) return -1;
|
||||
}
|
||||
}
|
||||
|
||||
tmp = e->value;
|
||||
if (tmp) {
|
||||
while (*tmp) {
|
||||
out[ptr++] = *tmp++;
|
||||
if (ptr >= (out_size - 1)) return -1;
|
||||
}
|
||||
}
|
||||
|
||||
tmp = line_break;
|
||||
if (tmp) {
|
||||
while (*tmp) {
|
||||
out[ptr++] = *tmp++;
|
||||
if (ptr >= (out_size - 1)) return -1;
|
||||
}
|
||||
}
|
||||
|
||||
e = e->next;
|
||||
}
|
||||
}
|
||||
|
||||
out[ptr] = (char)0;
|
||||
|
||||
return ptr;
|
||||
}
|
126
attic/historic/anode/libanode/impl/dictionary.h
Normal file
126
attic/historic/anode/libanode/impl/dictionary.h
Normal file
@ -0,0 +1,126 @@
|
||||
/* libanode: the Anode C reference implementation
|
||||
* Copyright (C) 2009-2010 Adam Ierymenko <adam.ierymenko@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
/* This is a simple string hash table suitable for small tables such as zone
|
||||
* files or HTTP header lists. */
|
||||
|
||||
#ifndef _ANODE_DICTIONARY_H
|
||||
#define _ANODE_DICTIONARY_H
|
||||
|
||||
#include "misc.h"
|
||||
|
||||
/* This is a fixed hash table and is designed for relatively small numbers
|
||||
* of keys for things like zone files. */
|
||||
#define ANODE_DICTIONARY_FIXED_HASH_TABLE_SIZE 16
|
||||
#define ANODE_DICTIONARY_FIXED_HASH_TABLE_MASK 15
|
||||
|
||||
/* Computes a hash code for a string and returns the hash bucket */
|
||||
static inline unsigned int AnodeDictionary__get_bucket(const char *s)
|
||||
{
|
||||
unsigned int hc = 3;
|
||||
while (*s)
|
||||
hc = ((hc << 4) + hc) + (unsigned int)*(s++);
|
||||
return ((hc ^ (hc >> 4)) & ANODE_DICTIONARY_FIXED_HASH_TABLE_MASK);
|
||||
}
|
||||
/* Case insensitive version of get_bucket */
|
||||
static inline unsigned int AnodeDictionary__get_bucket_ci(const char *s)
|
||||
{
|
||||
unsigned int hc = 3;
|
||||
while (*s)
|
||||
hc = ((hc << 4) + hc) + (unsigned int)Anode_tolower(*(s++));
|
||||
return ((hc ^ (hc >> 4)) & ANODE_DICTIONARY_FIXED_HASH_TABLE_MASK);
|
||||
}
|
||||
|
||||
struct AnodeDictionaryEntry
|
||||
{
|
||||
char *key;
|
||||
char *value;
|
||||
struct AnodeDictionaryEntry *next;
|
||||
};
|
||||
|
||||
struct AnodeDictionary
|
||||
{
|
||||
struct AnodeDictionaryEntry *ht[ANODE_DICTIONARY_FIXED_HASH_TABLE_SIZE];
|
||||
unsigned int size;
|
||||
int case_sensitive;
|
||||
};
|
||||
|
||||
static inline void AnodeDictionary_init(struct AnodeDictionary *d,int case_sensitive)
|
||||
{
|
||||
Anode_zero((void *)d,sizeof(struct AnodeDictionary));
|
||||
d->case_sensitive = case_sensitive;
|
||||
}
|
||||
|
||||
void AnodeDictionary_clear(struct AnodeDictionary *d);
|
||||
|
||||
static inline void AnodeDictionary_destroy(struct AnodeDictionary *d)
|
||||
{
|
||||
AnodeDictionary_clear(d);
|
||||
}
|
||||
|
||||
void AnodeDictionary_put(struct AnodeDictionary *d,const char *key,const char *value);
|
||||
|
||||
static inline const char *AnodeDictionary_get(struct AnodeDictionary *d,const char *key)
|
||||
{
|
||||
struct AnodeDictionaryEntry *e;
|
||||
unsigned int bucket = (d->case_sensitive) ? AnodeDictionary__get_bucket(key) : AnodeDictionary__get_bucket_ci(key);
|
||||
|
||||
e = d->ht[bucket];
|
||||
while (e) {
|
||||
if ((d->case_sensitive ? Anode_streq(key,e->key) : Anode_strcaseeq(key,e->key)))
|
||||
return e->value;
|
||||
e = e->next;
|
||||
}
|
||||
|
||||
return (const char *)0;
|
||||
}
|
||||
|
||||
static inline void AnodeDictionary_iterate(
|
||||
struct AnodeDictionary *d,
|
||||
void *arg,
|
||||
int (*func)(void *,const char *,const char *))
|
||||
{
|
||||
struct AnodeDictionaryEntry *e;
|
||||
unsigned int bucket;
|
||||
|
||||
for(bucket=0;bucket<ANODE_DICTIONARY_FIXED_HASH_TABLE_SIZE;++bucket) {
|
||||
e = d->ht[bucket];
|
||||
while (e) {
|
||||
if (!func(arg,e->key,e->value))
|
||||
return;
|
||||
e = e->next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void AnodeDictionary_read(
|
||||
struct AnodeDictionary *d,
|
||||
char *in,
|
||||
const char *line_breaks,
|
||||
const char *kv_breaks,
|
||||
const char *comment_chars,
|
||||
char escape_char,
|
||||
int trim_whitespace_from_keys,
|
||||
int trim_whitespace_from_values);
|
||||
|
||||
long AnodeDictionary_write(
|
||||
struct AnodeDictionary *d,
|
||||
char *out,
|
||||
long out_size,
|
||||
const char *line_break,
|
||||
const char *kv_break);
|
||||
|
||||
#endif
|
93
attic/historic/anode/libanode/impl/dns_txt.c
Normal file
93
attic/historic/anode/libanode/impl/dns_txt.c
Normal file
@ -0,0 +1,93 @@
|
||||
/* libanode: the Anode C reference implementation
|
||||
* Copyright (C) 2009-2010 Adam Ierymenko <adam.ierymenko@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/nameser.h>
|
||||
#include <resolv.h>
|
||||
#include <netdb.h>
|
||||
#include "dns_txt.h"
|
||||
|
||||
#ifndef C_IN
|
||||
#define C_IN ns_c_in
|
||||
#endif
|
||||
#ifndef T_TXT
|
||||
#define T_TXT ns_t_txt
|
||||
#endif
|
||||
|
||||
static volatile int Anode_resolver_initialized = 0;
|
||||
|
||||
int Anode_sync_resolve_txt(const char *host,char *txt,unsigned int txt_len)
|
||||
{
|
||||
unsigned char answer[16384],*pptr,*end;
|
||||
char name[16384];
|
||||
int len,explen,i;
|
||||
|
||||
if (!Anode_resolver_initialized) {
|
||||
Anode_resolver_initialized = 1;
|
||||
res_init();
|
||||
}
|
||||
|
||||
/* Do not taunt happy fun ball. */
|
||||
|
||||
len = res_search(host,C_IN,T_TXT,answer,sizeof(answer));
|
||||
if (len > 12) {
|
||||
pptr = answer + 12;
|
||||
end = answer + len;
|
||||
|
||||
explen = dn_expand(answer,end,pptr,name,sizeof(name));
|
||||
if (explen > 0) {
|
||||
pptr += explen;
|
||||
|
||||
if ((pptr + 2) >= end) return 2;
|
||||
if (ntohs(*((uint16_t *)pptr)) == T_TXT) {
|
||||
pptr += 4;
|
||||
if (pptr >= end) return 2;
|
||||
|
||||
explen = dn_expand(answer,end,pptr,name,sizeof(name));
|
||||
if (explen > 0) {
|
||||
pptr += explen;
|
||||
|
||||
if ((pptr + 2) >= end) return 2;
|
||||
if (ntohs(*((uint16_t *)pptr)) == T_TXT) {
|
||||
pptr += 10;
|
||||
if (pptr >= end) return 2;
|
||||
|
||||
len = *(pptr++);
|
||||
if (len <= 0) return 2;
|
||||
if ((pptr + len) > end) return 2;
|
||||
|
||||
if (txt_len < (len + 1))
|
||||
return 4;
|
||||
else {
|
||||
for(i=0;i<len;++i)
|
||||
txt[i] = pptr[i];
|
||||
txt[len] = (char)0;
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
/*
|
||||
* ZeroTier One - Network Virtualization Everywhere
|
||||
* Copyright (C) 2011-2015 ZeroTier, Inc.
|
||||
/* libanode: the Anode C reference implementation
|
||||
* Copyright (C) 2009-2010 Adam Ierymenko <adam.ierymenko@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -13,24 +12,26 @@
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _ANODE_DNS_TXT_H
|
||||
#define _ANODE_DNS_TXT_H
|
||||
|
||||
/**
|
||||
* Synchronous TXT resolver routine
|
||||
*
|
||||
* --
|
||||
* Error codes:
|
||||
* 1 - I/O error
|
||||
* 2 - Invalid response
|
||||
* 3 - TXT record not found
|
||||
* 4 - Destination buffer too small for result
|
||||
*
|
||||
* ZeroTier may be used and distributed under the terms of the GPLv3, which
|
||||
* are available at: http://www.gnu.org/licenses/gpl-3.0.html
|
||||
*
|
||||
* If you would like to embed ZeroTier into a commercial application or
|
||||
* redistribute it in a modified binary form, please contact ZeroTier Networks
|
||||
* LLC. Start here: http://www.zerotier.com/
|
||||
* @param host Host name
|
||||
* @param txt Buffer to store TXT result
|
||||
* @param txt_len Size of buffer
|
||||
* @return Zero on success, special error code on failure
|
||||
*/
|
||||
int Anode_sync_resolve_txt(const char *host,char *txt,unsigned int txt_len);
|
||||
|
||||
package com.zerotier.sdk;
|
||||
#endif
|
||||
|
||||
import java.lang.RuntimeException;
|
||||
|
||||
public class NodeException extends RuntimeException {
|
||||
public NodeException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
219
attic/historic/anode/libanode/impl/ec.c
Normal file
219
attic/historic/anode/libanode/impl/ec.c
Normal file
@ -0,0 +1,219 @@
|
||||
/* libanode: the Anode C reference implementation
|
||||
* Copyright (C) 2009-2010 Adam Ierymenko <adam.ierymenko@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/obj_mac.h>
|
||||
#include <openssl/rand.h>
|
||||
#include <openssl/ec.h>
|
||||
#include <openssl/ecdh.h>
|
||||
#include <openssl/ecdsa.h>
|
||||
#include "types.h"
|
||||
#include "misc.h"
|
||||
#include "ec.h"
|
||||
|
||||
static EC_GROUP *AnodeEC_group = (EC_GROUP *)0;
|
||||
|
||||
static void *AnodeEC_KDF(const void *in,size_t inlen,void *out,size_t *outlen)
|
||||
{
|
||||
unsigned long i,longest_length;
|
||||
|
||||
if (!*outlen)
|
||||
return out;
|
||||
|
||||
for(i=0;i<(unsigned long)*outlen;++i)
|
||||
((unsigned char *)out)[i] = (unsigned char)0;
|
||||
|
||||
longest_length = inlen;
|
||||
if (longest_length < *outlen)
|
||||
longest_length = *outlen;
|
||||
for(i=0;i<longest_length;++i)
|
||||
((unsigned char *)out)[i % (unsigned long)*outlen] ^= ((const unsigned char *)in)[i % (unsigned long)inlen];
|
||||
|
||||
return out;
|
||||
}
|
||||
|
||||
int AnodeECKeyPair_generate(struct AnodeECKeyPair *pair)
|
||||
{
|
||||
EC_KEY *key;
|
||||
int len;
|
||||
|
||||
#ifdef HAS_DEV_URANDOM
|
||||
char buf[128];
|
||||
FILE *f = fopen("/dev/urandom","r");
|
||||
if (f) {
|
||||
if (fread(buf,1,sizeof(buf),f) == sizeof(buf))
|
||||
RAND_add(buf,sizeof(buf),sizeof(buf)/2);
|
||||
fclose(f);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!AnodeEC_group) {
|
||||
AnodeEC_group = EC_GROUP_new_by_curve_name(ANODE_EC_GROUP);
|
||||
if (!AnodeEC_group) return 0;
|
||||
}
|
||||
|
||||
key = EC_KEY_new();
|
||||
if (!key) return 0;
|
||||
|
||||
if (!EC_KEY_set_group(key,AnodeEC_group)) {
|
||||
EC_KEY_free(key);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!EC_KEY_generate_key(key)) {
|
||||
EC_KEY_free(key);
|
||||
return 0;
|
||||
}
|
||||
|
||||
Anode_zero(pair,sizeof(struct AnodeECKeyPair));
|
||||
|
||||
/* Stuff the private key into priv.key */
|
||||
len = BN_num_bytes(EC_KEY_get0_private_key(key));
|
||||
if ((len > ANODE_EC_PRIME_BYTES)||(len < 0)) {
|
||||
EC_KEY_free(key);
|
||||
return 0;
|
||||
}
|
||||
BN_bn2bin(EC_KEY_get0_private_key(key),&(pair->priv.key[ANODE_EC_PRIME_BYTES - len]));
|
||||
pair->priv.bytes = ANODE_EC_PRIME_BYTES;
|
||||
|
||||
len = EC_POINT_point2oct(AnodeEC_group,EC_KEY_get0_public_key(key),POINT_CONVERSION_COMPRESSED,pair->pub.key,sizeof(pair->pub.key),0);
|
||||
if (len != ANODE_EC_PUBLIC_KEY_BYTES) {
|
||||
EC_KEY_free(key);
|
||||
return 0;
|
||||
}
|
||||
pair->pub.bytes = ANODE_EC_PUBLIC_KEY_BYTES;
|
||||
|
||||
/* Keep a copy of OpenSSL's structure around so we don't have to re-init
|
||||
* it every time we use our key pair structure. */
|
||||
pair->internal_key = key;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int AnodeECKeyPair_init(struct AnodeECKeyPair *pair,const struct AnodeECKey *pub,const struct AnodeECKey *priv)
|
||||
{
|
||||
EC_KEY *key;
|
||||
EC_POINT *kxy;
|
||||
BIGNUM *pn;
|
||||
|
||||
if (!AnodeEC_group) {
|
||||
AnodeEC_group = EC_GROUP_new_by_curve_name(ANODE_EC_GROUP);
|
||||
if (!AnodeEC_group) return 0;
|
||||
}
|
||||
|
||||
key = EC_KEY_new();
|
||||
if (!key)
|
||||
return 0;
|
||||
|
||||
if (!EC_KEY_set_group(key,AnodeEC_group)) {
|
||||
EC_KEY_free(key);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Grab the private key */
|
||||
if (priv->bytes != ANODE_EC_PRIME_BYTES) {
|
||||
EC_KEY_free(key);
|
||||
return 0;
|
||||
}
|
||||
pn = BN_new();
|
||||
if (!pn) {
|
||||
EC_KEY_free(key);
|
||||
return 0;
|
||||
}
|
||||
if (!BN_bin2bn(priv->key,ANODE_EC_PRIME_BYTES,pn)) {
|
||||
BN_free(pn);
|
||||
EC_KEY_free(key);
|
||||
return 0;
|
||||
}
|
||||
if (!EC_KEY_set_private_key(key,pn)) {
|
||||
BN_free(pn);
|
||||
EC_KEY_free(key);
|
||||
return 0;
|
||||
}
|
||||
BN_free(pn);
|
||||
|
||||
/* Set the public key */
|
||||
if (pub->bytes != ANODE_EC_PUBLIC_KEY_BYTES) {
|
||||
EC_KEY_free(key);
|
||||
return 0;
|
||||
}
|
||||
kxy = EC_POINT_new(AnodeEC_group);
|
||||
if (!kxy) {
|
||||
EC_KEY_free(key);
|
||||
return 0;
|
||||
}
|
||||
EC_POINT_oct2point(AnodeEC_group,kxy,pub->key,ANODE_EC_PUBLIC_KEY_BYTES,0);
|
||||
if (!EC_KEY_set_public_key(key,kxy)) {
|
||||
EC_POINT_free(kxy);
|
||||
EC_KEY_free(key);
|
||||
return 0;
|
||||
}
|
||||
EC_POINT_free(kxy);
|
||||
|
||||
Anode_zero(pair,sizeof(struct AnodeECKeyPair));
|
||||
Anode_memcpy((void *)&(pair->pub),(const void *)pub,sizeof(struct AnodeECKey));
|
||||
Anode_memcpy((void *)&(pair->priv),(const void *)priv,sizeof(struct AnodeECKey));
|
||||
pair->internal_key = key;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void AnodeECKeyPair_destroy(struct AnodeECKeyPair *pair)
|
||||
{
|
||||
if (pair) {
|
||||
if (pair->internal_key)
|
||||
EC_KEY_free((EC_KEY *)pair->internal_key);
|
||||
}
|
||||
}
|
||||
|
||||
int AnodeECKeyPair_agree(const struct AnodeECKeyPair *my_key_pair,const struct AnodeECKey *their_pub_key,unsigned char *key_buf,unsigned int key_len)
|
||||
{
|
||||
EC_POINT *pub;
|
||||
int i;
|
||||
|
||||
if (!AnodeEC_group) {
|
||||
AnodeEC_group = EC_GROUP_new_by_curve_name(ANODE_EC_GROUP);
|
||||
if (!AnodeEC_group) return 0;
|
||||
}
|
||||
|
||||
if (!my_key_pair->internal_key)
|
||||
return 0;
|
||||
|
||||
if (their_pub_key->bytes != ANODE_EC_PUBLIC_KEY_BYTES)
|
||||
return 0;
|
||||
pub = EC_POINT_new(AnodeEC_group);
|
||||
if (!pub)
|
||||
return 0;
|
||||
EC_POINT_oct2point(AnodeEC_group,pub,their_pub_key->key,ANODE_EC_PUBLIC_KEY_BYTES,0);
|
||||
|
||||
i = ECDH_compute_key(key_buf,key_len,pub,(EC_KEY *)my_key_pair->internal_key,&AnodeEC_KDF);
|
||||
if (i != (int)key_len) {
|
||||
EC_POINT_free(pub);
|
||||
return 0;
|
||||
}
|
||||
|
||||
EC_POINT_free(pub);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void AnodeEC_random(unsigned char *buf,unsigned int len)
|
||||
{
|
||||
RAND_pseudo_bytes(buf,len);
|
||||
}
|
61
attic/historic/anode/libanode/impl/ec.h
Normal file
61
attic/historic/anode/libanode/impl/ec.h
Normal file
@ -0,0 +1,61 @@
|
||||
/* libanode: the Anode C reference implementation
|
||||
* Copyright (C) 2009-2010 Adam Ierymenko <adam.ierymenko@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
/* Elliptic curve glue -- hides OpenSSL code behind this source module */
|
||||
|
||||
#ifndef _ANODE_EC_H
|
||||
#define _ANODE_EC_H
|
||||
|
||||
#include "misc.h"
|
||||
|
||||
/* Right now, only one mode is supported: NIST-P-256. This is the only mode
|
||||
* supported in the spec as well, and should be good for quite some time.
|
||||
* If other modes are needed this code will need to be refactored. */
|
||||
|
||||
/* NIST-P-256 prime size in bytes */
|
||||
#define ANODE_EC_PRIME_BYTES 32
|
||||
|
||||
/* Sizes of key fields */
|
||||
#define ANODE_EC_GROUP NID_X9_62_prime256v1
|
||||
#define ANODE_EC_PUBLIC_KEY_BYTES (ANODE_EC_PRIME_BYTES + 1)
|
||||
#define ANODE_EC_PRIVATE_KEY_BYTES ANODE_EC_PRIME_BYTES
|
||||
|
||||
/* Larger of public or private key bytes, used for buffers */
|
||||
#define ANODE_EC_MAX_BYTES ANODE_EC_PUBLIC_KEY_BYTES
|
||||
|
||||
struct AnodeECKey
|
||||
{
|
||||
unsigned char key[ANODE_EC_MAX_BYTES];
|
||||
unsigned int bytes;
|
||||
};
|
||||
|
||||
struct AnodeECKeyPair
|
||||
{
|
||||
struct AnodeECKey pub;
|
||||
struct AnodeECKey priv;
|
||||
void *internal_key;
|
||||
};
|
||||
|
||||
/* Key management functions */
|
||||
int AnodeECKeyPair_generate(struct AnodeECKeyPair *pair);
|
||||
int AnodeECKeyPair_init(struct AnodeECKeyPair *pair,const struct AnodeECKey *pub,const struct AnodeECKey *priv);
|
||||
void AnodeECKeyPair_destroy(struct AnodeECKeyPair *pair);
|
||||
int AnodeECKeyPair_agree(const struct AnodeECKeyPair *my_key_pair,const struct AnodeECKey *their_pub_key,unsigned char *key_buf,unsigned int key_len);
|
||||
|
||||
/* Provides access to the secure PRNG used to generate keys */
|
||||
void AnodeEC_random(unsigned char *buf,unsigned int len);
|
||||
|
||||
#endif
|
118
attic/historic/anode/libanode/impl/environment.c
Normal file
118
attic/historic/anode/libanode/impl/environment.c
Normal file
@ -0,0 +1,118 @@
|
||||
/* libanode: the Anode C reference implementation
|
||||
* Copyright (C) 2009-2010 Adam Ierymenko <adam.ierymenko@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "environment.h"
|
||||
|
||||
#ifdef WINDOWS
|
||||
#include <windows.h>
|
||||
#else
|
||||
#include <sys/stat.h>
|
||||
#include <string.h>
|
||||
#endif
|
||||
|
||||
static char Anode_cache_base[1024] = { 0 };
|
||||
|
||||
const char *Anode_get_cache()
|
||||
{
|
||||
if (Anode_cache_base[0])
|
||||
return Anode_cache_base;
|
||||
|
||||
#ifdef WINDOWS
|
||||
#else
|
||||
char tmp[1024];
|
||||
char home[1024];
|
||||
unsigned int i;
|
||||
struct stat st;
|
||||
const char *_home = getenv("HOME");
|
||||
|
||||
if (!_home)
|
||||
return (const char *)0;
|
||||
for(i=0;i<sizeof(home);++i) {
|
||||
home[i] = _home[i];
|
||||
if (!home[i]) {
|
||||
if (i == 0)
|
||||
return (const char *)0;
|
||||
else if (home[i-1] == ANODE_PATH_SEPARATOR)
|
||||
home[i-1] = (char)0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == sizeof(home))
|
||||
return (const char *)0;
|
||||
|
||||
#ifdef __APPLE__
|
||||
snprintf(tmp,sizeof(tmp),"%s%cLibrary",home,ANODE_PATH_SEPARATOR);
|
||||
tmp[sizeof(tmp)-1] = (char)0;
|
||||
if (!stat(tmp,&st)) {
|
||||
sprintf(tmp,"%s%cLibrary%cCaches",home,ANODE_PATH_SEPARATOR,ANODE_PATH_SEPARATOR);
|
||||
if (stat(tmp,&st)) {
|
||||
if (mkdir(tmp,0700))
|
||||
return (const char *)0;
|
||||
}
|
||||
snprintf(Anode_cache_base,sizeof(Anode_cache_base),"%s%ccom.zerotier.anode",tmp,ANODE_PATH_SEPARATOR);
|
||||
Anode_cache_base[sizeof(Anode_cache_base)-1] = (char)0;
|
||||
if (stat(Anode_cache_base,&st)) {
|
||||
if (mkdir(Anode_cache_base,0700)) {
|
||||
Anode_cache_base[0] = (char)0;
|
||||
return (const char *)0;
|
||||
}
|
||||
}
|
||||
return Anode_cache_base;
|
||||
}
|
||||
#endif
|
||||
|
||||
snprintf(tmp,sizeof(tmp),"%s%c.anode",home,ANODE_PATH_SEPARATOR);
|
||||
tmp[sizeof(tmp)-1] = (char)0;
|
||||
if (stat(tmp,&st)) {
|
||||
if (mkdir(tmp,0700)) {
|
||||
Anode_cache_base[0] = (char)0;
|
||||
return (const char *)0;
|
||||
}
|
||||
}
|
||||
snprintf(Anode_cache_base,sizeof(Anode_cache_base),"%s%ccaches",tmp,ANODE_PATH_SEPARATOR);
|
||||
Anode_cache_base[sizeof(Anode_cache_base)-1] = (char)0;
|
||||
if (stat(Anode_cache_base,&st)) {
|
||||
if (mkdir(Anode_cache_base,0700)) {
|
||||
Anode_cache_base[0] = (char)0;
|
||||
return (const char *)0;
|
||||
}
|
||||
}
|
||||
|
||||
return Anode_cache_base;
|
||||
#endif
|
||||
}
|
||||
|
||||
char *Anode_get_cache_sub(const char *cache_subdir,char *buf,unsigned int len)
|
||||
{
|
||||
struct stat st;
|
||||
const char *cache_base = Anode_get_cache();
|
||||
|
||||
if (!len)
|
||||
return (char *)0;
|
||||
if (!cache_base)
|
||||
return (char *)0;
|
||||
|
||||
snprintf(buf,len,"%s%c%s",cache_base,ANODE_PATH_SEPARATOR,cache_subdir);
|
||||
buf[len-1] = (char)0;
|
||||
if (stat(buf,&st)) {
|
||||
if (mkdir(buf,0700))
|
||||
return (char *)0;
|
||||
}
|
||||
|
||||
return buf;
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
/*
|
||||
* ZeroTier One - Network Virtualization Everywhere
|
||||
* Copyright (C) 2011-2016 ZeroTier, Inc. https://www.zerotier.com/
|
||||
/* libanode: the Anode C reference implementation
|
||||
* Copyright (C) 2009-2010 Adam Ierymenko <adam.ierymenko@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
@ -13,26 +12,19 @@
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef ZT_NONCOPYABLE_HPP__
|
||||
#define ZT_NONCOPYABLE_HPP__
|
||||
#ifndef _ANODE_ENVIRONMENT_H
|
||||
#define _ANODE_ENVIRONMENT_H
|
||||
|
||||
namespace ZeroTier {
|
||||
#ifdef WINDOWS
|
||||
#define ANODE_PATH_SEPARATOR '\\'
|
||||
#else
|
||||
#define ANODE_PATH_SEPARATOR '/'
|
||||
#endif
|
||||
|
||||
/**
|
||||
* A simple concept that belongs in the C++ language spec
|
||||
*/
|
||||
class NonCopyable
|
||||
{
|
||||
protected:
|
||||
NonCopyable() throw() {}
|
||||
private:
|
||||
NonCopyable(const NonCopyable&);
|
||||
const NonCopyable& operator=(const NonCopyable&);
|
||||
};
|
||||
|
||||
} // namespace ZeroTier
|
||||
const char *Anode_get_cache();
|
||||
char *Anode_get_cache_sub(const char *cache_subdir,char *buf,unsigned int len);
|
||||
|
||||
#endif
|
||||
|
558
attic/historic/anode/libanode/impl/http_client.c
Normal file
558
attic/historic/anode/libanode/impl/http_client.c
Normal file
@ -0,0 +1,558 @@
|
||||
/* libanode: the Anode C reference implementation
|
||||
* Copyright (C) 2009-2010 Adam Ierymenko <adam.ierymenko@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <netinet/in.h>
|
||||
#include <sys/socket.h>
|
||||
#include "http_client.h"
|
||||
#include "misc.h"
|
||||
#include "types.h"
|
||||
|
||||
/* How much to increment read buffer at each capacity top? */
|
||||
#define ANODE_HTTP_CAPACITY_INCREMENT 4096
|
||||
|
||||
static void AnodeHttpClient_close_and_fail(struct AnodeHttpClient *client)
|
||||
{
|
||||
if (client->impl.tcp_connection) {
|
||||
client->impl.transport_engine->tcp_close(client->impl.transport_engine,client->impl.tcp_connection);
|
||||
client->impl.tcp_connection = (AnodeTransportTcpConnection *)0;
|
||||
}
|
||||
|
||||
client->response.data_length = 0;
|
||||
client->impl.phase = ANODE_HTTP_REQUEST_PHASE_CLOSED;
|
||||
|
||||
if (client->handler)
|
||||
client->handler(client);
|
||||
}
|
||||
|
||||
static void AnodeHttpClient_do_initiate_client(struct AnodeHttpClient *client)
|
||||
{
|
||||
const char *method = "";
|
||||
long l,i;
|
||||
|
||||
switch(client->method) {
|
||||
case ANODE_HTTP_GET: method = "GET"; break;
|
||||
case ANODE_HTTP_HEAD: method = "HEAD"; break;
|
||||
case ANODE_HTTP_POST: method = "POST"; break;
|
||||
}
|
||||
client->impl.outbuf_len = snprintf((char *)client->impl.outbuf,sizeof(client->impl.outbuf),
|
||||
"%s %s%s%s HTTP/1.1\r\nHost: %s:%d\r\n%s",
|
||||
method,
|
||||
client->uri.path,
|
||||
((client->uri.query[0]) ? "?" : ""),
|
||||
client->uri.query,
|
||||
client->uri.host,
|
||||
((client->uri.port > 0) ? client->uri.port : 80),
|
||||
((client->keepalive) ? "" : "Connection: close\r\n")
|
||||
);
|
||||
if (client->impl.outbuf_len >= (sizeof(client->impl.outbuf) - 2)) {
|
||||
client->response.code = ANODE_HTTP_SPECIAL_RESPONSE_HEADERS_TOO_LARGE;
|
||||
AnodeHttpClient_close_and_fail(client);
|
||||
return;
|
||||
}
|
||||
|
||||
if (client->method == ANODE_HTTP_POST) {
|
||||
if ((client->data)&&(client->data_length)) {
|
||||
client->impl.outbuf_len += snprintf((char *)client->impl.outbuf + client->impl.outbuf_len,sizeof(client->impl.outbuf) - client->impl.outbuf_len,
|
||||
"Content-Type: %s\r\n",
|
||||
(client->data_content_type ? client->data_content_type : "application/x-www-form-urlencoded")
|
||||
);
|
||||
if (client->impl.outbuf_len >= (sizeof(client->impl.outbuf) - 2)) {
|
||||
client->response.code = ANODE_HTTP_SPECIAL_RESPONSE_HEADERS_TOO_LARGE;
|
||||
AnodeHttpClient_close_and_fail(client);
|
||||
return;
|
||||
}
|
||||
client->impl.outbuf_len += snprintf((char *)client->impl.outbuf + client->impl.outbuf_len,sizeof(client->impl.outbuf) - client->impl.outbuf_len,
|
||||
"Content-Length: %u\r\n",
|
||||
client->data_length
|
||||
);
|
||||
if (client->impl.outbuf_len >= (sizeof(client->impl.outbuf) - 2)) {
|
||||
client->response.code = ANODE_HTTP_SPECIAL_RESPONSE_HEADERS_TOO_LARGE;
|
||||
AnodeHttpClient_close_and_fail(client);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
client->impl.outbuf_len += snprintf((char *)client->impl.outbuf + client->impl.outbuf_len,sizeof(client->impl.outbuf) - client->impl.outbuf_len,
|
||||
"Content-Length: 0\r\n"
|
||||
);
|
||||
if (client->impl.outbuf_len >= (sizeof(client->impl.outbuf) - 2)) {
|
||||
client->response.code = ANODE_HTTP_SPECIAL_RESPONSE_HEADERS_TOO_LARGE;
|
||||
AnodeHttpClient_close_and_fail(client);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
l = AnodeDictionary_write(&(client->headers),(char *)client->impl.outbuf + client->impl.outbuf_len,(long)(sizeof(client->impl.outbuf) - client->impl.outbuf_len - 2),"\r\n",": ");
|
||||
if (l < 0) {
|
||||
client->response.code = ANODE_HTTP_SPECIAL_RESPONSE_HEADERS_TOO_LARGE;
|
||||
AnodeHttpClient_close_and_fail(client);
|
||||
return;
|
||||
}
|
||||
|
||||
client->impl.outbuf_len += (unsigned int)l;
|
||||
if (client->impl.outbuf_len >= (sizeof(client->impl.outbuf) - 2)) { /* sanity check */
|
||||
client->response.code = ANODE_HTTP_SPECIAL_RESPONSE_HEADERS_TOO_LARGE;
|
||||
AnodeHttpClient_close_and_fail(client);
|
||||
return;
|
||||
}
|
||||
|
||||
client->impl.outbuf[client->impl.outbuf_len++] = '\r';
|
||||
client->impl.outbuf[client->impl.outbuf_len++] = '\n';
|
||||
|
||||
if ((client->method == ANODE_HTTP_POST)&&(client->data)&&(client->data_length)) {
|
||||
i = sizeof(client->impl.outbuf) - client->impl.outbuf_len;
|
||||
if (i > client->data_length)
|
||||
i = client->data_length;
|
||||
Anode_memcpy((client->impl.outbuf + client->impl.outbuf_len),client->data,i);
|
||||
client->impl.request_data_ptr += i;
|
||||
client->impl.outbuf_len += i;
|
||||
}
|
||||
|
||||
client->impl.phase = ANODE_HTTP_REQUEST_PHASE_SEND;
|
||||
client->impl.transport_engine->tcp_start_writing(client->impl.transport_engine,client->impl.tcp_connection);
|
||||
}
|
||||
|
||||
static void AnodeHttpClient_tcp_outgoing_connect_handler(
|
||||
AnodeTransportEngine *transport,
|
||||
AnodeTransportTcpConnection *connection,
|
||||
int error_code)
|
||||
{
|
||||
struct AnodeHttpClient *client;
|
||||
|
||||
if (!(client = (struct AnodeHttpClient *)(connection->ptr)))
|
||||
return;
|
||||
|
||||
if ((client->impl.phase == ANODE_HTTP_REQUEST_PHASE_CONNECT)&&(!client->impl.freed)) {
|
||||
if (error_code) {
|
||||
client->response.code = ANODE_HTTP_SPECIAL_RESPONSE_CONNECT_FAILED;
|
||||
AnodeHttpClient_close_and_fail(client);
|
||||
} else {
|
||||
client->impl.tcp_connection = connection;
|
||||
AnodeHttpClient_do_initiate_client(client);
|
||||
}
|
||||
} else transport->tcp_close(transport,connection);
|
||||
}
|
||||
|
||||
static void AnodeHttpClient_tcp_connection_terminated_handler(
|
||||
AnodeTransportEngine *transport,
|
||||
AnodeTransportTcpConnection *connection,
|
||||
int error_code)
|
||||
{
|
||||
struct AnodeHttpClient *client;
|
||||
|
||||
if (!(client = (struct AnodeHttpClient *)(connection->ptr)))
|
||||
return;
|
||||
if (client->impl.freed)
|
||||
return;
|
||||
|
||||
client->response.data_length = 0;
|
||||
client->impl.tcp_connection = (AnodeTransportTcpConnection *)0;
|
||||
if ((client->impl.phase != ANODE_HTTP_REQUEST_PHASE_KEEPALIVE)&&(client->impl.phase != ANODE_HTTP_REQUEST_PHASE_CLOSED)) {
|
||||
client->response.code = ANODE_HTTP_SPECIAL_RESPONSE_SERVER_CLOSED_CONNECTION;
|
||||
client->impl.phase = ANODE_HTTP_REQUEST_PHASE_CLOSED;
|
||||
AnodeHttpClient_close_and_fail(client);
|
||||
} else client->impl.phase = ANODE_HTTP_REQUEST_PHASE_CLOSED;
|
||||
}
|
||||
|
||||
static void AnodeHttpClient_tcp_receive_handler(
|
||||
AnodeTransportEngine *transport,
|
||||
AnodeTransportTcpConnection *connection,
|
||||
void *data,
|
||||
unsigned int data_length)
|
||||
{
|
||||
struct AnodeHttpClient *client;
|
||||
char *p1,*p2;
|
||||
unsigned int i;
|
||||
long l;
|
||||
|
||||
if (!(client = (struct AnodeHttpClient *)(connection->ptr)))
|
||||
return;
|
||||
if (client->impl.freed) {
|
||||
transport->tcp_close(transport,connection);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!client->response.data)
|
||||
client->response.data = malloc(client->impl.response_data_capacity = ANODE_HTTP_CAPACITY_INCREMENT);
|
||||
|
||||
i = 0;
|
||||
while (i < data_length) {
|
||||
switch(client->impl.read_mode) {
|
||||
case ANODE_HTTP_READ_MODE_WAITING:
|
||||
for(;i<data_length;++i) {
|
||||
if (((const char *)data)[i] == '\n') {
|
||||
((char *)client->response.data)[client->response.data_length] = (char)0;
|
||||
client->response.data_length = 0;
|
||||
|
||||
p1 = (char *)Anode_strchr((char *)client->response.data,' ');
|
||||
if (!p1)
|
||||
p1 = (char *)Anode_strchr((char *)client->response.data,'\t');
|
||||
if (p1) {
|
||||
while ((*p1 == ' ')||(*p1 == '\t')) ++p1;
|
||||
if (!*p1) {
|
||||
client->response.code = ANODE_HTTP_SPECIAL_RESPONSE_INVALID_RESPONSE;
|
||||
AnodeHttpClient_close_and_fail(client);
|
||||
return;
|
||||
}
|
||||
p2 = p1 + 1;
|
||||
while (*p2) {
|
||||
if ((*p2 == ' ')||(*p2 == '\t')||(*p2 == '\r')||(*p2 == '\n')) {
|
||||
*p2 = (char)0;
|
||||
break;
|
||||
} else ++p2;
|
||||
}
|
||||
client->response.code = (int)strtol(p1,(char **)0,10);
|
||||
client->impl.read_mode = ANODE_HTTP_READ_MODE_HEADERS;
|
||||
++i; break; /* Exit inner for() */
|
||||
}
|
||||
} else {
|
||||
((char *)client->response.data)[client->response.data_length++] = ((const char *)data)[i];
|
||||
if (client->response.data_length >= client->impl.response_data_capacity)
|
||||
client->response.data = realloc(client->response.data,client->impl.response_data_capacity += ANODE_HTTP_CAPACITY_INCREMENT);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ANODE_HTTP_READ_MODE_HEADERS:
|
||||
case ANODE_HTTP_READ_MODE_CHUNKED_FOOTER:
|
||||
for(;i<data_length;++i) {
|
||||
if (((const char *)data)[i] == '\n') {
|
||||
client->impl.header_line_buf[client->impl.header_line_buf_ptr] = (char)0;
|
||||
client->impl.header_line_buf_ptr = 0;
|
||||
|
||||
if ((!client->impl.header_line_buf[0])||((client->impl.header_line_buf[0] == '\r')&&(!client->impl.header_line_buf[1]))) {
|
||||
/* If the line is empty (or is empty with \r\n as the
|
||||
* line terminator), we're at the end. */
|
||||
if (client->impl.read_mode == ANODE_HTTP_READ_MODE_CHUNKED_FOOTER) {
|
||||
/* If this is a chunked footer, we finally end the
|
||||
* chunked response. */
|
||||
client->impl.read_mode = ANODE_HTTP_READ_MODE_WAITING;
|
||||
if (client->keepalive)
|
||||
client->impl.phase = ANODE_HTTP_REQUEST_PHASE_KEEPALIVE;
|
||||
else {
|
||||
client->impl.transport_engine->tcp_close(client->impl.transport_engine,client->impl.tcp_connection);
|
||||
client->impl.tcp_connection = (AnodeTransportTcpConnection *)0;
|
||||
client->impl.phase = ANODE_HTTP_REQUEST_PHASE_CLOSED;
|
||||
}
|
||||
if (client->handler)
|
||||
client->handler(client);
|
||||
if (client->impl.freed)
|
||||
return;
|
||||
} else {
|
||||
/* Otherwise, this is a regular header block */
|
||||
if (client->response.code == 100) {
|
||||
/* Ignore 100 Continue messages */
|
||||
client->impl.read_mode = ANODE_HTTP_READ_MODE_WAITING;
|
||||
++i; break; /* Exit inner for() */
|
||||
} else if ((client->response.code == 200)&&(client->method != ANODE_HTTP_HEAD)) {
|
||||
/* Other messages get their headers parsed to determine
|
||||
* how to read them. */
|
||||
p1 = (char *)AnodeDictionary_get(&(client->response.headers),"transfer-encoding");
|
||||
if ((p1)&&(Anode_strcaseeq(p1,"chunked"))) {
|
||||
/* Chunked encoding enters chunked mode */
|
||||
client->impl.header_line_buf_ptr = 0;
|
||||
client->impl.read_mode = ANODE_HTTP_READ_MODE_CHUNKED_CHUNK_SIZE;
|
||||
++i; break; /* Exit inner for() */
|
||||
} else {
|
||||
/* Else we must have a Content-Length header */
|
||||
p1 = (char *)AnodeDictionary_get(&(client->response.headers),"content-length");
|
||||
if (!p1) {
|
||||
/* No chunked or content length is not supported */
|
||||
client->response.code = ANODE_HTTP_SPECIAL_RESPONSE_INVALID_RESPONSE;
|
||||
AnodeHttpClient_close_and_fail(client);
|
||||
return;
|
||||
} else {
|
||||
/* Enter block read mode with content length */
|
||||
l = strtol(p1,(char **)0,10);
|
||||
if (l <= 0) {
|
||||
/* Zero length data is all done... */
|
||||
client->impl.expecting_response_length = 0;
|
||||
client->impl.read_mode = ANODE_HTTP_READ_MODE_WAITING;
|
||||
if (client->keepalive)
|
||||
client->impl.phase = ANODE_HTTP_REQUEST_PHASE_KEEPALIVE;
|
||||
else {
|
||||
client->impl.transport_engine->tcp_close(client->impl.transport_engine,client->impl.tcp_connection);
|
||||
client->impl.tcp_connection = (AnodeTransportTcpConnection *)0;
|
||||
client->impl.phase = ANODE_HTTP_REQUEST_PHASE_CLOSED;
|
||||
}
|
||||
|
||||
if (client->handler)
|
||||
client->handler(client);
|
||||
if (client->impl.freed)
|
||||
return;
|
||||
|
||||
++i; break; /* Exit inner for() */
|
||||
} else {
|
||||
/* Else start reading... */
|
||||
client->impl.expecting_response_length = (unsigned int)l;
|
||||
client->impl.read_mode = ANODE_HTTP_READ_MODE_BLOCK;
|
||||
++i; break; /* Exit inner for() */
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* HEAD clients or non-200 codes get headers only */
|
||||
client->impl.expecting_response_length = 0;
|
||||
client->impl.read_mode = ANODE_HTTP_READ_MODE_WAITING;
|
||||
if (client->keepalive)
|
||||
client->impl.phase = ANODE_HTTP_REQUEST_PHASE_KEEPALIVE;
|
||||
else {
|
||||
client->impl.transport_engine->tcp_close(client->impl.transport_engine,client->impl.tcp_connection);
|
||||
client->impl.tcp_connection = (AnodeTransportTcpConnection *)0;
|
||||
client->impl.phase = ANODE_HTTP_REQUEST_PHASE_CLOSED;
|
||||
}
|
||||
|
||||
if (client->handler)
|
||||
client->handler(client);
|
||||
if (client->impl.freed)
|
||||
return;
|
||||
|
||||
++i; break; /* Exit inner for() */
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* Otherwise this is another header, add to dictionary */
|
||||
AnodeDictionary_read(
|
||||
&(client->response.headers),
|
||||
client->impl.header_line_buf,
|
||||
"\r\n",
|
||||
": \t",
|
||||
"",
|
||||
(char)0,
|
||||
1,
|
||||
1
|
||||
);
|
||||
}
|
||||
} else {
|
||||
client->impl.header_line_buf[client->impl.header_line_buf_ptr++] = ((const char *)data)[i];
|
||||
if (client->impl.header_line_buf_ptr >= sizeof(client->impl.header_line_buf)) {
|
||||
client->response.code = ANODE_HTTP_SPECIAL_RESPONSE_INVALID_RESPONSE;
|
||||
AnodeHttpClient_close_and_fail(client);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ANODE_HTTP_READ_MODE_BLOCK:
|
||||
if ((client->response.data_length + client->impl.expecting_response_length) > client->impl.response_data_capacity)
|
||||
client->response.data = realloc(client->response.data,client->impl.response_data_capacity = (client->response.data_length + client->impl.expecting_response_length));
|
||||
|
||||
for(;((i<data_length)&&(client->impl.expecting_response_length));++i) {
|
||||
((char *)client->response.data)[client->response.data_length++] = ((const char *)data)[i];
|
||||
--client->impl.expecting_response_length;
|
||||
}
|
||||
|
||||
if (!client->impl.expecting_response_length) {
|
||||
client->impl.read_mode = ANODE_HTTP_READ_MODE_WAITING;
|
||||
if (client->keepalive)
|
||||
client->impl.phase = ANODE_HTTP_REQUEST_PHASE_KEEPALIVE;
|
||||
else {
|
||||
client->impl.transport_engine->tcp_close(client->impl.transport_engine,client->impl.tcp_connection);
|
||||
client->impl.tcp_connection = (AnodeTransportTcpConnection *)0;
|
||||
client->impl.phase = ANODE_HTTP_REQUEST_PHASE_CLOSED;
|
||||
}
|
||||
|
||||
if (client->handler)
|
||||
client->handler(client);
|
||||
if (client->impl.freed)
|
||||
return;
|
||||
}
|
||||
break;
|
||||
case ANODE_HTTP_READ_MODE_CHUNKED_CHUNK_SIZE:
|
||||
for(;i<data_length;++i) {
|
||||
if (((const char *)data)[i] == '\n') {
|
||||
client->impl.header_line_buf[client->impl.header_line_buf_ptr] = (char)0;
|
||||
client->impl.header_line_buf_ptr = 0;
|
||||
|
||||
p1 = client->impl.header_line_buf;
|
||||
while (*p1) {
|
||||
if ((*p1 == ';')||(*p1 == ' ')||(*p1 == '\r')||(*p1 == '\n')||(*p1 == '\t')) {
|
||||
*p1 = (char)0;
|
||||
break;
|
||||
} else ++p1;
|
||||
}
|
||||
|
||||
if (client->impl.header_line_buf[0]) {
|
||||
l = strtol(client->impl.header_line_buf,(char **)0,16);
|
||||
if (l <= 0) {
|
||||
/* Zero length ends chunked and enters footer mode */
|
||||
client->impl.expecting_response_length = 0;
|
||||
client->impl.read_mode = ANODE_HTTP_READ_MODE_CHUNKED_FOOTER;
|
||||
} else {
|
||||
/* Otherwise the next chunk is to be read */
|
||||
client->impl.expecting_response_length = (unsigned int)l;
|
||||
client->impl.read_mode = ANODE_HTTP_READ_MODE_CHUNKED_DATA;
|
||||
}
|
||||
++i; break; /* Exit inner for() */
|
||||
}
|
||||
} else {
|
||||
client->impl.header_line_buf[client->impl.header_line_buf_ptr++] = ((const char *)data)[i];
|
||||
if (client->impl.header_line_buf_ptr >= sizeof(client->impl.header_line_buf)) {
|
||||
client->response.code = ANODE_HTTP_SPECIAL_RESPONSE_INVALID_RESPONSE;
|
||||
AnodeHttpClient_close_and_fail(client);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ANODE_HTTP_READ_MODE_CHUNKED_DATA:
|
||||
if ((client->response.data_length + client->impl.expecting_response_length) > client->impl.response_data_capacity)
|
||||
client->response.data = realloc(client->response.data,client->impl.response_data_capacity = (client->response.data_length + client->impl.expecting_response_length));
|
||||
|
||||
for(;((i<data_length)&&(client->impl.expecting_response_length));++i) {
|
||||
((char *)client->response.data)[client->response.data_length++] = ((const char *)data)[i];
|
||||
--client->impl.expecting_response_length;
|
||||
}
|
||||
|
||||
if (!client->impl.expecting_response_length)
|
||||
client->impl.read_mode = ANODE_HTTP_READ_MODE_CHUNKED_CHUNK_SIZE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void AnodeHttpClient_tcp_available_for_write_handler(
|
||||
AnodeTransportEngine *transport,
|
||||
AnodeTransportTcpConnection *connection)
|
||||
{
|
||||
struct AnodeHttpClient *client;
|
||||
unsigned int i,j;
|
||||
int n;
|
||||
|
||||
if (!(client = (struct AnodeHttpClient *)(connection->ptr)))
|
||||
return;
|
||||
if (client->impl.freed) {
|
||||
transport->tcp_close(transport,connection);
|
||||
return;
|
||||
}
|
||||
|
||||
if (client->impl.phase == ANODE_HTTP_REQUEST_PHASE_SEND) {
|
||||
n = client->impl.transport_engine->tcp_send(client->impl.transport_engine,client->impl.tcp_connection,(const void *)client->impl.outbuf,(int)client->impl.outbuf_len);
|
||||
if (n < 0) {
|
||||
client->response.code = ANODE_HTTP_SPECIAL_RESPONSE_SERVER_CLOSED_CONNECTION;
|
||||
AnodeHttpClient_close_and_fail(client);
|
||||
} else if (n > 0) {
|
||||
for(i=0,j=(client->impl.outbuf_len - (unsigned int)n);i<j;++i)
|
||||
client->impl.outbuf[i] = client->impl.outbuf[i + (unsigned int)n];
|
||||
client->impl.outbuf_len -= (unsigned int)n;
|
||||
|
||||
if ((client->method == ANODE_HTTP_POST)&&(client->data)&&(client->data_length)) {
|
||||
i = sizeof(client->impl.outbuf) - client->impl.outbuf_len;
|
||||
j = client->data_length - client->impl.request_data_ptr;
|
||||
if (i > j)
|
||||
i = j;
|
||||
Anode_memcpy((client->impl.outbuf + client->impl.outbuf_len),client->data,i);
|
||||
client->impl.request_data_ptr += i;
|
||||
client->impl.outbuf_len += i;
|
||||
}
|
||||
|
||||
if (!client->impl.outbuf_len) {
|
||||
client->impl.transport_engine->tcp_stop_writing(client->impl.transport_engine,client->impl.tcp_connection);
|
||||
client->impl.phase = ANODE_HTTP_REQUEST_PHASE_RECEIVE;
|
||||
}
|
||||
}
|
||||
} else client->impl.transport_engine->tcp_stop_writing(client->impl.transport_engine,client->impl.tcp_connection);
|
||||
}
|
||||
|
||||
static void AnodeHttpClient_dns_result_handler(
|
||||
AnodeTransportEngine *transport,
|
||||
void *ptr,
|
||||
int error_code,
|
||||
const char *name,
|
||||
const AnodeTransportIpAddress *ip_addresses,
|
||||
unsigned int ip_address_count,
|
||||
const AnodeAddress *anode_address)
|
||||
{
|
||||
struct AnodeHttpClient *client;
|
||||
AnodeTransportIpEndpoint to_endpoint;
|
||||
|
||||
if (!(client = (struct AnodeHttpClient *)ptr))
|
||||
return;
|
||||
if (client->impl.freed)
|
||||
return;
|
||||
|
||||
if ((error_code)||(!ip_address_count)) {
|
||||
if (client->impl.phase == ANODE_HTTP_REQUEST_PHASE_RESOLVE) {
|
||||
client->response.code = ANODE_HTTP_SPECIAL_RESPONSE_DNS_RESOLVE_FAILED;
|
||||
AnodeHttpClient_close_and_fail(client);
|
||||
}
|
||||
} else {
|
||||
client->impl.phase = ANODE_HTTP_REQUEST_PHASE_CONNECT;
|
||||
Anode_memcpy(&to_endpoint.address,ip_addresses,sizeof(AnodeTransportIpAddress));
|
||||
to_endpoint.port = (client->uri.port > 0) ? client->uri.port : 80;
|
||||
client->impl.transport_engine->tcp_connect(
|
||||
client->impl.transport_engine,
|
||||
client,
|
||||
&AnodeHttpClient_tcp_outgoing_connect_handler,
|
||||
&AnodeHttpClient_tcp_connection_terminated_handler,
|
||||
&AnodeHttpClient_tcp_receive_handler,
|
||||
&AnodeHttpClient_tcp_available_for_write_handler,
|
||||
&to_endpoint);
|
||||
}
|
||||
}
|
||||
|
||||
struct AnodeHttpClient *AnodeHttpClient_new(AnodeTransportEngine *transport_engine)
|
||||
{
|
||||
struct AnodeHttpClient *req = malloc(sizeof(struct AnodeHttpClient));
|
||||
Anode_zero(req,sizeof(struct AnodeHttpClient));
|
||||
|
||||
AnodeDictionary_init(&(req->headers),0);
|
||||
AnodeDictionary_init(&(req->response.headers),0);
|
||||
|
||||
req->impl.transport_engine = transport_engine;
|
||||
|
||||
return req;
|
||||
}
|
||||
|
||||
void AnodeHttpClient_send(struct AnodeHttpClient *client)
|
||||
{
|
||||
client->response.code = 0;
|
||||
client->response.data_length = 0;
|
||||
AnodeDictionary_clear(&(client->response.headers));
|
||||
|
||||
client->impl.request_data_ptr = 0;
|
||||
client->impl.expecting_response_length = 0;
|
||||
client->impl.read_mode = ANODE_HTTP_READ_MODE_WAITING;
|
||||
client->impl.outbuf_len = 0;
|
||||
|
||||
if (!client->impl.tcp_connection) {
|
||||
client->impl.transport_engine->dns_resolve(
|
||||
client->impl.transport_engine,
|
||||
&AnodeHttpClient_dns_result_handler,
|
||||
client,
|
||||
client->uri.host,
|
||||
ANODE_TRANSPORT_DNS_QUERY_ALWAYS,
|
||||
ANODE_TRANSPORT_DNS_QUERY_IF_NO_PREVIOUS,
|
||||
ANODE_TRANSPORT_DNS_QUERY_NEVER);
|
||||
} else AnodeHttpClient_do_initiate_client(client);
|
||||
}
|
||||
|
||||
void AnodeHttpClient_free(struct AnodeHttpClient *client)
|
||||
{
|
||||
AnodeDictionary_destroy(&(client->headers));
|
||||
AnodeDictionary_destroy(&(client->response.headers));
|
||||
|
||||
if (client->impl.tcp_connection) {
|
||||
client->impl.transport_engine->tcp_close(client->impl.transport_engine,client->impl.tcp_connection);
|
||||
client->impl.tcp_connection = (AnodeTransportTcpConnection *)0;
|
||||
}
|
||||
|
||||
if (client->response.data)
|
||||
free(client->response.data);
|
||||
|
||||
client->impl.freed = 1;
|
||||
client->impl.transport_engine->run_later(client->impl.transport_engine,client,&free);
|
||||
}
|
200
attic/historic/anode/libanode/impl/http_client.h
Normal file
200
attic/historic/anode/libanode/impl/http_client.h
Normal file
@ -0,0 +1,200 @@
|
||||
/* libanode: the Anode C reference implementation
|
||||
* Copyright (C) 2009-2010 Adam Ierymenko <adam.ierymenko@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _ANODE_HTTP_CLIENT_H
|
||||
#define _ANODE_HTTP_CLIENT_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "dictionary.h"
|
||||
#include "../anode.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/**
|
||||
* HTTP request type
|
||||
*/
|
||||
enum AnodeHttpClientRequestMethod
|
||||
{
|
||||
ANODE_HTTP_GET = 0,
|
||||
ANODE_HTTP_HEAD = 1,
|
||||
ANODE_HTTP_POST = 2
|
||||
};
|
||||
|
||||
/*
|
||||
* Special response codes to indicate I/O errors
|
||||
*/
|
||||
#define ANODE_HTTP_SPECIAL_RESPONSE_DNS_RESOLVE_FAILED -1
|
||||
#define ANODE_HTTP_SPECIAL_RESPONSE_CONNECT_FAILED -2
|
||||
#define ANODE_HTTP_SPECIAL_RESPONSE_HEADERS_TOO_LARGE -3
|
||||
#define ANODE_HTTP_SPECIAL_RESPONSE_SERVER_CLOSED_CONNECTION -4
|
||||
#define ANODE_HTTP_SPECIAL_RESPONSE_INVALID_RESPONSE -5
|
||||
|
||||
/**
|
||||
* Simple HTTP client
|
||||
*/
|
||||
struct AnodeHttpClient
|
||||
{
|
||||
/**
|
||||
* Request URI
|
||||
*/
|
||||
AnodeURI uri;
|
||||
|
||||
/**
|
||||
* Request method: GET, PUT, HEAD, or POST
|
||||
*/
|
||||
enum AnodeHttpClientRequestMethod method;
|
||||
|
||||
/**
|
||||
* Data for POST requests
|
||||
*
|
||||
* It is your responsibility to manage and/or free this pointer. The HTTP
|
||||
* client only reads from it.
|
||||
*/
|
||||
const void *data;
|
||||
unsigned int data_length;
|
||||
|
||||
/**
|
||||
* Content type for data, or null for application/x-www-form-urlencoded
|
||||
*/
|
||||
const char *data_content_type;
|
||||
|
||||
/**
|
||||
* Set to non-zero to use HTTP connection keepalive
|
||||
*
|
||||
* If keepalive is enabled, this request can be modified and re-used and
|
||||
* its associated connection will stay open (being reopened if needed)
|
||||
* until it is freed.
|
||||
*
|
||||
* Note that this client is too dumb to pool connections and pick them on
|
||||
* the basis of host. Keepalive mode should only be set if the next request
|
||||
* will be from the same host and port, otherwise you will get a '404'.
|
||||
*/
|
||||
int keepalive;
|
||||
|
||||
/**
|
||||
* Function pointer to be called when request is complete (or fails)
|
||||
*/
|
||||
void (*handler)(struct AnodeHttpClient *);
|
||||
|
||||
/**
|
||||
* Two arbitrary pointers that can be stored here for use by the handler.
|
||||
* These are not accessed or modified by the client.
|
||||
*/
|
||||
void *ptr[2];
|
||||
|
||||
/**
|
||||
* Request headers
|
||||
*/
|
||||
struct AnodeDictionary headers;
|
||||
|
||||
struct {
|
||||
/**
|
||||
* Response code, set on completion or failure before handler is called
|
||||
*
|
||||
* Also check for the special response codes defined in http_client.h as
|
||||
* these negative codes indicate network or other errors.
|
||||
*/
|
||||
int code;
|
||||
|
||||
/**
|
||||
* Response data, for GET and POST requests
|
||||
*/
|
||||
void *data;
|
||||
|
||||
/**
|
||||
* Length of response data
|
||||
*/
|
||||
unsigned int data_length;
|
||||
|
||||
/**
|
||||
* Response headers
|
||||
*/
|
||||
struct AnodeDictionary headers;
|
||||
} response;
|
||||
|
||||
/**
|
||||
* Internal fields used by implementation
|
||||
*/
|
||||
struct {
|
||||
/* Transport engine being used by request */
|
||||
AnodeTransportEngine *transport_engine;
|
||||
|
||||
/* Connection to which request has been sent, or null if none */
|
||||
struct AnodeHttpConnection *connection;
|
||||
|
||||
/* Buffer for reading chunked mode chunk lines (can't use data buf) */
|
||||
char header_line_buf[256];
|
||||
unsigned int header_line_buf_ptr;
|
||||
|
||||
/* Where are we in sending request data? */
|
||||
unsigned int request_data_ptr;
|
||||
|
||||
/* Capacity of response_data buffer */
|
||||
unsigned int response_data_capacity;
|
||||
|
||||
/* How much response data are we currently expecting? */
|
||||
/* This is content-length in block mode or chunk length in chunked mode */
|
||||
unsigned int expecting_response_length;
|
||||
|
||||
/* Read mode */
|
||||
enum {
|
||||
ANODE_HTTP_READ_MODE_WAITING = 0,
|
||||
ANODE_HTTP_READ_MODE_HEADERS = 1,
|
||||
ANODE_HTTP_READ_MODE_BLOCK = 2,
|
||||
ANODE_HTTP_READ_MODE_CHUNKED_CHUNK_SIZE = 3,
|
||||
ANODE_HTTP_READ_MODE_CHUNKED_DATA = 4,
|
||||
ANODE_HTTP_READ_MODE_CHUNKED_FOOTER = 5
|
||||
} read_mode;
|
||||
|
||||
/* Connection from transport engine */
|
||||
AnodeTransportTcpConnection *tcp_connection;
|
||||
|
||||
/* Write buffer */
|
||||
unsigned char outbuf[16384];
|
||||
unsigned int outbuf_len;
|
||||
|
||||
/* Phase of request state machine */
|
||||
enum {
|
||||
ANODE_HTTP_REQUEST_PHASE_RESOLVE = 0,
|
||||
ANODE_HTTP_REQUEST_PHASE_CONNECT = 1,
|
||||
ANODE_HTTP_REQUEST_PHASE_SEND = 2,
|
||||
ANODE_HTTP_REQUEST_PHASE_RECEIVE = 3,
|
||||
ANODE_HTTP_REQUEST_PHASE_KEEPALIVE = 4,
|
||||
ANODE_HTTP_REQUEST_PHASE_CLOSED = 5
|
||||
} phase;
|
||||
|
||||
/* Has request object been freed? */
|
||||
int freed;
|
||||
|
||||
/**
|
||||
* Pointer used internally for putting requests into linked lists
|
||||
*/
|
||||
struct AnodeHttpClient *next;
|
||||
} impl;
|
||||
};
|
||||
|
||||
struct AnodeHttpClient *AnodeHttpClient_new(AnodeTransportEngine *transport_engine);
|
||||
void AnodeHttpClient_send(struct AnodeHttpClient *client);
|
||||
void AnodeHttpClient_free(struct AnodeHttpClient *client);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
190
attic/historic/anode/libanode/impl/misc.c
Normal file
190
attic/historic/anode/libanode/impl/misc.c
Normal file
@ -0,0 +1,190 @@
|
||||
/* libanode: the Anode C reference implementation
|
||||
* Copyright (C) 2009-2010 Adam Ierymenko <adam.ierymenko@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "misc.h"
|
||||
#include "types.h"
|
||||
|
||||
static const char Anode_hex_chars[16] = {
|
||||
'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'
|
||||
};
|
||||
|
||||
static const char Anode_base32_chars[32] = {
|
||||
'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q',
|
||||
'r','s','t','u','v','w','x','y','z','2','3','4','5','6','7'
|
||||
};
|
||||
static const unsigned char Anode_base32_bits[256] = {
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,26,27,28,29,30,31,0,0,0,0,0,0,0,0,0,0,1,2,3,4,5,
|
||||
6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,0,0,0,0,0,0,0,1,2,
|
||||
3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||
};
|
||||
|
||||
/* Table for converting ASCII chars to lower case */
|
||||
const unsigned char Anode_ascii_tolower_table[256] = {
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
||||
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
|
||||
0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
|
||||
0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
|
||||
0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f,
|
||||
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
|
||||
0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0x3e, 0x3f,
|
||||
0x40, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
|
||||
0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
|
||||
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
|
||||
0x78, 0x79, 0x7a, 0x5b, 0x5c, 0x5d, 0x5e, 0x5f,
|
||||
0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
|
||||
0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f,
|
||||
0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
|
||||
0x78, 0x79, 0x7a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
|
||||
0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
|
||||
0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
|
||||
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
|
||||
0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
|
||||
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
|
||||
0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
|
||||
0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
|
||||
0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
|
||||
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
|
||||
0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
|
||||
0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
|
||||
0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
|
||||
0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,
|
||||
0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
|
||||
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,
|
||||
0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff
|
||||
};
|
||||
|
||||
void Anode_trim(char *s)
|
||||
{
|
||||
char *dest = s;
|
||||
char *last;
|
||||
while ((*s)&&((*s == ' ')||(*s == '\t')||(*s == '\r')||(*s == '\n')))
|
||||
++s;
|
||||
last = s;
|
||||
while ((*dest = *s)) {
|
||||
if ((*dest != ' ')&&(*dest != '\t')&&(*dest != '\r')&&(*dest != '\n'))
|
||||
last = dest;
|
||||
++dest;
|
||||
++s;
|
||||
}
|
||||
if (*last)
|
||||
*(++last) = (char)0;
|
||||
}
|
||||
|
||||
unsigned int Anode_rand()
|
||||
{
|
||||
static volatile int need_seed = 1;
|
||||
|
||||
if (need_seed) {
|
||||
need_seed = 0;
|
||||
srandom((unsigned long)Anode_time64());
|
||||
}
|
||||
|
||||
return (unsigned int)random();
|
||||
}
|
||||
|
||||
void Anode_to_hex(const unsigned char *b,unsigned int len,char *h,unsigned int hlen)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
if ((len * 2) >= hlen)
|
||||
len = (hlen - 1) / 2;
|
||||
|
||||
for(i=0;i<len;++i) {
|
||||
*(h++) = Anode_hex_chars[b[i] >> 4];
|
||||
*(h++) = Anode_hex_chars[b[i] & 0xf];
|
||||
}
|
||||
*h = (char)0;
|
||||
}
|
||||
|
||||
void Anode_from_hex(const char *h,unsigned char *b,unsigned int blen)
|
||||
{
|
||||
unsigned char *end = b + blen;
|
||||
unsigned char v = (unsigned char)0;
|
||||
|
||||
while (b != end) {
|
||||
switch(*(h++)) {
|
||||
case '0': v = 0x00; break;
|
||||
case '1': v = 0x10; break;
|
||||
case '2': v = 0x20; break;
|
||||
case '3': v = 0x30; break;
|
||||
case '4': v = 0x40; break;
|
||||
case '5': v = 0x50; break;
|
||||
case '6': v = 0x60; break;
|
||||
case '7': v = 0x70; break;
|
||||
case '8': v = 0x80; break;
|
||||
case '9': v = 0x90; break;
|
||||
case 'a': v = 0xa0; break;
|
||||
case 'b': v = 0xb0; break;
|
||||
case 'c': v = 0xc0; break;
|
||||
case 'd': v = 0xd0; break;
|
||||
case 'e': v = 0xe0; break;
|
||||
case 'f': v = 0xf0; break;
|
||||
default: return;
|
||||
}
|
||||
|
||||
switch(*(h++)) {
|
||||
case '0': v |= 0x00; break;
|
||||
case '1': v |= 0x01; break;
|
||||
case '2': v |= 0x02; break;
|
||||
case '3': v |= 0x03; break;
|
||||
case '4': v |= 0x04; break;
|
||||
case '5': v |= 0x05; break;
|
||||
case '6': v |= 0x06; break;
|
||||
case '7': v |= 0x07; break;
|
||||
case '8': v |= 0x08; break;
|
||||
case '9': v |= 0x09; break;
|
||||
case 'a': v |= 0x0a; break;
|
||||
case 'b': v |= 0x0b; break;
|
||||
case 'c': v |= 0x0c; break;
|
||||
case 'd': v |= 0x0d; break;
|
||||
case 'e': v |= 0x0e; break;
|
||||
case 'f': v |= 0x0f; break;
|
||||
default: return;
|
||||
}
|
||||
|
||||
*(b++) = v;
|
||||
}
|
||||
}
|
||||
|
||||
void Anode_base32_5_to_8(const unsigned char *in,char *out)
|
||||
{
|
||||
out[0] = Anode_base32_chars[(in[0]) >> 3];
|
||||
out[1] = Anode_base32_chars[(in[0] & 0x07) << 2 | (in[1] & 0xc0) >> 6];
|
||||
out[2] = Anode_base32_chars[(in[1] & 0x3e) >> 1];
|
||||
out[3] = Anode_base32_chars[(in[1] & 0x01) << 4 | (in[2] & 0xf0) >> 4];
|
||||
out[4] = Anode_base32_chars[(in[2] & 0x0f) << 1 | (in[3] & 0x80) >> 7];
|
||||
out[5] = Anode_base32_chars[(in[3] & 0x7c) >> 2];
|
||||
out[6] = Anode_base32_chars[(in[3] & 0x03) << 3 | (in[4] & 0xe0) >> 5];
|
||||
out[7] = Anode_base32_chars[(in[4] & 0x1f)];
|
||||
}
|
||||
|
||||
void Anode_base32_8_to_5(const char *in,unsigned char *out)
|
||||
{
|
||||
out[0] = ((Anode_base32_bits[(unsigned int)in[0]]) << 3) | (Anode_base32_bits[(unsigned int)in[1]] & 0x1C) >> 2;
|
||||
out[1] = ((Anode_base32_bits[(unsigned int)in[1]] & 0x03) << 6) | (Anode_base32_bits[(unsigned int)in[2]]) << 1 | (Anode_base32_bits[(unsigned int)in[3]] & 0x10) >> 4;
|
||||
out[2] = ((Anode_base32_bits[(unsigned int)in[3]] & 0x0F) << 4) | (Anode_base32_bits[(unsigned int)in[4]] & 0x1E) >> 1;
|
||||
out[3] = ((Anode_base32_bits[(unsigned int)in[4]] & 0x01) << 7) | (Anode_base32_bits[(unsigned int)in[5]]) << 2 | (Anode_base32_bits[(unsigned int)in[6]] & 0x18) >> 3;
|
||||
out[4] = ((Anode_base32_bits[(unsigned int)in[6]] & 0x07) << 5) | (Anode_base32_bits[(unsigned int)in[7]]);
|
||||
}
|
193
attic/historic/anode/libanode/impl/misc.h
Normal file
193
attic/historic/anode/libanode/impl/misc.h
Normal file
@ -0,0 +1,193 @@
|
||||
/* libanode: the Anode C reference implementation
|
||||
* Copyright (C) 2009-2010 Adam Ierymenko <adam.ierymenko@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
/* This contains miscellaneous functions, including some re-implementations
|
||||
* of some functions from string.h. This is to help us port to some platforms
|
||||
* (cough Windows Mobile cough) that lack a lot of the basic C library. */
|
||||
|
||||
#ifndef _ANODE_MISC_H
|
||||
#define _ANODE_MISC_H
|
||||
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include "types.h"
|
||||
|
||||
#ifndef ANODE_NO_STRING_H
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#endif
|
||||
|
||||
/* Table mapping ASCII characters to themselves or their lower case */
|
||||
extern const unsigned char Anode_ascii_tolower_table[256];
|
||||
|
||||
/* Get the lower case version of an ASCII char */
|
||||
#define Anode_tolower(c) ((char)Anode_ascii_tolower_table[((unsigned long)((unsigned char)(c)))])
|
||||
|
||||
/* Test strings for equality, return nonzero if equal */
|
||||
static inline unsigned int Anode_streq(const char *restrict a,const char *restrict b)
|
||||
{
|
||||
if ((!a)||(!b))
|
||||
return 0;
|
||||
while (*a == *(b++)) {
|
||||
if (!*(a++))
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Equality test ignoring (ASCII) case */
|
||||
static inline unsigned int Anode_strcaseeq(const char *restrict a,const char *restrict b)
|
||||
{
|
||||
if ((!a)||(!b))
|
||||
return 0;
|
||||
while (Anode_tolower(*a) == Anode_tolower(*(b++))) {
|
||||
if (!*(a++))
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Safe c-string copy, ensuring that dest[] always ends with zero */
|
||||
static inline void Anode_str_copy(char *restrict dest,const char *restrict src,unsigned int dest_size)
|
||||
{
|
||||
char *restrict dest_end = dest + (dest_size - 1);
|
||||
while ((*src)&&(dest != dest_end))
|
||||
*(dest++) = *(src++);
|
||||
*dest = (char)0;
|
||||
}
|
||||
|
||||
/* Simple memcpy() */
|
||||
#ifdef ANODE_NO_STRING_H
|
||||
static inline void Anode_memcpy(void *restrict dest,const void *restrict src,unsigned int len)
|
||||
{
|
||||
unsigned int i;
|
||||
for(i=0;i<len;++i)
|
||||
((unsigned char *restrict)dest)[i] = ((const unsigned char *restrict)src)[i];
|
||||
}
|
||||
#else
|
||||
#define Anode_memcpy(d,s,l) memcpy((d),(s),(l))
|
||||
#endif
|
||||
|
||||
/* Memory test for equality */
|
||||
#ifdef ANODE_NO_STRING_H
|
||||
static inline unsigned int Anode_mem_eq(const void *restrict a,const void *restrict b,unsigned int len)
|
||||
{
|
||||
unsigned int i;
|
||||
for(i=0;i<len;++i) {
|
||||
if (((const unsigned char *restrict)a)[i] != ((const unsigned char *restrict)b)[i])
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
#else
|
||||
#define Anode_mem_eq(a,b,l) (!memcmp((a),(b),(l)))
|
||||
#endif
|
||||
|
||||
/* Zero memory */
|
||||
#ifdef ANODE_NO_STRING_H
|
||||
static inline void Anode_zero(void *restrict ptr,unsigned int len)
|
||||
{
|
||||
unsigned int i;
|
||||
for(i=0;i<len;++i)
|
||||
((unsigned char *restrict)ptr)[i] = (unsigned char)0;
|
||||
}
|
||||
#else
|
||||
#define Anode_zero(p,l) memset((p),0,(l))
|
||||
#endif
|
||||
|
||||
/* Get a pointer to the first occurrance of a character in a string */
|
||||
#ifdef ANODE_NO_STRING_H
|
||||
static inline const char *Anode_strchr(const char *s,char c)
|
||||
{
|
||||
while (*s) {
|
||||
if (*s == c)
|
||||
return s;
|
||||
++s;
|
||||
}
|
||||
return (char *)0;
|
||||
}
|
||||
#else
|
||||
#define Anode_strchr(s,c) strchr((s),(c))
|
||||
#endif
|
||||
|
||||
static inline unsigned int Anode_count_char(const char *s,char c)
|
||||
{
|
||||
unsigned int cnt = 0;
|
||||
while (s) {
|
||||
if (*s == c)
|
||||
++cnt;
|
||||
++s;
|
||||
}
|
||||
return cnt;
|
||||
}
|
||||
|
||||
/* Strip all of a given set of characters from a string */
|
||||
static inline void Anode_strip_all(char *s,const char *restrict schars)
|
||||
{
|
||||
char *d = s;
|
||||
|
||||
while (*s) {
|
||||
if (!Anode_strchr(schars,*s))
|
||||
*(d++) = *s;
|
||||
++s;
|
||||
}
|
||||
*d = (char)0;
|
||||
}
|
||||
|
||||
/* Trim whitespace from beginning and end of string */
|
||||
void Anode_trim(char *s);
|
||||
|
||||
/* Get the length of a string */
|
||||
#ifdef ANODE_NO_STRING_H
|
||||
static inline unsigned int Anode_strlen(const char *s)
|
||||
{
|
||||
const char *ptr = s;
|
||||
while (*ptr) ++ptr;
|
||||
return (unsigned int)(ptr - s);
|
||||
}
|
||||
#else
|
||||
#define Anode_strlen(s) strlen((s))
|
||||
#endif
|
||||
|
||||
/* Returns number of milliseconds since the epoch (Java-style) */
|
||||
static inline uint64_t Anode_time64()
|
||||
{
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv,(void *)0);
|
||||
return ( (((uint64_t)tv.tv_sec) / 1000ULL) + ((uint64_t)(tv.tv_usec / 1000ULL)) );
|
||||
}
|
||||
|
||||
/* Returns number of seconds since the epoch (*nix style) */
|
||||
static inline unsigned long Anode_time()
|
||||
{
|
||||
struct timeval tv;
|
||||
gettimeofday(&tv,(void *)0);
|
||||
return (unsigned long)tv.tv_sec;
|
||||
}
|
||||
|
||||
/* Simple random function, not cryptographically safe */
|
||||
unsigned int Anode_rand();
|
||||
|
||||
/* Fast hex/ascii conversion */
|
||||
void Anode_to_hex(const unsigned char *b,unsigned int len,char *h,unsigned int hlen);
|
||||
void Anode_from_hex(const char *h,unsigned char *b,unsigned int blen);
|
||||
|
||||
/* Convert back and forth from base32 encoding */
|
||||
/* 5 bytes -> 8 base32 characters and vice versa */
|
||||
void Anode_base32_5_to_8(const unsigned char *in,char *out);
|
||||
void Anode_base32_8_to_5(const char *in,unsigned char *out);
|
||||
|
||||
#endif
|
34
attic/historic/anode/libanode/impl/mutex.h
Normal file
34
attic/historic/anode/libanode/impl/mutex.h
Normal file
@ -0,0 +1,34 @@
|
||||
/* libanode: the Anode C reference implementation
|
||||
* Copyright (C) 2009-2010 Adam Ierymenko <adam.ierymenko@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _ANODE_MUTEX_H
|
||||
#define _ANODE_MUTEX_H
|
||||
|
||||
#ifdef WINDOWS
|
||||
|
||||
#else /* WINDOWS */
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#define AnodeMutex pthread_mutex_t
|
||||
#define AnodeMutex_init(m) pthread_mutex_init((m),(const pthread_mutexattr_t *)0)
|
||||
#define AnodeMutex_destroy(m) pthread_mutex_destroy((m))
|
||||
#define AnodeMutex_lock(m) pthread_mutex_lock((m))
|
||||
#define AnodeMutex_unlock(m) pthread_mutex_unlock((m))
|
||||
|
||||
#endif /* WINDOWS */
|
||||
|
||||
#endif
|
58
attic/historic/anode/libanode/impl/thread.c
Normal file
58
attic/historic/anode/libanode/impl/thread.c
Normal file
@ -0,0 +1,58 @@
|
||||
/* libanode: the Anode C reference implementation
|
||||
* Copyright (C) 2009-2010 Adam Ierymenko <adam.ierymenko@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include "thread.h"
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef WINDOWS
|
||||
|
||||
#else /* not WINDOWS */
|
||||
|
||||
struct _AnodeThread
|
||||
{
|
||||
void (*func)(void *);
|
||||
void *arg;
|
||||
int wait_for_join;
|
||||
pthread_t thread;
|
||||
};
|
||||
|
||||
static void *_AnodeThread_main(void *arg)
|
||||
{
|
||||
((struct _AnodeThread *)arg)->func(((struct _AnodeThread *)arg)->arg);
|
||||
if (!((struct _AnodeThread *)arg)->wait_for_join)
|
||||
free(arg);
|
||||
return (void *)0;
|
||||
}
|
||||
|
||||
AnodeThread *AnodeThread_create(void (*func)(void *),void *arg,int wait_for_join)
|
||||
{
|
||||
struct _AnodeThread *t = malloc(sizeof(struct _AnodeThread));
|
||||
t->func = func;
|
||||
t->arg = arg;
|
||||
t->wait_for_join = wait_for_join;
|
||||
pthread_create(&t->thread,(const pthread_attr_t *)0,&_AnodeThread_main,(void *)t);
|
||||
if (!wait_for_join)
|
||||
pthread_detach(t->thread);
|
||||
return (AnodeThread *)t;
|
||||
}
|
||||
|
||||
void AnodeThread_join(AnodeThread *thread)
|
||||
{
|
||||
pthread_join(((struct _AnodeThread *)thread)->thread,(void **)0);
|
||||
free((void *)thread);
|
||||
}
|
||||
|
||||
#endif /* WINDOWS / not WINDOWS */
|
65
attic/historic/anode/libanode/impl/thread.h
Normal file
65
attic/historic/anode/libanode/impl/thread.h
Normal file
@ -0,0 +1,65 @@
|
||||
/* libanode: the Anode C reference implementation
|
||||
* Copyright (C) 2009-2010 Adam Ierymenko <adam.ierymenko@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _ANODE_THREAD_H
|
||||
#define _ANODE_THREAD_H
|
||||
|
||||
#ifdef WINDOWS
|
||||
|
||||
#include <windows.h>
|
||||
#include <thread.h>
|
||||
typedef DWORD AnodeThreadId;
|
||||
|
||||
#else /* not WINDOWS */
|
||||
|
||||
#include <pthread.h>
|
||||
typedef pthread_t AnodeThreadId;
|
||||
|
||||
#define AnodeThread_self() pthread_self()
|
||||
#define AnodeThreadId_equal(a,b) pthread_equal((pthread_t)(a),(pthread_t)(b))
|
||||
|
||||
#endif
|
||||
|
||||
typedef void AnodeThread;
|
||||
|
||||
/**
|
||||
* Create and launch a new thread
|
||||
*
|
||||
* If wait_for_join is true (nonzero), the thread can and must be joined. The
|
||||
* thread object won't be freed until join is called and returns. If
|
||||
* wait_for_join is false, the thread object frees itself automatically on
|
||||
* termination.
|
||||
*
|
||||
* If wait_for_join is false (zero), there is really no need to keep track of
|
||||
* the thread object.
|
||||
*
|
||||
* @param func Function to call as thread main
|
||||
* @param arg Argument to pass to function
|
||||
* @param wait_for_join If false, thread deletes itself when it terminates
|
||||
*/
|
||||
AnodeThread *AnodeThread_create(void (*func)(void *),void *arg,int wait_for_join);
|
||||
|
||||
/**
|
||||
* Wait for a thread to terminate and delete thread object
|
||||
*
|
||||
* This can only be used for threads created with wait_for_join set to true.
|
||||
* The thread object is no longer valid after this call.
|
||||
*
|
||||
* @param thread Thread to wait for termination and delete
|
||||
*/
|
||||
void AnodeThread_join(AnodeThread *thread);
|
||||
|
||||
#endif
|
25
attic/historic/anode/libanode/impl/types.h
Normal file
25
attic/historic/anode/libanode/impl/types.h
Normal file
@ -0,0 +1,25 @@
|
||||
/* libanode: the Anode C reference implementation
|
||||
* Copyright (C) 2009-2010 Adam Ierymenko <adam.ierymenko@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _ANODE_TYPES_H
|
||||
#define _ANODE_TYPES_H
|
||||
|
||||
#ifdef WINDOWS
|
||||
#else
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
#endif
|
136
attic/historic/anode/libanode/network_address.c
Normal file
136
attic/historic/anode/libanode/network_address.c
Normal file
@ -0,0 +1,136 @@
|
||||
/* libanode: the Anode C reference implementation
|
||||
* Copyright (C) 2009-2010 Adam Ierymenko <adam.ierymenko@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include "impl/misc.h"
|
||||
#include "impl/types.h"
|
||||
#include "anode.h"
|
||||
|
||||
const AnodeNetworkAddress AnodeNetworkAddress_ANY4 = {
|
||||
ANODE_NETWORK_ADDRESS_IPV4,
|
||||
{ 0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
|
||||
};
|
||||
const AnodeNetworkAddress AnodeNetworkAddress_ANY6 = {
|
||||
ANODE_NETWORK_ADDRESS_IPV6,
|
||||
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
|
||||
};
|
||||
const AnodeNetworkAddress AnodeNetworkAddress_LOCAL4 = {
|
||||
ANODE_NETWORK_ADDRESS_IPV4,
|
||||
{ 127,0,0,1, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
|
||||
};
|
||||
const AnodeNetworkAddress AnodeNetworkAddress_LOCAL6 = {
|
||||
ANODE_NETWORK_ADDRESS_IPV6,
|
||||
{ 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1 ,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
|
||||
};
|
||||
|
||||
int AnodeNetworkAddress_to_string(const AnodeNetworkAddress *address,char *buf,int len)
|
||||
{
|
||||
const char *s;
|
||||
|
||||
switch(address->type) {
|
||||
case ANODE_NETWORK_ADDRESS_IPV4:
|
||||
s = inet_ntop(AF_INET,(const void *)address->bits,buf,len);
|
||||
if (s)
|
||||
return Anode_strlen(s);
|
||||
else return ANODE_ERR_INVALID_ARGUMENT;
|
||||
break;
|
||||
case ANODE_NETWORK_ADDRESS_IPV6:
|
||||
s = inet_ntop(AF_INET6,address->bits,buf,len);
|
||||
if (s)
|
||||
return Anode_strlen(s);
|
||||
else return ANODE_ERR_INVALID_ARGUMENT;
|
||||
/*
|
||||
case ANODE_NETWORK_ADDRESS_ETHERNET:
|
||||
break;
|
||||
case ANODE_NETWORK_ADDRESS_USB:
|
||||
break;
|
||||
case ANODE_NETWORK_ADDRESS_BLUETOOTH:
|
||||
break;
|
||||
case ANODE_NETWORK_ADDRESS_IPC:
|
||||
break;
|
||||
case ANODE_NETWORK_ADDRESS_80211S:
|
||||
break;
|
||||
case ANODE_NETWORK_ADDRESS_SERIAL:
|
||||
break;
|
||||
*/
|
||||
case ANODE_NETWORK_ADDRESS_ANODE_256_40:
|
||||
return AnodeAddress_to_string((const AnodeAddress *)address->bits,buf,len);
|
||||
default:
|
||||
return ANODE_ERR_ADDRESS_TYPE_NOT_SUPPORTED;
|
||||
}
|
||||
}
|
||||
|
||||
int AnodeNetworkAddress_from_string(const char *str,AnodeNetworkAddress *address)
|
||||
{
|
||||
unsigned int dots = Anode_count_char(str,'.');
|
||||
unsigned int colons = Anode_count_char(str,':');
|
||||
|
||||
if ((dots == 3)&&(!colons)) {
|
||||
address->type = ANODE_NETWORK_ADDRESS_IPV4;
|
||||
if (inet_pton(AF_INET,str,address->bits) > 0)
|
||||
return 0;
|
||||
else return ANODE_ERR_INVALID_ARGUMENT;
|
||||
} else if ((colons)&&(!dots)) {
|
||||
address->type = ANODE_NETWORK_ADDRESS_IPV6;
|
||||
if (inet_pton(AF_INET6,str,address->bits) > 0)
|
||||
return 0;
|
||||
else return ANODE_ERR_INVALID_ARGUMENT;
|
||||
} else {
|
||||
address->type = ANODE_NETWORK_ADDRESS_ANODE_256_40;
|
||||
return AnodeAddress_from_string(str,(AnodeAddress *)address->bits);
|
||||
}
|
||||
}
|
||||
|
||||
int AnodeNetworkEndpoint_from_sockaddr(const void *sockaddr,AnodeNetworkEndpoint *endpoint)
|
||||
{
|
||||
switch(((struct sockaddr_storage *)sockaddr)->ss_family) {
|
||||
case AF_INET:
|
||||
*((uint32_t *)endpoint->address.bits) = (uint32_t)(((struct sockaddr_in *)sockaddr)->sin_addr.s_addr);
|
||||
endpoint->port = (int)ntohs(((struct sockaddr_in *)sockaddr)->sin_port);
|
||||
return 0;
|
||||
case AF_INET6:
|
||||
Anode_memcpy(endpoint->address.bits,((struct sockaddr_in6 *)sockaddr)->sin6_addr.s6_addr,16);
|
||||
endpoint->port = (int)ntohs(((struct sockaddr_in6 *)sockaddr)->sin6_port);
|
||||
return 0;
|
||||
default:
|
||||
return ANODE_ERR_INVALID_ARGUMENT;
|
||||
}
|
||||
}
|
||||
|
||||
int AnodeNetworkEndpoint_to_sockaddr(const AnodeNetworkEndpoint *endpoint,void *sockaddr,int sockaddr_len)
|
||||
{
|
||||
switch(endpoint->address.type) {
|
||||
case ANODE_NETWORK_ADDRESS_IPV4:
|
||||
if (sockaddr_len < (int)sizeof(struct sockaddr_in))
|
||||
return ANODE_ERR_BUFFER_TOO_SMALL;
|
||||
Anode_zero(sockaddr,sizeof(struct sockaddr_in));
|
||||
((struct sockaddr_in *)sockaddr)->sin_family = AF_INET;
|
||||
((struct sockaddr_in *)sockaddr)->sin_port = htons((uint16_t)endpoint->port);
|
||||
((struct sockaddr_in *)sockaddr)->sin_addr.s_addr = *((uint32_t *)endpoint->address.bits);
|
||||
return 0;
|
||||
case ANODE_NETWORK_ADDRESS_IPV6:
|
||||
if (sockaddr_len < (int)sizeof(struct sockaddr_in6))
|
||||
return ANODE_ERR_BUFFER_TOO_SMALL;
|
||||
Anode_zero(sockaddr,sizeof(struct sockaddr_in6));
|
||||
((struct sockaddr_in6 *)sockaddr)->sin6_family = AF_INET6;
|
||||
((struct sockaddr_in6 *)sockaddr)->sin6_port = htons((uint16_t)endpoint->port);
|
||||
Anode_memcpy(((struct sockaddr_in6 *)sockaddr)->sin6_addr.s6_addr,endpoint->address.bits,16);
|
||||
return 0;
|
||||
default:
|
||||
return ANODE_ERR_INVALID_ARGUMENT;
|
||||
}
|
||||
}
|
88
attic/historic/anode/libanode/secure_random.c
Normal file
88
attic/historic/anode/libanode/secure_random.c
Normal file
@ -0,0 +1,88 @@
|
||||
/* libanode: the Anode C reference implementation
|
||||
* Copyright (C) 2009-2010 Adam Ierymenko <adam.ierymenko@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "impl/aes.h"
|
||||
#include "impl/misc.h"
|
||||
#include "anode.h"
|
||||
|
||||
#ifdef WINDOWS
|
||||
#include <windows.h>
|
||||
#include <wincrypt.h>
|
||||
#endif
|
||||
|
||||
struct AnodeSecureRandomImpl
|
||||
{
|
||||
AnodeAesExpandedKey key;
|
||||
unsigned char state[ANODE_AES_BLOCK_SIZE];
|
||||
unsigned char block[ANODE_AES_BLOCK_SIZE];
|
||||
unsigned int ptr;
|
||||
};
|
||||
|
||||
AnodeSecureRandom *AnodeSecureRandom_new()
|
||||
{
|
||||
unsigned char keybuf[ANODE_AES_KEY_SIZE + ANODE_AES_BLOCK_SIZE + ANODE_AES_BLOCK_SIZE];
|
||||
unsigned int i;
|
||||
struct AnodeSecureRandomImpl *srng;
|
||||
|
||||
#ifdef WINDOWS
|
||||
HCRYPTPROV hProv;
|
||||
if (CryptAcquireContext(&hProv,NULL,NULL,PROV_RSA_FULL,CRYPT_VERIFYCONTEXT|CRYPT_SILENT)) {
|
||||
CryptGenRandom(hProv,sizeof(keybuf),keybuf);
|
||||
CryptReleaseContext(hProv,0);
|
||||
}
|
||||
#else
|
||||
FILE *urandf = fopen("/dev/urandom","rb");
|
||||
if (urandf) {
|
||||
fread((void *)keybuf,sizeof(keybuf),1,urandf);
|
||||
fclose(urandf);
|
||||
}
|
||||
#endif
|
||||
|
||||
for(i=0;i<sizeof(keybuf);++i)
|
||||
keybuf[i] ^= (unsigned char)(Anode_rand() >> 5);
|
||||
|
||||
srng = malloc(sizeof(struct AnodeSecureRandomImpl));
|
||||
Anode_aes256_expand_key(keybuf,&srng->key);
|
||||
for(i=0;i<ANODE_AES_BLOCK_SIZE;++i)
|
||||
srng->state[i] = keybuf[ANODE_AES_KEY_SIZE + i];
|
||||
for(i=0;i<ANODE_AES_BLOCK_SIZE;++i)
|
||||
srng->block[i] = keybuf[ANODE_AES_KEY_SIZE + ANODE_AES_KEY_SIZE + i];
|
||||
srng->ptr = ANODE_AES_BLOCK_SIZE;
|
||||
|
||||
return (AnodeSecureRandom *)srng;
|
||||
}
|
||||
|
||||
void AnodeSecureRandom_gen_bytes(AnodeSecureRandom *srng,void *buf,long count)
|
||||
{
|
||||
long i,j;
|
||||
|
||||
for(i=0;i<count;++i) {
|
||||
if (((struct AnodeSecureRandomImpl *)srng)->ptr == ANODE_AES_BLOCK_SIZE) {
|
||||
Anode_aes256_encrypt(&((struct AnodeSecureRandomImpl *)srng)->key,((struct AnodeSecureRandomImpl *)srng)->state,((struct AnodeSecureRandomImpl *)srng)->state);
|
||||
for(j=0;j<ANODE_AES_KEY_SIZE;++j)
|
||||
((struct AnodeSecureRandomImpl *)srng)->block[j] ^= ((struct AnodeSecureRandomImpl *)srng)->state[j];
|
||||
((struct AnodeSecureRandomImpl *)srng)->ptr = 0;
|
||||
}
|
||||
((unsigned char *)buf)[i] = ((struct AnodeSecureRandomImpl *)srng)->block[((struct AnodeSecureRandomImpl *)srng)->ptr++];
|
||||
}
|
||||
}
|
||||
|
||||
void AnodeSecureRandom_delete(AnodeSecureRandom *srng)
|
||||
{
|
||||
free(srng);
|
||||
}
|
948
attic/historic/anode/libanode/system_transport.c
Normal file
948
attic/historic/anode/libanode/system_transport.c
Normal file
@ -0,0 +1,948 @@
|
||||
/* libanode: the Anode C reference implementation
|
||||
* Copyright (C) 2009-2010 Adam Ierymenko <adam.ierymenko@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <netdb.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
#include <arpa/inet.h>
|
||||
#include "anode.h"
|
||||
#include "impl/mutex.h"
|
||||
#include "impl/thread.h"
|
||||
#include "impl/misc.h"
|
||||
#include "impl/dns_txt.h"
|
||||
|
||||
#ifdef WINDOWS
|
||||
#include <windows.h>
|
||||
#include <winsock2.h>
|
||||
#define AnodeSystemTransport__close_socket(s) closesocket((s))
|
||||
#define ANODE_USE_SELECT 1
|
||||
#else
|
||||
#include <poll.h>
|
||||
#include <unistd.h>
|
||||
#define AnodeSystemTransport__close_socket(s) close((s))
|
||||
#endif
|
||||
|
||||
static const char *AnodeSystemTransport_CLASS = "SystemTransport";
|
||||
|
||||
/* ======================================================================== */
|
||||
|
||||
struct AnodeSystemTransport;
|
||||
|
||||
struct AnodeSystemTransport_AnodeSocket
|
||||
{
|
||||
AnodeSocket base; /* must be first */
|
||||
unsigned int entry_idx;
|
||||
};
|
||||
|
||||
#define ANODE_SYSTEM_TRANSPORT_DNS_MAX_RESULTS 16
|
||||
struct AnodeSystemTransport__dns_request
|
||||
{
|
||||
struct AnodeSystemTransport__dns_request *next;
|
||||
|
||||
AnodeThread *thread;
|
||||
struct AnodeSystemTransport *owner;
|
||||
|
||||
void (*event_handler)(const AnodeEvent *event);
|
||||
|
||||
char name[256];
|
||||
enum AnodeTransportDnsIncludeMode ipv4_include_mode;
|
||||
enum AnodeTransportDnsIncludeMode ipv6_include_mode;
|
||||
enum AnodeTransportDnsIncludeMode anode_include_mode;
|
||||
|
||||
AnodeNetworkAddress addresses[ANODE_SYSTEM_TRANSPORT_DNS_MAX_RESULTS];
|
||||
unsigned int address_count;
|
||||
|
||||
int error_code;
|
||||
};
|
||||
|
||||
#ifdef ANODE_USE_SELECT
|
||||
typedef int AnodeSystemTransport__poll_fd; /* for select() */
|
||||
#else
|
||||
typedef struct pollfd AnodeSystemTransport__poll_fd; /* for poll() */
|
||||
#endif
|
||||
|
||||
struct AnodeSystemTransport
|
||||
{
|
||||
AnodeTransport interface; /* must be first */
|
||||
|
||||
AnodeTransport *base;
|
||||
|
||||
#ifdef ANODE_USE_SELECT
|
||||
FD_SET readfds;
|
||||
FD_SET writefds;
|
||||
#endif
|
||||
|
||||
void (*default_event_handler)(const AnodeEvent *event);
|
||||
|
||||
AnodeSystemTransport__poll_fd *fds;
|
||||
struct AnodeSystemTransport_AnodeSocket *sockets;
|
||||
unsigned int fd_count;
|
||||
unsigned int fd_capacity;
|
||||
|
||||
struct AnodeSystemTransport__dns_request *pending_dns_requests;
|
||||
|
||||
int invoke_pipe[2];
|
||||
AnodeMutex invoke_pipe_m;
|
||||
void *invoke_pipe_buf[2];
|
||||
unsigned int invoke_pipe_buf_ptr;
|
||||
};
|
||||
|
||||
/* ======================================================================== */
|
||||
/* Internal helper methods */
|
||||
|
||||
static unsigned int AnodeSystemTransport__add_entry(struct AnodeSystemTransport *transport)
|
||||
{
|
||||
if ((transport->fd_count + 1) > transport->fd_capacity) {
|
||||
transport->fd_capacity += 8;
|
||||
transport->fds = realloc(transport->fds,sizeof(AnodeSystemTransport__poll_fd) * transport->fd_capacity);
|
||||
transport->sockets = realloc(transport->sockets,sizeof(struct AnodeSystemTransport_AnodeSocket) * transport->fd_capacity);
|
||||
}
|
||||
return transport->fd_count++;
|
||||
}
|
||||
|
||||
static void AnodeSystemTransport__remove_entry(struct AnodeSystemTransport *transport,const unsigned int idx)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
--transport->fd_count;
|
||||
for(i=idx;i<transport->fd_count;++i) {
|
||||
Anode_memcpy(&transport->fds[i],&transport->fds[i+1],sizeof(AnodeSystemTransport__poll_fd));
|
||||
Anode_memcpy(&transport->sockets[i],&transport->sockets[i+1],sizeof(struct AnodeSystemTransport_AnodeSocket));
|
||||
}
|
||||
|
||||
if ((transport->fd_capacity - transport->fd_count) > 16) {
|
||||
transport->fd_capacity -= 16;
|
||||
transport->fds = realloc(transport->fds,sizeof(AnodeSystemTransport__poll_fd) * transport->fd_capacity);
|
||||
transport->sockets = realloc(transport->sockets,sizeof(struct AnodeSystemTransport_AnodeSocket) * transport->fd_capacity);
|
||||
}
|
||||
}
|
||||
|
||||
static void AnodeSystemTransport__dns_invoke_on_completion(void *_dreq)
|
||||
{
|
||||
struct AnodeSystemTransport__dns_request *dreq = (struct AnodeSystemTransport__dns_request *)_dreq;
|
||||
struct AnodeSystemTransport__dns_request *ptr,**lastnext;
|
||||
|
||||
AnodeThread_join(dreq->thread);
|
||||
|
||||
ptr = dreq->owner->pending_dns_requests;
|
||||
lastnext = &dreq->owner->pending_dns_requests;
|
||||
while (ptr) {
|
||||
if (ptr == dreq) {
|
||||
*lastnext = ptr->next;
|
||||
break;
|
||||
} else {
|
||||
lastnext = &ptr->next;
|
||||
ptr = ptr->next;
|
||||
}
|
||||
}
|
||||
|
||||
free(dreq);
|
||||
}
|
||||
|
||||
static void AnodeSystemTransport__dns_thread_main(void *_dreq)
|
||||
{
|
||||
struct AnodeSystemTransport__dns_request *dreq = (struct AnodeSystemTransport__dns_request *)_dreq;
|
||||
|
||||
dreq->owner->interface.invoke((AnodeTransport *)dreq->owner,dreq,&AnodeSystemTransport__dns_invoke_on_completion);
|
||||
}
|
||||
|
||||
static void AnodeSystemTransport__do_close(struct AnodeSystemTransport *transport,struct AnodeSystemTransport_AnodeSocket *sock,const int error_code,const int generate_event)
|
||||
{
|
||||
AnodeEvent evbuf;
|
||||
int fd;
|
||||
|
||||
if (sock->base.class_name == AnodeSystemTransport_CLASS) {
|
||||
#ifdef ANODE_USE_SELECT
|
||||
fd = (int)(transport->fds[((struct AnodeSystemTransport_AnodeSocket *)sock)->entry_idx]);
|
||||
#else
|
||||
fd = transport->fds[((struct AnodeSystemTransport_AnodeSocket *)sock)->entry_idx].fd;
|
||||
#endif
|
||||
|
||||
if ((sock->base.type == ANODE_SOCKET_STREAM_CONNECTION)&&(sock->base.state != ANODE_SOCKET_CLOSED)) {
|
||||
sock->base.state = ANODE_SOCKET_CLOSED;
|
||||
|
||||
if (generate_event) {
|
||||
evbuf.type = ANODE_TRANSPORT_EVENT_STREAM_CLOSED;
|
||||
evbuf.transport = (AnodeTransport *)transport;
|
||||
evbuf.sock = (AnodeSocket *)sock;
|
||||
evbuf.datagram_from = NULL;
|
||||
evbuf.dns_name = NULL;
|
||||
evbuf.dns_addresses = NULL;
|
||||
evbuf.dns_address_count = 0;
|
||||
evbuf.error_code = error_code;
|
||||
evbuf.data_length = 0;
|
||||
evbuf.data = NULL;
|
||||
|
||||
if (sock->base.event_handler)
|
||||
sock->base.event_handler(&evbuf);
|
||||
else if (transport->default_event_handler)
|
||||
transport->default_event_handler(&evbuf);
|
||||
}
|
||||
}
|
||||
|
||||
AnodeSystemTransport__close_socket(fd);
|
||||
AnodeSystemTransport__remove_entry(transport,((struct AnodeSystemTransport_AnodeSocket *)sock)->entry_idx);
|
||||
|
||||
#ifdef ANODE_USE_SELECT
|
||||
FD_CLR(sock,&THIS->readfds);
|
||||
FD_CLR(sock,&THIS->writefds);
|
||||
#endif
|
||||
} else transport->base->close(transport->base,(AnodeSocket *)sock);
|
||||
}
|
||||
|
||||
static int AnodeSystemTransport__populate_network_endpoint(const struct sockaddr_storage *saddr,AnodeNetworkEndpoint *ep)
|
||||
{
|
||||
switch(saddr->ss_family) {
|
||||
case AF_INET:
|
||||
ep->address.type = ANODE_NETWORK_ADDRESS_IPV4;
|
||||
*((uint32_t *)ep->address.bits) = ((struct sockaddr_in *)saddr)->sin_addr.s_addr;
|
||||
ep->port = ntohs(((struct sockaddr_in *)saddr)->sin_port);
|
||||
return 1;
|
||||
case AF_INET6:
|
||||
ep->address.type = ANODE_NETWORK_ADDRESS_IPV6;
|
||||
Anode_memcpy(ep->address.bits,((struct sockaddr_in6 *)saddr)->sin6_addr.s6_addr,16);
|
||||
ep->port = ntohs(((struct sockaddr_in6 *)saddr)->sin6_port);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ======================================================================== */
|
||||
|
||||
#ifdef THIS
|
||||
#undef THIS
|
||||
#endif
|
||||
#define THIS ((struct AnodeSystemTransport *)transport)
|
||||
|
||||
static void AnodeSystemTransport_invoke(AnodeTransport *transport,
|
||||
void *ptr,
|
||||
void (*func)(void *))
|
||||
{
|
||||
void *invoke_msg[2];
|
||||
|
||||
invoke_msg[0] = ptr;
|
||||
invoke_msg[1] = (void *)func;
|
||||
|
||||
AnodeMutex_lock(&THIS->invoke_pipe_m);
|
||||
write(THIS->invoke_pipe[1],(void *)(&invoke_msg),sizeof(invoke_msg));
|
||||
AnodeMutex_unlock(&THIS->invoke_pipe_m);
|
||||
}
|
||||
|
||||
static void AnodeSystemTransport_dns_resolve(AnodeTransport *transport,
|
||||
const char *name,
|
||||
void (*event_handler)(const AnodeEvent *),
|
||||
enum AnodeTransportDnsIncludeMode ipv4_include_mode,
|
||||
enum AnodeTransportDnsIncludeMode ipv6_include_mode,
|
||||
enum AnodeTransportDnsIncludeMode anode_include_mode)
|
||||
{
|
||||
struct AnodeSystemTransport__dns_request *dreq = malloc(sizeof(struct AnodeSystemTransport__dns_request));
|
||||
|
||||
dreq->owner = THIS;
|
||||
dreq->event_handler = event_handler;
|
||||
Anode_str_copy(dreq->name,name,sizeof(dreq->name));
|
||||
dreq->ipv4_include_mode = ipv4_include_mode;
|
||||
dreq->ipv6_include_mode = ipv6_include_mode;
|
||||
dreq->anode_include_mode = anode_include_mode;
|
||||
|
||||
dreq->address_count = 0;
|
||||
dreq->error_code = 0;
|
||||
|
||||
dreq->next = THIS->pending_dns_requests;
|
||||
THIS->pending_dns_requests = dreq;
|
||||
|
||||
dreq->thread = AnodeThread_create(&AnodeSystemTransport__dns_thread_main,dreq,0);
|
||||
}
|
||||
|
||||
static AnodeSocket *AnodeSystemTransport_datagram_listen(AnodeTransport *transport,
|
||||
const AnodeNetworkAddress *local_address,
|
||||
int local_port,
|
||||
int *error_code)
|
||||
{
|
||||
struct sockaddr_in sin4;
|
||||
struct sockaddr_in6 sin6;
|
||||
struct AnodeSystemTransport_AnodeSocket *sock;
|
||||
unsigned int entry_idx;
|
||||
int fd;
|
||||
int tmp;
|
||||
|
||||
switch(local_address->type) {
|
||||
case ANODE_NETWORK_ADDRESS_IPV4:
|
||||
fd = socket(AF_INET,SOCK_DGRAM,0);
|
||||
if (fd <= 0) {
|
||||
*error_code = ANODE_ERR_UNABLE_TO_BIND;
|
||||
return (AnodeSocket *)0;
|
||||
}
|
||||
tmp = 1;
|
||||
setsockopt(fd,SOL_SOCKET,SO_REUSEADDR,&tmp,sizeof(tmp));
|
||||
fcntl(fd,F_SETFL,O_NONBLOCK);
|
||||
|
||||
Anode_zero(&sin4,sizeof(struct sockaddr_in));
|
||||
sin4.sin_family = AF_INET;
|
||||
sin4.sin_port = htons(local_port);
|
||||
sin4.sin_addr.s_addr = *((uint32_t *)local_address->bits);
|
||||
|
||||
if (bind(fd,(const struct sockaddr *)&sin4,sizeof(sin4))) {
|
||||
AnodeSystemTransport__close_socket(fd);
|
||||
*error_code = ANODE_ERR_UNABLE_TO_BIND;
|
||||
return (AnodeSocket *)0;
|
||||
}
|
||||
break;
|
||||
case ANODE_NETWORK_ADDRESS_IPV6:
|
||||
fd = socket(AF_INET6,SOCK_DGRAM,0);
|
||||
if (fd <= 0) {
|
||||
*error_code = ANODE_ERR_UNABLE_TO_BIND;
|
||||
return (AnodeSocket *)0;
|
||||
}
|
||||
tmp = 1; setsockopt(fd,SOL_SOCKET,SO_REUSEADDR,&tmp,sizeof(tmp));
|
||||
fcntl(fd,F_SETFL,O_NONBLOCK);
|
||||
#ifdef IPV6_V6ONLY
|
||||
tmp = 1; setsockopt(fd,IPPROTO_IPV6,IPV6_V6ONLY,&tmp,sizeof(tmp));
|
||||
#endif
|
||||
|
||||
Anode_zero(&sin6,sizeof(struct sockaddr_in6));
|
||||
sin6.sin6_family = AF_INET6;
|
||||
sin6.sin6_port = htons(local_port);
|
||||
Anode_memcpy(sin6.sin6_addr.s6_addr,local_address->bits,16);
|
||||
|
||||
if (bind(fd,(const struct sockaddr *)&sin6,sizeof(sin6))) {
|
||||
AnodeSystemTransport__close_socket(fd);
|
||||
*error_code = ANODE_ERR_UNABLE_TO_BIND;
|
||||
return (AnodeSocket *)0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (THIS->base)
|
||||
return THIS->base->datagram_listen(THIS->base,local_address,local_port,error_code);
|
||||
else {
|
||||
*error_code = ANODE_ERR_ADDRESS_TYPE_NOT_SUPPORTED;
|
||||
return (AnodeSocket *)0;
|
||||
}
|
||||
}
|
||||
|
||||
entry_idx = AnodeSystemTransport__add_entry(THIS);
|
||||
sock = &(THIS->sockets[entry_idx]);
|
||||
|
||||
sock->base.type = ANODE_SOCKET_DATAGRAM;
|
||||
sock->base.state = ANODE_SOCKET_OPEN;
|
||||
Anode_memcpy(&sock->base.endpoint.address,local_address,sizeof(AnodeNetworkAddress));
|
||||
sock->base.endpoint.port = local_port;
|
||||
sock->base.class_name = AnodeSystemTransport_CLASS;
|
||||
sock->base.user_ptr[0] = NULL;
|
||||
sock->base.user_ptr[1] = NULL;
|
||||
sock->base.event_handler = NULL;
|
||||
sock->entry_idx = entry_idx;
|
||||
|
||||
THIS->fds[entry_idx].fd = fd;
|
||||
THIS->fds[entry_idx].events = POLLIN;
|
||||
THIS->fds[entry_idx].revents = 0;
|
||||
|
||||
*error_code = 0;
|
||||
return (AnodeSocket *)sock;
|
||||
}
|
||||
|
||||
static AnodeSocket *AnodeSystemTransport_stream_listen(AnodeTransport *transport,
|
||||
const AnodeNetworkAddress *local_address,
|
||||
int local_port,
|
||||
int *error_code)
|
||||
{
|
||||
struct sockaddr_in sin4;
|
||||
struct sockaddr_in6 sin6;
|
||||
struct AnodeSystemTransport_AnodeSocket *sock;
|
||||
unsigned int entry_idx;
|
||||
int fd;
|
||||
int tmp;
|
||||
|
||||
switch(local_address->type) {
|
||||
case ANODE_NETWORK_ADDRESS_IPV4:
|
||||
fd = socket(AF_INET,SOCK_STREAM,0);
|
||||
if (fd < 0) {
|
||||
*error_code = ANODE_ERR_UNABLE_TO_BIND;
|
||||
return (AnodeSocket *)0;
|
||||
}
|
||||
fcntl(fd,F_SETFL,O_NONBLOCK);
|
||||
|
||||
Anode_zero(&sin4,sizeof(struct sockaddr_in));
|
||||
sin4.sin_family = AF_INET;
|
||||
sin4.sin_port = htons(local_port);
|
||||
sin4.sin_addr.s_addr = *((uint32_t *)local_address->bits);
|
||||
|
||||
if (bind(fd,(const struct sockaddr *)&sin4,sizeof(sin4))) {
|
||||
AnodeSystemTransport__close_socket(fd);
|
||||
*error_code = ANODE_ERR_UNABLE_TO_BIND;
|
||||
return (AnodeSocket *)0;
|
||||
}
|
||||
if (listen(fd,8)) {
|
||||
AnodeSystemTransport__close_socket(fd);
|
||||
*error_code = ANODE_ERR_UNABLE_TO_BIND;
|
||||
return (AnodeSocket *)0;
|
||||
}
|
||||
break;
|
||||
case ANODE_NETWORK_ADDRESS_IPV6:
|
||||
fd = socket(AF_INET6,SOCK_STREAM,0);
|
||||
if (fd < 0) {
|
||||
*error_code = ANODE_ERR_UNABLE_TO_BIND;
|
||||
return (AnodeSocket *)0;
|
||||
}
|
||||
fcntl(fd,F_SETFL,O_NONBLOCK);
|
||||
#ifdef IPV6_V6ONLY
|
||||
tmp = 1; setsockopt(fd,IPPROTO_IPV6,IPV6_V6ONLY,&tmp,sizeof(tmp));
|
||||
#endif
|
||||
|
||||
Anode_zero(&sin6,sizeof(struct sockaddr_in6));
|
||||
sin6.sin6_family = AF_INET6;
|
||||
sin6.sin6_port = htons(local_port);
|
||||
Anode_memcpy(sin6.sin6_addr.s6_addr,local_address->bits,16);
|
||||
|
||||
if (bind(fd,(const struct sockaddr *)&sin6,sizeof(sin6))) {
|
||||
AnodeSystemTransport__close_socket(fd);
|
||||
*error_code = ANODE_ERR_UNABLE_TO_BIND;
|
||||
return (AnodeSocket *)0;
|
||||
}
|
||||
if (listen(fd,8)) {
|
||||
AnodeSystemTransport__close_socket(fd);
|
||||
*error_code = ANODE_ERR_UNABLE_TO_BIND;
|
||||
return (AnodeSocket *)0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (THIS->base)
|
||||
return THIS->base->stream_listen(THIS->base,local_address,local_port,error_code);
|
||||
else {
|
||||
*error_code = ANODE_ERR_ADDRESS_TYPE_NOT_SUPPORTED;
|
||||
return (AnodeSocket *)0;
|
||||
}
|
||||
}
|
||||
|
||||
entry_idx = AnodeSystemTransport__add_entry(THIS);
|
||||
sock = &(THIS->sockets[entry_idx]);
|
||||
|
||||
sock->base.type = ANODE_SOCKET_STREAM_LISTEN;
|
||||
sock->base.state = ANODE_SOCKET_OPEN;
|
||||
Anode_memcpy(&sock->base.endpoint.address,local_address,sizeof(AnodeNetworkAddress));
|
||||
sock->base.endpoint.port = local_port;
|
||||
sock->base.class_name = AnodeSystemTransport_CLASS;
|
||||
sock->base.user_ptr[0] = NULL;
|
||||
sock->base.user_ptr[1] = NULL;
|
||||
sock->base.event_handler = NULL;
|
||||
sock->entry_idx = entry_idx;
|
||||
|
||||
THIS->fds[entry_idx].fd = fd;
|
||||
THIS->fds[entry_idx].events = POLLIN;
|
||||
THIS->fds[entry_idx].revents = 0;
|
||||
|
||||
*error_code = 0;
|
||||
return (AnodeSocket *)sock;
|
||||
}
|
||||
|
||||
static int AnodeSystemTransport_datagram_send(AnodeTransport *transport,
|
||||
AnodeSocket *sock,
|
||||
const void *data,
|
||||
int data_len,
|
||||
const AnodeNetworkEndpoint *to_endpoint)
|
||||
{
|
||||
struct sockaddr_in sin4;
|
||||
struct sockaddr_in6 sin6;
|
||||
|
||||
#ifdef ANODE_USE_SELECT
|
||||
const int fd = (int)(THIS->fds[((struct AnodeSystemTransport_AnodeSocket *)sock)->entry_idx]);
|
||||
#else
|
||||
const int fd = THIS->fds[((struct AnodeSystemTransport_AnodeSocket *)sock)->entry_idx].fd;
|
||||
#endif
|
||||
|
||||
switch(to_endpoint->address.type) {
|
||||
case ANODE_NETWORK_ADDRESS_IPV4:
|
||||
Anode_zero(&sin4,sizeof(struct sockaddr_in));
|
||||
sin4.sin_family = AF_INET;
|
||||
sin4.sin_port = htons((uint16_t)to_endpoint->port);
|
||||
sin4.sin_addr.s_addr = *((uint32_t *)to_endpoint->address.bits);
|
||||
sendto(fd,data,data_len,0,(struct sockaddr *)&sin4,sizeof(sin4));
|
||||
return 0;
|
||||
case ANODE_NETWORK_ADDRESS_IPV6:
|
||||
Anode_zero(&sin6,sizeof(struct sockaddr_in6));
|
||||
sin6.sin6_family = AF_INET6;
|
||||
sin6.sin6_port = htons((uint16_t)to_endpoint->port);
|
||||
Anode_memcpy(sin6.sin6_addr.s6_addr,to_endpoint->address.bits,16);
|
||||
sendto(fd,data,data_len,0,(struct sockaddr *)&sin6,sizeof(sin6));
|
||||
return 0;
|
||||
default:
|
||||
if (THIS->base)
|
||||
return THIS->base->datagram_send(THIS->base,sock,data,data_len,to_endpoint);
|
||||
else return ANODE_ERR_ADDRESS_TYPE_NOT_SUPPORTED;
|
||||
}
|
||||
}
|
||||
|
||||
static AnodeSocket *AnodeSystemTransport_stream_connect(AnodeTransport *transport,
|
||||
const AnodeNetworkEndpoint *to_endpoint,
|
||||
int *error_code)
|
||||
{
|
||||
struct sockaddr_in sin4;
|
||||
struct sockaddr_in6 sin6;
|
||||
struct AnodeSystemTransport_AnodeSocket *sock;
|
||||
unsigned int entry_idx;
|
||||
int fd;
|
||||
|
||||
switch(to_endpoint->address.type) {
|
||||
case ANODE_NETWORK_ADDRESS_IPV4:
|
||||
Anode_zero(&sin4,sizeof(struct sockaddr_in));
|
||||
sin4.sin_family = AF_INET;
|
||||
sin4.sin_port = htons(to_endpoint->port);
|
||||
sin4.sin_addr.s_addr = *((uint32_t *)to_endpoint->address.bits);
|
||||
|
||||
fd = socket(AF_INET,SOCK_STREAM,0);
|
||||
if (fd < 0) {
|
||||
*error_code = ANODE_ERR_ADDRESS_TYPE_NOT_SUPPORTED;
|
||||
return (AnodeSocket *)0;
|
||||
}
|
||||
fcntl(fd,F_SETFL,O_NONBLOCK);
|
||||
|
||||
if (connect(fd,(struct sockaddr *)&sin4,sizeof(sin4))) {
|
||||
if (errno != EINPROGRESS) {
|
||||
*error_code = ANODE_ERR_CONNECT_FAILED;
|
||||
AnodeSystemTransport__close_socket(fd);
|
||||
return (AnodeSocket *)0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ANODE_NETWORK_ADDRESS_IPV6:
|
||||
Anode_zero(&sin6,sizeof(struct sockaddr_in6));
|
||||
sin6.sin6_family = AF_INET6;
|
||||
sin6.sin6_port = htons(to_endpoint->port);
|
||||
Anode_memcpy(sin6.sin6_addr.s6_addr,to_endpoint->address.bits,16);
|
||||
|
||||
fd = socket(AF_INET6,SOCK_STREAM,0);
|
||||
if (fd < 0) {
|
||||
*error_code = ANODE_ERR_ADDRESS_TYPE_NOT_SUPPORTED;
|
||||
return (AnodeSocket *)0;
|
||||
}
|
||||
fcntl(fd,F_SETFL,O_NONBLOCK);
|
||||
|
||||
if (connect(fd,(struct sockaddr *)&sin6,sizeof(sin6))) {
|
||||
if (errno == EINPROGRESS) {
|
||||
*error_code = ANODE_ERR_CONNECT_FAILED;
|
||||
AnodeSystemTransport__close_socket(fd);
|
||||
return (AnodeSocket *)0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
if (THIS->base)
|
||||
return THIS->base->stream_connect(THIS->base,to_endpoint,error_code);
|
||||
else {
|
||||
*error_code = ANODE_ERR_ADDRESS_TYPE_NOT_SUPPORTED;
|
||||
return (AnodeSocket *)0;
|
||||
}
|
||||
}
|
||||
|
||||
entry_idx = AnodeSystemTransport__add_entry(THIS);
|
||||
sock = &(THIS->sockets[entry_idx]);
|
||||
|
||||
sock->base.type = ANODE_SOCKET_STREAM_CONNECTION;
|
||||
sock->base.state = ANODE_SOCKET_CONNECTING;
|
||||
Anode_memcpy(&sock->base.endpoint,to_endpoint,sizeof(AnodeNetworkEndpoint));
|
||||
sock->base.class_name = AnodeSystemTransport_CLASS;
|
||||
sock->base.user_ptr[0] = NULL;
|
||||
sock->base.user_ptr[1] = NULL;
|
||||
sock->base.event_handler = NULL;
|
||||
sock->entry_idx = entry_idx;
|
||||
|
||||
THIS->fds[entry_idx].fd = fd;
|
||||
THIS->fds[entry_idx].events = POLLIN|POLLOUT;
|
||||
THIS->fds[entry_idx].revents = 0;
|
||||
|
||||
return (AnodeSocket *)sock;
|
||||
}
|
||||
|
||||
static void AnodeSystemTransport_stream_start_writing(AnodeTransport *transport,
|
||||
AnodeSocket *sock)
|
||||
{
|
||||
if ((sock->type == ANODE_SOCKET_STREAM_CONNECTION)&&(((struct AnodeSystemTransport_AnodeSocket *)sock)->base.state == ANODE_SOCKET_OPEN)) {
|
||||
if (sock->class_name == AnodeSystemTransport_CLASS) {
|
||||
#ifdef ANODE_USE_SELECT
|
||||
FD_SET((int)(THIS->fds[((struct AnodeSystemTransport_AnodeSocket *)sock)->entry_idx]),&THIS->writefds);
|
||||
#else
|
||||
THIS->fds[((struct AnodeSystemTransport_AnodeSocket *)sock)->entry_idx].events = (POLLIN|POLLOUT);
|
||||
#endif
|
||||
} else THIS->base->stream_start_writing(THIS->base,sock);
|
||||
}
|
||||
}
|
||||
|
||||
static void AnodeSystemTransport_stream_stop_writing(AnodeTransport *transport,
|
||||
AnodeSocket *sock)
|
||||
{
|
||||
if ((sock->type == ANODE_SOCKET_STREAM_CONNECTION)&&(((struct AnodeSystemTransport_AnodeSocket *)sock)->base.state == ANODE_SOCKET_OPEN)) {
|
||||
if (sock->class_name == AnodeSystemTransport_CLASS) {
|
||||
#ifdef ANODE_USE_SELECT
|
||||
FD_CLR((int)(THIS->fds[((struct AnodeSystemTransport_AnodeSocket *)sock)->entry_idx]),&THIS->writefds);
|
||||
#else
|
||||
THIS->fds[((struct AnodeSystemTransport_AnodeSocket *)sock)->entry_idx].events = POLLIN;
|
||||
#endif
|
||||
} else THIS->base->stream_stop_writing(THIS->base,sock);
|
||||
}
|
||||
}
|
||||
|
||||
static int AnodeSystemTransport_stream_send(AnodeTransport *transport,
|
||||
AnodeSocket *sock,
|
||||
const void *data,
|
||||
int data_len)
|
||||
{
|
||||
int result;
|
||||
|
||||
if (sock->type == ANODE_SOCKET_STREAM_CONNECTION) {
|
||||
if (sock->class_name == AnodeSystemTransport_CLASS) {
|
||||
if (((struct AnodeSystemTransport_AnodeSocket *)sock)->base.state != ANODE_SOCKET_OPEN)
|
||||
return ANODE_ERR_CONNECTION_CLOSED;
|
||||
|
||||
#ifdef ANODE_USE_SELECT
|
||||
result = send((int)(THIS->fds[((struct AnodeSystemTransport_AnodeSocket *)sock)->entry_idx]),data,data_len,0);
|
||||
#else
|
||||
result = send(THIS->fds[((struct AnodeSystemTransport_AnodeSocket *)sock)->entry_idx].fd,data,data_len,0);
|
||||
#endif
|
||||
|
||||
if (result >= 0)
|
||||
return result;
|
||||
else {
|
||||
AnodeSystemTransport__do_close(THIS,(struct AnodeSystemTransport_AnodeSocket *)sock,ANODE_ERR_CONNECTION_CLOSED_BY_REMOTE,1);
|
||||
return ANODE_ERR_CONNECTION_CLOSED;
|
||||
}
|
||||
} else return THIS->base->stream_send(THIS->base,sock,data,data_len);
|
||||
} else return ANODE_ERR_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
static void AnodeSystemTransport_close(AnodeTransport *transport,
|
||||
AnodeSocket *sock)
|
||||
{
|
||||
AnodeSystemTransport__do_close(THIS,(struct AnodeSystemTransport_AnodeSocket *)sock,0,1);
|
||||
}
|
||||
|
||||
static void AnodeSystemTransport__poll_do_read_datagram(struct AnodeSystemTransport *transport,int fd,struct AnodeSystemTransport_AnodeSocket *sock)
|
||||
{
|
||||
char buf[16384];
|
||||
struct sockaddr_storage fromaddr;
|
||||
AnodeNetworkEndpoint tmp_ep;
|
||||
AnodeEvent evbuf;
|
||||
socklen_t addrlen;
|
||||
int n;
|
||||
|
||||
addrlen = sizeof(struct sockaddr_storage);
|
||||
n = recvfrom(fd,buf,sizeof(buf),0,(struct sockaddr *)&fromaddr,&addrlen);
|
||||
if ((n >= 0)&&(AnodeSystemTransport__populate_network_endpoint(&fromaddr,&tmp_ep))) {
|
||||
evbuf.type = ANODE_TRANSPORT_EVENT_DATAGRAM_RECEIVED;
|
||||
evbuf.transport = (AnodeTransport *)transport;
|
||||
evbuf.sock = (AnodeSocket *)sock;
|
||||
evbuf.datagram_from = &tmp_ep;
|
||||
evbuf.dns_name = NULL;
|
||||
evbuf.dns_addresses = NULL;
|
||||
evbuf.dns_address_count = 0;
|
||||
evbuf.error_code = 0;
|
||||
evbuf.data_length = n;
|
||||
evbuf.data = buf;
|
||||
|
||||
if (sock->base.event_handler)
|
||||
sock->base.event_handler(&evbuf);
|
||||
else if (transport->default_event_handler)
|
||||
transport->default_event_handler(&evbuf);
|
||||
}
|
||||
}
|
||||
|
||||
static void AnodeSystemTransport__poll_do_accept_incoming_connection(struct AnodeSystemTransport *transport,int fd,struct AnodeSystemTransport_AnodeSocket *sock)
|
||||
{
|
||||
struct sockaddr_storage fromaddr;
|
||||
AnodeNetworkEndpoint tmp_ep;
|
||||
AnodeEvent evbuf;
|
||||
struct AnodeSystemTransport_AnodeSocket *newsock;
|
||||
socklen_t addrlen;
|
||||
int n;
|
||||
unsigned int entry_idx;
|
||||
|
||||
addrlen = sizeof(struct sockaddr_storage);
|
||||
n = accept(fd,(struct sockaddr *)&fromaddr,&addrlen);
|
||||
if ((n >= 0)&&(AnodeSystemTransport__populate_network_endpoint(&fromaddr,&tmp_ep))) {
|
||||
entry_idx = AnodeSystemTransport__add_entry(transport);
|
||||
newsock = &(transport->sockets[entry_idx]);
|
||||
|
||||
newsock->base.type = ANODE_SOCKET_STREAM_CONNECTION;
|
||||
newsock->base.state = ANODE_SOCKET_OPEN;
|
||||
Anode_memcpy(&newsock->base.endpoint,&tmp_ep,sizeof(AnodeNetworkEndpoint));
|
||||
newsock->base.class_name = AnodeSystemTransport_CLASS;
|
||||
newsock->base.user_ptr[0] = NULL;
|
||||
newsock->base.user_ptr[1] = NULL;
|
||||
newsock->base.event_handler = NULL;
|
||||
newsock->entry_idx = entry_idx;
|
||||
|
||||
THIS->fds[entry_idx].fd = n;
|
||||
THIS->fds[entry_idx].events = POLLIN;
|
||||
THIS->fds[entry_idx].revents = 0;
|
||||
|
||||
evbuf.type = ANODE_TRANSPORT_EVENT_STREAM_INCOMING_CONNECT;
|
||||
evbuf.transport = (AnodeTransport *)transport;
|
||||
evbuf.sock = (AnodeSocket *)newsock;
|
||||
evbuf.datagram_from = NULL;
|
||||
evbuf.dns_name = NULL;
|
||||
evbuf.dns_addresses = NULL;
|
||||
evbuf.dns_address_count = 0;
|
||||
evbuf.error_code = 0;
|
||||
evbuf.data_length = 0;
|
||||
evbuf.data = NULL;
|
||||
|
||||
if (sock->base.event_handler)
|
||||
sock->base.event_handler(&evbuf);
|
||||
else if (transport->default_event_handler)
|
||||
transport->default_event_handler(&evbuf);
|
||||
}
|
||||
}
|
||||
|
||||
static void AnodeSystemTransport__poll_do_read_stream(struct AnodeSystemTransport *transport,int fd,struct AnodeSystemTransport_AnodeSocket *sock)
|
||||
{
|
||||
char buf[65536];
|
||||
AnodeEvent evbuf;
|
||||
int n;
|
||||
|
||||
n = recv(fd,buf,sizeof(buf),0);
|
||||
if (n > 0) {
|
||||
evbuf.type = ANODE_TRANSPORT_EVENT_STREAM_DATA_RECEIVED;
|
||||
evbuf.transport = (AnodeTransport *)transport;
|
||||
evbuf.sock = (AnodeSocket *)sock;
|
||||
evbuf.datagram_from = NULL;
|
||||
evbuf.dns_name = NULL;
|
||||
evbuf.dns_addresses = NULL;
|
||||
evbuf.dns_address_count = 0;
|
||||
evbuf.error_code = 0;
|
||||
evbuf.data_length = n;
|
||||
evbuf.data = buf;
|
||||
|
||||
if (sock->base.event_handler)
|
||||
sock->base.event_handler(&evbuf);
|
||||
else if (transport->default_event_handler)
|
||||
transport->default_event_handler(&evbuf);
|
||||
} else AnodeSystemTransport__do_close(transport,sock,ANODE_ERR_CONNECTION_CLOSED_BY_REMOTE,1);
|
||||
}
|
||||
|
||||
static void AnodeSystemTransport__poll_do_stream_available_for_write(struct AnodeSystemTransport *transport,int fd,struct AnodeSystemTransport_AnodeSocket *sock)
|
||||
{
|
||||
AnodeEvent evbuf;
|
||||
|
||||
evbuf.type = ANODE_TRANSPORT_EVENT_STREAM_DATA_RECEIVED;
|
||||
evbuf.transport = (AnodeTransport *)transport;
|
||||
evbuf.sock = (AnodeSocket *)sock;
|
||||
evbuf.datagram_from = NULL;
|
||||
evbuf.dns_name = NULL;
|
||||
evbuf.dns_addresses = NULL;
|
||||
evbuf.dns_address_count = 0;
|
||||
evbuf.error_code = 0;
|
||||
evbuf.data_length = 0;
|
||||
evbuf.data = NULL;
|
||||
|
||||
if (sock->base.event_handler)
|
||||
sock->base.event_handler(&evbuf);
|
||||
else if (transport->default_event_handler)
|
||||
transport->default_event_handler(&evbuf);
|
||||
}
|
||||
|
||||
static void AnodeSystemTransport__poll_do_outgoing_connect(struct AnodeSystemTransport *transport,int fd,struct AnodeSystemTransport_AnodeSocket *sock)
|
||||
{
|
||||
AnodeEvent evbuf;
|
||||
int err_code;
|
||||
socklen_t optlen;
|
||||
|
||||
optlen = sizeof(err_code);
|
||||
if (getsockopt(fd,SOL_SOCKET,SO_ERROR,(void *)&err_code,&optlen)) {
|
||||
/* Error getting result, so we assume a failure */
|
||||
evbuf.type = ANODE_TRANSPORT_EVENT_STREAM_OUTGOING_CONNECT_FAILED;
|
||||
evbuf.transport = (AnodeTransport *)transport;
|
||||
evbuf.sock = (AnodeSocket *)sock;
|
||||
evbuf.datagram_from = NULL;
|
||||
evbuf.dns_name = NULL;
|
||||
evbuf.dns_addresses = NULL;
|
||||
evbuf.dns_address_count = 0;
|
||||
evbuf.error_code = ANODE_ERR_CONNECT_FAILED;
|
||||
evbuf.data_length = 0;
|
||||
evbuf.data = NULL;
|
||||
|
||||
AnodeSystemTransport__do_close(transport,sock,0,0);
|
||||
} else if (err_code) {
|
||||
/* Error code is nonzero, so connect failed */
|
||||
evbuf.type = ANODE_TRANSPORT_EVENT_STREAM_OUTGOING_CONNECT_FAILED;
|
||||
evbuf.transport = (AnodeTransport *)transport;
|
||||
evbuf.sock = (AnodeSocket *)sock;
|
||||
evbuf.datagram_from = NULL;
|
||||
evbuf.dns_name = NULL;
|
||||
evbuf.dns_addresses = NULL;
|
||||
evbuf.dns_address_count = 0;
|
||||
evbuf.error_code = ANODE_ERR_CONNECT_FAILED;
|
||||
evbuf.data_length = 0;
|
||||
evbuf.data = NULL;
|
||||
|
||||
AnodeSystemTransport__do_close(transport,sock,0,0);
|
||||
} else {
|
||||
/* Connect succeeded */
|
||||
evbuf.type = ANODE_TRANSPORT_EVENT_STREAM_OUTGOING_CONNECT_ESTABLISHED;
|
||||
evbuf.transport = (AnodeTransport *)transport;
|
||||
evbuf.sock = (AnodeSocket *)sock;
|
||||
evbuf.datagram_from = NULL;
|
||||
evbuf.dns_name = NULL;
|
||||
evbuf.dns_addresses = NULL;
|
||||
evbuf.dns_address_count = 0;
|
||||
evbuf.error_code = 0;
|
||||
evbuf.data_length = 0;
|
||||
evbuf.data = NULL;
|
||||
}
|
||||
|
||||
if (sock->base.event_handler)
|
||||
sock->base.event_handler(&evbuf);
|
||||
else if (transport->default_event_handler)
|
||||
transport->default_event_handler(&evbuf);
|
||||
}
|
||||
|
||||
static int AnodeSystemTransport_poll(AnodeTransport *transport)
|
||||
{
|
||||
int timeout = -1;
|
||||
unsigned int fd_idx;
|
||||
int event_count = 0;
|
||||
int n;
|
||||
|
||||
if (poll((struct pollfd *)THIS->fds,THIS->fd_count,timeout) > 0) {
|
||||
for(fd_idx=0;fd_idx<THIS->fd_count;++fd_idx) {
|
||||
if ((THIS->fds[fd_idx].revents & (POLLERR|POLLHUP|POLLNVAL))) {
|
||||
if (THIS->sockets[fd_idx].base.type == ANODE_SOCKET_STREAM_CONNECTION) {
|
||||
if (THIS->sockets[fd_idx].base.state == ANODE_SOCKET_CONNECTING)
|
||||
AnodeSystemTransport__poll_do_outgoing_connect(THIS,THIS->fds[fd_idx].fd,&THIS->sockets[fd_idx]);
|
||||
else AnodeSystemTransport__do_close(THIS,&THIS->sockets[fd_idx],ANODE_ERR_CONNECTION_CLOSED_BY_REMOTE,1);
|
||||
++event_count;
|
||||
}
|
||||
} else {
|
||||
if ((THIS->fds[fd_idx].revents & POLLIN)) {
|
||||
if (THIS->fds[fd_idx].fd == THIS->invoke_pipe[0]) {
|
||||
n = read(THIS->invoke_pipe[0],&(((unsigned char *)(&(THIS->invoke_pipe_buf)))[THIS->invoke_pipe_buf_ptr]),sizeof(THIS->invoke_pipe_buf) - THIS->invoke_pipe_buf_ptr);
|
||||
if (n > 0) {
|
||||
THIS->invoke_pipe_buf_ptr += (unsigned int)n;
|
||||
if (THIS->invoke_pipe_buf_ptr >= sizeof(THIS->invoke_pipe_buf)) {
|
||||
THIS->invoke_pipe_buf_ptr -= sizeof(THIS->invoke_pipe_buf);
|
||||
((void (*)(void *))(THIS->invoke_pipe_buf[1]))(THIS->invoke_pipe_buf[0]);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
switch(THIS->sockets[fd_idx].base.type) {
|
||||
case ANODE_SOCKET_DATAGRAM:
|
||||
AnodeSystemTransport__poll_do_read_datagram(THIS,THIS->fds[fd_idx].fd,&THIS->sockets[fd_idx]);
|
||||
break;
|
||||
case ANODE_SOCKET_STREAM_LISTEN:
|
||||
AnodeSystemTransport__poll_do_accept_incoming_connection(THIS,THIS->fds[fd_idx].fd,&THIS->sockets[fd_idx]);
|
||||
break;
|
||||
case ANODE_SOCKET_STREAM_CONNECTION:
|
||||
if (THIS->sockets[fd_idx].base.state == ANODE_SOCKET_CONNECTING)
|
||||
AnodeSystemTransport__poll_do_outgoing_connect(THIS,THIS->fds[fd_idx].fd,&THIS->sockets[fd_idx]);
|
||||
else AnodeSystemTransport__poll_do_read_stream(THIS,THIS->fds[fd_idx].fd,&THIS->sockets[fd_idx]);
|
||||
break;
|
||||
}
|
||||
++event_count;
|
||||
}
|
||||
}
|
||||
|
||||
if ((THIS->fds[fd_idx].revents & POLLOUT)) {
|
||||
if (THIS->sockets[fd_idx].base.state == ANODE_SOCKET_CONNECTING)
|
||||
AnodeSystemTransport__poll_do_outgoing_connect(THIS,THIS->fds[fd_idx].fd,&THIS->sockets[fd_idx]);
|
||||
else AnodeSystemTransport__poll_do_stream_available_for_write(THIS,THIS->fds[fd_idx].fd,&THIS->sockets[fd_idx]);
|
||||
++event_count;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return event_count;
|
||||
}
|
||||
|
||||
static int AnodeSystemTransport_supports_address_type(const AnodeTransport *transport,
|
||||
enum AnodeNetworkAddressType at)
|
||||
{
|
||||
switch(at) {
|
||||
case ANODE_NETWORK_ADDRESS_IPV4:
|
||||
return 1;
|
||||
case ANODE_NETWORK_ADDRESS_IPV6:
|
||||
return 1;
|
||||
default:
|
||||
if (THIS->base)
|
||||
return THIS->base->supports_address_type(THIS->base,at);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static AnodeTransport *AnodeSystemTransport_base_instance(const AnodeTransport *transport)
|
||||
{
|
||||
return THIS->base;
|
||||
}
|
||||
|
||||
static const char *AnodeSystemTransport_class_name(AnodeTransport *transport)
|
||||
{
|
||||
return AnodeSystemTransport_CLASS;
|
||||
}
|
||||
|
||||
static void AnodeSystemTransport_delete(AnodeTransport *transport)
|
||||
{
|
||||
close(THIS->invoke_pipe[0]);
|
||||
close(THIS->invoke_pipe[1]);
|
||||
|
||||
AnodeMutex_destroy(&THIS->invoke_pipe_m);
|
||||
|
||||
if (THIS->fds) free(THIS->fds);
|
||||
if (THIS->sockets) free(THIS->sockets);
|
||||
|
||||
if (THIS->base) THIS->base->delete(THIS->base);
|
||||
|
||||
free(transport);
|
||||
}
|
||||
|
||||
/* ======================================================================== */
|
||||
|
||||
AnodeTransport *AnodeSystemTransport_new(AnodeTransport *base)
|
||||
{
|
||||
struct AnodeSystemTransport *t;
|
||||
unsigned int entry_idx;
|
||||
|
||||
t = malloc(sizeof(struct AnodeSystemTransport));
|
||||
if (!t) return (AnodeTransport *)0;
|
||||
Anode_zero(t,sizeof(struct AnodeSystemTransport));
|
||||
|
||||
t->interface.invoke = &AnodeSystemTransport_invoke;
|
||||
t->interface.dns_resolve = &AnodeSystemTransport_dns_resolve;
|
||||
t->interface.datagram_listen = &AnodeSystemTransport_datagram_listen;
|
||||
t->interface.stream_listen = &AnodeSystemTransport_stream_listen;
|
||||
t->interface.datagram_send = &AnodeSystemTransport_datagram_send;
|
||||
t->interface.stream_connect = &AnodeSystemTransport_stream_connect;
|
||||
t->interface.stream_start_writing = &AnodeSystemTransport_stream_start_writing;
|
||||
t->interface.stream_stop_writing = &AnodeSystemTransport_stream_stop_writing;
|
||||
t->interface.stream_send = &AnodeSystemTransport_stream_send;
|
||||
t->interface.close = &AnodeSystemTransport_close;
|
||||
t->interface.poll = &AnodeSystemTransport_poll;
|
||||
t->interface.supports_address_type = &AnodeSystemTransport_supports_address_type;
|
||||
t->interface.base_instance = &AnodeSystemTransport_base_instance;
|
||||
t->interface.class_name = &AnodeSystemTransport_class_name;
|
||||
t->interface.delete = &AnodeSystemTransport_delete;
|
||||
|
||||
t->base = base;
|
||||
|
||||
pipe(t->invoke_pipe);
|
||||
fcntl(t->invoke_pipe[0],F_SETFL,O_NONBLOCK);
|
||||
entry_idx = AnodeSystemTransport__add_entry(t);
|
||||
t->fds[entry_idx].fd = t->invoke_pipe[0];
|
||||
t->fds[entry_idx].events = POLLIN;
|
||||
t->fds[entry_idx].revents = 0;
|
||||
AnodeMutex_init(&t->invoke_pipe_m);
|
||||
|
||||
return (AnodeTransport *)t;
|
||||
}
|
25
attic/historic/anode/libanode/tests/Makefile
Normal file
25
attic/historic/anode/libanode/tests/Makefile
Normal file
@ -0,0 +1,25 @@
|
||||
all: force clean anode-utils-test anode-zone-test aes-test ec-test
|
||||
|
||||
aes-test:
|
||||
gcc -Wall -O6 -ftree-vectorize -std=c99 -o aes-test aes-test.c ../aes_digest.c -lcrypto
|
||||
|
||||
http_client-test:
|
||||
gcc -O0 -g -std=c99 -o http_client-test http_client-test.c ../anode-utils.c ../misc.c ../http_client.c ../dictionary.c ../iptransport.c ../anode-transport.c -lcrypto
|
||||
|
||||
anode-utils-test:
|
||||
gcc -O0 -g -std=c99 -o anode-utils-test anode-utils-test.c ../anode-utils.c ../misc.c
|
||||
|
||||
ec-test:
|
||||
gcc -O0 -g -std=c99 -o ec-test ec-test.c ../impl/ec.c ../impl/misc.c -lcrypto
|
||||
|
||||
anode-zone-test:
|
||||
gcc -O0 -g -std=c99 -o anode-zone-test anode-zone-test.c ../anode-zone.c ../http_client.c ../dictionary.c ../misc.c ../anode-transport.c ../iptransport.c ../environment.c
|
||||
|
||||
system_transport-test:
|
||||
gcc -O0 -g -std=c99 -o system_transport-test system_transport-test.c ../system_transport.c ../network_address.c ../address.c ../aes_digest.c ../impl/misc.c ../impl/thread.c ../impl/dns_txt.c ../impl/aes.c -lresolv -lcrypto
|
||||
|
||||
clean: force
|
||||
rm -rf *.dSYM
|
||||
rm -f http_client-test anode-utils-test anode-zone-test ec-test aes-test system_transport-test
|
||||
|
||||
force: ;
|
191
attic/historic/anode/libanode/tests/aes-test.c
Normal file
191
attic/historic/anode/libanode/tests/aes-test.c
Normal file
@ -0,0 +1,191 @@
|
||||
/* libanode: the Anode C reference implementation
|
||||
* Copyright (C) 2009 Adam Ierymenko <adam.ierymenko@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "../impl/aes.h"
|
||||
#include "../anode.h"
|
||||
|
||||
static const unsigned char AES_TEST_KEY[32] = {
|
||||
0x08,0x09,0x0A,0x0B,0x0D,0x0E,0x0F,0x10,0x12,0x13,0x14,0x15,0x17,0x18,0x19,0x1A,
|
||||
0x1C,0x1D,0x1E,0x1F,0x21,0x22,0x23,0x24,0x26,0x27,0x28,0x29,0x2B,0x2C,0x2D,0x2E
|
||||
};
|
||||
static const unsigned char AES_TEST_IN[16] = {
|
||||
0x06,0x9A,0x00,0x7F,0xC7,0x6A,0x45,0x9F,0x98,0xBA,0xF9,0x17,0xFE,0xDF,0x95,0x21
|
||||
};
|
||||
static const unsigned char AES_TEST_OUT[16] = {
|
||||
0x08,0x0e,0x95,0x17,0xeb,0x16,0x77,0x71,0x9a,0xcf,0x72,0x80,0x86,0x04,0x0a,0xe3
|
||||
};
|
||||
|
||||
static const unsigned char CMAC_TEST_KEY[32] = {
|
||||
0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
|
||||
0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
|
||||
};
|
||||
|
||||
static const unsigned char CMAC_TEST1_OUT[16] = {
|
||||
0x02,0x89,0x62,0xf6,0x1b,0x7b,0xf8,0x9e,0xfc,0x6b,0x55,0x1f,0x46,0x67,0xd9,0x83
|
||||
};
|
||||
|
||||
static const unsigned char CMAC_TEST2_IN[16] = {
|
||||
0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a
|
||||
};
|
||||
static const unsigned char CMAC_TEST2_OUT[16] = {
|
||||
0x28,0xa7,0x02,0x3f,0x45,0x2e,0x8f,0x82,0xbd,0x4b,0xf2,0x8d,0x8c,0x37,0xc3,0x5c
|
||||
};
|
||||
|
||||
static const unsigned char CMAC_TEST3_IN[40] = {
|
||||
0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
|
||||
0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
|
||||
0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11
|
||||
};
|
||||
static const unsigned char CMAC_TEST3_OUT[16] = {
|
||||
0xaa,0xf3,0xd8,0xf1,0xde,0x56,0x40,0xc2,0x32,0xf5,0xb1,0x69,0xb9,0xc9,0x11,0xe6
|
||||
};
|
||||
|
||||
static const unsigned char CMAC_TEST4_IN[64] = {
|
||||
0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
|
||||
0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
|
||||
0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
|
||||
0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
|
||||
};
|
||||
static const unsigned char CMAC_TEST4_OUT[16] = {
|
||||
0xe1,0x99,0x21,0x90,0x54,0x9f,0x6e,0xd5,0x69,0x6a,0x2c,0x05,0x6c,0x31,0x54,0x10
|
||||
};
|
||||
|
||||
static void test_cmac(const AnodeAesExpandedKey *expkey,const unsigned char *in,unsigned int inlen,const unsigned char *expected)
|
||||
{
|
||||
unsigned int i;
|
||||
unsigned char out[16];
|
||||
|
||||
printf("Testing CMAC with %u byte input:\n",inlen);
|
||||
printf(" IN: ");
|
||||
for(i=0;i<inlen;++i)
|
||||
printf("%.2x",(int)in[i]);
|
||||
printf("\n");
|
||||
printf(" EXP: ");
|
||||
for(i=0;i<16;++i)
|
||||
printf("%.2x",(int)expected[i]);
|
||||
printf("\n");
|
||||
Anode_cmac_aes256(expkey,in,inlen,out);
|
||||
printf(" OUT: ");
|
||||
for(i=0;i<16;++i)
|
||||
printf("%.2x",(int)out[i]);
|
||||
printf("\n");
|
||||
if (memcmp(expected,out,16)) {
|
||||
printf("FAILED!\n");
|
||||
exit(1);
|
||||
} else printf("Passed.\n");
|
||||
}
|
||||
|
||||
static void test_cfb(const AnodeAesExpandedKey *expkey,const unsigned char *in,unsigned int inlen,unsigned char *iv,const unsigned char *expected)
|
||||
{
|
||||
unsigned char tmp[131072];
|
||||
unsigned char tmp2[131072];
|
||||
unsigned char tmpiv[16];
|
||||
|
||||
printf("Testing AES-256 CFB mode with %u bytes: ",inlen);
|
||||
fflush(stdout);
|
||||
|
||||
memcpy(tmpiv,iv,16);
|
||||
Anode_aes256_cfb_encrypt(expkey,in,tmp,tmpiv,inlen);
|
||||
if (!memcmp(tmp,expected,inlen)) {
|
||||
printf("FAILED (didn't encrypt)!\n");
|
||||
exit(1);
|
||||
}
|
||||
memcpy(tmpiv,iv,16);
|
||||
Anode_aes256_cfb_decrypt(expkey,tmp,tmp2,tmpiv,inlen);
|
||||
if (memcmp(tmp2,expected,inlen)) {
|
||||
printf("FAILED (didn't encrypt)!\n");
|
||||
exit(1);
|
||||
} else printf("Passed.\n");
|
||||
}
|
||||
|
||||
static const char *AES_DIGEST_TEST_1 = "test";
|
||||
static const char *AES_DIGEST_TEST_2 = "supercalifragilisticexpealidocious";
|
||||
static const char *AES_DIGEST_TEST_3 = "12345678";
|
||||
static const char *AES_DIGEST_TEST_4 = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
|
||||
|
||||
int main(int argc,char **argv)
|
||||
{
|
||||
AnodeAesExpandedKey expkey;
|
||||
unsigned int i;
|
||||
unsigned char aestestbuf[16];
|
||||
unsigned char cfbin[131072];
|
||||
unsigned char iv[16];
|
||||
|
||||
printf("Testing AES-256:");
|
||||
Anode_aes256_expand_key(AES_TEST_KEY,&expkey);
|
||||
printf(" IN: ");
|
||||
for(i=0;i<16;++i)
|
||||
printf("%.2x",(int)AES_TEST_IN[i]);
|
||||
printf("\n");
|
||||
printf(" EXP: ");
|
||||
for(i=0;i<16;++i)
|
||||
printf("%.2x",(int)AES_TEST_OUT[i]);
|
||||
printf("\n");
|
||||
Anode_aes256_encrypt(&expkey,AES_TEST_IN,aestestbuf);
|
||||
printf(" OUT: ");
|
||||
for(i=0;i<16;++i)
|
||||
printf("%.2x",(int)aestestbuf[i]);
|
||||
printf("\n");
|
||||
if (memcmp(AES_TEST_OUT,aestestbuf,16)) {
|
||||
printf("FAILED!\n");
|
||||
return 1;
|
||||
} else printf("Passed.\n");
|
||||
printf("\n");
|
||||
|
||||
Anode_aes256_expand_key(CMAC_TEST_KEY,&expkey);
|
||||
test_cmac(&expkey,(unsigned char *)0,0,CMAC_TEST1_OUT);
|
||||
test_cmac(&expkey,CMAC_TEST2_IN,16,CMAC_TEST2_OUT);
|
||||
test_cmac(&expkey,CMAC_TEST3_IN,40,CMAC_TEST3_OUT);
|
||||
test_cmac(&expkey,CMAC_TEST4_IN,64,CMAC_TEST4_OUT);
|
||||
printf("\n");
|
||||
|
||||
for(i=0;i<131072;++i)
|
||||
cfbin[i] = (unsigned char)(i & 0xff);
|
||||
for(i=0;i<16;++i)
|
||||
iv[i] = (unsigned char)(i & 0xff);
|
||||
for(i=12345;i<131072;i+=7777)
|
||||
test_cfb(&expkey,cfbin,i,iv,cfbin);
|
||||
|
||||
printf("\nTesting AES-DIGEST...\n");
|
||||
printf("0 bytes: ");
|
||||
Anode_aes_digest(cfbin,0,iv);
|
||||
for(i=0;i<16;++i) printf("%.2x",(unsigned int)iv[i]);
|
||||
printf("\n");
|
||||
printf("%d bytes: ",(int)strlen(AES_DIGEST_TEST_1));
|
||||
Anode_aes_digest(AES_DIGEST_TEST_1,strlen(AES_DIGEST_TEST_1),iv);
|
||||
for(i=0;i<16;++i) printf("%.2x",(unsigned int)iv[i]);
|
||||
printf("\n");
|
||||
printf("%d bytes: ",(int)strlen(AES_DIGEST_TEST_2));
|
||||
Anode_aes_digest(AES_DIGEST_TEST_2,strlen(AES_DIGEST_TEST_2),iv);
|
||||
for(i=0;i<16;++i) printf("%.2x",(unsigned int)iv[i]);
|
||||
printf("\n");
|
||||
printf("%d bytes: ",(int)strlen(AES_DIGEST_TEST_3));
|
||||
Anode_aes_digest(AES_DIGEST_TEST_3,strlen(AES_DIGEST_TEST_3),iv);
|
||||
for(i=0;i<16;++i) printf("%.2x",(unsigned int)iv[i]);
|
||||
printf("\n");
|
||||
printf("%d bytes: ",(int)strlen(AES_DIGEST_TEST_4));
|
||||
Anode_aes_digest(AES_DIGEST_TEST_4,strlen(AES_DIGEST_TEST_4),iv);
|
||||
for(i=0;i<16;++i) printf("%.2x",(unsigned int)iv[i]);
|
||||
printf("\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -0,0 +1,38 @@
|
||||
/* libanode: the Anode C reference implementation
|
||||
* Copyright (C) 2009-2010 Adam Ierymenko <adam.ierymenko@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "../anode.h"
|
||||
#include "../misc.h"
|
||||
|
||||
int main(int argc,char **argv)
|
||||
{
|
||||
unsigned char test[10005];
|
||||
unsigned int i;
|
||||
AnodeSecureRandom srng;
|
||||
|
||||
AnodeSecureRandom_init(&srng);
|
||||
|
||||
AnodeSecureRandom_gen_bytes(&srng,test,sizeof(test));
|
||||
|
||||
for(i=0;i<sizeof(test);++i) {
|
||||
printf("%.2x",(unsigned int)test[i]);
|
||||
if ((i % 20) == 19)
|
||||
printf("\n");
|
||||
}
|
||||
printf("\n");
|
||||
}
|
75
attic/historic/anode/libanode/tests/anode-utils-test.c
Normal file
75
attic/historic/anode/libanode/tests/anode-utils-test.c
Normal file
@ -0,0 +1,75 @@
|
||||
/* libanode: the Anode C reference implementation
|
||||
* Copyright (C) 2009-2010 Adam Ierymenko <adam.ierymenko@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "../anode.h"
|
||||
#include "../misc.h"
|
||||
|
||||
static const char *testuris[22] = {
|
||||
"http://www.test.com",
|
||||
"http://www.test.com/",
|
||||
"http://www.test.com/path/to/something",
|
||||
"http://user@www.test.com",
|
||||
"http://user@www.test.com/path/to/something",
|
||||
"http://user:password@www.test.com/path/to/something",
|
||||
"http://www.test.com/path/to/something?query=foo&bar=baz",
|
||||
"http://www.test.com/path/to/something#fragment",
|
||||
"http://www.test.com/path/to/something?query=foo&bar=baz#fragment",
|
||||
"http://user:password@www.test.com/path/to/something#fragment",
|
||||
"http://user:password@www.test.com/path/to/something?query=foo&bar=baz#fragment",
|
||||
"http://@www.test.com/",
|
||||
"http://:@www.test.com/",
|
||||
"http://www.test.com:8080/path/to/something",
|
||||
"http://user:password@www.test.com:8080/path/to/something?query=foo#fragment",
|
||||
"http://",
|
||||
"http://www.test.com/path/to/something?#",
|
||||
"http://www.test.com/path/to/something?#fragment",
|
||||
"http:",
|
||||
"http",
|
||||
"mailto:this_is_a_urn@somedomain.com",
|
||||
""
|
||||
};
|
||||
|
||||
int main(int argc,char **argv)
|
||||
{
|
||||
int i,r;
|
||||
char reconstbuf[2048];
|
||||
char *reconst;
|
||||
AnodeURI uri;
|
||||
|
||||
for(i=0;i<22;++i) {
|
||||
printf("\"%s\":\n",testuris[i]);
|
||||
r = AnodeURI_parse(&uri,testuris[i]);
|
||||
if (r) {
|
||||
printf(" error: %d\n",r);
|
||||
} else {
|
||||
printf(" scheme: %s\n",uri.scheme);
|
||||
printf(" username: %s\n",uri.username);
|
||||
printf(" password: %s\n",uri.password);
|
||||
printf(" host: %s\n",uri.host);
|
||||
printf(" port: %d\n",uri.port);
|
||||
printf(" path: %s\n",uri.path);
|
||||
printf(" query: %s\n",uri.query);
|
||||
printf(" fragment: %s\n",uri.fragment);
|
||||
}
|
||||
reconst = AnodeURI_to_string(&uri,reconstbuf,sizeof(reconstbuf));
|
||||
printf("Reconstituted URI: %s\n",reconst ? reconst : "(null)");
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
47
attic/historic/anode/libanode/tests/anode-zone-test.c
Normal file
47
attic/historic/anode/libanode/tests/anode-zone-test.c
Normal file
@ -0,0 +1,47 @@
|
||||
/* libanode: the Anode C reference implementation
|
||||
* Copyright (C) 2009 Adam Ierymenko <adam.ierymenko@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "../anode.h"
|
||||
#include "../dictionary.h"
|
||||
|
||||
static int got_it = 0;
|
||||
|
||||
static void zone_lookup_handler(void *ptr,long zone_id,AnodeZone *zone)
|
||||
{
|
||||
if (zone)
|
||||
printf("got %.8lx: %d entries\n",(unsigned long)zone_id & 0xffffffff,((struct AnodeDictionary *)zone)->size);
|
||||
else printf("failed.\n");
|
||||
got_it = 1;
|
||||
}
|
||||
|
||||
int main(int argc,char **argv)
|
||||
{
|
||||
AnodeTransportEngine transport;
|
||||
|
||||
Anode_init_ip_transport_engine(&transport);
|
||||
|
||||
AnodeZone_lookup(&transport,0,0,&zone_lookup_handler);
|
||||
|
||||
while (!got_it)
|
||||
transport.poll(&transport);
|
||||
|
||||
transport.destroy(&transport);
|
||||
|
||||
return 0;
|
||||
}
|
149
attic/historic/anode/libanode/tests/dictionary-test.c
Normal file
149
attic/historic/anode/libanode/tests/dictionary-test.c
Normal file
@ -0,0 +1,149 @@
|
||||
/* libanode: the Anode C reference implementation
|
||||
* Copyright (C) 2009 Adam Ierymenko <adam.ierymenko@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include "../dictionary.h"
|
||||
|
||||
static const char *HASH_TESTS[16] = {
|
||||
"test",
|
||||
"testt",
|
||||
"",
|
||||
"foo",
|
||||
"fooo",
|
||||
"1",
|
||||
"2",
|
||||
"3",
|
||||
"4",
|
||||
"11",
|
||||
"22",
|
||||
"33",
|
||||
"44",
|
||||
"adklfjklejrer",
|
||||
"erngnetbekjrq",
|
||||
"erklerqqqqre"
|
||||
};
|
||||
|
||||
int diterate(void *arg,const char *key,const char *value)
|
||||
{
|
||||
printf(" %s: %s\n",key ? key : "(null)",value ? value : "(null)");
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main(int argc,char **argv)
|
||||
{
|
||||
char tmp[1024];
|
||||
char fuzzparam1[16],fuzzparam2[16],fuzzparam3[16];
|
||||
struct AnodeDictionary d;
|
||||
unsigned int i,j,k,cs;
|
||||
|
||||
srandom(time(0));
|
||||
|
||||
printf("Trying out hash function a little...\n");
|
||||
for(i=0;i<16;++i)
|
||||
printf(" %s: %u\n",HASH_TESTS[i],(unsigned int)AnodeDictionary__get_bucket(HASH_TESTS[i]));
|
||||
|
||||
for(cs=0;cs<2;++cs) {
|
||||
printf("\nTesting with case sensitivity = %d\n",cs);
|
||||
AnodeDictionary_init(&d,cs);
|
||||
|
||||
printf("\nTesting dictionary by adding and retrieving some keys...\n");
|
||||
AnodeDictionary_put(&d,"test1","This is the first test");
|
||||
AnodeDictionary_put(&d,"test2","This is the second test");
|
||||
AnodeDictionary_put(&d,"test3","This is the third test (lower case)");
|
||||
AnodeDictionary_put(&d,"TEST3","This is the third test (UPPER CASE)");
|
||||
AnodeDictionary_iterate(&d,(void *)0,&diterate);
|
||||
if (d.size != (cs ? 4 : 3)) {
|
||||
printf("Failed (size).\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
AnodeDictionary_clear(&d);
|
||||
if (d.size||(AnodeDictionary_get(&d,"test1"))) {
|
||||
printf("Failed (clear).\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("\nTesting read, trial 1: simple key=value with unterminated line\n");
|
||||
strcpy(tmp,"foo=bar\nbar=baz\ntest1=Happy happy joyjoy!\ntest2=foobarbaz\nlinewithnocr=thisworked");
|
||||
AnodeDictionary_read(&d,tmp,"\r\n","=","",'\\',0,0);
|
||||
printf("Results:\n");
|
||||
AnodeDictionary_iterate(&d,(void *)0,&diterate);
|
||||
AnodeDictionary_clear(&d);
|
||||
|
||||
printf("\nTesting read, trial 2: key=value with escape chars, escaped CRs\n");
|
||||
strcpy(tmp,"foo=bar\r\nbar==baz\nte\\=st1=\\=Happy happy joyjoy!\ntest2=foobarbaz\\\nfoobarbaz on next line\r\n");
|
||||
AnodeDictionary_read(&d,tmp,"\r\n","=","",'\\',0,0);
|
||||
printf("Results:\n");
|
||||
AnodeDictionary_iterate(&d,(void *)0,&diterate);
|
||||
AnodeDictionary_clear(&d);
|
||||
|
||||
printf("\nTesting read, trial 3: HTTP header-like dictionary\n");
|
||||
strcpy(tmp,"Host: some.host.net\r\nX-Some-Header: foo bar\r\nX-Some-Other-Header: y0y0y0y0y0\r\n");
|
||||
AnodeDictionary_read(&d,tmp,"\r\n",": ","",0,0,0);
|
||||
printf("Results:\n");
|
||||
AnodeDictionary_iterate(&d,(void *)0,&diterate);
|
||||
AnodeDictionary_clear(&d);
|
||||
|
||||
printf("\nTesting read, trial 4: single line key/value\n");
|
||||
strcpy(tmp,"Header: one line only");
|
||||
AnodeDictionary_read(&d,tmp,"\r\n",": ","",0,0,0);
|
||||
printf("Results:\n");
|
||||
AnodeDictionary_iterate(&d,(void *)0,&diterate);
|
||||
AnodeDictionary_clear(&d);
|
||||
|
||||
printf("\nFuzzing dictionary reader...\n"); fflush(stdout);
|
||||
for(i=0;i<200000;++i) {
|
||||
j = random() % (sizeof(tmp) - 1);
|
||||
for(k=0;k<j;++k) {
|
||||
tmp[k] = (char)((unsigned int)random() >> 3);
|
||||
if (!tmp[k]) tmp[k] = 1;
|
||||
}
|
||||
tmp[j] = (char)0;
|
||||
|
||||
j = random() % (sizeof(fuzzparam1) - 1);
|
||||
for(k=0;k<j;++k) {
|
||||
fuzzparam1[k] = (char)((unsigned int)random() >> 3);
|
||||
if (!fuzzparam1[k]) fuzzparam1[k] = 1;
|
||||
}
|
||||
fuzzparam1[j] = (char)0;
|
||||
|
||||
j = random() % (sizeof(fuzzparam2) - 1);
|
||||
for(k=0;k<j;++k) {
|
||||
fuzzparam1[k] = (char)((unsigned int)random() >> 3);
|
||||
if (!fuzzparam2[k]) fuzzparam2[k] = 1;
|
||||
}
|
||||
fuzzparam2[j] = (char)0;
|
||||
|
||||
j = random() % (sizeof(fuzzparam3) - 1);
|
||||
for(k=0;k<j;++k) {
|
||||
fuzzparam3[k] = (char)((unsigned int)random() >> 3);
|
||||
if (!fuzzparam3[k]) fuzzparam3[k] = 1;
|
||||
}
|
||||
fuzzparam3[j] = (char)0;
|
||||
|
||||
AnodeDictionary_read(&d,tmp,fuzzparam1,fuzzparam2,fuzzparam3,random() & 3,random() & 1,random() & 1);
|
||||
AnodeDictionary_clear(&d);
|
||||
}
|
||||
|
||||
AnodeDictionary_destroy(&d);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
97
attic/historic/anode/libanode/tests/ec-test.c
Normal file
97
attic/historic/anode/libanode/tests/ec-test.c
Normal file
@ -0,0 +1,97 @@
|
||||
/* libanode: the Anode C reference implementation
|
||||
* Copyright (C) 2009 Adam Ierymenko <adam.ierymenko@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include "../impl/ec.h"
|
||||
#include "../impl/misc.h"
|
||||
|
||||
#define TEST_KEY_LEN 128
|
||||
#define AnodeEC_key_to_hex(k,b,l) Anode_to_hex((k)->key,(k)->bytes,(b),l)
|
||||
|
||||
int main(int argc,char **argv)
|
||||
{
|
||||
struct AnodeECKeyPair pair1;
|
||||
struct AnodeECKeyPair pair2;
|
||||
struct AnodeECKeyPair pair3;
|
||||
unsigned char key[TEST_KEY_LEN];
|
||||
char str[16384];
|
||||
|
||||
printf("Creating key pair #1...\n");
|
||||
if (!AnodeECKeyPair_generate(&pair1)) {
|
||||
printf("Could not create key pair.\n");
|
||||
return 1;
|
||||
}
|
||||
AnodeEC_key_to_hex(&pair1.pub,str,sizeof(str));
|
||||
printf("Public: %s\n",str);
|
||||
AnodeEC_key_to_hex(&pair1.priv,str,sizeof(str));
|
||||
printf("Private: %s\n\n",str);
|
||||
|
||||
printf("Creating key pair #2...\n");
|
||||
if (!AnodeECKeyPair_generate(&pair2)) {
|
||||
printf("Could not create key pair.\n");
|
||||
return 1;
|
||||
}
|
||||
AnodeEC_key_to_hex(&pair2.pub,str,sizeof(str));
|
||||
printf("Public: %s\n",str);
|
||||
AnodeEC_key_to_hex(&pair2.priv,str,sizeof(str));
|
||||
printf("Private: %s\n\n",str);
|
||||
|
||||
printf("Key agreement between public #2 and private #1...\n");
|
||||
if (!AnodeECKeyPair_agree(&pair1,&pair2.pub,key,TEST_KEY_LEN)) {
|
||||
printf("Agreement failed.\n");
|
||||
return 1;
|
||||
}
|
||||
Anode_to_hex(key,TEST_KEY_LEN,str,sizeof(str));
|
||||
printf("Agreed secret: %s\n\n",str);
|
||||
|
||||
printf("Key agreement between public #1 and private #2...\n");
|
||||
if (!AnodeECKeyPair_agree(&pair2,&pair1.pub,key,TEST_KEY_LEN)) {
|
||||
printf("Agreement failed.\n");
|
||||
return 1;
|
||||
}
|
||||
Anode_to_hex(key,TEST_KEY_LEN,str,sizeof(str));
|
||||
printf("Agreed secret: %s\n\n",str);
|
||||
|
||||
printf("Testing key pair init function (init #3 from #2's parts)...\n");
|
||||
if (!AnodeECKeyPair_init(&pair3,&(pair2.pub),&(pair2.priv))) {
|
||||
printf("Init failed.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Key agreement between public #1 and private #3...\n");
|
||||
if (!AnodeECKeyPair_agree(&pair3,&pair1.pub,key,TEST_KEY_LEN)) {
|
||||
printf("Agreement failed.\n");
|
||||
return 1;
|
||||
}
|
||||
Anode_to_hex(key,TEST_KEY_LEN,str,sizeof(str));
|
||||
printf("Agreed secret: %s\n\n",str);
|
||||
|
||||
printf("Key agreement between public #1 and private #1...\n");
|
||||
if (!AnodeECKeyPair_agree(&pair1,&pair1.pub,key,TEST_KEY_LEN)) {
|
||||
printf("Agreement failed.\n");
|
||||
return 1;
|
||||
}
|
||||
Anode_to_hex(key,TEST_KEY_LEN,str,sizeof(str));
|
||||
printf("Agreed secret (should not match): %s\n\n",str);
|
||||
|
||||
AnodeECKeyPair_destroy(&pair1);
|
||||
AnodeECKeyPair_destroy(&pair2);
|
||||
AnodeECKeyPair_destroy(&pair3);
|
||||
|
||||
return 0;
|
||||
}
|
28
attic/historic/anode/libanode/tests/environment-test.c
Normal file
28
attic/historic/anode/libanode/tests/environment-test.c
Normal file
@ -0,0 +1,28 @@
|
||||
/* libanode: the Anode C reference implementation
|
||||
* Copyright (C) 2009 Adam Ierymenko <adam.ierymenko@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "../environment.h"
|
||||
|
||||
int main(int argc,char **argv)
|
||||
{
|
||||
const char *cache = Anode_get_cache();
|
||||
|
||||
printf("Cache folder: %s\n",cache ? cache : "(null)");
|
||||
|
||||
return 0;
|
||||
}
|
233
attic/historic/anode/libanode/tests/http_client-test.c
Normal file
233
attic/historic/anode/libanode/tests/http_client-test.c
Normal file
@ -0,0 +1,233 @@
|
||||
/* libanode: the Anode C reference implementation
|
||||
* Copyright (C) 2009-2010 Adam Ierymenko <adam.ierymenko@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <openssl/sha.h>
|
||||
#include "../anode.h"
|
||||
#include "../misc.h"
|
||||
#include "../http_client.h"
|
||||
#include "../dictionary.h"
|
||||
|
||||
struct TestCase
|
||||
{
|
||||
int method;
|
||||
AnodeURI uri;
|
||||
const void *client_data;
|
||||
unsigned int client_data_len;
|
||||
const char *expected_sha1;
|
||||
char actual_sha1[64];
|
||||
int got_it;
|
||||
int keepalive;
|
||||
struct TestCase *next;
|
||||
};
|
||||
|
||||
#define NUM_TEST_CASES 7
|
||||
static struct TestCase test_cases[NUM_TEST_CASES];
|
||||
|
||||
static void init_test_cases(int keepalive)
|
||||
{
|
||||
AnodeURI_parse(&(test_cases[0].uri),"http://zerotier.com/for_unit_tests/test1.txt");
|
||||
test_cases[0].method = ANODE_HTTP_GET;
|
||||
test_cases[0].client_data_len = 0;
|
||||
test_cases[0].expected_sha1 = "0828324174b10cc867b7255a84a8155cf89e1b8b";
|
||||
test_cases[0].actual_sha1[0] = (char)0;
|
||||
test_cases[0].got_it = 0;
|
||||
test_cases[0].keepalive = keepalive;
|
||||
test_cases[0].next = &(test_cases[1]);
|
||||
|
||||
AnodeURI_parse(&(test_cases[1].uri),"http://zerotier.com/for_unit_tests/test2.bin");
|
||||
test_cases[1].method = ANODE_HTTP_GET;
|
||||
test_cases[1].client_data_len = 0;
|
||||
test_cases[1].expected_sha1 = "6b67c635786ab52666211d02412c0d0f0372980d";
|
||||
test_cases[1].actual_sha1[0] = (char)0;
|
||||
test_cases[1].got_it = 0;
|
||||
test_cases[1].keepalive = keepalive;
|
||||
test_cases[1].next = &(test_cases[2]);
|
||||
|
||||
AnodeURI_parse(&(test_cases[2].uri),"http://zerotier.com/for_unit_tests/test3.bin");
|
||||
test_cases[2].method = ANODE_HTTP_GET;
|
||||
test_cases[2].client_data_len = 0;
|
||||
test_cases[2].expected_sha1 = "efa7722029fdbb6abd0e3ed32a0b44bfb982cff0";
|
||||
test_cases[2].actual_sha1[0] = (char)0;
|
||||
test_cases[2].got_it = 0;
|
||||
test_cases[2].keepalive = keepalive;
|
||||
test_cases[2].next = &(test_cases[3]);
|
||||
|
||||
AnodeURI_parse(&(test_cases[3].uri),"http://zerotier.com/for_unit_tests/test4.bin");
|
||||
test_cases[3].method = ANODE_HTTP_GET;
|
||||
test_cases[3].client_data_len = 0;
|
||||
test_cases[3].expected_sha1 = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
|
||||
test_cases[3].actual_sha1[0] = (char)0;
|
||||
test_cases[3].got_it = 0;
|
||||
test_cases[3].keepalive = keepalive;
|
||||
test_cases[3].next = &(test_cases[4]);
|
||||
|
||||
AnodeURI_parse(&(test_cases[4].uri),"http://zerotier.com/for_unit_tests/echo.php?echo=foobar");
|
||||
test_cases[4].method = ANODE_HTTP_GET;
|
||||
test_cases[4].client_data_len = 0;
|
||||
test_cases[4].expected_sha1 = "8843d7f92416211de9ebb963ff4ce28125932878";
|
||||
test_cases[4].actual_sha1[0] = (char)0;
|
||||
test_cases[4].got_it = 0;
|
||||
test_cases[4].keepalive = keepalive;
|
||||
test_cases[4].next = &(test_cases[5]);
|
||||
|
||||
AnodeURI_parse(&(test_cases[5].uri),"http://zerotier.com/for_unit_tests/echo.php");
|
||||
test_cases[5].method = ANODE_HTTP_POST;
|
||||
test_cases[5].client_data = "echo=foobar";
|
||||
test_cases[5].client_data_len = strlen((char *)test_cases[5].client_data);
|
||||
test_cases[5].expected_sha1 = "8843d7f92416211de9ebb963ff4ce28125932878";
|
||||
test_cases[5].actual_sha1[0] = (char)0;
|
||||
test_cases[5].got_it = 0;
|
||||
test_cases[5].keepalive = keepalive;
|
||||
test_cases[5].next = &(test_cases[6]);
|
||||
|
||||
AnodeURI_parse(&(test_cases[6].uri),"http://zerotier.com/for_unit_tests/test3.bin");
|
||||
test_cases[6].method = ANODE_HTTP_HEAD;
|
||||
test_cases[6].client_data_len = 0;
|
||||
test_cases[6].expected_sha1 = "da39a3ee5e6b4b0d3255bfef95601890afd80709";
|
||||
test_cases[6].actual_sha1[0] = (char)0;
|
||||
test_cases[6].got_it = 0;
|
||||
test_cases[6].keepalive = keepalive;
|
||||
test_cases[6].next = 0;
|
||||
}
|
||||
|
||||
static int http_handler_dump_headers(void *arg,const char *key,const char *value)
|
||||
{
|
||||
printf(" H %s: %s\n",key,value);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void http_handler(struct AnodeHttpClient *client)
|
||||
{
|
||||
const char *method = "???";
|
||||
char buf[1024];
|
||||
unsigned char sha[20];
|
||||
struct TestCase *test = (struct TestCase *)client->ptr[0];
|
||||
|
||||
switch(client->method) {
|
||||
case ANODE_HTTP_GET:
|
||||
method = "GET";
|
||||
break;
|
||||
case ANODE_HTTP_HEAD:
|
||||
method = "HEAD";
|
||||
break;
|
||||
case ANODE_HTTP_POST:
|
||||
method = "POST";
|
||||
break;
|
||||
}
|
||||
|
||||
if (client->response.code == 200) {
|
||||
SHA1((unsigned char *)client->response.data,client->response.data_length,sha);
|
||||
Anode_to_hex(sha,20,test->actual_sha1,sizeof(test->actual_sha1));
|
||||
printf("%s %s\n * SHA1: %s exp: %s\n",method,AnodeURI_to_string(&(test->uri),buf,sizeof(buf)),test->actual_sha1,test->expected_sha1);
|
||||
if (strcmp(test->actual_sha1,test->expected_sha1))
|
||||
printf(" ! SHA1 MISMATCH!\n");
|
||||
AnodeDictionary_iterate(&(client->response.headers),0,&http_handler_dump_headers);
|
||||
} else printf("%s %s: ERROR: %d\n",method,AnodeURI_to_string(&(test->uri),buf,sizeof(buf)),client->response.code);
|
||||
|
||||
test->got_it = 1;
|
||||
|
||||
if (!test->keepalive)
|
||||
AnodeHttpClient_free(client);
|
||||
else {
|
||||
test = test->next;
|
||||
if (test) {
|
||||
memcpy((void *)&(client->uri),(const void *)&(test->uri),sizeof(AnodeURI));
|
||||
|
||||
client->data = test->client_data;
|
||||
client->data_length = test->client_data_len;
|
||||
client->ptr[0] = test;
|
||||
client->keepalive = test->keepalive;
|
||||
client->method = test->method;
|
||||
client->handler = &http_handler;
|
||||
|
||||
AnodeHttpClient_send(client);
|
||||
} else {
|
||||
AnodeHttpClient_free(client);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc,char **argv)
|
||||
{
|
||||
struct AnodeHttpClient *client;
|
||||
AnodeTransportEngine transport_engine;
|
||||
int i;
|
||||
|
||||
if (Anode_init_ip_transport_engine(&transport_engine)) {
|
||||
printf("Failed (transport engine init)\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
printf("Testing without keepalive...\n\n");
|
||||
init_test_cases(0);
|
||||
for(i=0;i<NUM_TEST_CASES;++i) {
|
||||
client = AnodeHttpClient_new(&transport_engine);
|
||||
|
||||
memcpy((void *)&(client->uri),(const void *)&(test_cases[i].uri),sizeof(AnodeURI));
|
||||
client->data = test_cases[i].client_data;
|
||||
client->data_length = test_cases[i].client_data_len;
|
||||
client->ptr[0] = &test_cases[i];
|
||||
client->keepalive = test_cases[i].keepalive;
|
||||
client->method = test_cases[i].method;
|
||||
client->handler = &http_handler;
|
||||
|
||||
AnodeHttpClient_send(client);
|
||||
}
|
||||
|
||||
for(;;) {
|
||||
for(i=0;i<NUM_TEST_CASES;++i) {
|
||||
if (!test_cases[i].got_it)
|
||||
break;
|
||||
}
|
||||
if (i == NUM_TEST_CASES)
|
||||
break;
|
||||
transport_engine.poll(&transport_engine);
|
||||
}
|
||||
printf("\n\n");
|
||||
|
||||
printf("Testing with keepalive...\n\n");
|
||||
init_test_cases(1);
|
||||
|
||||
client = AnodeHttpClient_new(&transport_engine);
|
||||
|
||||
i = 0;
|
||||
memcpy((void *)&(client->uri),(const void *)&(test_cases[i].uri),sizeof(AnodeURI));
|
||||
client->data = test_cases[i].client_data;
|
||||
client->data_length = test_cases[i].client_data_len;
|
||||
client->ptr[0] = &test_cases[i];
|
||||
client->keepalive = test_cases[i].keepalive;
|
||||
client->method = test_cases[i].method;
|
||||
client->handler = &http_handler;
|
||||
|
||||
AnodeHttpClient_send(client);
|
||||
|
||||
for(;;) {
|
||||
for(i=0;i<NUM_TEST_CASES;++i) {
|
||||
if (!test_cases[i].got_it)
|
||||
break;
|
||||
}
|
||||
if (i == NUM_TEST_CASES)
|
||||
break;
|
||||
transport_engine.poll(&transport_engine);
|
||||
}
|
||||
|
||||
transport_engine.destroy(&transport_engine);
|
||||
|
||||
return 0;
|
||||
}
|
137
attic/historic/anode/libanode/tests/misc-test.c
Normal file
137
attic/historic/anode/libanode/tests/misc-test.c
Normal file
@ -0,0 +1,137 @@
|
||||
/* libanode: the Anode C reference implementation
|
||||
* Copyright (C) 2009 Adam Ierymenko <adam.ierymenko@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include "../misc.h"
|
||||
|
||||
int main(int argc,char **argv)
|
||||
{
|
||||
const char *base32TestStr = "asdf";
|
||||
char *fields[16];
|
||||
char buf[1024];
|
||||
char buf2[1024];
|
||||
char buf3[4096];
|
||||
unsigned int i;
|
||||
unsigned long tmpl,tmpl2;
|
||||
unsigned long long tmp64;
|
||||
|
||||
srand(time(0));
|
||||
|
||||
Anode_base32_5_to_8((const unsigned char *)base32TestStr,buf);
|
||||
printf("Base32 from test string: %s\n",buf);
|
||||
Anode_base32_8_to_5("MFZWIZQA",(unsigned char *)buf2);
|
||||
printf("Test string from Base32 (upper case): %s\n",buf2);
|
||||
Anode_base32_8_to_5("mfzwizqa",(unsigned char *)buf2);
|
||||
printf("Test string from Base32 (lower case): %s\n",buf2);
|
||||
printf("Testing variable length encoding/decoded with pad5 functions...\n");
|
||||
for(i=0;i<1024;++i) {
|
||||
tmpl = rand() % (sizeof(buf) - 8);
|
||||
if (!tmpl)
|
||||
tmpl = 1;
|
||||
for(tmpl2=0;tmpl2<tmpl;++tmpl2)
|
||||
buf[tmpl2] = (buf2[tmpl2] = (char)(rand() >> 3));
|
||||
if (!Anode_base32_encode_pad5(buf2,tmpl,buf3,sizeof(buf3))) {
|
||||
printf("Failed (encode failed).\n");
|
||||
return 1;
|
||||
}
|
||||
memset(buf2,0,sizeof(buf2));
|
||||
if (!Anode_base32_decode_pad5(buf3,buf2,sizeof(buf2))) {
|
||||
printf("Failed (decode failed).\n");
|
||||
return 1;
|
||||
}
|
||||
if (memcmp(buf,buf2,tmpl)) {
|
||||
printf("Failed (compare failed).\n");
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
printf("Anode_htonll(0x0102030405060708) == 0x%.16llx\n",tmp64 = Anode_htonll(0x0102030405060708ULL));
|
||||
printf("Anode_ntohll(0x%.16llx) == 0x%.16llx\n",tmp64,Anode_ntohll(tmp64));
|
||||
if (Anode_ntohll(tmp64) != 0x0102030405060708ULL) {
|
||||
printf("Failed.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
strcpy(buf,"foo bar baz");
|
||||
Anode_trim(buf);
|
||||
printf("Testing string trim: 'foo bar baz' -> '%s'\n",buf);
|
||||
strcpy(buf,"foo bar baz ");
|
||||
Anode_trim(buf);
|
||||
printf("Testing string trim: 'foo bar baz ' -> '%s'\n",buf);
|
||||
strcpy(buf," foo bar baz");
|
||||
Anode_trim(buf);
|
||||
printf("Testing string trim: ' foo bar baz' -> '%s'\n",buf);
|
||||
strcpy(buf," foo bar baz ");
|
||||
Anode_trim(buf);
|
||||
printf("Testing string trim: ' foo bar baz ' -> '%s'\n",buf);
|
||||
strcpy(buf,"");
|
||||
Anode_trim(buf);
|
||||
printf("Testing string trim: '' -> '%s'\n",buf);
|
||||
strcpy(buf," ");
|
||||
Anode_trim(buf);
|
||||
printf("Testing string trim: ' ' -> '%s'\n",buf);
|
||||
|
||||
printf("Testing string split.\n");
|
||||
strcpy(buf,"66.246.138.121,5323,0");
|
||||
i = Anode_split(buf,';',fields,16);
|
||||
if (i != 1) {
|
||||
printf("Failed.\n");
|
||||
return 1;
|
||||
} else printf("Fields: %s\n",fields[0]);
|
||||
strcpy(buf,"a;b;c");
|
||||
i = Anode_split(buf,';',fields,16);
|
||||
if (i != 3) {
|
||||
printf("Failed.\n");
|
||||
return 1;
|
||||
} else printf("Fields: %s %s %s\n",fields[0],fields[1],fields[2]);
|
||||
strcpy(buf,";;");
|
||||
i = Anode_split(buf,';',fields,16);
|
||||
if (i != 3) {
|
||||
printf("Failed.\n");
|
||||
return 1;
|
||||
} else printf("Fields: %s %s %s\n",fields[0],fields[1],fields[2]);
|
||||
strcpy(buf,"a;b;");
|
||||
i = Anode_split(buf,';',fields,16);
|
||||
if (i != 3) {
|
||||
printf("Failed.\n");
|
||||
return 1;
|
||||
} else printf("Fields: %s %s %s\n",fields[0],fields[1],fields[2]);
|
||||
strcpy(buf,"a;;c");
|
||||
i = Anode_split(buf,';',fields,16);
|
||||
if (i != 3) {
|
||||
printf("Failed.\n");
|
||||
return 1;
|
||||
} else printf("Fields: %s %s %s\n",fields[0],fields[1],fields[2]);
|
||||
strcpy(buf,";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;");
|
||||
i = Anode_split(buf,';',fields,16);
|
||||
if (i != 16) {
|
||||
printf("Failed.\n");
|
||||
return 1;
|
||||
}
|
||||
strcpy(buf,"");
|
||||
i = Anode_split(buf,';',fields,16);
|
||||
if (i != 0) {
|
||||
printf("Failed.\n");
|
||||
return 1;
|
||||
}
|
||||
printf("Passed.\n");
|
||||
|
||||
return 0;
|
||||
}
|
70
attic/historic/anode/libanode/tests/system_transport-test.c
Normal file
70
attic/historic/anode/libanode/tests/system_transport-test.c
Normal file
@ -0,0 +1,70 @@
|
||||
/* libanode: the Anode C reference implementation
|
||||
* Copyright (C) 2009-2010 Adam Ierymenko <adam.ierymenko@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/socket.h>
|
||||
#include "../anode.h"
|
||||
#include "../impl/thread.h"
|
||||
|
||||
static int do_client()
|
||||
{
|
||||
AnodeTransport *st;
|
||||
AnodeSocket *udp_sock;
|
||||
int run = 1;
|
||||
|
||||
st = AnodeSystemTransport_new(NULL);
|
||||
if (!st) {
|
||||
printf("FAILED: unable to construct AnodeSystemTransport.\n");
|
||||
return -1;
|
||||
}
|
||||
printf("Created AnodeSystemTransport.\n");
|
||||
|
||||
while (run)
|
||||
st->poll(st);
|
||||
}
|
||||
|
||||
static int do_server()
|
||||
{
|
||||
AnodeTransport *st;
|
||||
AnodeSocket *udp_sock;
|
||||
AnodeSocket *tcp_sock;
|
||||
int run = 1;
|
||||
|
||||
st = AnodeSystemTransport_new(NULL);
|
||||
if (!st) {
|
||||
printf("FAILED: unable to construct AnodeSystemTransport.\n");
|
||||
return -1;
|
||||
}
|
||||
printf("Created AnodeSystemTransport.\n");
|
||||
|
||||
while (run)
|
||||
st->poll(st);
|
||||
}
|
||||
|
||||
int main(int argc,char **argv)
|
||||
{
|
||||
if (argc == 2) {
|
||||
if (!strcmp(argv[1],"client"))
|
||||
return do_client();
|
||||
else if (!strcmp(argv[1],"server"))
|
||||
return do_server();
|
||||
}
|
||||
|
||||
printf("Usage: system_transport-test <client / server>\n");
|
||||
return -1;
|
||||
}
|
185
attic/historic/anode/libanode/uri.c
Normal file
185
attic/historic/anode/libanode/uri.c
Normal file
@ -0,0 +1,185 @@
|
||||
/* libanode: the Anode C reference implementation
|
||||
* Copyright (C) 2009-2010 Adam Ierymenko <adam.ierymenko@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include "impl/misc.h"
|
||||
#include "anode.h"
|
||||
|
||||
int AnodeURI_parse(AnodeURI *parsed_uri,const char *uri_string)
|
||||
{
|
||||
char buf[sizeof(AnodeURI)];
|
||||
unsigned long ptr = 0;
|
||||
char c;
|
||||
char *p1,*p2;
|
||||
|
||||
Anode_zero((void *)parsed_uri,sizeof(AnodeURI));
|
||||
|
||||
/* Get the scheme */
|
||||
for(;;) {
|
||||
c = *(uri_string++);
|
||||
if (!c) {
|
||||
parsed_uri->scheme[ptr] = (char)0;
|
||||
return ANODE_ERR_INVALID_URI;
|
||||
} else if (c == ':') {
|
||||
parsed_uri->scheme[ptr] = (char)0;
|
||||
break;
|
||||
} else {
|
||||
parsed_uri->scheme[ptr++] = c;
|
||||
if (ptr == sizeof(parsed_uri->scheme))
|
||||
return ANODE_ERR_BUFFER_TOO_SMALL;
|
||||
}
|
||||
}
|
||||
|
||||
if (*uri_string == '/') {
|
||||
/* If it starts with /, it's a URL */
|
||||
|
||||
/* Skip double slash */
|
||||
if (!(*(++uri_string)))
|
||||
return 0; /* Scheme with no path */
|
||||
if (*uri_string == '/') {
|
||||
if (!(*(++uri_string)))
|
||||
return 0; /* Scheme with no path */
|
||||
}
|
||||
|
||||
/* Get the host section and put it in buf[] */
|
||||
ptr = 0;
|
||||
while ((*uri_string)&&(*uri_string != '/')) {
|
||||
buf[ptr++] = *(uri_string++);
|
||||
if (ptr == sizeof(buf))
|
||||
return ANODE_ERR_BUFFER_TOO_SMALL;
|
||||
}
|
||||
buf[ptr] = (char)0;
|
||||
|
||||
/* Parse host section for host, username, password, and port */
|
||||
if (buf[0]) {
|
||||
p1 = (char *)Anode_strchr(buf,'@');
|
||||
if (p1) {
|
||||
*(p1++) = (char)0;
|
||||
if (*p1) {
|
||||
p2 = (char *)Anode_strchr(buf,':');
|
||||
if (p2) {
|
||||
*(p2++) = (char)0;
|
||||
Anode_str_copy(parsed_uri->password,p2,sizeof(parsed_uri->password));
|
||||
}
|
||||
Anode_str_copy(parsed_uri->username,buf,sizeof(parsed_uri->username));
|
||||
} else return ANODE_ERR_INVALID_URI;
|
||||
} else p1 = buf;
|
||||
|
||||
p2 = (char *)Anode_strchr(p1,':');
|
||||
if (p2) {
|
||||
*(p2++) = (char)0;
|
||||
if (*p2)
|
||||
parsed_uri->port = (int)strtoul(p2,(char **)0,10);
|
||||
}
|
||||
Anode_str_copy(parsed_uri->host,p1,sizeof(parsed_uri->host));
|
||||
}
|
||||
|
||||
/* Get the path, query, and fragment section and put it in buf[] */
|
||||
ptr = 0;
|
||||
while ((buf[ptr++] = *(uri_string++))) {
|
||||
if (ptr == sizeof(buf))
|
||||
return ANODE_ERR_BUFFER_TOO_SMALL;
|
||||
}
|
||||
|
||||
/* Parse path section for path, query, and fragment */
|
||||
if (buf[0]) {
|
||||
p1 = (char *)Anode_strchr(buf,'?');
|
||||
if (p1) {
|
||||
*(p1++) = (char)0;
|
||||
p2 = (char *)Anode_strchr(p1,'#');
|
||||
if (p2) {
|
||||
*(p2++) = (char)0;
|
||||
Anode_str_copy(parsed_uri->fragment,p2,sizeof(parsed_uri->fragment));
|
||||
}
|
||||
Anode_str_copy(parsed_uri->query,p1,sizeof(parsed_uri->query));
|
||||
} else {
|
||||
p2 = (char *)Anode_strchr(buf,'#');
|
||||
if (p2) {
|
||||
*(p2++) = (char)0;
|
||||
Anode_str_copy(parsed_uri->fragment,p2,sizeof(parsed_uri->fragment));
|
||||
}
|
||||
}
|
||||
Anode_str_copy(parsed_uri->path,buf,sizeof(parsed_uri->path));
|
||||
}
|
||||
} else {
|
||||
/* Otherwise, it's a URN and what remains is all path */
|
||||
ptr = 0;
|
||||
while ((parsed_uri->path[ptr++] = *(uri_string++))) {
|
||||
if (ptr == sizeof(parsed_uri->path))
|
||||
return ANODE_ERR_BUFFER_TOO_SMALL;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
char *AnodeURI_to_string(const AnodeURI *uri,char *buf,int len)
|
||||
{
|
||||
int i = 0;
|
||||
char portbuf[16];
|
||||
const char *p;
|
||||
|
||||
p = uri->scheme;
|
||||
while (*p) { buf[i++] = *(p++); if (i >= len) return (char *)0; }
|
||||
|
||||
buf[i++] = ':'; if (i >= len) return (char *)0;
|
||||
|
||||
if (uri->host[0]) {
|
||||
buf[i++] = '/'; if (i >= len) return (char *)0;
|
||||
buf[i++] = '/'; if (i >= len) return (char *)0;
|
||||
|
||||
if (uri->username[0]) {
|
||||
p = uri->username;
|
||||
while (*p) { buf[i++] = *(p++); if (i >= len) return (char *)0; }
|
||||
if (uri->password[0]) {
|
||||
buf[i++] = ':'; if (i >= len) return (char *)0;
|
||||
p = uri->password;
|
||||
while (*p) { buf[i++] = *(p++); if (i >= len) return (char *)0; }
|
||||
}
|
||||
buf[i++] = '@'; if (i >= len) return (char *)0;
|
||||
}
|
||||
|
||||
p = uri->host;
|
||||
while (*p) { buf[i++] = *(p++); if (i >= len) return (char *)0; }
|
||||
|
||||
if ((uri->port > 0)&&(uri->port <= 0xffff)) {
|
||||
buf[i++] = ':'; if (i >= len) return (char *)0;
|
||||
snprintf(portbuf,sizeof(portbuf),"%d",uri->port);
|
||||
p = portbuf;
|
||||
while (*p) { buf[i++] = *(p++); if (i >= len) return (char *)0; }
|
||||
}
|
||||
}
|
||||
|
||||
p = uri->path;
|
||||
while (*p) { buf[i++] = *(p++); if (i >= len) return (char *)0; }
|
||||
|
||||
if (uri->query[0]) {
|
||||
buf[i++] = '?'; if (i >= len) return (char *)0;
|
||||
p = uri->query;
|
||||
while (*p) { buf[i++] = *(p++); if (i >= len) return (char *)0; }
|
||||
}
|
||||
|
||||
if (uri->fragment[0]) {
|
||||
buf[i++] = '#'; if (i >= len) return (char *)0;
|
||||
p = uri->fragment;
|
||||
while (*p) { buf[i++] = *(p++); if (i >= len) return (char *)0; }
|
||||
}
|
||||
|
||||
buf[i] = (char)0;
|
||||
|
||||
return buf;
|
||||
}
|
50
attic/historic/anode/libanode/utils/anode-make-identity.c
Normal file
50
attic/historic/anode/libanode/utils/anode-make-identity.c
Normal file
@ -0,0 +1,50 @@
|
||||
/* libanode: the Anode C reference implementation
|
||||
* Copyright (C) 2009 Adam Ierymenko <adam.ierymenko@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <arpa/inet.h>
|
||||
#include "../anode.h"
|
||||
#include "../impl/misc.h"
|
||||
#include "../impl/types.h"
|
||||
|
||||
int main(int argc,char **argv)
|
||||
{
|
||||
char str[1024];
|
||||
AnodeZone zone;
|
||||
AnodeIdentity identity;
|
||||
|
||||
if (argc < 2) {
|
||||
printf("Usage: anode-make-identity <32-bit zone ID hex>\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
*((uint32_t *)zone.bits) = htonl((uint32_t)strtoul(argv[1],(char **)0,16));
|
||||
|
||||
if (AnodeIdentity_generate(&identity,&zone,ANODE_ADDRESS_ANODE_256_40)) {
|
||||
fprintf(stderr,"Error: identity key pair generation failed (check build settings).\n");
|
||||
return 1;
|
||||
}
|
||||
if (AnodeIdentity_to_string(&identity,str,sizeof(str)) <= 0) {
|
||||
fprintf(stderr,"Error: internal error converting identity to string.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
printf("%s\n",str);
|
||||
|
||||
return 0;
|
||||
}
|
184
attic/historic/anode/libanode/zone.c
Normal file
184
attic/historic/anode/libanode/zone.c
Normal file
@ -0,0 +1,184 @@
|
||||
/* libanode: the Anode C reference implementation
|
||||
* Copyright (C) 2009-2010 Adam Ierymenko <adam.ierymenko@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include "impl/types.h"
|
||||
#include "impl/misc.h"
|
||||
#include "impl/dictionary.h"
|
||||
#include "impl/environment.h"
|
||||
#include "impl/http_client.h"
|
||||
#include "anode.h"
|
||||
|
||||
static const char *_MONTHS[12] = { "Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec" };
|
||||
static const char *_DAYS_OF_WEEK[7] = { "Sun","Mon","Tue","Wed","Thu","Fri","Sat" };
|
||||
static inline unsigned long get_file_time_for_http(const char *path,char *buf,unsigned int len)
|
||||
{
|
||||
struct stat st;
|
||||
struct tm *gmt;
|
||||
|
||||
if (!stat(path,(struct stat *)&st)) {
|
||||
gmt = gmtime(&st.st_mtime);
|
||||
if (gmt) {
|
||||
snprintf(buf,len,"%s, %d %s %d %d:%d:%d GMT",
|
||||
_DAYS_OF_WEEK[gmt->tm_wday],
|
||||
gmt->tm_mday,
|
||||
_MONTHS[gmt->tm_mon],
|
||||
(1900 + gmt->tm_year),
|
||||
gmt->tm_hour,
|
||||
gmt->tm_min,
|
||||
gmt->tm_sec);
|
||||
buf[len - 1] = (char)0;
|
||||
return (unsigned long)st.st_size;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct AnodeZoneLookupJob
|
||||
{
|
||||
char cached_zone_file[2048];
|
||||
struct AnodeDictionary *zone_dict;
|
||||
AnodeZone zone;
|
||||
void *ptr;
|
||||
void (*zone_lookup_handler)(void *,const AnodeZone *,AnodeZoneFile *);
|
||||
int had_cached_zone;
|
||||
};
|
||||
|
||||
static void AnodeZone_lookup_http_handler(struct AnodeHttpClient *client)
|
||||
{
|
||||
char *data_tmp;
|
||||
struct AnodeZoneLookupJob *job = (struct AnodeZoneLookupJob *)client->ptr[0];
|
||||
FILE *zf;
|
||||
|
||||
if ((client->response.code == 200)&&(client->response.data_length > 0)) {
|
||||
zf = fopen(job->cached_zone_file,"w");
|
||||
if (zf) {
|
||||
fwrite(client->response.data,1,client->response.data_length,zf);
|
||||
fclose(zf);
|
||||
}
|
||||
|
||||
data_tmp = (char *)malloc(client->response.data_length + 1);
|
||||
Anode_memcpy((void *)data_tmp,client->response.data,client->response.data_length);
|
||||
data_tmp[client->response.data_length] = (char)0;
|
||||
|
||||
AnodeDictionary_clear(job->zone_dict);
|
||||
AnodeDictionary_read(
|
||||
job->zone_dict,
|
||||
data_tmp,
|
||||
"\r\n",
|
||||
"=",
|
||||
";",
|
||||
'\\',
|
||||
1,1);
|
||||
|
||||
free((void *)data_tmp);
|
||||
|
||||
job->zone_lookup_handler(job->ptr,&job->zone,(AnodeZoneFile *)job->zone_dict);
|
||||
} else if (job->had_cached_zone)
|
||||
job->zone_lookup_handler(job->ptr,&job->zone,(AnodeZoneFile *)job->zone_dict);
|
||||
else {
|
||||
AnodeDictionary_destroy(job->zone_dict);
|
||||
free((void *)job->zone_dict);
|
||||
job->zone_lookup_handler(job->ptr,&job->zone,(AnodeZoneFile *)0);
|
||||
}
|
||||
|
||||
free((void *)job);
|
||||
AnodeHttpClient_free(client);
|
||||
}
|
||||
|
||||
void AnodeZone_lookup(
|
||||
AnodeTransportEngine *transport,
|
||||
const AnodeZone *zone,
|
||||
void *ptr,
|
||||
void (*zone_lookup_handler)(void *,const AnodeZone *,AnodeZone *))
|
||||
{
|
||||
char cached_zones_folder[2048];
|
||||
char cached_zone_file[2048];
|
||||
char if_modified_since[256];
|
||||
unsigned long file_size;
|
||||
struct AnodeZoneLookupJob *job;
|
||||
struct AnodeHttpClient *client;
|
||||
char *file_data;
|
||||
FILE *zf;
|
||||
|
||||
if (Anode_get_cache_sub("zones",cached_zones_folder,sizeof(cached_zones_folder))) {
|
||||
snprintf(cached_zone_file,sizeof(cached_zone_file),"%s%c%.2x%.2x%.2x%.2x.z",cached_zones_folder,ANODE_PATH_SEPARATOR,(unsigned int)zone->bits[0],(unsigned int)zone->bits[1],(unsigned int)zone->bits[2],(unsigned int)zone->bits[3]);
|
||||
cached_zone_file[sizeof(cached_zone_file)-1] = (char)0;
|
||||
|
||||
job = (struct AnodeZoneLookupJob *)malloc(sizeof(struct AnodeZoneLookupJob));
|
||||
Anode_str_copy(job->cached_zone_file,cached_zone_file,sizeof(job->cached_zone_file));
|
||||
job->zone_dict = (struct AnodeDictionary *)malloc(sizeof(struct AnodeDictionary));
|
||||
AnodeDictionary_init(job->zone_dict,0);
|
||||
job->zone.bits[0] = zone->bits[0];
|
||||
job->zone.bits[1] = zone->bits[1];
|
||||
job->zone.bits[2] = zone->bits[2];
|
||||
job->zone.bits[3] = zone->bits[3];
|
||||
job->ptr = ptr;
|
||||
job->zone_lookup_handler = zone_lookup_handler;
|
||||
job->had_cached_zone = 0;
|
||||
|
||||
client = AnodeHttpClient_new(transport);
|
||||
|
||||
Anode_str_copy(client->uri.scheme,"http",sizeof(client->uri.scheme));
|
||||
snprintf(client->uri.host,sizeof(client->uri.host),"a--%.2x%.2x%.2x%.2x.net",(unsigned int)zone->bits[0],(unsigned int)zone->bits[1],(unsigned int)zone->bits[2],(unsigned int)zone->bits[3]);
|
||||
client->uri.host[sizeof(client->uri.host)-1] = (char)0;
|
||||
Anode_str_copy(client->uri.path,"/z",sizeof(client->uri.path));
|
||||
|
||||
client->handler = &AnodeZone_lookup_http_handler;
|
||||
client->ptr[0] = job;
|
||||
|
||||
if ((file_size = get_file_time_for_http(cached_zone_file,if_modified_since,sizeof(if_modified_since)))) {
|
||||
zf = fopen(cached_zone_file,"r");
|
||||
if (zf) {
|
||||
AnodeDictionary_put(&client->headers,"If-Modified-Since",if_modified_since);
|
||||
file_data = (char *)malloc(file_size + 1);
|
||||
if (fread((void *)file_data,1,file_size,zf)) {
|
||||
file_data[file_size] = (char)0;
|
||||
AnodeDictionary_read(
|
||||
job->zone_dict,
|
||||
file_data,
|
||||
"\r\n",
|
||||
"=",
|
||||
";",
|
||||
'\\',
|
||||
1,1);
|
||||
job->had_cached_zone = 1;
|
||||
}
|
||||
free((void *)file_data);
|
||||
fclose(zf);
|
||||
}
|
||||
}
|
||||
|
||||
AnodeHttpClient_send(client);
|
||||
} else zone_lookup_handler(ptr,zone,(AnodeZone *)0);
|
||||
}
|
||||
|
||||
const char *AnodeZoneFile_get(AnodeZoneFile *zone,const char *key)
|
||||
{
|
||||
return AnodeDictionary_get((struct AnodeDictionary *)zone,key);
|
||||
}
|
||||
|
||||
void AnodeZoneFile_free(AnodeZoneFile *zone)
|
||||
{
|
||||
AnodeDictionary_destroy((struct AnodeDictionary *)zone);
|
||||
free((void *)zone);
|
||||
}
|
16
attic/historic/anode/libspark/Makefile
Normal file
16
attic/historic/anode/libspark/Makefile
Normal file
@ -0,0 +1,16 @@
|
||||
SYSNAME:=${shell uname}
|
||||
SYSNAME!=uname
|
||||
include ../config.mk.${SYSNAME}
|
||||
|
||||
LIBSPARK_OBJS=
|
||||
|
||||
all: libspark
|
||||
|
||||
libspark: $(LIBSPARK_OBJS)
|
||||
ar rcs libspark.a $(LIBSPARK_OBJS)
|
||||
ranlib libspark.a
|
||||
|
||||
clean: force
|
||||
rm -f *.a *.so *.dylib *.dll *.lib *.exe *.o
|
||||
|
||||
force: ;
|
@ -0,0 +1,161 @@
|
||||
// Searches for good delimiters to cut streams into relatively well sized
|
||||
// segments.
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <boost/cstdint.hpp>
|
||||
#include <boost/array.hpp>
|
||||
#include <boost/random/mersenne_twister.hpp>
|
||||
#include <boost/thread.hpp>
|
||||
#include <boost/bind.hpp>
|
||||
#include <boost/shared_ptr.hpp>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
// Desired size range
|
||||
#define MIN_DESIRED_SIZE 4096
|
||||
#define MAX_DESIRED_SIZE 131072
|
||||
|
||||
#define DELIMITER_SET_SIZE 1
|
||||
typedef boost::array<boost::uint16_t,DELIMITER_SET_SIZE> DelimArray;
|
||||
|
||||
struct BestEntry
|
||||
{
|
||||
DelimArray best;
|
||||
double bestScore;
|
||||
std::vector<unsigned char> data;
|
||||
};
|
||||
|
||||
boost::mutex bestLock;
|
||||
boost::mutex outLock;
|
||||
std::map<std::string,BestEntry> best;
|
||||
|
||||
static void runThread(const std::string &fileName)
|
||||
{
|
||||
char tmp[4096];
|
||||
|
||||
boost::mt19937 prng;
|
||||
{
|
||||
boost::uint32_t seed;
|
||||
FILE *ur = fopen("/dev/urandom","r");
|
||||
fread((void *)&seed,1,sizeof(seed),ur);
|
||||
fclose(ur);
|
||||
prng.seed(seed);
|
||||
}
|
||||
|
||||
BestEntry *myEntry;
|
||||
{
|
||||
boost::mutex::scoped_lock l(bestLock);
|
||||
myEntry = &(best[fileName]);
|
||||
myEntry->bestScore = 99999999.0;
|
||||
}
|
||||
|
||||
{
|
||||
boost::mutex::scoped_lock l(outLock);
|
||||
|
||||
std::cout << "*** Reading test data from: " << fileName << std::endl;
|
||||
FILE *f = fopen(fileName.c_str(),"r");
|
||||
if (f) {
|
||||
int n;
|
||||
while ((n = fread((void *)tmp,1,sizeof(tmp),f)) > 0) {
|
||||
for(int i=0;i<n;++i)
|
||||
myEntry->data.push_back((unsigned char)tmp[i]);
|
||||
}
|
||||
fclose(f);
|
||||
}
|
||||
|
||||
if (myEntry->data.size() <= 0) {
|
||||
std::cout << "Error: no data read." << std::endl;
|
||||
exit(1);
|
||||
} else std::cout << "*** Read " << myEntry->data.size() << " bytes of test data." << std::endl;
|
||||
|
||||
std::cout.flush();
|
||||
}
|
||||
|
||||
DelimArray current;
|
||||
for(unsigned int i=0;i<DELIMITER_SET_SIZE;++i)
|
||||
current[i] = (boost::uint16_t)prng();
|
||||
|
||||
for(;;) {
|
||||
unsigned long numTooShort = 0;
|
||||
unsigned long numTooLong = 0;
|
||||
unsigned long numGood = 0;
|
||||
|
||||
boost::uint32_t shiftRegister = 0;
|
||||
unsigned long segSize = 0;
|
||||
for(std::vector<unsigned char>::iterator i=myEntry->data.begin();i!=myEntry->data.end();++i) {
|
||||
shiftRegister <<= 1;
|
||||
shiftRegister |= (((boost::uint32_t)*i) & 1);
|
||||
|
||||
++segSize;
|
||||
|
||||
boost::uint16_t transformedShiftRegister = (boost::uint16_t)(shiftRegister);
|
||||
|
||||
for(DelimArray::iterator d=current.begin();d!=current.end();++d) {
|
||||
if (transformedShiftRegister == *d) {
|
||||
if (segSize < MIN_DESIRED_SIZE)
|
||||
++numTooShort;
|
||||
else if (segSize > MAX_DESIRED_SIZE)
|
||||
++numTooLong;
|
||||
else ++numGood;
|
||||
segSize = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (segSize) {
|
||||
if (segSize < MIN_DESIRED_SIZE)
|
||||
++numTooShort;
|
||||
else if (segSize > MAX_DESIRED_SIZE)
|
||||
++numTooLong;
|
||||
else ++numGood;
|
||||
}
|
||||
|
||||
if (numGood) {
|
||||
double score = ((double)(numTooShort + numTooLong)) / ((double)numGood);
|
||||
|
||||
if (score < myEntry->bestScore) {
|
||||
myEntry->best = current;
|
||||
myEntry->bestScore = score;
|
||||
|
||||
boost::mutex::scoped_lock l(outLock);
|
||||
|
||||
std::cout << fileName << ": ";
|
||||
|
||||
for(DelimArray::iterator d=current.begin();d!=current.end();++d) {
|
||||
sprintf(tmp,"0x%.4x",(unsigned int)*d);
|
||||
if (d != current.begin())
|
||||
std::cout << ',';
|
||||
std::cout << tmp;
|
||||
}
|
||||
|
||||
std::cout << ": " << numTooShort << " / " << numGood << " / " << numTooLong << " (" << score << ")" << std::endl;
|
||||
std::cout.flush();
|
||||
|
||||
if ((numTooShort == 0)&&(numTooLong == 0))
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for(DelimArray::iterator i=current.begin();i!=current.end();++i)
|
||||
*i = (boost::uint16_t)prng();
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc,char **argv)
|
||||
{
|
||||
std::vector< boost::shared_ptr<boost::thread> > threads;
|
||||
|
||||
for(int i=1;i<argc;++i) {
|
||||
boost::shared_ptr<boost::thread> t(new boost::thread(boost::bind(&runThread,std::string(argv[i]))));
|
||||
threads.push_back(t);
|
||||
}
|
||||
|
||||
for(std::vector< boost::shared_ptr<boost::thread> >::iterator i=threads.begin();i!=threads.end();++i)
|
||||
(*i)->join();
|
||||
|
||||
return 0;
|
||||
}
|
5
attic/historic/anode/libspark/experiments/Makefile
Normal file
5
attic/historic/anode/libspark/experiments/Makefile
Normal file
@ -0,0 +1,5 @@
|
||||
all:
|
||||
g++ -O6 -ftree-vectorize -o FindGoodSegmentDelimiters FindGoodSegmentDelimiters.cpp -lboost_thread -lpthread
|
||||
|
||||
clean:
|
||||
rm FindGoodSegmentDelimiters
|
108
attic/historic/anode/libspark/streamencoder.h
Normal file
108
attic/historic/anode/libspark/streamencoder.h
Normal file
@ -0,0 +1,108 @@
|
||||
/* libanode: the Anode C reference implementation
|
||||
* Copyright (C) 2009 Adam Ierymenko <adam.ierymenko@gmail.com>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
||||
|
||||
#ifndef _SPARK_STREAMENCODER_H
|
||||
#define _SPARK_STREAMENCODER_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
unsigned char *input_buf;
|
||||
unsigned long input_buf_capacity;
|
||||
unsigned long input_length;
|
||||
|
||||
unsigned char *stream_out_buf;
|
||||
unsigned long stream_out_buf_capacity;
|
||||
unsigned long stream_out_length;
|
||||
|
||||
void (*data_segment_add_func)(const void *data,unsigned long len,const void *global_hash,unsigned long global_hash_len);
|
||||
} SparkStreamEncoder;
|
||||
|
||||
/**
|
||||
* Initialize a spark stream encoder
|
||||
*
|
||||
* @param enc Encoder structure to initialize
|
||||
* @param data_segment_add_func Function to call to store or cache data
|
||||
*/
|
||||
void SparkStreamEncoder_init(
|
||||
SparkStreamEncoder *enc,
|
||||
void (*data_segment_add_func)(
|
||||
const void *data,
|
||||
unsigned long len,
|
||||
const void *global_hash,
|
||||
unsigned long global_hash_len));
|
||||
|
||||
/**
|
||||
* Clean up a spark stream encoder structure
|
||||
*
|
||||
* @param enc Structure to clear
|
||||
*/
|
||||
void SparkStreamEncoder_destroy(SparkStreamEncoder *enc);
|
||||
|
||||
/**
|
||||
* Add data to encode
|
||||
*
|
||||
* @param enc Encoder structure
|
||||
* @param data Data to encode
|
||||
* @param len Length of data in bytes
|
||||
* @return Number of bytes of result stream now available
|
||||
*/
|
||||
unsigned long SparkStreamEncoder_put(
|
||||
SparkStreamEncoder *enc,
|
||||
const void *data,
|
||||
unsigned long len);
|
||||
|
||||
/**
|
||||
* Flush all data currently in input buffer
|
||||
*
|
||||
* @param enc Encoder structure to flush
|
||||
*/
|
||||
void SparkStreamEncoder_flush(SparkStreamEncoder *enc);
|
||||
|
||||
/**
|
||||
* @return Number of bytes of output stream available
|
||||
*/
|
||||
static inline unsigned long SparkStreamEncoder_available(SparkStreamEncoder *enc)
|
||||
{
|
||||
return enc->stream_out_length;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Pointer to result stream bytes (may return null if none available)
|
||||
*/
|
||||
static inline const void *SparkStreamEncoder_get(SparkStreamEncoder *enc)
|
||||
{
|
||||
return (const void *)(enc->stream_out_buf);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return "Consume" result stream bytes after they're read or sent
|
||||
*/
|
||||
static inline void SparkStreamEncoder_consume(SparkStreamEncoder *enc,unsigned long len)
|
||||
{
|
||||
unsigned long i;
|
||||
for(i=len;i<enc->stream_out_length;++i)
|
||||
enc->stream_out_buf[i - len] = enc->stream_out_buf[i];
|
||||
}
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user