mirror of
https://github.com/amnezia-vpn/amnezia-client.git
synced 2026-05-08 14:33:23 +00:00
Compare commits
786 Commits
bugfix/ada
...
bugfix/use
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5bdd7b2362 | ||
|
|
d4fff4af3c | ||
|
|
f0903c32f3 | ||
|
|
ea8875478e | ||
|
|
4c08e9f3bc | ||
|
|
e8736102bf | ||
|
|
371cadcc02 | ||
|
|
c3805195af | ||
|
|
2ef267bc44 | ||
|
|
02a98b9d68 | ||
|
|
94bae4b859 | ||
|
|
425acc5f8b | ||
|
|
bb87c0838d | ||
|
|
268adfb0a1 | ||
|
|
c681611102 | ||
|
|
4fc2a23f49 | ||
|
|
23f4a6ec8e | ||
|
|
504862c2b8 | ||
|
|
a22a9448ca | ||
|
|
862e83ddf5 | ||
|
|
8735eee662 | ||
|
|
ff82cf5dc4 | ||
|
|
8648790583 | ||
|
|
b881d92a80 | ||
|
|
7ad7f31e4d | ||
|
|
138e6f70a4 | ||
|
|
6f94f4646a | ||
|
|
4a01d2cf20 | ||
|
|
8948601caa | ||
|
|
aa92ccd06d | ||
|
|
253ae75795 | ||
|
|
87cb5f620a | ||
|
|
46cd740a84 | ||
|
|
76e5039578 | ||
|
|
c6b131aa4c | ||
|
|
5e72bf945c | ||
|
|
eebf7eccec | ||
|
|
168c293bfe | ||
|
|
aae3cdcac1 | ||
|
|
96566f04ee | ||
|
|
fff15fffe2 | ||
|
|
4e5a03e7f1 | ||
|
|
7571bbc36e | ||
|
|
db4a1a62e5 | ||
|
|
581773ce03 | ||
|
|
46058f614e | ||
|
|
9cab51fb00 | ||
|
|
918be16372 | ||
|
|
175477d31f | ||
|
|
cd70b7e619 | ||
|
|
22011e263e | ||
|
|
88a2b9a07a | ||
|
|
248f487d4e | ||
|
|
572ef09296 | ||
|
|
03078236ab | ||
|
|
b39a0a1d94 | ||
|
|
e94fc688ba | ||
|
|
558f613acc | ||
|
|
d800a95a1d | ||
|
|
b8f100d4fa | ||
|
|
51618fb882 | ||
|
|
14f537ba76 | ||
|
|
3458ed78d7 | ||
|
|
4bc571f609 | ||
|
|
ee61f842e5 | ||
|
|
758b25947c | ||
|
|
b036c38981 | ||
|
|
eab2b8e45a | ||
|
|
dfdec2bf4b | ||
|
|
843156cf1b | ||
|
|
01413e5a4c | ||
|
|
743304c359 | ||
|
|
6c5d590169 | ||
|
|
a1e68f5506 | ||
|
|
424315b17f | ||
|
|
b83e74427e | ||
|
|
8fefae0325 | ||
|
|
ede633ea03 | ||
|
|
b4469064a2 | ||
|
|
393e289784 | ||
|
|
d18423ee8c | ||
|
|
3fc9edd346 | ||
|
|
1a1f75d873 | ||
|
|
df02e0bf78 | ||
|
|
264d77463d | ||
|
|
0a37ffd5e3 | ||
|
|
1343d10aa7 | ||
|
|
6f96ebd8bf | ||
|
|
cb531dacb3 | ||
|
|
dfd0b4d0e5 | ||
|
|
f978f55e7f | ||
|
|
73516c28af | ||
|
|
dc85a99e08 | ||
|
|
ef06fcb4f4 | ||
|
|
ffe2314d47 | ||
|
|
4e970322d0 | ||
|
|
8dee0d27cf | ||
|
|
c520f9a2a4 | ||
|
|
003c3a23c4 | ||
|
|
1754a82f67 | ||
|
|
3384008277 | ||
|
|
af22115706 | ||
|
|
4b114fd3b6 | ||
|
|
9d531f5d74 | ||
|
|
a5564148f5 | ||
|
|
196f7778fc | ||
|
|
de20add857 | ||
|
|
c59216b58a | ||
|
|
acf7fa261a | ||
|
|
c3eddc92bd | ||
|
|
18c74f4b02 | ||
|
|
3f90ee915d | ||
|
|
401ad0db0e | ||
|
|
5945133d30 | ||
|
|
ff4fbde0b0 | ||
|
|
74ae4f3e67 | ||
|
|
ae4b33d042 | ||
|
|
53fa280037 | ||
|
|
8ecde90bc7 | ||
|
|
34a583f272 | ||
|
|
5de4b8eeb8 | ||
|
|
aae420e469 | ||
|
|
0612f70c06 | ||
|
|
d0c82efa1c | ||
|
|
cf8492240e | ||
|
|
2bceb9f7ba | ||
|
|
760f935965 | ||
|
|
eeeb2805c5 | ||
|
|
9a592d67ad | ||
|
|
ea6618b2f6 | ||
|
|
7b092e73ad | ||
|
|
b2e25c42c7 | ||
|
|
c8dd38ac31 | ||
|
|
563ee4703f | ||
|
|
beceed81de | ||
|
|
3bf96253db | ||
|
|
da2d0ec203 | ||
|
|
008b858203 | ||
|
|
130fc8277d | ||
|
|
468d3357b8 | ||
|
|
f1271da527 | ||
|
|
249a7c7ca3 | ||
|
|
0094d0ebc4 | ||
|
|
834b504dff | ||
|
|
a516d0e757 | ||
|
|
afdfbdbc59 | ||
|
|
ef712b7054 | ||
|
|
c22f9ff08a | ||
|
|
04fb1825d5 | ||
|
|
4f8f873682 | ||
|
|
9fe75c6120 | ||
|
|
bb7e8f46cb | ||
|
|
5db0c281ee | ||
|
|
aac9bfcea6 | ||
|
|
e6ee9085a2 | ||
|
|
d62ade58a5 | ||
|
|
d8020878d5 | ||
|
|
b027fff103 | ||
|
|
a0c06048cd | ||
|
|
53746f2f66 | ||
|
|
2649dba4ad | ||
|
|
6a1e3c07b1 | ||
|
|
a365eff76f | ||
|
|
8f9acd9367 | ||
|
|
53fdf5f70d | ||
|
|
9be13ea465 | ||
|
|
871aced1d1 | ||
|
|
2254bfc128 | ||
|
|
b71dcb8dd0 | ||
|
|
33d1518fd2 | ||
|
|
ee5344a4ea | ||
|
|
abb3c918e3 | ||
|
|
ff348a348c | ||
|
|
d67c378bff | ||
|
|
d85a0439c5 | ||
|
|
9faabe9e7d | ||
|
|
5bd8c33a6d | ||
|
|
24759c92ad | ||
|
|
9e92ee020e | ||
|
|
7a4f6b628b | ||
|
|
7e2f223d7f | ||
|
|
eb48e4b668 | ||
|
|
9ace09a604 | ||
|
|
702735c2ca | ||
|
|
174f2ac3db | ||
|
|
e3b5b4a9d9 | ||
|
|
72ba012765 | ||
|
|
0f9bbcd060 | ||
|
|
a9d038d8bf | ||
|
|
54a6845315 | ||
|
|
0c7059a476 | ||
|
|
5bed92ab0b | ||
|
|
49a14785c6 | ||
|
|
2c78c06dda | ||
|
|
cf8a0efd0d | ||
|
|
5211cdd4c0 | ||
|
|
d10aa43d8b | ||
|
|
6b0f1ed429 | ||
|
|
4bde1ccb44 | ||
|
|
03c18c44e2 | ||
|
|
72ffc7ce6a | ||
|
|
87b738ef16 | ||
|
|
b868831bcb | ||
|
|
477d7214c5 | ||
|
|
f3cd3d4f06 | ||
|
|
aea4cc2389 | ||
|
|
245aa8eb8c | ||
|
|
f14a2add0f | ||
|
|
89703ba58f | ||
|
|
23715fca8b | ||
|
|
d90685600e | ||
|
|
f007e5eb5c | ||
|
|
a8ccea00c7 | ||
|
|
cd2ee00769 | ||
|
|
c98a418807 | ||
|
|
0e4ae26bae | ||
|
|
d50e7dd3f4 | ||
|
|
f0085f52eb | ||
|
|
5c19b08e5e | ||
|
|
79edbe52a3 | ||
|
|
0dd181bb5b | ||
|
|
d8682003fa | ||
|
|
f4a2cf9984 | ||
|
|
98e6358fd3 | ||
|
|
af90065d2e | ||
|
|
f372f4074b | ||
|
|
6a2e5f83a1 | ||
|
|
a2badd46c4 | ||
|
|
8623a983b8 | ||
|
|
151e662027 | ||
|
|
f588fe29db | ||
|
|
030b0351a2 | ||
|
|
d4453a5f38 | ||
|
|
2252905596 | ||
|
|
ec650a65f7 | ||
|
|
6953f8d814 | ||
|
|
624a84cbfb | ||
|
|
506d9793e1 | ||
|
|
ef52f6ab08 | ||
|
|
5312a6e885 | ||
|
|
fdd600794e | ||
|
|
7bfbdca72a | ||
|
|
a22c08a41d | ||
|
|
10ea9b418a | ||
|
|
e39efb1d68 | ||
|
|
7db84122f9 | ||
|
|
84ad167ab4 | ||
|
|
ed7e217a6b | ||
|
|
c1b0d4a4a7 | ||
|
|
2f84e24353 | ||
|
|
f73586185b | ||
|
|
653ffb9a68 | ||
|
|
fe8c2d157a | ||
|
|
86367a1276 | ||
|
|
b0fcf92ada | ||
|
|
283b6ebf81 | ||
|
|
d0a7fc5116 | ||
|
|
9851aacba7 | ||
|
|
51f9fb9e0a | ||
|
|
0325761f3e | ||
|
|
a6ca1b12da | ||
|
|
82a9e7e27d | ||
|
|
f5301e1315 | ||
|
|
adab30fc81 | ||
|
|
e7bd24f065 | ||
|
|
2ec448ba13 | ||
|
|
c6e6f2ae84 | ||
|
|
e9468a4c2f | ||
|
|
45de951897 | ||
|
|
db8d966fac | ||
|
|
6b69bc9618 | ||
|
|
0089b0b799 | ||
|
|
e4841e809b | ||
|
|
ba4237f1dd | ||
|
|
f6acec53c0 | ||
|
|
5f631eaa76 | ||
|
|
7730dd510c | ||
|
|
30bd264f17 | ||
|
|
5206665fa0 | ||
|
|
073491ccb4 | ||
|
|
561b62cd40 | ||
|
|
1284ed4d84 | ||
|
|
6f34443191 | ||
|
|
02f186c54e | ||
|
|
784c6cf585 | ||
|
|
14f132e127 | ||
|
|
9cb624e681 | ||
|
|
516e3da7e2 | ||
|
|
0e83586cae | ||
|
|
95bdae68f4 | ||
|
|
294778884b | ||
|
|
10caecbffd | ||
|
|
553a6a73dd | ||
|
|
e646b85e56 | ||
|
|
b7c513c05f | ||
|
|
9f82b4c21f | ||
|
|
02b2da38cf | ||
|
|
f51077b2be | ||
|
|
33f49bfddb | ||
|
|
9a81f13f81 | ||
|
|
915fb6759a | ||
|
|
c5a5bfde69 | ||
|
|
0a90fd110d | ||
|
|
541d6eb0b8 | ||
|
|
d443a0063d | ||
|
|
f0c6edb670 | ||
|
|
9189b53a0d | ||
|
|
fceccaefcc | ||
|
|
fbeabf43ca | ||
|
|
78c7893f90 | ||
|
|
cb9a25006c | ||
|
|
0e87550d85 | ||
|
|
dceb0ab832 | ||
|
|
a33590476a | ||
|
|
deaf618520 | ||
|
|
3d8a56d922 | ||
|
|
36af7cf471 | ||
|
|
ebd3449b4a | ||
|
|
99182f4a67 | ||
|
|
da84ba1a4d | ||
|
|
bca68fc185 | ||
|
|
59a7265bac | ||
|
|
9201ca1e03 | ||
|
|
6b6a76d2cc | ||
|
|
840c388ab9 | ||
|
|
5b4ec608c8 | ||
|
|
79ff1b81e0 | ||
|
|
ea67c01da8 | ||
|
|
1137e169ea | ||
|
|
17748cca47 | ||
|
|
080e1d98c6 | ||
|
|
ca633ae882 | ||
|
|
bb7b64fb96 | ||
|
|
bf901631bf | ||
|
|
0c0ce54b1f | ||
|
|
ee762c4cef | ||
|
|
ed9efb5a79 | ||
|
|
73eb85f2f4 | ||
|
|
cd055cff62 | ||
|
|
f8b2cce618 | ||
|
|
e648054c7a | ||
|
|
fe558163cc | ||
|
|
3883b8ff34 | ||
|
|
d286664763 | ||
|
|
b05ad2392b | ||
|
|
6dbdb85aaf | ||
|
|
26b48cfe4f | ||
|
|
2f39136143 | ||
|
|
8d0d3c5ce9 | ||
|
|
256081e4ed | ||
|
|
1dd7b0a221 | ||
|
|
82c0b28906 | ||
|
|
985fe083f0 | ||
|
|
6a0000dc4b | ||
|
|
1dd2f38066 | ||
|
|
004e1e3ca5 | ||
|
|
7c560d709b | ||
|
|
d3743ad62f | ||
|
|
ac234b77e2 | ||
|
|
9886987e68 | ||
|
|
d34cb8898f | ||
|
|
13aadbda64 | ||
|
|
c7c7c8eb01 | ||
|
|
b1e5bba33f | ||
|
|
474e7c6d62 | ||
|
|
794ec921b8 | ||
|
|
b674240362 | ||
|
|
a768c7c451 | ||
|
|
28d2a4ec2c | ||
|
|
9f1210d18f | ||
|
|
3012559627 | ||
|
|
b3ed57aee7 | ||
|
|
89d0a8107d | ||
|
|
6c0b71bd1b | ||
|
|
61abf74b2d | ||
|
|
21fdf02921 | ||
|
|
7a245d80ee | ||
|
|
da85922f23 | ||
|
|
a5356b6319 | ||
|
|
3828891b9b | ||
|
|
15d866ce04 | ||
|
|
560eb3d620 | ||
|
|
ac894254cc | ||
|
|
17e3fbde25 | ||
|
|
ee11a8410c | ||
|
|
ff5c51cfd9 | ||
|
|
b3943ae5e3 | ||
|
|
a32952fde6 | ||
|
|
9c4ee4014d | ||
|
|
dc9069f1f4 | ||
|
|
e402cacc05 | ||
|
|
a98cd248d6 | ||
|
|
00fbfb6a01 | ||
|
|
86c31c3766 | ||
|
|
698cfe910c | ||
|
|
16db23c159 | ||
|
|
b05a5ee1c6 | ||
|
|
8cb298937f | ||
|
|
68fe20ddf6 | ||
|
|
fab167bb34 | ||
|
|
f640d4b5f5 | ||
|
|
074562b141 | ||
|
|
fd030a5fd4 | ||
|
|
82fa6b13c6 | ||
|
|
bf16298c40 | ||
|
|
bcebb0a2b5 | ||
|
|
b27442cf74 | ||
|
|
92fbbd4812 | ||
|
|
321ed810e3 | ||
|
|
17ff530683 | ||
|
|
2b413736a4 | ||
|
|
a416d03614 | ||
|
|
4de9a274dd | ||
|
|
0b8f3c9d9d | ||
|
|
f3a168fd43 | ||
|
|
158c11a0ec | ||
|
|
f2d13148a3 | ||
|
|
6c8b4e1fb2 | ||
|
|
c95dffff0c | ||
|
|
6346fc04ae | ||
|
|
3a87354f8d | ||
|
|
e0863a58aa | ||
|
|
dba05aab07 | ||
|
|
fec904fd28 | ||
|
|
db321bed5d | ||
|
|
28cc0218c5 | ||
|
|
a2d5f25b58 | ||
|
|
3100160927 | ||
|
|
1c3fdd3c72 | ||
|
|
0c13eda1f5 | ||
|
|
f37b7cec87 | ||
|
|
962c75b2ca | ||
|
|
9a62e2ae41 | ||
|
|
0f00dc4e7c | ||
|
|
0f04cf6eae | ||
|
|
dc76ad820f | ||
|
|
e0cde9f138 | ||
|
|
db1dc78e38 | ||
|
|
fd98ef1250 | ||
|
|
cdf46c968a | ||
|
|
72b20ef563 | ||
|
|
30a0ac0def | ||
|
|
090208bd2c | ||
|
|
1e5c9c9c4d | ||
|
|
5918f37ffa | ||
|
|
554e1b1b91 | ||
|
|
8f510c1431 | ||
|
|
4723019624 | ||
|
|
1be9078b6c | ||
|
|
520658a295 | ||
|
|
b9ec722abb | ||
|
|
d917c798d7 | ||
|
|
0d168c039f | ||
|
|
af8f265555 | ||
|
|
c0e0d64284 | ||
|
|
9466a71141 | ||
|
|
d28a586a97 | ||
|
|
6fde0b6663 | ||
|
|
d143b9213b | ||
|
|
16433e9e46 | ||
|
|
39479d1999 | ||
|
|
a03b766e33 | ||
|
|
7df2655ba0 | ||
|
|
5c2ca9803d | ||
|
|
4e6af947fa | ||
|
|
bc9d5c8fd6 | ||
|
|
f412ac6260 | ||
|
|
26d8dfbb7f | ||
|
|
b45517bafd | ||
|
|
3edb6755b4 | ||
|
|
bda64fa391 | ||
|
|
e7040f7cc8 | ||
|
|
229970e799 | ||
|
|
7b0a9a055f | ||
|
|
06d370f716 | ||
|
|
ce0a4f1f96 | ||
|
|
3240aa3cb3 | ||
|
|
5c5935c738 | ||
|
|
00b2b1abcd | ||
|
|
e0891e1a15 | ||
|
|
f7df621c56 | ||
|
|
0b6dc5bcfc | ||
|
|
cbd6755aa5 | ||
|
|
3afbc248b1 | ||
|
|
30af81fe0a | ||
|
|
427b43c99b | ||
|
|
ed08ac6b46 | ||
|
|
1a2c1fa1b5 | ||
|
|
709fbac231 | ||
|
|
6b80a56f92 | ||
|
|
5c9d45a8a8 | ||
|
|
2edac24945 | ||
|
|
b68c9cc145 | ||
|
|
6f02d4eb62 | ||
|
|
6e60688e70 | ||
|
|
140b5c4292 | ||
|
|
8ee2ebbd20 | ||
|
|
b3eda4106d | ||
|
|
885e22be7c | ||
|
|
83ec073734 | ||
|
|
0160b0f9dc | ||
|
|
f55bd5e1a1 | ||
|
|
4d88eb8e79 | ||
|
|
874de74ac8 | ||
|
|
b3a4b34d48 | ||
|
|
f7b9d2bae7 | ||
|
|
ec4574bfcf | ||
|
|
73cfab166f | ||
|
|
0e8f85057d | ||
|
|
2e4908c557 | ||
|
|
401784414a | ||
|
|
8495124bc8 | ||
|
|
ba6ed540f5 | ||
|
|
19a60ea856 | ||
|
|
aecf1b463c | ||
|
|
ff24ba1011 | ||
|
|
802b708232 | ||
|
|
adeff3efb9 | ||
|
|
0103c1722e | ||
|
|
f9123e7b71 | ||
|
|
0f9ed4e69c | ||
|
|
9dfc95bac0 | ||
|
|
9b7914538f | ||
|
|
85c9cd260d | ||
|
|
73751cc049 | ||
|
|
2b61c48303 | ||
|
|
47b03f2bf4 | ||
|
|
3e02dfef63 | ||
|
|
4176d0130a | ||
|
|
f6175c2c69 | ||
|
|
b8b423ca19 | ||
|
|
3702d69b9d | ||
|
|
3253de9384 | ||
|
|
51070635a5 | ||
|
|
9b533f1ba6 | ||
|
|
9371dd405e | ||
|
|
27d8108e55 | ||
|
|
820a3f0b77 | ||
|
|
3d61b20271 | ||
|
|
eec81f8124 | ||
|
|
d7fbddb97f | ||
|
|
9170cb0318 | ||
|
|
76dec6fa9c | ||
|
|
4e3edcfc0a | ||
|
|
ad21d7ab64 | ||
|
|
f576eb509d | ||
|
|
33e229d0b2 | ||
|
|
78420d617b | ||
|
|
2552e33d64 | ||
|
|
301141c755 | ||
|
|
fac57ac89a | ||
|
|
da5ad0a845 | ||
|
|
60aeefe1c2 | ||
|
|
d527f6a5ce | ||
|
|
2802b42747 | ||
|
|
66c5d2f0a8 | ||
|
|
6dbf4ac62c | ||
|
|
ae2872830b | ||
|
|
6f4a3587e4 | ||
|
|
145f51906e | ||
|
|
12e72bc74b | ||
|
|
65a04799ef | ||
|
|
88cd5825d3 | ||
|
|
ecdad2a315 | ||
|
|
0398ddd6a2 | ||
|
|
50ea4d3b0f | ||
|
|
77be8169f2 | ||
|
|
7a435f76b6 | ||
|
|
42949e0dea | ||
|
|
26db423232 | ||
|
|
645cf52803 | ||
|
|
673b8ad5b2 | ||
|
|
2a03834bb2 | ||
|
|
c1b6149e49 | ||
|
|
0690d86e52 | ||
|
|
bb8a11d110 | ||
|
|
4f7ba4c9a8 | ||
|
|
aa41e4d915 | ||
|
|
bb43b5451f | ||
|
|
69dd415ab5 | ||
|
|
e605f549bd | ||
|
|
a961932b2e | ||
|
|
e8cc80f046 | ||
|
|
67f29ac483 | ||
|
|
c9bde5cdc0 | ||
|
|
e878911819 | ||
|
|
f1a0b7f0ef | ||
|
|
3e0a5104e7 | ||
|
|
8f53d563a4 | ||
|
|
414740ffb7 | ||
|
|
7437d47d92 | ||
|
|
a68f19d72f | ||
|
|
11641c5e22 | ||
|
|
8d3e21d46a | ||
|
|
5ad54bfdc1 | ||
|
|
a8f5e95fb1 | ||
|
|
a4f3d08c02 | ||
|
|
3d2174d84e | ||
|
|
12fbc7d258 | ||
|
|
164b7e2551 | ||
|
|
eafac491d8 | ||
|
|
3cfb6e968d | ||
|
|
375825125f | ||
|
|
a8520e7545 | ||
|
|
ac154cdd83 | ||
|
|
9290775ab5 | ||
|
|
d14e8cdee4 | ||
|
|
7aac9f9d0e | ||
|
|
41aaac7d32 | ||
|
|
c8d2399db9 | ||
|
|
f37c8e5fd4 | ||
|
|
9f5025c10b | ||
|
|
c27d999c41 | ||
|
|
9681bea237 | ||
|
|
8905d6352c | ||
|
|
8599b20678 | ||
|
|
491f09a51b | ||
|
|
0f1519a21f | ||
|
|
1a17f2956a | ||
|
|
d94e27bfa9 | ||
|
|
b892156092 | ||
|
|
7b1b8dc749 | ||
|
|
6d0167dcf3 | ||
|
|
0c2d661e1c | ||
|
|
95d1440d6f | ||
|
|
0cabf60dc4 | ||
|
|
836ca1cc6b | ||
|
|
be799daafe | ||
|
|
ad9d674a03 | ||
|
|
f52c3c430f | ||
|
|
a91ab0e910 | ||
|
|
39d1f1677f | ||
|
|
b0dcae3586 | ||
|
|
ed6351f8f1 | ||
|
|
e486a2fb26 | ||
|
|
195bdb947e | ||
|
|
1576aed1ea | ||
|
|
e66fbc3289 | ||
|
|
b4c89ad58f | ||
|
|
8cc5846808 | ||
|
|
2eaaf01ca1 | ||
|
|
67694c0f96 | ||
|
|
163e5b2c52 | ||
|
|
508f1d3a42 | ||
|
|
d2207a5255 | ||
|
|
bf03f5c9ae | ||
|
|
656223f57d | ||
|
|
dc6e3ec53b | ||
|
|
5835a756ce | ||
|
|
f3f98a50ed | ||
|
|
0f4bb78712 | ||
|
|
c4014518cb | ||
|
|
3605f62feb | ||
|
|
5c3e253067 | ||
|
|
8d43cee52e | ||
|
|
1e64413904 | ||
|
|
6fd1ea26ee | ||
|
|
e619fd4af9 | ||
|
|
e7658f9859 | ||
|
|
3defb09da9 | ||
|
|
a672434909 | ||
|
|
c3fdd977b1 | ||
|
|
dd233f77fc | ||
|
|
02efd9c217 | ||
|
|
20f3c0388a | ||
|
|
ef530780bd | ||
|
|
d7ec611ff4 | ||
|
|
b897e7102e | ||
|
|
1cc5c5384e | ||
|
|
db602ac65b | ||
|
|
eaa209bc3a | ||
|
|
51d4aea9e2 | ||
|
|
9738ada946 | ||
|
|
8ec105bee0 | ||
|
|
4fd0852bb3 | ||
|
|
a53e904f7b | ||
|
|
2d22b52b5d | ||
|
|
426ac49f6f | ||
|
|
c164814abd | ||
|
|
3084892ed8 | ||
|
|
9297f877c4 | ||
|
|
1bf808c9ee | ||
|
|
91f44fb394 | ||
|
|
385a52f676 | ||
|
|
8ef16781eb | ||
|
|
ad5ea1ca44 | ||
|
|
0ba5d754d5 | ||
|
|
ccdcfdce8a | ||
|
|
712fb4d0d3 | ||
|
|
de65a03998 | ||
|
|
6d6710db4a | ||
|
|
c34c3e51ea | ||
|
|
5dc3b64e0b | ||
|
|
e8ceeb6e20 | ||
|
|
d38c7ce6a5 | ||
|
|
e625543b94 | ||
|
|
679bd4e4c9 | ||
|
|
c6a312845a | ||
|
|
ef0530ec6b | ||
|
|
2c98a90d60 | ||
|
|
b90fad6664 | ||
|
|
5a5ea4a018 | ||
|
|
bc68c487ee | ||
|
|
617cdf14ad | ||
|
|
f1c970461f | ||
|
|
2fde47a86f | ||
|
|
4e5f2f44b6 | ||
|
|
e8a2e54d05 | ||
|
|
d77f3ecee8 | ||
|
|
06776ebe8f | ||
|
|
e1eec55f62 | ||
|
|
fcabf08e74 | ||
|
|
b4694313a0 | ||
|
|
abb2cae1f8 | ||
|
|
b0004fd9dc | ||
|
|
362a82f944 | ||
|
|
19fe61ed29 | ||
|
|
72de38b4fb | ||
|
|
02c0f96e5e | ||
|
|
aee82282ac | ||
|
|
8497aeeb91 | ||
|
|
5e9f688000 | ||
|
|
6a7e346695 | ||
|
|
071738116e | ||
|
|
147726ecb0 | ||
|
|
ae4ee6431d | ||
|
|
9cfcb714ae | ||
|
|
d1ccde2a4b | ||
|
|
4848091203 | ||
|
|
282f159311 | ||
|
|
4ef8c77a2d | ||
|
|
08c1cf2439 | ||
|
|
2fc33875bb | ||
|
|
9e92e4b5ff | ||
|
|
7f2cf70bf5 | ||
|
|
40725d4155 | ||
|
|
8164026891 | ||
|
|
0e23b3a1ac | ||
|
|
1739d4861e | ||
|
|
a6b6e7850d | ||
|
|
3e9dea6f07 | ||
|
|
1b37ca805f | ||
|
|
c772f56da7 | ||
|
|
bc183e39bb | ||
|
|
306d4f70a8 | ||
|
|
a386d39495 | ||
|
|
22b14dff5f | ||
|
|
e749cc7578 | ||
|
|
3e03002ead | ||
|
|
4ae9cddcce | ||
|
|
16724645ce | ||
|
|
6a12cad1c9 | ||
|
|
c15665803d | ||
|
|
97090888d5 | ||
|
|
4642308fbb | ||
|
|
59bccb1188 | ||
|
|
cd8fc007ac | ||
|
|
7cfb38307e | ||
|
|
994aa32745 | ||
|
|
f0b872e86b | ||
|
|
0c33432436 | ||
|
|
0bb4dd9442 | ||
|
|
7a54dc15da | ||
|
|
e16a1100d8 | ||
|
|
99214e22e3 | ||
|
|
c77d35a2ed | ||
|
|
d98fdbdc5c | ||
|
|
78c83b2e21 | ||
|
|
414a47e2f2 | ||
|
|
32c304dc1b | ||
|
|
4ea1a19572 | ||
|
|
fcf6bb43b7 | ||
|
|
f5f72f87a6 | ||
|
|
3340451245 | ||
|
|
c14f1b5000 | ||
|
|
546d4c1d3d | ||
|
|
2a0166bb26 | ||
|
|
2df612ec1f | ||
|
|
9cf5590371 | ||
|
|
2a4a01a4be | ||
|
|
501670bdd2 | ||
|
|
24637a1693 | ||
|
|
7bd1340190 | ||
|
|
b78bf39767 | ||
|
|
25f8283edd | ||
|
|
9090ec54e7 |
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -3,3 +3,4 @@ deploy/data/windows/x64/tap/windows_10/OemVista.inf eol=crlf
|
||||
deploy/data/windows/x32/tap/windows_7/OemVista.inf eol=crlf
|
||||
deploy/data/windows/x32/tap/windows_10/OemVista.inf eol=crlf
|
||||
client/3rd/* linguist-vendored
|
||||
client/android/gradlew.bat eol=crlf
|
||||
|
||||
256
.github/workflows/deploy.yml
vendored
256
.github/workflows/deploy.yml
vendored
@@ -1,16 +1,22 @@
|
||||
name: 'Deploy workflow'
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- '**'
|
||||
|
||||
on: [push]
|
||||
env:
|
||||
QT_MIRROR: https://mirrors.ocf.berkeley.edu/qt/ # https://download.qt.io/static/mirrorlist/
|
||||
|
||||
jobs:
|
||||
Build-Linux-Ubuntu:
|
||||
name: 'Build-Linux-Ubuntu'
|
||||
runs-on: ubuntu-20.04
|
||||
|
||||
env:
|
||||
QT_VERSION: 6.5.1
|
||||
QIF_VERSION: 4.6
|
||||
QT_VERSION: 6.6.2
|
||||
QIF_VERSION: 4.7
|
||||
PROD_AGW_PUBLIC_KEY: ${{ secrets.PROD_AGW_PUBLIC_KEY }}
|
||||
DEV_AGW_PUBLIC_KEY: ${{ secrets.DEV_AGW_PUBLIC_KEY }}
|
||||
|
||||
steps:
|
||||
- name: 'Install Qt'
|
||||
@@ -25,10 +31,10 @@ jobs:
|
||||
setup-python: 'true'
|
||||
tools: 'tools_ifw'
|
||||
set-env: 'true'
|
||||
extra: '--external 7z'
|
||||
extra: '--external 7z --base ${{ env.QT_MIRROR }}'
|
||||
|
||||
- name: 'Get sources'
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: 'true'
|
||||
fetch-depth: 10
|
||||
@@ -43,33 +49,45 @@ jobs:
|
||||
export QIF_BIN_DIR=${{ runner.temp }}/Qt/Tools/QtInstallerFramework/${{ env.QIF_VERSION }}/bin
|
||||
bash deploy/build_linux.sh
|
||||
|
||||
- name: 'Pack installer'
|
||||
run: cd deploy && tar -cf AmneziaVPN_Linux_Installer.tar AmneziaVPN_Linux_Installer.bin
|
||||
|
||||
- name: 'Upload installer artifact'
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: AmneziaVPN_Linux_installer
|
||||
path: deploy/AmneziaVPN_Linux_Installer
|
||||
name: AmneziaVPN_Linux_installer.tar
|
||||
path: deploy/AmneziaVPN_Linux_Installer.tar
|
||||
retention-days: 7
|
||||
|
||||
- name: 'Upload unpacked artifact'
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: AmneziaVPN_Linux_unpacked
|
||||
path: deploy/AppDir
|
||||
retention-days: 7
|
||||
|
||||
- name: 'Upload translations artifact'
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: AmneziaVPN_translations
|
||||
path: client/translations
|
||||
retention-days: 7
|
||||
|
||||
# ------------------------------------------------------
|
||||
|
||||
Build-Windows:
|
||||
name: Build-Windows
|
||||
runs-on: windows-latest
|
||||
|
||||
env:
|
||||
QT_VERSION: 6.5.1
|
||||
QIF_VERSION: 4.6
|
||||
QT_VERSION: 6.6.2
|
||||
QIF_VERSION: 4.7
|
||||
BUILD_ARCH: 64
|
||||
PROD_AGW_PUBLIC_KEY: ${{ secrets.PROD_AGW_PUBLIC_KEY }}
|
||||
DEV_AGW_PUBLIC_KEY: ${{ secrets.DEV_AGW_PUBLIC_KEY }}
|
||||
|
||||
steps:
|
||||
- name: 'Get sources'
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: 'true'
|
||||
fetch-depth: 10
|
||||
@@ -89,7 +107,7 @@ jobs:
|
||||
setup-python: 'true'
|
||||
tools: 'tools_ifw'
|
||||
set-env: 'true'
|
||||
extra: '--external 7z'
|
||||
extra: '--external 7z --base ${{ env.QT_MIRROR }}'
|
||||
|
||||
- name: 'Setup mvsc'
|
||||
uses: ilammy/msvc-dev-cmd@v1
|
||||
@@ -105,13 +123,14 @@ jobs:
|
||||
call deploy\\build_windows.bat
|
||||
|
||||
- name: 'Upload installer artifact'
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: AmneziaVPN_Windows_installer
|
||||
path: AmneziaVPN_x${{ env.BUILD_ARCH }}.exe
|
||||
retention-days: 7
|
||||
|
||||
- name: 'Upload unpacked artifact'
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: AmneziaVPN_Windows_unpacked
|
||||
path: deploy\\build_${{ env.BUILD_ARCH }}\\client\\Release
|
||||
@@ -119,19 +138,21 @@ jobs:
|
||||
|
||||
# ------------------------------------------------------
|
||||
|
||||
Build-IOS:
|
||||
name: 'Build-IOS'
|
||||
runs-on: macos-12
|
||||
Build-iOS:
|
||||
runs-on: macos-13
|
||||
|
||||
env:
|
||||
QT_VERSION: 6.5.2
|
||||
QT_VERSION: 6.6.2
|
||||
CC: cc
|
||||
CXX: c++
|
||||
PROD_AGW_PUBLIC_KEY: ${{ secrets.PROD_AGW_PUBLIC_KEY }}
|
||||
DEV_AGW_PUBLIC_KEY: ${{ secrets.DEV_AGW_PUBLIC_KEY }}
|
||||
|
||||
steps:
|
||||
# Just select XCode
|
||||
- name: 'Setup xcode'
|
||||
uses: maxim-lobanov/setup-xcode@v1
|
||||
with:
|
||||
xcode-version: '14.2'
|
||||
xcode-version: '15.2'
|
||||
|
||||
- name: 'Install desktop Qt'
|
||||
uses: jurplel/install-qt-action@v3
|
||||
@@ -143,6 +164,7 @@ jobs:
|
||||
arch: 'clang_64'
|
||||
dir: ${{ runner.temp }}
|
||||
set-env: 'true'
|
||||
extra: '--base ${{ env.QT_MIRROR }}'
|
||||
|
||||
- name: 'Install iOS Qt'
|
||||
uses: jurplel/install-qt-action@v3
|
||||
@@ -154,10 +176,13 @@ jobs:
|
||||
dir: ${{ runner.temp }}
|
||||
setup-python: 'true'
|
||||
set-env: 'true'
|
||||
extra: '--external 7z'
|
||||
extra: '--external 7z --base ${{ env.QT_MIRROR }}'
|
||||
|
||||
- name: 'Install go'
|
||||
uses: actions/setup-go@v3
|
||||
uses: actions/setup-go@v5
|
||||
with:
|
||||
go-version: '1.22.1'
|
||||
cache: false
|
||||
|
||||
- name: 'Setup gomobile'
|
||||
run: |
|
||||
@@ -166,7 +191,7 @@ jobs:
|
||||
gomobile init
|
||||
|
||||
- name: 'Get sources'
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: 'true'
|
||||
fetch-depth: 10
|
||||
@@ -174,7 +199,7 @@ jobs:
|
||||
- name: 'Setup ccache'
|
||||
uses: hendrikmuhs/ccache-action@v1.2
|
||||
|
||||
- name: Install dependencies
|
||||
- name: 'Install dependencies'
|
||||
run: pip install jsonschema jinja2
|
||||
|
||||
- name: 'Build project'
|
||||
@@ -195,7 +220,7 @@ jobs:
|
||||
IOS_NE_PROVISIONING_PROFILE: ${{ secrets.IOS_NE_PROVISIONING_PROFILE }}
|
||||
|
||||
# - name: 'Upload appstore .ipa and dSYMs to artifacts'
|
||||
# uses: actions/upload-artifact@v3
|
||||
# uses: actions/upload-artifact@v4
|
||||
# with:
|
||||
# name: app-store ipa & dsyms
|
||||
# path: |
|
||||
@@ -206,19 +231,20 @@ jobs:
|
||||
# ------------------------------------------------------
|
||||
|
||||
Build-MacOS:
|
||||
name: 'Build-MacOS'
|
||||
runs-on: macos-latest
|
||||
|
||||
env:
|
||||
# Keep compat with MacOS 10.15 aka Catalina by Qt 6.4
|
||||
QT_VERSION: 6.4.3
|
||||
QIF_VERSION: 4.6
|
||||
PROD_AGW_PUBLIC_KEY: ${{ secrets.PROD_AGW_PUBLIC_KEY }}
|
||||
DEV_AGW_PUBLIC_KEY: ${{ secrets.DEV_AGW_PUBLIC_KEY }}
|
||||
|
||||
steps:
|
||||
- name: 'Setup xcode'
|
||||
uses: maxim-lobanov/setup-xcode@v1
|
||||
with:
|
||||
xcode-version: '13.4'
|
||||
xcode-version: '14.3.1'
|
||||
|
||||
- name: 'Install Qt'
|
||||
uses: jurplel/install-qt-action@v3
|
||||
@@ -230,12 +256,17 @@ jobs:
|
||||
modules: 'qtremoteobjects qt5compat qtshadertools'
|
||||
dir: ${{ runner.temp }}
|
||||
setup-python: 'true'
|
||||
tools: 'tools_ifw'
|
||||
set-env: 'true'
|
||||
extra: '--external 7z'
|
||||
extra: '--external 7z --base ${{ env.QT_MIRROR }}'
|
||||
|
||||
- name: 'Install Qt Installer Framework ${{ env.QIF_VERSION }}'
|
||||
run: |
|
||||
mkdir -pv ${{ runner.temp }}/Qt/Tools/QtInstallerFramework
|
||||
wget https://qt.amzsvc.com/tools/ifw/${{ env.QIF_VERSION }}.zip
|
||||
unzip ${{ env.QIF_VERSION }}.zip -d ${{ runner.temp }}/Qt/Tools/QtInstallerFramework/
|
||||
|
||||
- name: 'Get sources'
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: 'true'
|
||||
fetch-depth: 10
|
||||
@@ -250,13 +281,14 @@ jobs:
|
||||
bash deploy/build_macos.sh
|
||||
|
||||
- name: 'Upload installer artifact'
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: AmneziaVPN_MacOS_installer
|
||||
path: AmneziaVPN.dmg
|
||||
retention-days: 7
|
||||
|
||||
- name: 'Upload unpacked artifact'
|
||||
uses: actions/upload-artifact@v3
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: AmneziaVPN_MacOS_unpacked
|
||||
path: deploy/build/client/AmneziaVPN.app
|
||||
@@ -265,59 +297,78 @@ jobs:
|
||||
# ------------------------------------------------------
|
||||
|
||||
Build-Android:
|
||||
name: 'Build-Android'
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
matrix:
|
||||
include:
|
||||
- abi: 'x86_64'
|
||||
qt_arch: 'android_x86_64'
|
||||
- abi: 'x86'
|
||||
qt_arch: 'android_x86'
|
||||
- abi: 'armeabi-v7a'
|
||||
qt_arch: 'android_armv7'
|
||||
- abi: 'arm64-v8a'
|
||||
qt_arch: 'android_arm64_v8a'
|
||||
|
||||
env:
|
||||
QT_VERSION: 6.5.2
|
||||
ANDROID_BUILD_PLATFORM: android-33
|
||||
ANDROID_BUILD_PLATFORM: android-34
|
||||
QT_VERSION: 6.7.2
|
||||
QT_MODULES: 'qtremoteobjects qt5compat qtimageformats qtshadertools'
|
||||
PROD_AGW_PUBLIC_KEY: ${{ secrets.PROD_AGW_PUBLIC_KEY }}
|
||||
DEV_AGW_PUBLIC_KEY: ${{ secrets.DEV_AGW_PUBLIC_KEY }}
|
||||
|
||||
steps:
|
||||
- name: 'Install desktop Qt'
|
||||
uses: jurplel/install-qt-action@v3
|
||||
uses: jurplel/install-qt-action@v4
|
||||
with:
|
||||
version: ${{ env.QT_VERSION }}
|
||||
host: 'linux'
|
||||
target: 'desktop'
|
||||
arch: 'gcc_64'
|
||||
modules: 'qtremoteobjects qt5compat qtimageformats qtshadertools'
|
||||
arch: 'linux_gcc_64'
|
||||
modules: ${{ env.QT_MODULES }}
|
||||
dir: ${{ runner.temp }}
|
||||
setup-python: 'true'
|
||||
set-env: 'true'
|
||||
extra: '--external 7z'
|
||||
extra: '--external 7z --base ${{ env.QT_MIRROR }}'
|
||||
|
||||
- name: 'Install android Qt'
|
||||
uses: jurplel/install-qt-action@v3
|
||||
- name: 'Install android_x86_64 Qt'
|
||||
uses: jurplel/install-qt-action@v4
|
||||
with:
|
||||
version: ${{ env.QT_VERSION }}
|
||||
host: 'linux'
|
||||
target: 'android'
|
||||
arch: ${{ matrix.qt_arch }}
|
||||
modules: 'qtremoteobjects qt5compat qtimageformats qtshadertools'
|
||||
arch: 'android_x86_64'
|
||||
modules: ${{ env.QT_MODULES }}
|
||||
dir: ${{ runner.temp }}
|
||||
setup-python: 'true'
|
||||
set-env: 'true'
|
||||
extra: '--external 7z'
|
||||
extra: '--external 7z --base ${{ env.QT_MIRROR }}'
|
||||
|
||||
- name: 'Install android_x86 Qt'
|
||||
uses: jurplel/install-qt-action@v4
|
||||
with:
|
||||
version: ${{ env.QT_VERSION }}
|
||||
host: 'linux'
|
||||
target: 'android'
|
||||
arch: 'android_x86'
|
||||
modules: ${{ env.QT_MODULES }}
|
||||
dir: ${{ runner.temp }}
|
||||
extra: '--external 7z --base ${{ env.QT_MIRROR }}'
|
||||
|
||||
- name: 'Install android_armv7 Qt'
|
||||
uses: jurplel/install-qt-action@v4
|
||||
with:
|
||||
version: ${{ env.QT_VERSION }}
|
||||
host: 'linux'
|
||||
target: 'android'
|
||||
arch: 'android_armv7'
|
||||
modules: ${{ env.QT_MODULES }}
|
||||
dir: ${{ runner.temp }}
|
||||
extra: '--external 7z --base ${{ env.QT_MIRROR }}'
|
||||
|
||||
- name: 'Install android_arm64_v8a Qt'
|
||||
uses: jurplel/install-qt-action@v4
|
||||
with:
|
||||
version: ${{ env.QT_VERSION }}
|
||||
host: 'linux'
|
||||
target: 'android'
|
||||
arch: 'android_arm64_v8a'
|
||||
modules: ${{ env.QT_MODULES }}
|
||||
dir: ${{ runner.temp }}
|
||||
extra: '--external 7z --base ${{ env.QT_MIRROR }}'
|
||||
|
||||
- name: 'Grant execute permission for qt-cmake'
|
||||
shell: bash
|
||||
run: |
|
||||
chmod +x ${{ runner.temp }}/Qt/${{ env.QT_VERSION }}/${{ matrix.qt_arch }}/bin/qt-cmake
|
||||
chmod +x ${{ runner.temp }}/Qt/${{ env.QT_VERSION }}/android_x86_64/bin/qt-cmake
|
||||
|
||||
- name: 'Get sources'
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
submodules: 'true'
|
||||
|
||||
@@ -325,18 +376,17 @@ jobs:
|
||||
uses: hendrikmuhs/ccache-action@v1.2
|
||||
|
||||
- name: 'Setup Java'
|
||||
uses: actions/setup-java@v3
|
||||
uses: actions/setup-java@v4
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: '11'
|
||||
java-version: '17'
|
||||
cache: 'gradle'
|
||||
|
||||
- name: 'Setup Android NDK'
|
||||
id: setup-ndk
|
||||
uses: nttld/setup-ndk@v1
|
||||
with:
|
||||
ndk-version: 'r25c'
|
||||
local-cache: 'true'
|
||||
ndk-version: 'r26b'
|
||||
|
||||
- name: 'Decode keystore secret to file'
|
||||
env:
|
||||
@@ -349,16 +399,66 @@ jobs:
|
||||
env:
|
||||
ANDROID_NDK_ROOT: ${{ steps.setup-ndk.outputs.ndk-path }}
|
||||
QT_HOST_PATH: ${{ runner.temp }}/Qt/${{ env.QT_VERSION }}/gcc_64
|
||||
QT_ANDROID_KEYSTORE_PATH: ${{ github.workspace }}/android.keystore
|
||||
QT_ANDROID_KEYSTORE_ALIAS: ${{ secrets.ANDROID_RELEASE_KEYSTORE_KEY_ALIAS }}
|
||||
QT_ANDROID_KEYSTORE_STORE_PASS: ${{ secrets.ANDROID_RELEASE_KEYSTORE_KEY_PASS }}
|
||||
QT_ANDROID_KEYSTORE_KEY_PASS: ${{ secrets.ANDROID_RELEASE_KEYSTORE_KEY_PASS }}
|
||||
ANDROID_KEYSTORE_PATH: ${{ github.workspace }}/android.keystore
|
||||
ANDROID_KEYSTORE_KEY_ALIAS: ${{ secrets.ANDROID_RELEASE_KEYSTORE_KEY_ALIAS }}
|
||||
ANDROID_KEYSTORE_KEY_PASS: ${{ secrets.ANDROID_RELEASE_KEYSTORE_KEY_PASS }}
|
||||
shell: bash
|
||||
run: ./deploy/build_android.sh --apk ${{ matrix.abi }} --platform ${{ env.ANDROID_BUILD_PLATFORM }}
|
||||
run: ./deploy/build_android.sh --aab --apk all --build-platform ${{ env.ANDROID_BUILD_PLATFORM }}
|
||||
|
||||
- name: 'Upload apk'
|
||||
uses: actions/upload-artifact@v3
|
||||
- name: 'Upload x86_64 apk'
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: AmneziaVPN-android-${{ matrix.abi }}
|
||||
path: deploy/build/AmneziaVPN-${{ matrix.abi }}-release-signed.apk
|
||||
name: AmneziaVPN-android-x86_64
|
||||
path: deploy/build/AmneziaVPN-x86_64-release.apk
|
||||
compression-level: 0
|
||||
retention-days: 7
|
||||
|
||||
- name: 'Upload x86 apk'
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: AmneziaVPN-android-x86
|
||||
path: deploy/build/AmneziaVPN-x86-release.apk
|
||||
compression-level: 0
|
||||
retention-days: 7
|
||||
|
||||
- name: 'Upload arm64-v8a apk'
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: AmneziaVPN-android-arm64-v8a
|
||||
path: deploy/build/AmneziaVPN-arm64-v8a-release.apk
|
||||
compression-level: 0
|
||||
retention-days: 7
|
||||
|
||||
- name: 'Upload armeabi-v7a apk'
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: AmneziaVPN-android-armeabi-v7a
|
||||
path: deploy/build/AmneziaVPN-armeabi-v7a-release.apk
|
||||
compression-level: 0
|
||||
retention-days: 7
|
||||
|
||||
- name: 'Upload aab'
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: AmneziaVPN-android
|
||||
path: deploy/build/AmneziaVPN-release.aab
|
||||
compression-level: 0
|
||||
retention-days: 7
|
||||
|
||||
Extra:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Search a corresponding PR
|
||||
uses: octokit/request-action@v2.x
|
||||
id: pull_request
|
||||
with:
|
||||
route: GET /repos/${{ github.repository }}/pulls
|
||||
head: ${{ github.repository_owner }}:${{ github.ref_name }}
|
||||
env:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
- name: Add PR link to build summary
|
||||
if: ${{ fromJSON(steps.pull_request.outputs.data)[0].number != '' }}
|
||||
run: |
|
||||
echo "Pull request:" >> $GITHUB_STEP_SUMMARY
|
||||
echo "[[#${{ fromJSON(steps.pull_request.outputs.data)[0].number }}] ${{ fromJSON(steps.pull_request.outputs.data)[0].title }}](${{ fromJSON(steps.pull_request.outputs.data)[0].html_url }})" >> $GITHUB_STEP_SUMMARY
|
||||
|
||||
2
.github/workflows/tag-deploy.yml
vendored
2
.github/workflows/tag-deploy.yml
vendored
@@ -15,6 +15,8 @@ jobs:
|
||||
env:
|
||||
QT_VERSION: 6.4.1
|
||||
QIF_VERSION: 4.5
|
||||
PROD_AGW_PUBLIC_KEY: ${{ secrets.PROD_AGW_PUBLIC_KEY }}
|
||||
DEV_AGW_PUBLIC_KEY: ${{ secrets.DEV_AGW_PUBLIC_KEY }}
|
||||
|
||||
steps:
|
||||
- name: 'Install desktop Qt'
|
||||
|
||||
64
.github/workflows/tag-upload.yml
vendored
Normal file
64
.github/workflows/tag-upload.yml
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
name: 'Upload a new version'
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- '[0-9]+.[0-9]+.[0-9]+.[0-9]+'
|
||||
|
||||
jobs:
|
||||
upload:
|
||||
runs-on: ubuntu-latest
|
||||
name: upload
|
||||
steps:
|
||||
- name: Checkout CMakeLists.txt
|
||||
uses: actions/checkout@v4
|
||||
with:
|
||||
ref: ${{ github.ref_name }}
|
||||
sparse-checkout: |
|
||||
CMakeLists.txt
|
||||
sparse-checkout-cone-mode: false
|
||||
|
||||
- name: Verify git tag
|
||||
run: |
|
||||
GIT_TAG=${{ github.ref_name }}
|
||||
CMAKE_TAG=$(grep 'project.*VERSION' CMakeLists.txt | sed -E 's/.* ([0-9]+.[0-9]+.[0-9]+.[0-9]+)$/\1/')
|
||||
|
||||
if [[ "$GIT_TAG" == "$CMAKE_TAG" ]]; then
|
||||
echo "Git tag ($GIT_TAG) and version in CMakeLists.txt ($CMAKE_TAG) are the same. Continuing..."
|
||||
else
|
||||
echo "Git tag ($GIT_TAG) and version in CMakeLists.txt ($CMAKE_TAG) are not the same! Cancelling..."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
- name: Download artifacts from the "${{ github.ref_name }}" tag
|
||||
uses: robinraju/release-downloader@v1.8
|
||||
with:
|
||||
tag: ${{ github.ref_name }}
|
||||
fileName: "AmneziaVPN_(Linux_|)${{ github.ref_name }}*"
|
||||
out-file-path: ${{ github.ref_name }}
|
||||
|
||||
- name: Upload beta version
|
||||
uses: jakejarvis/s3-sync-action@master
|
||||
if: contains(github.event.base_ref, 'dev')
|
||||
with:
|
||||
args: --include "AmneziaVPN*" --delete
|
||||
env:
|
||||
AWS_S3_BUCKET: updates
|
||||
AWS_ACCESS_KEY_ID: ${{ secrets.CF_R2_ACCESS_KEY_ID }}
|
||||
AWS_SECRET_ACCESS_KEY: ${{ secrets.CF_R2_SECRET_ACCESS_KEY }}
|
||||
AWS_S3_ENDPOINT: https://${{ vars.CF_ACCOUNT_ID }}.r2.cloudflarestorage.com
|
||||
SOURCE_DIR: ${{ github.ref_name }}
|
||||
DEST_DIR: beta/${{ github.ref_name }}
|
||||
|
||||
- name: Upload stable version
|
||||
uses: jakejarvis/s3-sync-action@master
|
||||
if: contains(github.event.base_ref, 'master')
|
||||
with:
|
||||
args: --include "AmneziaVPN*" --delete
|
||||
env:
|
||||
AWS_S3_BUCKET: updates
|
||||
AWS_ACCESS_KEY_ID: ${{ secrets.CF_R2_ACCESS_KEY_ID }}
|
||||
AWS_SECRET_ACCESS_KEY: ${{ secrets.CF_R2_SECRET_ACCESS_KEY }}
|
||||
AWS_S3_ENDPOINT: https://${{ vars.CF_ACCOUNT_ID }}.r2.cloudflarestorage.com
|
||||
SOURCE_DIR: ${{ github.ref_name }}
|
||||
DEST_DIR: stable/${{ github.ref_name }}
|
||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -131,3 +131,6 @@ client/3rd/ShadowSocks/ss_ios.xcconfig
|
||||
|
||||
# UML generated pics
|
||||
out/
|
||||
|
||||
# CMake files
|
||||
CMakeFiles/
|
||||
21
.gitmodules
vendored
21
.gitmodules
vendored
@@ -1,18 +1,6 @@
|
||||
[submodule "client/3rd/OpenVPNAdapter"]
|
||||
path = client/3rd/OpenVPNAdapter
|
||||
url = https://github.com/amnezia-vpn/OpenVPNAdapter.git
|
||||
[submodule "client/3rd/ShadowPath"]
|
||||
path = client/3rd/ShadowPath
|
||||
url = https://github.com/qman9501/ShadowPath
|
||||
[submodule "client/3rd/outline-go-tun2socks"]
|
||||
path = client/3rd/outline-go-tun2socks
|
||||
url = https://github.com/Jigsaw-Code/outline-go-tun2socks.git
|
||||
[submodule "client/3rd/CocoaAsyncSocket"]
|
||||
path = client/3rd/CocoaAsyncSocket
|
||||
url = https://github.com/robbiehanson/CocoaAsyncSocket.git
|
||||
[submodule "client/3rd/CocoaLumberjack"]
|
||||
path = client/3rd/CocoaLumberjack
|
||||
url = https://github.com/CocoaLumberjack/CocoaLumberjack.git
|
||||
[submodule "client/3rd/qtkeychain"]
|
||||
path = client/3rd/qtkeychain
|
||||
url = https://github.com/frankosterfeld/qtkeychain.git
|
||||
@@ -22,6 +10,9 @@
|
||||
[submodule "client/3rd-prebuilt"]
|
||||
path = client/3rd-prebuilt
|
||||
url = https://github.com/amnezia-vpn/3rd-prebuilt
|
||||
[submodule "client/3rd/awg-apple"]
|
||||
path = client/3rd/awg-apple
|
||||
url = https://github.com/amnezia-vpn/awg-apple
|
||||
[submodule "client/3rd/amneziawg-apple"]
|
||||
path = client/3rd/amneziawg-apple
|
||||
url = https://github.com/amnezia-vpn/amneziawg-apple
|
||||
[submodule "client/3rd/QSimpleCrypto"]
|
||||
path = client/3rd/QSimpleCrypto
|
||||
url = https://github.com/amnezia-vpn/QSimpleCrypto.git
|
||||
|
||||
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.25.0 FATAL_ERROR)
|
||||
|
||||
set(PROJECT AmneziaVPN)
|
||||
|
||||
project(${PROJECT} VERSION 4.0.8.5
|
||||
project(${PROJECT} VERSION 4.8.1.9
|
||||
DESCRIPTION "AmneziaVPN"
|
||||
HOMEPAGE_URL "https://amnezia.org/"
|
||||
)
|
||||
@@ -11,6 +11,7 @@ string(TIMESTAMP CURRENT_DATE "%Y-%m-%d")
|
||||
set(RELEASE_DATE "${CURRENT_DATE}")
|
||||
|
||||
set(APP_MAJOR_VERSION ${CMAKE_PROJECT_VERSION_MAJOR}.${CMAKE_PROJECT_VERSION_MINOR}.${CMAKE_PROJECT_VERSION_PATCH})
|
||||
set(APP_ANDROID_VERSION_CODE 65)
|
||||
|
||||
if(${CMAKE_SYSTEM_NAME} STREQUAL "Linux")
|
||||
set(MZ_PLATFORM_NAME "linux")
|
||||
|
||||
147
README.md
147
README.md
@@ -6,29 +6,54 @@
|
||||
|
||||
Amnezia is an open-source VPN client, with a key feature that enables you to deploy your own VPN server on your server.
|
||||
|
||||

|
||||
|
||||
<br>
|
||||
|
||||
<a href="https://github.com/amnezia-vpn/amnezia-client/releases/download/4.7.0.0/AmneziaVPN_4.7.0.0_x64.exe"><img src="https://github.com/amnezia-vpn/amnezia-client/blob/dev/metadata/img-readme/win.png" width="150" style="max-width: 100%;"></a>
|
||||
<a href="https://github.com/amnezia-vpn/amnezia-client/releases/download/4.7.0.0/AmneziaVPN_4.7.0.0.dmg"><img src="https://github.com/amnezia-vpn/amnezia-client/blob/dev/metadata/img-readme/mac.png" width="150" style="max-width: 100%;"></a>
|
||||
<a href="https://github.com/amnezia-vpn/amnezia-client/releases/download/4.7.0.0/AmneziaVPN_Linux_4.7.0.0.tar.zip"><img src="https://github.com/amnezia-vpn/amnezia-client/blob/dev/metadata/img-readme/lin.png" width="150" style="max-width: 100%;"></a>
|
||||
<a href="https://github.com/amnezia-vpn/amnezia-client/releases/tag/4.7.0.0"><img src="https://github.com/amnezia-vpn/amnezia-client/blob/dev/metadata/img-readme/andr.png" width="150" style="max-width: 100%;"></a>
|
||||
|
||||
<br>
|
||||
|
||||
<a href="https://play.google.com/store/search?q=amnezia+vpn&c=apps"><img src="https://github.com/amnezia-vpn/amnezia-client/blob/dev/metadata/img-readme/play.png" width="150" style="max-width: 100%;"></a>
|
||||
<a href="https://apps.apple.com/us/app/amneziavpn/id1600529900"><img src="https://github.com/amnezia-vpn/amnezia-client/blob/dev/metadata/img-readme/apl.png" width="150" style="max-width: 100%;"></a>
|
||||
|
||||
|
||||
[All releases](https://github.com/amnezia-vpn/amnezia-client/releases)
|
||||
|
||||
<br>
|
||||
|
||||
|
||||
## Features
|
||||
- Very easy to use - enter your ip address, ssh login and password, and Amnezia will automatically install VPN docker containers to your server and connect to VPN.
|
||||
- OpenVPN, ShadowSocks, WireGuard, IKEv2 protocols support.
|
||||
- Masking VPN with OpenVPN over Cloak plugin
|
||||
- Split tunneling support - add any sites to client to enable VPN only for them (only for desktops)
|
||||
|
||||
- Very easy to use - enter your IP address, SSH login, password and Amnezia will automatically install VPN docker containers to your server and connect to the VPN.
|
||||
- Classic VPN-protocols: OpenVPN, WireGuard and IKEv2 protocols.
|
||||
- Protocols with traffic Masking (Obfuscation): OpenVPN over [Cloak](https://github.com/cbeuw/Cloak) plugin, Shadowsocks (OpenVPN over Shadowsocks), [AmneziaWG](https://docs.amnezia.org/documentation/amnezia-wg/) and XRay.
|
||||
- Split tunneling support - add any sites to the client to enable VPN only for them or add Apps (only for Android and Desktop).
|
||||
- Windows, MacOS, Linux, Android, iOS releases.
|
||||
- Support for AmneziaWG protocol configuration on [Keenetic beta firmware](https://docs.keenetic.com/ua/air/kn-1611/en/6319-latest-development-release.html#UUID-186c4108-5afd-c10b-f38a-cdff6c17fab3_section-idm33192196168192-improved).
|
||||
|
||||
## Links
|
||||
[https://amnezia.org](https://amnezia.org) - project website
|
||||
[https://www.reddit.com/r/AmneziaVPN](https://www.reddit.com/r/AmneziaVPN) - Reddit
|
||||
[https://t.me/amnezia_vpn_en](https://t.me/amnezia_vpn_en) - Telegram support channel (English)
|
||||
[https://t.me/amnezia_vpn](https://t.me/amnezia_vpn) - Telegram support channel (Russian)
|
||||
[https://signal.group/...](https://signal.group/#CjQKIB2gUf8QH_IXnOJMGQWMDjYz9cNfmRQipGWLFiIgc4MwEhAKBONrSiWHvoUFbbD0xwdh) - Signal channel
|
||||
|
||||
- [https://amnezia.org](https://amnezia.org) - project website
|
||||
- [https://www.reddit.com/r/AmneziaVPN](https://www.reddit.com/r/AmneziaVPN) - Reddit
|
||||
- [https://t.me/amnezia_vpn_en](https://t.me/amnezia_vpn_en) - Telegram support channel (English)
|
||||
- [https://t.me/amnezia_vpn_ir](https://t.me/amnezia_vpn_ir) - Telegram support channel (Farsi)
|
||||
- [https://t.me/amnezia_vpn_mm](https://t.me/amnezia_vpn_mm) - Telegram support channel (Myanmar)
|
||||
- [https://t.me/amnezia_vpn](https://t.me/amnezia_vpn) - Telegram support channel (Russian)
|
||||
- [https://vpnpay.io/en/amnezia-premium/](https://vpnpay.io/en/amnezia-premium/) - Amnezia Premium
|
||||
|
||||
## Tech
|
||||
|
||||
AmneziaVPN uses a number of open source projects to work:
|
||||
AmneziaVPN uses several open-source projects to work:
|
||||
|
||||
- [OpenSSL](https://www.openssl.org/)
|
||||
- [OpenVPN](https://openvpn.net/)
|
||||
- [ShadowSocks](https://shadowsocks.org/)
|
||||
- [Shadowsocks](https://shadowsocks.org/)
|
||||
- [Qt](https://www.qt.io/)
|
||||
- [LibSsh](https://libssh.org) - forked form Qt Creator
|
||||
- [LibSsh](https://libssh.org) - forked from Qt Creator
|
||||
- and more...
|
||||
|
||||
## Checking out the source code
|
||||
@@ -36,40 +61,63 @@ AmneziaVPN uses a number of open source projects to work:
|
||||
Make sure to pull all submodules after checking out the repo.
|
||||
|
||||
```bash
|
||||
git submodule update --init
|
||||
git submodule update --init --recursive
|
||||
```
|
||||
|
||||
## Development
|
||||
|
||||
Want to contribute? Welcome!
|
||||
|
||||
### Building sources and deployment
|
||||
Look deploy folder for build scripts.
|
||||
### Help with translations
|
||||
|
||||
### How to build iOS app from source code on MacOS
|
||||
Download the most actual translation files.
|
||||
|
||||
Go to ["Actions" tab](https://github.com/amnezia-vpn/amnezia-client/actions?query=is%3Asuccess+branch%3Adev), click on the first line.
|
||||
Then scroll down to the "Artifacts" section and download "AmneziaVPN_translations".
|
||||
|
||||
Unzip this file.
|
||||
Each *.ts file contains strings for one corresponding language.
|
||||
|
||||
Translate or correct some strings in one or multiple *.ts files and commit them back to this repository into the ``client/translations`` folder.
|
||||
You can do it via a web-interface or any other method you're familiar with.
|
||||
|
||||
### Building sources and deployment
|
||||
|
||||
Check deploy folder for build scripts.
|
||||
|
||||
### How to build an iOS app from source code on MacOS
|
||||
|
||||
1. First, make sure you have [XCode](https://developer.apple.com/xcode/) installed, at least version 14 or higher.
|
||||
|
||||
2. We use QT to generate the XCode project. we need QT version 6.4. Install QT for macos in [here](https://doc.qt.io/qt-6/macos.html)
|
||||
2. We use QT to generate the XCode project. We need QT version 6.6.2. Install QT for MacOS [here](https://doc.qt.io/qt-6/macos.html) or [QT Online Installer](https://www.qt.io/download-open-source). Required modules:
|
||||
- MacOS
|
||||
- iOS
|
||||
- Qt 5 Compatibility Module
|
||||
- Qt Shader Tools
|
||||
- Additional Libraries:
|
||||
- Qt Image Formats
|
||||
- Qt Multimedia
|
||||
- Qt Remote Objects
|
||||
|
||||
3. Install cmake is require. We recommend cmake version 3.25. You can install cmake in [here](https://cmake.org/download/)
|
||||
3. Install CMake if required. We recommend CMake version 3.25. You can install CMake [here](https://cmake.org/download/)
|
||||
|
||||
4. You also need to install go >= v1.16. If you don't have it done already,
|
||||
4. You also need to install go >= v1.16. If you don't have it installed already,
|
||||
download go from the [official website](https://golang.org/dl/) or use Homebrew.
|
||||
Latest version is recommended. Install gomobile
|
||||
The latest version is recommended. Install gomobile
|
||||
```bash
|
||||
export PATH=$PATH:~/go/bin
|
||||
go install golang.org/x/mobile/cmd/gomobile@latest
|
||||
gomobile init
|
||||
```
|
||||
|
||||
5. Build project
|
||||
5. Build the project
|
||||
```bash
|
||||
export QT_BIN_DIR="<PATH-TO-QT-FOLDER>/Qt/<QT-VERSION>/ios/bin"
|
||||
export QT_MACOS_ROOT_DIR="<PATH-TO-QT-FOLDER>/Qt/<QT-VERSION>/macos"
|
||||
export QT_IOS_BIN=$QT_BIN_DIR
|
||||
export PATH=$PATH:~/go/bin
|
||||
mkdir build-ios
|
||||
$QT_IOS_BIN/qt-cmake . -B build-ios -GXcode -DQT_HOST_PATH=$QT_BIN_DIR
|
||||
$QT_IOS_BIN/qt-cmake . -B build-ios -GXcode -DQT_HOST_PATH=$QT_MACOS_ROOT_DIR
|
||||
```
|
||||
Replace PATH-TO-QT-FOLDER and QT-VERSION to your environment
|
||||
|
||||
@@ -80,62 +128,67 @@ of the bin folder where gomobile was installed. Usually, it's in `GOPATH`.
|
||||
export PATH=$(PATH):/path/to/GOPATH/bin
|
||||
```
|
||||
|
||||
5. Open XCode project. You can then run/test/archive/ship the app.
|
||||
6. Open the XCode project. You can then run /test/archive/ship the app.
|
||||
|
||||
If build fails with the following error
|
||||
If the build fails with the following error
|
||||
```
|
||||
make: ***
|
||||
[$(PROJECTDIR)/client/build/AmneziaVPN.build/Debug-iphoneos/wireguard-go-bridge/goroot/.prepared]
|
||||
Error 1
|
||||
```
|
||||
Add a user defined variable to both AmneziaVPN and WireGuardNetworkExtension targets' build settings with
|
||||
Add a user-defined variable to both AmneziaVPN and WireGuardNetworkExtension targets' build settings with
|
||||
key `PATH` and value `${PATH}/path/to/bin/folder/with/go/executable`, e.g. `${PATH}:/usr/local/go/bin`.
|
||||
|
||||
if above error still persists on you M1 Mac, then most probably you need to install arch based cmake
|
||||
if the above error persists on your M1 Mac, then most probably you need to install arch based CMake
|
||||
```
|
||||
arch -arm64 brew install cmake
|
||||
```
|
||||
|
||||
Build might fail with "source files not found" error the first time you try it, because modern XCode build system compiles
|
||||
dependencies in parallel, and some dependencies end up being built after the ones that
|
||||
require them. In this case simply restart the build.
|
||||
Build might fail with the "source files not found" error the first time you try it, because the modern XCode build system compiles dependencies in parallel, and some dependencies end up being built after the ones that
|
||||
require them. In this case, simply restart the build.
|
||||
|
||||
## How to build the Android app
|
||||
_tested on Mac OS_
|
||||
|
||||
_Tested on Mac OS_
|
||||
|
||||
The Android app has the following requirements:
|
||||
* JDK 11
|
||||
* Android platform SDK 33
|
||||
* cmake 3.25.0
|
||||
* CMake 3.25.0
|
||||
|
||||
After you have installed QT, QT Creator and Android Studio installed, you need to configure QT Creator correctly. Click in the top menu bar on `QT Creator` -> `Preferences` -> `Devices` and select the tab `Android`.
|
||||
* set path to jdk 11
|
||||
* set path to Android SDK ($ANDROID_HOME)
|
||||
After you have installed QT, QT Creator, and Android Studio, you need to configure QT Creator correctly.
|
||||
|
||||
In case you get errors regarding missing SDK or 'sdkmanager not running', you cannot fix them by correcting the paths and you have some spare GBs on your disk, you can let QT Creator install all requirements by choosing an empty folder for `Android SDK location` and click on `Set Up SDK`. Be aware: This will install a second Android SDK and NDK on your machine!
|
||||
- Click in the top menu bar on `QT Creator` -> `Preferences` -> `Devices` and select the tab `Android`.
|
||||
- Set path to JDK 11
|
||||
- Set path to Android SDK (`$ANDROID_HOME`)
|
||||
|
||||
Double check that the right cmake version is configured: Click on `QT Creator` -> `Preferences` and click on the side menu on `Kits`. Under the center content view's `Kits` tab you'll find an entry `CMake Tool`. If the default selected CMake version is lower than 3.25.0, install on your system CMake >= 3.25.0 and choose `System CMake at <path>` from the drop down list. If this entry is missing, you either have not installed CMake yet or QT Creator hasn't found the path to it. In that case click in the preferences window on the side menu item `CMake`, then on the tab `Tools`in the center content view and finally on the Button `Add` to set the path to your installed CMake.
|
||||
In case you get errors regarding missing SDK or 'SDK manager not running', you cannot fix them by correcting the paths. If you have some spare GBs on your disk, you can let QT Creator install all requirements by choosing an empty folder for `Android SDK location` and clicking on `Set Up SDK`. Be aware: This will install a second Android SDK and NDK on your machine!
|
||||
Double-check that the right CMake version is configured: Click on `QT Creator` -> `Preferences` and click on the side menu on `Kits`. Under the center content view's `Kits` tab, you'll find an entry for `CMake Tool`. If the default selected CMake version is lower than 3.25.0, install on your system CMake >= 3.25.0 and choose `System CMake at <path>` from the drop-down list. If this entry is missing, you either have not installed CMake yet or QT Creator hasn't found the path to it. In that case, click in the preferences window on the side menu item `CMake`, then on the tab `Tools` in the center content view, and finally on the button `Add` to set the path to your installed CMake.
|
||||
Please make sure that you have selected Android Platform SDK 33 for your project: click in the main view's side menu on `Projects`, and on the left, you'll see a section `Build & Run` showing different Android build targets. You can select any of them, Amnezia VPN's project setup is designed in a way that all Android targets will be built. Click on the targets submenu item `Build` and scroll in the center content view to `Build Steps`. Click on `Details` at the end of the headline `Build Android APK` (the `Details` button might be hidden in case the QT Creator Window is not running in full screen!). Here we are: Choose `android-33` as `Android Build Platform SDK`.
|
||||
|
||||
Please make sure that you have selected Android Platform SDK 33 for your project: click in the main view's side menu on on `Projects`, on the left you'll see a section `Build & Run` showing different Android build targets. You can select any of them, Amnezia VPN's project setup is designed in a way that always all Android targets will be build. Click on the targets submenu item `Build` and scroll in the center content view to `Build Steps`. Click on `Details` at the end of the headline `Build Android APK` (The `Details` button might be hidden in case QT Creator Window is not running in full screen!). Here we are: choose `android-33` as `Android Build platform SDK`.
|
||||
|
||||
That's it you should be ready to compile the project from QT Creator!
|
||||
That's it! You should be ready to compile the project from QT Creator!
|
||||
|
||||
### Development flow
|
||||
After you've hit the build button, QT-Creator copies the whole project to a folder in the repositories parent directory. The folder should look something like `build-amnezia-client-Android_Qt_<version>_Clang_<architecture>-<BuildType>`.
|
||||
If you want to develop Amnezia VPNs Android components written in Kotlin, such as components using system APIs, you need to import the generated project in Android Studio with `build-amnezia-client-Android_Qt_<version>_Clang_<architecture>-<BuildType>/client/android-build` as the projects root directory. While you should be able to compile the generated project from Android Studio, you cannot work directly in the repository's Android project. So whenever you are confident with your work in the generated project, you'll need to copy and paste the affected files to the corresponding path in the repositories Android project so that you can add and commit your changes!
|
||||
|
||||
You may face compiling issues in QT Creator after you've worked in Android Studio on the generated project. Just do a `./gradlew clean` in the generated project's root directory (`<path>/client/android-build/.`) and you should be good to continue.
|
||||
After you've hit the build button, QT-Creator copies the whole project to a folder in the repository parent directory. The folder should look something like `build-amnezia-client-Android_Qt_<version>_Clang_<architecture>-<BuildType>`.
|
||||
If you want to develop Amnezia VPNs Android components written in Kotlin, such as components using system APIs, you need to import the generated project in Android Studio with `build-amnezia-client-Android_Qt_<version>_Clang_<architecture>-<BuildType>/client/android-build` as the projects root directory. While you should be able to compile the generated project from Android Studio, you cannot work directly in the repository's Android project. So whenever you are confident with your work in the generated project, you'll need to copy and paste the affected files to the corresponding path in the repository's Android project so that you can add and commit your changes!
|
||||
|
||||
You may face compiling issues in QT Creator after you've worked in Android Studio on the generated project. Just do a `./gradlew clean` in the generated project's root directory (`<path>/client/android-build/.`) and you should be good to go.
|
||||
|
||||
## License
|
||||
GPL v.3
|
||||
|
||||
GPL v3.0
|
||||
|
||||
## Donate
|
||||
Bitcoin: bc1qn9rhsffuxwnhcuuu4qzrwp4upkrq94xnh8r26u
|
||||
|
||||
Patreon: [https://www.patreon.com/amneziavpn](https://www.patreon.com/amneziavpn)
|
||||
|
||||
Bitcoin: bc1q26eevjcg9j0wuyywd2e3uc9cs2w58lpkpjxq6p <br>
|
||||
USDT BEP20: 0x6abD576765a826f87D1D95183438f9408C901bE4 <br>
|
||||
USDT TRC20: TELAitazF1MZGmiNjTcnxDjEiH5oe7LC9d <br>
|
||||
XMR: 48spms39jt1L2L5vyw2RQW6CXD6odUd4jFu19GZcDyKKQV9U88wsJVjSbL4CfRys37jVMdoaWVPSvezCQPhHXUW5UKLqUp3
|
||||
payeer.com: P2561305
|
||||
ko-fi.com: [https://ko-fi.com/amnezia_vpn](https://ko-fi.com/amnezia_vpn)
|
||||
|
||||
## Acknowledgments
|
||||
|
||||
## etc
|
||||
This project is tested with BrowserStack.
|
||||
We express our gratitude to [BrowserStack](https://www.browserstack.com) for supporting our project.
|
||||
|
||||
Submodule client/3rd-prebuilt updated: ac32d33555...ba580dc5bd
1
client/3rd/CocoaAsyncSocket
vendored
1
client/3rd/CocoaAsyncSocket
vendored
Submodule client/3rd/CocoaAsyncSocket deleted from 5ddba5e72f
1
client/3rd/CocoaLumberjack
vendored
1
client/3rd/CocoaLumberjack
vendored
Submodule client/3rd/CocoaLumberjack deleted from 70f04b1dc5
2
client/3rd/OpenVPNAdapter
vendored
2
client/3rd/OpenVPNAdapter
vendored
Submodule client/3rd/OpenVPNAdapter updated: f95f0b2b56...7c821a8d5c
File diff suppressed because it is too large
Load Diff
@@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Workspace
|
||||
version = "1.0">
|
||||
<FileRef
|
||||
location = "self:">
|
||||
</FileRef>
|
||||
</Workspace>
|
||||
@@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>IDEDidComputeMac32BitWarning</key>
|
||||
<true/>
|
||||
</dict>
|
||||
</plist>
|
||||
Binary file not shown.
@@ -1,14 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>SchemeUserState</key>
|
||||
<dict>
|
||||
<key>PacketProcessor.xcscheme_^#shared#^_</key>
|
||||
<dict>
|
||||
<key>orderHint</key>
|
||||
<integer>0</integer>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
Binary file not shown.
@@ -1,18 +0,0 @@
|
||||
//
|
||||
// CocoaAsyncSocket.h
|
||||
// CocoaAsyncSocket
|
||||
//
|
||||
// Created by Derek Clarkson on 10/08/2015.
|
||||
// CocoaAsyncSocket project is in the public domain.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
//! Project version number for CocoaAsyncSocket.
|
||||
FOUNDATION_EXPORT double cocoaAsyncSocketVersionNumber;
|
||||
|
||||
//! Project version string for CocoaAsyncSocket.
|
||||
FOUNDATION_EXPORT const unsigned char cocoaAsyncSocketVersionString[];
|
||||
|
||||
#import <CocoaAsyncSocket/GCDAsyncSocket.h>
|
||||
#import <CocoaAsyncSocket/GCDAsyncUdpSocket.h>
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
@@ -1,6 +0,0 @@
|
||||
framework module CocoaAsyncSocket {
|
||||
umbrella header "CocoaAsyncSocket.h"
|
||||
|
||||
export *
|
||||
module * { export * }
|
||||
}
|
||||
@@ -1,162 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>files</key>
|
||||
<dict>
|
||||
<key>Headers/CocoaAsyncSocket.h</key>
|
||||
<data>
|
||||
19xueMkhcDCf6A2ihyiTCDjWjd4=
|
||||
</data>
|
||||
<key>Headers/GCDAsyncSocket.h</key>
|
||||
<data>
|
||||
JwDJxahaKup9fnB5MJuoxDHbdDs=
|
||||
</data>
|
||||
<key>Headers/GCDAsyncUdpSocket.h</key>
|
||||
<data>
|
||||
9hL7D86xSUKQ1TBRDa+fDNkDlqI=
|
||||
</data>
|
||||
<key>Info.plist</key>
|
||||
<data>
|
||||
eCKEB+C8HfC7DIu6eNc6P3wxyLo=
|
||||
</data>
|
||||
<key>Modules/module.modulemap</key>
|
||||
<data>
|
||||
+n94rYTWDjekX3imyh+PSyA9vgA=
|
||||
</data>
|
||||
</dict>
|
||||
<key>files2</key>
|
||||
<dict>
|
||||
<key>Headers/CocoaAsyncSocket.h</key>
|
||||
<dict>
|
||||
<key>hash</key>
|
||||
<data>
|
||||
19xueMkhcDCf6A2ihyiTCDjWjd4=
|
||||
</data>
|
||||
<key>hash2</key>
|
||||
<data>
|
||||
VpE7gL1U1p/0urO77FEjPNjY06qrttQJnalOd+6VYDQ=
|
||||
</data>
|
||||
</dict>
|
||||
<key>Headers/GCDAsyncSocket.h</key>
|
||||
<dict>
|
||||
<key>hash</key>
|
||||
<data>
|
||||
JwDJxahaKup9fnB5MJuoxDHbdDs=
|
||||
</data>
|
||||
<key>hash2</key>
|
||||
<data>
|
||||
JL0b2lWPgVphz/ekZLsGMKrShDXTK2YY53aKtusc9hk=
|
||||
</data>
|
||||
</dict>
|
||||
<key>Headers/GCDAsyncUdpSocket.h</key>
|
||||
<dict>
|
||||
<key>hash</key>
|
||||
<data>
|
||||
9hL7D86xSUKQ1TBRDa+fDNkDlqI=
|
||||
</data>
|
||||
<key>hash2</key>
|
||||
<data>
|
||||
uNVm5yZ0jBhGDXZuAynPXvem1qcBvAVdWXAewQdJbh8=
|
||||
</data>
|
||||
</dict>
|
||||
<key>Modules/module.modulemap</key>
|
||||
<dict>
|
||||
<key>hash</key>
|
||||
<data>
|
||||
+n94rYTWDjekX3imyh+PSyA9vgA=
|
||||
</data>
|
||||
<key>hash2</key>
|
||||
<data>
|
||||
RoVn8xMeEnU3Izg0DtYjYL/krI8V7qw0sa7Ggf+08Rs=
|
||||
</data>
|
||||
</dict>
|
||||
</dict>
|
||||
<key>rules</key>
|
||||
<dict>
|
||||
<key>^.*</key>
|
||||
<true/>
|
||||
<key>^.*\.lproj/</key>
|
||||
<dict>
|
||||
<key>optional</key>
|
||||
<true/>
|
||||
<key>weight</key>
|
||||
<real>1000</real>
|
||||
</dict>
|
||||
<key>^.*\.lproj/locversion.plist$</key>
|
||||
<dict>
|
||||
<key>omit</key>
|
||||
<true/>
|
||||
<key>weight</key>
|
||||
<real>1100</real>
|
||||
</dict>
|
||||
<key>^Base\.lproj/</key>
|
||||
<dict>
|
||||
<key>weight</key>
|
||||
<real>1010</real>
|
||||
</dict>
|
||||
<key>^version.plist$</key>
|
||||
<true/>
|
||||
</dict>
|
||||
<key>rules2</key>
|
||||
<dict>
|
||||
<key>.*\.dSYM($|/)</key>
|
||||
<dict>
|
||||
<key>weight</key>
|
||||
<real>11</real>
|
||||
</dict>
|
||||
<key>^(.*/)?\.DS_Store$</key>
|
||||
<dict>
|
||||
<key>omit</key>
|
||||
<true/>
|
||||
<key>weight</key>
|
||||
<real>2000</real>
|
||||
</dict>
|
||||
<key>^.*</key>
|
||||
<true/>
|
||||
<key>^.*\.lproj/</key>
|
||||
<dict>
|
||||
<key>optional</key>
|
||||
<true/>
|
||||
<key>weight</key>
|
||||
<real>1000</real>
|
||||
</dict>
|
||||
<key>^.*\.lproj/locversion.plist$</key>
|
||||
<dict>
|
||||
<key>omit</key>
|
||||
<true/>
|
||||
<key>weight</key>
|
||||
<real>1100</real>
|
||||
</dict>
|
||||
<key>^Base\.lproj/</key>
|
||||
<dict>
|
||||
<key>weight</key>
|
||||
<real>1010</real>
|
||||
</dict>
|
||||
<key>^Info\.plist$</key>
|
||||
<dict>
|
||||
<key>omit</key>
|
||||
<true/>
|
||||
<key>weight</key>
|
||||
<real>20</real>
|
||||
</dict>
|
||||
<key>^PkgInfo$</key>
|
||||
<dict>
|
||||
<key>omit</key>
|
||||
<true/>
|
||||
<key>weight</key>
|
||||
<real>20</real>
|
||||
</dict>
|
||||
<key>^embedded\.provisionprofile$</key>
|
||||
<dict>
|
||||
<key>weight</key>
|
||||
<real>20</real>
|
||||
</dict>
|
||||
<key>^version\.plist$</key>
|
||||
<dict>
|
||||
<key>weight</key>
|
||||
<real>20</real>
|
||||
</dict>
|
||||
</dict>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -1,8 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||
<plist version="1.0">
|
||||
<dict>
|
||||
<key>CFBundleSignature</key>
|
||||
<string>????</string>
|
||||
</dict>
|
||||
</plist>
|
||||
@@ -1,19 +0,0 @@
|
||||
//
|
||||
// PacketProcessor.h
|
||||
// PacketProcessor
|
||||
//
|
||||
// Created by sanchez on 20.12.2021.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
//! Project version number for PacketProcessor.
|
||||
FOUNDATION_EXPORT double PacketProcessorVersionNumber;
|
||||
|
||||
//! Project version string for PacketProcessor.
|
||||
FOUNDATION_EXPORT const unsigned char PacketProcessorVersionString[];
|
||||
|
||||
// In this header, you should import all the public headers of your framework using statements like #import <PacketProcessor/PublicHeader.h>
|
||||
|
||||
|
||||
#import "TunnelInterface.h"
|
||||
@@ -1,23 +0,0 @@
|
||||
//
|
||||
// TunnelInterface.h
|
||||
// Potatso
|
||||
//
|
||||
// Created by LEI on 12/23/15.
|
||||
// Copyright © 2015 TouchingApp. All rights reserved.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@import NetworkExtension;
|
||||
|
||||
#define TunnelMTU 1600
|
||||
#define kTun2SocksStoppedNotification @"kTun2SocksStoppedNotification"
|
||||
|
||||
@interface TunnelInterface : NSObject
|
||||
+ (TunnelInterface *)sharedInterface;
|
||||
+ (NSError *)setupWithPacketTunnelFlow:(NEPacketTunnelFlow *)packetFlow;
|
||||
+ (void)processPackets;
|
||||
+ (void)writePacket: (NSData *)packet;
|
||||
+ (void)startTun2Socks: (int)socksServerPort;
|
||||
+ (void)stop;
|
||||
@end
|
||||
@@ -1,239 +0,0 @@
|
||||
//
|
||||
// TunnelInterface.m
|
||||
// Potatso
|
||||
//
|
||||
// Created by LEI on 12/23/15.
|
||||
// Copyright © 2015 TouchingApp. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TunnelInterface.h"
|
||||
#import <netinet/ip.h>
|
||||
#import "ipv4/lwip/ip4.h"
|
||||
#import "lwip/udp.h"
|
||||
#import "lwip/ip.h"
|
||||
#import <arpa/inet.h>
|
||||
#import "inet_chksum.h"
|
||||
#import "tun2socks/tun2socks.h"
|
||||
@import CocoaAsyncSocket;
|
||||
|
||||
#define kTunnelInterfaceErrorDomain [NSString stringWithFormat:@"%@.TunnelInterface", [[NSBundle mainBundle] bundleIdentifier]]
|
||||
|
||||
@interface TunnelInterface () <GCDAsyncUdpSocketDelegate>
|
||||
@property (nonatomic) NEPacketTunnelFlow *tunnelPacketFlow;
|
||||
@property (nonatomic) NSMutableDictionary *udpSession;
|
||||
@property (nonatomic) GCDAsyncUdpSocket *udpSocket;
|
||||
@property (nonatomic) int readFd;
|
||||
@property (nonatomic) int writeFd;
|
||||
@end
|
||||
|
||||
@implementation TunnelInterface
|
||||
|
||||
+ (TunnelInterface *)sharedInterface {
|
||||
static dispatch_once_t onceToken;
|
||||
static TunnelInterface *interface;
|
||||
dispatch_once(&onceToken, ^{
|
||||
interface = [TunnelInterface new];
|
||||
});
|
||||
return interface;
|
||||
}
|
||||
|
||||
- (instancetype)init {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_udpSession = [NSMutableDictionary dictionaryWithCapacity:5];
|
||||
_udpSocket = [[GCDAsyncUdpSocket alloc] initWithDelegate:self delegateQueue:dispatch_queue_create("udp", NULL)];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
+ (NSError *)setupWithPacketTunnelFlow:(NEPacketTunnelFlow *)packetFlow {
|
||||
if (packetFlow == nil) {
|
||||
return [NSError errorWithDomain:kTunnelInterfaceErrorDomain code:1 userInfo:@{NSLocalizedDescriptionKey: @"PacketTunnelFlow can't be nil."}];
|
||||
}
|
||||
[TunnelInterface sharedInterface].tunnelPacketFlow = packetFlow;
|
||||
|
||||
NSError *error;
|
||||
GCDAsyncUdpSocket *udpSocket = [TunnelInterface sharedInterface].udpSocket;
|
||||
[udpSocket bindToPort:0 error:&error];
|
||||
if (error) {
|
||||
return [NSError errorWithDomain:kTunnelInterfaceErrorDomain code:1 userInfo:@{NSLocalizedDescriptionKey: [NSString stringWithFormat:@"UDP bind fail(%@).", [error localizedDescription]]}];
|
||||
}
|
||||
[udpSocket beginReceiving:&error];
|
||||
if (error) {
|
||||
return [NSError errorWithDomain:kTunnelInterfaceErrorDomain code:1 userInfo:@{NSLocalizedDescriptionKey: [NSString stringWithFormat:@"UDP bind fail(%@).", [error localizedDescription]]}];
|
||||
}
|
||||
|
||||
int fds[2];
|
||||
if (pipe(fds) < 0) {
|
||||
return [NSError errorWithDomain:kTunnelInterfaceErrorDomain code:-1 userInfo:@{NSLocalizedDescriptionKey: @"Unable to pipe."}];
|
||||
}
|
||||
[TunnelInterface sharedInterface].readFd = fds[0];
|
||||
[TunnelInterface sharedInterface].writeFd = fds[1];
|
||||
return nil;
|
||||
}
|
||||
|
||||
+ (void)startTun2Socks: (int)socksServerPort {
|
||||
[NSThread detachNewThreadSelector:@selector(_startTun2Socks:) toTarget:[TunnelInterface sharedInterface] withObject:@(socksServerPort)];
|
||||
}
|
||||
|
||||
+ (void)stop {
|
||||
stop_tun2socks();
|
||||
}
|
||||
|
||||
+ (void)writePacket:(NSData *)packet {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[[TunnelInterface sharedInterface].tunnelPacketFlow writePackets:@[packet] withProtocols:@[@(AF_INET)]];
|
||||
});
|
||||
}
|
||||
|
||||
+ (void)processPackets {
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[[TunnelInterface sharedInterface].tunnelPacketFlow readPacketsWithCompletionHandler:^(NSArray<NSData *> * _Nonnull packets, NSArray<NSNumber *> * _Nonnull protocols) {
|
||||
for (NSData *packet in packets) {
|
||||
uint8_t *data = (uint8_t *)packet.bytes;
|
||||
struct ip_hdr *iphdr = (struct ip_hdr *)data;
|
||||
uint8_t proto = IPH_PROTO(iphdr);
|
||||
if (proto == IP_PROTO_UDP) {
|
||||
[[TunnelInterface sharedInterface] handleUDPPacket:packet];
|
||||
}else if (proto == IP_PROTO_TCP) {
|
||||
[[TunnelInterface sharedInterface] handleTCPPPacket:packet];
|
||||
}
|
||||
}
|
||||
[weakSelf processPackets];
|
||||
}];
|
||||
|
||||
}
|
||||
|
||||
- (void)_startTun2Socks: (NSNumber *)socksServerPort {
|
||||
char socks_server[50];
|
||||
sprintf(socks_server, "127.0.0.1:%d", (int)([socksServerPort integerValue]));
|
||||
#if TCP_DATA_LOG_ENABLE
|
||||
char *log_lvel = "debug";
|
||||
#else
|
||||
char *log_lvel = "none";
|
||||
#endif
|
||||
char *argv[] = {
|
||||
"tun2socks",
|
||||
"--netif-ipaddr",
|
||||
"192.0.2.4",
|
||||
"--netif-netmask",
|
||||
"255.255.255.0",
|
||||
"--loglevel",
|
||||
log_lvel,
|
||||
"--socks-server-addr",
|
||||
socks_server
|
||||
};
|
||||
tun2socks_main(sizeof(argv)/sizeof(argv[0]), argv, self.readFd, TunnelMTU);
|
||||
close(self.readFd);
|
||||
close(self.writeFd);
|
||||
[[NSNotificationCenter defaultCenter] postNotificationName:kTun2SocksStoppedNotification object:nil];
|
||||
}
|
||||
|
||||
- (void)handleTCPPPacket: (NSData *)packet {
|
||||
uint8_t message[TunnelMTU+2];
|
||||
memcpy(message + 2, packet.bytes, packet.length);
|
||||
message[0] = packet.length / 256;
|
||||
message[1] = packet.length % 256;
|
||||
write(self.writeFd , message , packet.length + 2);
|
||||
}
|
||||
|
||||
- (void)handleUDPPacket: (NSData *)packet {
|
||||
uint8_t *data = (uint8_t *)packet.bytes;
|
||||
int data_len = (int)packet.length;
|
||||
struct ip_hdr *iphdr = (struct ip_hdr *)data;
|
||||
uint8_t version = IPH_V(iphdr);
|
||||
|
||||
switch (version) {
|
||||
case 4: {
|
||||
uint16_t iphdr_hlen = IPH_HL(iphdr) * 4;
|
||||
data = data + iphdr_hlen;
|
||||
data_len -= iphdr_hlen;
|
||||
struct udp_hdr *udphdr = (struct udp_hdr *)data;
|
||||
|
||||
data = data + sizeof(struct udp_hdr *);
|
||||
data_len -= sizeof(struct udp_hdr *);
|
||||
|
||||
NSData *outData = [[NSData alloc] initWithBytes:data length:data_len];
|
||||
struct in_addr dest = { iphdr->dest.addr };
|
||||
NSString *destHost = [NSString stringWithUTF8String:inet_ntoa(dest)];
|
||||
NSString *key = [self strForHost:iphdr->dest.addr port:udphdr->dest];
|
||||
NSString *value = [self strForHost:iphdr->src.addr port:udphdr->src];;
|
||||
self.udpSession[key] = value;
|
||||
[self.udpSocket sendData:outData toHost:destHost port:ntohs(udphdr->dest) withTimeout:30 tag:0];
|
||||
} break;
|
||||
case 6: {
|
||||
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
- (void)udpSocket:(GCDAsyncUdpSocket *)sock didReceiveData:(NSData *)data fromAddress:(NSData *)address withFilterContext:(id)filterContext {
|
||||
const struct sockaddr_in *addr = (const struct sockaddr_in *)[address bytes];
|
||||
ip_addr_p_t dest ={ addr->sin_addr.s_addr };
|
||||
in_port_t dest_port = addr->sin_port;
|
||||
NSString *strHostPort = self.udpSession[[self strForHost:dest.addr port:dest_port]];
|
||||
NSArray *hostPortArray = [strHostPort componentsSeparatedByString:@":"];
|
||||
int src_ip = [hostPortArray[0] intValue];
|
||||
int src_port = [hostPortArray[1] intValue];
|
||||
uint8_t *bytes = (uint8_t *)[data bytes];
|
||||
int bytes_len = (int)data.length;
|
||||
int udp_length = sizeof(struct udp_hdr) + bytes_len;
|
||||
int total_len = IP_HLEN + udp_length;
|
||||
|
||||
ip_addr_p_t src = {src_ip};
|
||||
struct ip_hdr *iphdr = generateNewIPHeader(IP_PROTO_UDP, dest, src, total_len);
|
||||
|
||||
struct udp_hdr udphdr;
|
||||
udphdr.src = dest_port;
|
||||
udphdr.dest = src_port;
|
||||
udphdr.len = hton16(udp_length);
|
||||
udphdr.chksum = hton16(0);
|
||||
|
||||
uint8_t *udpdata = malloc(sizeof(uint8_t) * udp_length);
|
||||
memcpy(udpdata, &udphdr, sizeof(struct udp_hdr));
|
||||
memcpy(udpdata + sizeof(struct udp_hdr), bytes, bytes_len);
|
||||
|
||||
ip_addr_t odest = { dest.addr };
|
||||
ip_addr_t osrc = { src_ip };
|
||||
|
||||
struct pbuf *p_udp = pbuf_alloc(PBUF_TRANSPORT, udp_length, PBUF_RAM);
|
||||
pbuf_take(p_udp, udpdata, udp_length);
|
||||
|
||||
struct udp_hdr *new_udphdr = (struct udp_hdr *) p_udp->payload;
|
||||
new_udphdr->chksum = inet_chksum_pseudo(p_udp, IP_PROTO_UDP, p_udp->len, &odest, &osrc);
|
||||
|
||||
uint8_t *ipdata = malloc(sizeof(uint8_t) * total_len);
|
||||
memcpy(ipdata, iphdr, IP_HLEN);
|
||||
memcpy(ipdata + sizeof(struct ip_hdr), p_udp->payload, udp_length);
|
||||
|
||||
NSData *outData = [[NSData alloc] initWithBytes:ipdata length:total_len];
|
||||
free(ipdata);
|
||||
free(iphdr);
|
||||
free(udpdata);
|
||||
pbuf_free(p_udp);
|
||||
[TunnelInterface writePacket:outData];
|
||||
}
|
||||
|
||||
struct ip_hdr *generateNewIPHeader(u8_t proto, ip_addr_p_t src, ip_addr_p_t dest, uint16_t total_len) {
|
||||
struct ip_hdr *iphdr = malloc(sizeof(struct ip_hdr));
|
||||
IPH_VHL_SET(iphdr, 4, IP_HLEN / 4);
|
||||
IPH_TOS_SET(iphdr, 0);
|
||||
IPH_LEN_SET(iphdr, htons(total_len));
|
||||
IPH_ID_SET(iphdr, 0);
|
||||
IPH_OFFSET_SET(iphdr, 0);
|
||||
IPH_TTL_SET(iphdr, 64);
|
||||
IPH_PROTO_SET(iphdr, IP_PROTO_UDP);
|
||||
iphdr->src = src;
|
||||
iphdr->dest = dest;
|
||||
IPH_CHKSUM_SET(iphdr, 0);
|
||||
IPH_CHKSUM_SET(iphdr, inet_chksum(iphdr, IP_HLEN));
|
||||
return iphdr;
|
||||
}
|
||||
|
||||
- (NSString *)strForHost: (int)host port: (int)port {
|
||||
return [NSString stringWithFormat:@"%d:%d",host, port];
|
||||
}
|
||||
|
||||
|
||||
|
||||
@end
|
||||
@@ -1,400 +0,0 @@
|
||||
/**
|
||||
* @file BLog.h
|
||||
* @author Ambroz Bizjak <ambrop7@gmail.com>
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @section DESCRIPTION
|
||||
*
|
||||
* A global object for logging.
|
||||
*/
|
||||
|
||||
#ifndef BADVPN_BLOG_H
|
||||
#define BADVPN_BLOG_H
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "misc/debug.h"
|
||||
#include "misc/memref.h"
|
||||
#include "base/BMutex.h"
|
||||
|
||||
// auto-generated channel numbers and number of channels
|
||||
#include "generated/blog_channels_defines.h"
|
||||
|
||||
// keep in sync with level names in BLog.c!
|
||||
#define BLOG_ERROR 1
|
||||
#define BLOG_WARNING 2
|
||||
#define BLOG_NOTICE 3
|
||||
#define BLOG_INFO 4
|
||||
#define BLOG_DEBUG 5
|
||||
|
||||
#define BLog(...) BLog_LogToChannel(BLOG_CURRENT_CHANNEL, __VA_ARGS__)
|
||||
#define BContextLog(context, ...) BLog_ContextLog((context), BLOG_CURRENT_CHANNEL, __VA_ARGS__)
|
||||
#define BLOG_CCCC(context) BLog_MakeChannelContext((context), BLOG_CURRENT_CHANNEL)
|
||||
|
||||
typedef void (*_BLog_log_func) (int channel, int level, const char *msg);
|
||||
typedef void (*_BLog_free_func) (void);
|
||||
|
||||
struct _BLog_channel {
|
||||
const char *name;
|
||||
int loglevel;
|
||||
};
|
||||
|
||||
struct _BLog_global {
|
||||
#ifndef NDEBUG
|
||||
int initialized; // initialized statically
|
||||
#endif
|
||||
struct _BLog_channel channels[BLOG_NUM_CHANNELS];
|
||||
_BLog_log_func log_func;
|
||||
_BLog_free_func free_func;
|
||||
BMutex mutex;
|
||||
#ifndef NDEBUG
|
||||
int logging;
|
||||
#endif
|
||||
char logbuf[2048];
|
||||
int logbuf_pos;
|
||||
};
|
||||
|
||||
extern struct _BLog_channel blog_channel_list[];
|
||||
extern struct _BLog_global blog_global;
|
||||
|
||||
typedef void (*BLog_logfunc) (void *);
|
||||
|
||||
typedef struct {
|
||||
BLog_logfunc logfunc;
|
||||
void *logfunc_user;
|
||||
} BLogContext;
|
||||
|
||||
typedef struct {
|
||||
BLogContext context;
|
||||
int channel;
|
||||
} BLogChannelContext;
|
||||
|
||||
static int BLogGlobal_GetChannelByName (const char *channel_name);
|
||||
|
||||
static void BLog_Init (_BLog_log_func log_func, _BLog_free_func free_func);
|
||||
static void BLog_Free (void);
|
||||
static void BLog_SetChannelLoglevel (int channel, int loglevel);
|
||||
static int BLog_WouldLog (int channel, int level);
|
||||
static void BLog_Begin (void);
|
||||
static void BLog_AppendVarArg (const char *fmt, va_list vl);
|
||||
static void BLog_Append (const char *fmt, ...);
|
||||
static void BLog_AppendBytes (MemRef data);
|
||||
static void BLog_Finish (int channel, int level);
|
||||
static void BLog_LogToChannelVarArg (int channel, int level, const char *fmt, va_list vl);
|
||||
static void BLog_LogToChannel (int channel, int level, const char *fmt, ...);
|
||||
static void BLog_LogViaFuncVarArg (BLog_logfunc func, void *arg, int channel, int level, const char *fmt, va_list vl);
|
||||
static void BLog_LogViaFunc (BLog_logfunc func, void *arg, int channel, int level, const char *fmt, ...);
|
||||
static BLogContext BLog_RootContext (void);
|
||||
static BLogContext BLog_MakeContext (BLog_logfunc logfunc, void *logfunc_user);
|
||||
static void BLog_ContextLogVarArg (BLogContext context, int channel, int level, const char *fmt, va_list vl);
|
||||
static void BLog_ContextLog (BLogContext context, int channel, int level, const char *fmt, ...);
|
||||
static BLogChannelContext BLog_MakeChannelContext (BLogContext context, int channel);
|
||||
static void BLog_ChannelContextLogVarArg (BLogChannelContext ccontext, int level, const char *fmt, va_list vl);
|
||||
static void BLog_ChannelContextLog (BLogChannelContext ccontext, int level, const char *fmt, ...);
|
||||
|
||||
void BLog_InitStdout (void);
|
||||
void BLog_InitStderr (void);
|
||||
|
||||
int BLogGlobal_GetChannelByName (const char *channel_name)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < BLOG_NUM_CHANNELS; i++) {
|
||||
if (!strcmp(blog_channel_list[i].name, channel_name)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
void BLog_Init (_BLog_log_func log_func, _BLog_free_func free_func)
|
||||
{
|
||||
ASSERT(!blog_global.initialized)
|
||||
|
||||
#ifndef NDEBUG
|
||||
blog_global.initialized = 1;
|
||||
#endif
|
||||
|
||||
// initialize channels
|
||||
memcpy(blog_global.channels, blog_channel_list, BLOG_NUM_CHANNELS * sizeof(struct _BLog_channel));
|
||||
|
||||
blog_global.log_func = log_func;
|
||||
blog_global.free_func = free_func;
|
||||
#ifndef NDEBUG
|
||||
blog_global.logging = 0;
|
||||
#endif
|
||||
blog_global.logbuf_pos = 0;
|
||||
blog_global.logbuf[0] = '\0';
|
||||
|
||||
ASSERT_FORCE(BMutex_Init(&blog_global.mutex))
|
||||
}
|
||||
|
||||
void BLog_Free (void)
|
||||
{
|
||||
ASSERT(blog_global.initialized)
|
||||
#ifndef NDEBUG
|
||||
ASSERT(!blog_global.logging)
|
||||
#endif
|
||||
|
||||
BMutex_Free(&blog_global.mutex);
|
||||
|
||||
#ifndef NDEBUG
|
||||
blog_global.initialized = 0;
|
||||
#endif
|
||||
|
||||
blog_global.free_func();
|
||||
}
|
||||
|
||||
void BLog_SetChannelLoglevel (int channel, int loglevel)
|
||||
{
|
||||
ASSERT(blog_global.initialized)
|
||||
ASSERT(channel >= 0 && channel < BLOG_NUM_CHANNELS)
|
||||
ASSERT(loglevel >= 0 && loglevel <= BLOG_DEBUG)
|
||||
|
||||
blog_global.channels[channel].loglevel = loglevel;
|
||||
}
|
||||
|
||||
int BLog_WouldLog (int channel, int level)
|
||||
{
|
||||
ASSERT(blog_global.initialized)
|
||||
ASSERT(channel >= 0 && channel < BLOG_NUM_CHANNELS)
|
||||
ASSERT(level >= BLOG_ERROR && level <= BLOG_DEBUG)
|
||||
|
||||
return (level <= blog_global.channels[channel].loglevel);
|
||||
}
|
||||
|
||||
void BLog_Begin (void)
|
||||
{
|
||||
ASSERT(blog_global.initialized)
|
||||
|
||||
BMutex_Lock(&blog_global.mutex);
|
||||
|
||||
#ifndef NDEBUG
|
||||
ASSERT(!blog_global.logging)
|
||||
blog_global.logging = 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
void BLog_AppendVarArg (const char *fmt, va_list vl)
|
||||
{
|
||||
ASSERT(blog_global.initialized)
|
||||
#ifndef NDEBUG
|
||||
ASSERT(blog_global.logging)
|
||||
#endif
|
||||
ASSERT(blog_global.logbuf_pos >= 0)
|
||||
ASSERT(blog_global.logbuf_pos < sizeof(blog_global.logbuf))
|
||||
|
||||
int w = vsnprintf(blog_global.logbuf + blog_global.logbuf_pos, sizeof(blog_global.logbuf) - blog_global.logbuf_pos, fmt, vl);
|
||||
|
||||
if (w >= sizeof(blog_global.logbuf) - blog_global.logbuf_pos) {
|
||||
blog_global.logbuf_pos = sizeof(blog_global.logbuf) - 1;
|
||||
} else {
|
||||
blog_global.logbuf_pos += w;
|
||||
}
|
||||
}
|
||||
|
||||
void BLog_Append (const char *fmt, ...)
|
||||
{
|
||||
ASSERT(blog_global.initialized)
|
||||
#ifndef NDEBUG
|
||||
ASSERT(blog_global.logging)
|
||||
#endif
|
||||
|
||||
va_list vl;
|
||||
va_start(vl, fmt);
|
||||
BLog_AppendVarArg(fmt, vl);
|
||||
va_end(vl);
|
||||
}
|
||||
|
||||
void BLog_AppendBytes (MemRef data)
|
||||
{
|
||||
ASSERT(blog_global.initialized)
|
||||
#ifndef NDEBUG
|
||||
ASSERT(blog_global.logging)
|
||||
#endif
|
||||
ASSERT(blog_global.logbuf_pos >= 0)
|
||||
ASSERT(blog_global.logbuf_pos < sizeof(blog_global.logbuf))
|
||||
|
||||
size_t avail = (sizeof(blog_global.logbuf) - 1) - blog_global.logbuf_pos;
|
||||
data.len = (data.len > avail ? avail : data.len);
|
||||
|
||||
memcpy(blog_global.logbuf + blog_global.logbuf_pos, data.ptr, data.len);
|
||||
blog_global.logbuf_pos += data.len;
|
||||
blog_global.logbuf[blog_global.logbuf_pos] = '\0';
|
||||
}
|
||||
|
||||
void BLog_Finish (int channel, int level)
|
||||
{
|
||||
ASSERT(blog_global.initialized)
|
||||
#ifndef NDEBUG
|
||||
ASSERT(blog_global.logging)
|
||||
#endif
|
||||
ASSERT(channel >= 0 && channel < BLOG_NUM_CHANNELS)
|
||||
ASSERT(level >= BLOG_ERROR && level <= BLOG_DEBUG)
|
||||
ASSERT(BLog_WouldLog(channel, level))
|
||||
|
||||
ASSERT(blog_global.logbuf_pos >= 0)
|
||||
ASSERT(blog_global.logbuf_pos < sizeof(blog_global.logbuf))
|
||||
ASSERT(blog_global.logbuf[blog_global.logbuf_pos] == '\0')
|
||||
|
||||
blog_global.log_func(channel, level, blog_global.logbuf);
|
||||
|
||||
#ifndef NDEBUG
|
||||
blog_global.logging = 0;
|
||||
#endif
|
||||
blog_global.logbuf_pos = 0;
|
||||
blog_global.logbuf[0] = '\0';
|
||||
|
||||
BMutex_Unlock(&blog_global.mutex);
|
||||
}
|
||||
|
||||
void BLog_LogToChannelVarArg (int channel, int level, const char *fmt, va_list vl)
|
||||
{
|
||||
ASSERT(blog_global.initialized)
|
||||
ASSERT(channel >= 0 && channel < BLOG_NUM_CHANNELS)
|
||||
ASSERT(level >= BLOG_ERROR && level <= BLOG_DEBUG)
|
||||
|
||||
if (!BLog_WouldLog(channel, level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
BLog_Begin();
|
||||
BLog_AppendVarArg(fmt, vl);
|
||||
BLog_Finish(channel, level);
|
||||
}
|
||||
|
||||
void BLog_LogToChannel (int channel, int level, const char *fmt, ...)
|
||||
{
|
||||
ASSERT(blog_global.initialized)
|
||||
ASSERT(channel >= 0 && channel < BLOG_NUM_CHANNELS)
|
||||
ASSERT(level >= BLOG_ERROR && level <= BLOG_DEBUG)
|
||||
|
||||
if (!BLog_WouldLog(channel, level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
va_list vl;
|
||||
va_start(vl, fmt);
|
||||
|
||||
BLog_Begin();
|
||||
BLog_AppendVarArg(fmt, vl);
|
||||
BLog_Finish(channel, level);
|
||||
|
||||
va_end(vl);
|
||||
}
|
||||
|
||||
void BLog_LogViaFuncVarArg (BLog_logfunc func, void *arg, int channel, int level, const char *fmt, va_list vl)
|
||||
{
|
||||
ASSERT(blog_global.initialized)
|
||||
ASSERT(channel >= 0 && channel < BLOG_NUM_CHANNELS)
|
||||
ASSERT(level >= BLOG_ERROR && level <= BLOG_DEBUG)
|
||||
|
||||
if (!BLog_WouldLog(channel, level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
BLog_Begin();
|
||||
func(arg);
|
||||
BLog_AppendVarArg(fmt, vl);
|
||||
BLog_Finish(channel, level);
|
||||
}
|
||||
|
||||
void BLog_LogViaFunc (BLog_logfunc func, void *arg, int channel, int level, const char *fmt, ...)
|
||||
{
|
||||
ASSERT(blog_global.initialized)
|
||||
ASSERT(channel >= 0 && channel < BLOG_NUM_CHANNELS)
|
||||
ASSERT(level >= BLOG_ERROR && level <= BLOG_DEBUG)
|
||||
|
||||
if (!BLog_WouldLog(channel, level)) {
|
||||
return;
|
||||
}
|
||||
|
||||
va_list vl;
|
||||
va_start(vl, fmt);
|
||||
|
||||
BLog_Begin();
|
||||
func(arg);
|
||||
BLog_AppendVarArg(fmt, vl);
|
||||
BLog_Finish(channel, level);
|
||||
|
||||
va_end(vl);
|
||||
}
|
||||
|
||||
static void BLog__root_logfunc (void *unused)
|
||||
{
|
||||
}
|
||||
|
||||
static BLogContext BLog_RootContext (void)
|
||||
{
|
||||
return BLog_MakeContext(BLog__root_logfunc, NULL);
|
||||
}
|
||||
|
||||
static BLogContext BLog_MakeContext (BLog_logfunc logfunc, void *logfunc_user)
|
||||
{
|
||||
ASSERT(logfunc)
|
||||
|
||||
BLogContext context;
|
||||
context.logfunc = logfunc;
|
||||
context.logfunc_user = logfunc_user;
|
||||
return context;
|
||||
}
|
||||
|
||||
static void BLog_ContextLogVarArg (BLogContext context, int channel, int level, const char *fmt, va_list vl)
|
||||
{
|
||||
BLog_LogViaFuncVarArg(context.logfunc, context.logfunc_user, channel, level, fmt, vl);
|
||||
}
|
||||
|
||||
static void BLog_ContextLog (BLogContext context, int channel, int level, const char *fmt, ...)
|
||||
{
|
||||
va_list vl;
|
||||
va_start(vl, fmt);
|
||||
BLog_ContextLogVarArg(context, channel, level, fmt, vl);
|
||||
va_end(vl);
|
||||
}
|
||||
|
||||
static BLogChannelContext BLog_MakeChannelContext (BLogContext context, int channel)
|
||||
{
|
||||
BLogChannelContext ccontext;
|
||||
ccontext.context = context;
|
||||
ccontext.channel = channel;
|
||||
return ccontext;
|
||||
}
|
||||
|
||||
static void BLog_ChannelContextLogVarArg (BLogChannelContext ccontext, int level, const char *fmt, va_list vl)
|
||||
{
|
||||
BLog_ContextLogVarArg(ccontext.context, ccontext.channel, level, fmt, vl);
|
||||
}
|
||||
|
||||
static void BLog_ChannelContextLog (BLogChannelContext ccontext, int level, const char *fmt, ...)
|
||||
{
|
||||
va_list vl;
|
||||
va_start(vl, fmt);
|
||||
BLog_ChannelContextLogVarArg(ccontext, level, fmt, vl);
|
||||
va_end(vl);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,75 +0,0 @@
|
||||
/**
|
||||
* @file BLog.c
|
||||
* @author Ambroz Bizjak <ambrop7@gmail.com>
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stddef.h>
|
||||
#include <Foundation/Foundation.h>
|
||||
|
||||
#include "BLog.h"
|
||||
|
||||
#ifndef BADVPN_PLUGIN
|
||||
|
||||
struct _BLog_channel blog_channel_list[] = {
|
||||
#include "generated/blog_channels_list.h"
|
||||
};
|
||||
|
||||
struct _BLog_global blog_global = {
|
||||
#ifndef NDEBUG
|
||||
0
|
||||
#endif
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
// keep in sync with level numbers in BLog.h!
|
||||
static char *level_names[] = { NULL, "ERROR", "WARNING", "NOTICE", "INFO", "DEBUG" };
|
||||
|
||||
static void stdout_log (int channel, int level, const char *msg)
|
||||
{
|
||||
NSLog(@"%s(%s): %s\n", level_names[level], blog_global.channels[channel].name, msg);
|
||||
}
|
||||
|
||||
static void stderr_log (int channel, int level, const char *msg)
|
||||
{
|
||||
NSLog(@"%s(%s): %s\n", level_names[level], blog_global.channels[channel].name, msg);
|
||||
}
|
||||
|
||||
static void stdout_stderr_free (void)
|
||||
{
|
||||
}
|
||||
|
||||
void BLog_InitStdout (void)
|
||||
{
|
||||
BLog_Init(stdout_log, stdout_stderr_free);
|
||||
}
|
||||
|
||||
void BLog_InitStderr (void)
|
||||
{
|
||||
BLog_Init(stderr_log, stdout_stderr_free);
|
||||
}
|
||||
@@ -1,150 +0,0 @@
|
||||
/**
|
||||
* @file BLog_syslog.c
|
||||
* @author Ambroz Bizjak <ambrop7@gmail.com>
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <syslog.h>
|
||||
|
||||
#include "misc/debug.h"
|
||||
|
||||
#include "BLog_syslog.h"
|
||||
|
||||
static int resolve_facility (char *str, int *out)
|
||||
{
|
||||
if (!strcmp(str, "authpriv")) {
|
||||
*out = LOG_AUTHPRIV;
|
||||
}
|
||||
else if (!strcmp(str, "cron")) {
|
||||
*out = LOG_CRON;
|
||||
}
|
||||
else if (!strcmp(str, "daemon")) {
|
||||
*out = LOG_DAEMON;
|
||||
}
|
||||
else if (!strcmp(str, "ftp")) {
|
||||
*out = LOG_FTP;
|
||||
}
|
||||
else if (!strcmp(str, "local0")) {
|
||||
*out = LOG_LOCAL0;
|
||||
}
|
||||
else if (!strcmp(str, "local1")) {
|
||||
*out = LOG_LOCAL1;
|
||||
}
|
||||
else if (!strcmp(str, "local2")) {
|
||||
*out = LOG_LOCAL2;
|
||||
}
|
||||
else if (!strcmp(str, "local3")) {
|
||||
*out = LOG_LOCAL3;
|
||||
}
|
||||
else if (!strcmp(str, "local4")) {
|
||||
*out = LOG_LOCAL4;
|
||||
}
|
||||
else if (!strcmp(str, "local5")) {
|
||||
*out = LOG_LOCAL5;
|
||||
}
|
||||
else if (!strcmp(str, "local6")) {
|
||||
*out = LOG_LOCAL6;
|
||||
}
|
||||
else if (!strcmp(str, "local7")) {
|
||||
*out = LOG_LOCAL7;
|
||||
}
|
||||
else if (!strcmp(str, "lpr")) {
|
||||
*out = LOG_LPR;
|
||||
}
|
||||
else if (!strcmp(str, "mail")) {
|
||||
*out = LOG_MAIL;
|
||||
}
|
||||
else if (!strcmp(str, "news")) {
|
||||
*out = LOG_NEWS;
|
||||
}
|
||||
else if (!strcmp(str, "syslog")) {
|
||||
*out = LOG_SYSLOG;
|
||||
}
|
||||
else if (!strcmp(str, "user")) {
|
||||
*out = LOG_USER;
|
||||
}
|
||||
else if (!strcmp(str, "uucp")) {
|
||||
*out = LOG_UUCP;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int convert_level (int level)
|
||||
{
|
||||
ASSERT(level >= BLOG_ERROR && level <= BLOG_DEBUG)
|
||||
|
||||
switch (level) {
|
||||
case BLOG_ERROR:
|
||||
return LOG_ERR;
|
||||
case BLOG_WARNING:
|
||||
return LOG_WARNING;
|
||||
case BLOG_NOTICE:
|
||||
return LOG_NOTICE;
|
||||
case BLOG_INFO:
|
||||
return LOG_INFO;
|
||||
case BLOG_DEBUG:
|
||||
return LOG_DEBUG;
|
||||
default:
|
||||
ASSERT(0)
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static struct {
|
||||
char ident[200];
|
||||
} syslog_global;
|
||||
|
||||
static void syslog_log (int channel, int level, const char *msg)
|
||||
{
|
||||
syslog(convert_level(level), "%s: %s", blog_global.channels[channel].name, msg);
|
||||
}
|
||||
|
||||
static void syslog_free (void)
|
||||
{
|
||||
closelog();
|
||||
}
|
||||
|
||||
int BLog_InitSyslog (char *ident, char *facility_str)
|
||||
{
|
||||
int facility;
|
||||
if (!resolve_facility(facility_str, &facility)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
snprintf(syslog_global.ident, sizeof(syslog_global.ident), "%s", ident);
|
||||
|
||||
openlog(syslog_global.ident, 0, facility);
|
||||
|
||||
BLog_Init(syslog_log, syslog_free);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
/**
|
||||
* @file BLog_syslog.h
|
||||
* @author Ambroz Bizjak <ambrop7@gmail.com>
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @section DESCRIPTION
|
||||
*
|
||||
* BLog syslog backend.
|
||||
*/
|
||||
|
||||
#ifndef BADVPN_BLOG_SYSLOG_H
|
||||
#define BADVPN_BLOG_SYSLOG_H
|
||||
|
||||
#include "misc/debug.h"
|
||||
#include "base/BLog.h"
|
||||
|
||||
int BLog_InitSyslog (char *ident, char *facility) WARN_UNUSED;
|
||||
|
||||
#endif
|
||||
@@ -1,101 +0,0 @@
|
||||
/**
|
||||
* @file BMutex.h
|
||||
* @author Ambroz Bizjak <ambrop7@gmail.com>
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#ifndef BADVPN_BMUTEX_H
|
||||
#define BADVPN_BMUTEX_H
|
||||
|
||||
#if !defined(BADVPN_THREAD_SAFE) || (BADVPN_THREAD_SAFE != 0 && BADVPN_THREAD_SAFE != 1)
|
||||
#error BADVPN_THREAD_SAFE is not defined or incorrect
|
||||
#endif
|
||||
|
||||
#if BADVPN_THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
#include "misc/debug.h"
|
||||
#include "base/DebugObject.h"
|
||||
|
||||
typedef struct {
|
||||
#if BADVPN_THREAD_SAFE
|
||||
pthread_mutex_t pthread_mutex;
|
||||
#endif
|
||||
DebugObject d_obj;
|
||||
} BMutex;
|
||||
|
||||
static int BMutex_Init (BMutex *o) WARN_UNUSED;
|
||||
static void BMutex_Free (BMutex *o);
|
||||
static void BMutex_Lock (BMutex *o);
|
||||
static void BMutex_Unlock (BMutex *o);
|
||||
|
||||
static int BMutex_Init (BMutex *o)
|
||||
{
|
||||
#if BADVPN_THREAD_SAFE
|
||||
if (pthread_mutex_init(&o->pthread_mutex, NULL) != 0) {
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
DebugObject_Init(&o->d_obj);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void BMutex_Free (BMutex *o)
|
||||
{
|
||||
DebugObject_Free(&o->d_obj);
|
||||
|
||||
#if BADVPN_THREAD_SAFE
|
||||
int res = pthread_mutex_destroy(&o->pthread_mutex);
|
||||
B_USE(res)
|
||||
ASSERT(res == 0)
|
||||
#endif
|
||||
}
|
||||
|
||||
static void BMutex_Lock (BMutex *o)
|
||||
{
|
||||
DebugObject_Access(&o->d_obj);
|
||||
|
||||
#if BADVPN_THREAD_SAFE
|
||||
int res = pthread_mutex_lock(&o->pthread_mutex);
|
||||
B_USE(res)
|
||||
ASSERT(res == 0)
|
||||
#endif
|
||||
}
|
||||
|
||||
static void BMutex_Unlock (BMutex *o)
|
||||
{
|
||||
DebugObject_Access(&o->d_obj);
|
||||
|
||||
#if BADVPN_THREAD_SAFE
|
||||
int res = pthread_mutex_unlock(&o->pthread_mutex);
|
||||
B_USE(res)
|
||||
ASSERT(res == 0)
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,205 +0,0 @@
|
||||
/**
|
||||
* @file BPending.c
|
||||
* @author Ambroz Bizjak <ambrop7@gmail.com>
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "misc/debug.h"
|
||||
#include "misc/offset.h"
|
||||
|
||||
#include "BPending.h"
|
||||
|
||||
#include "BPending_list.h"
|
||||
#include "structure/SLinkedList_impl.h"
|
||||
|
||||
void BPendingGroup_Init (BPendingGroup *g)
|
||||
{
|
||||
// init jobs list
|
||||
BPending__List_Init(&g->jobs);
|
||||
|
||||
// init pending counter
|
||||
DebugCounter_Init(&g->pending_ctr);
|
||||
|
||||
// init debug object
|
||||
DebugObject_Init(&g->d_obj);
|
||||
}
|
||||
|
||||
void BPendingGroup_Free (BPendingGroup *g)
|
||||
{
|
||||
DebugCounter_Free(&g->pending_ctr);
|
||||
ASSERT(BPending__List_IsEmpty(&g->jobs))
|
||||
DebugObject_Free(&g->d_obj);
|
||||
}
|
||||
|
||||
int BPendingGroup_HasJobs (BPendingGroup *g)
|
||||
{
|
||||
DebugObject_Access(&g->d_obj);
|
||||
|
||||
return !BPending__List_IsEmpty(&g->jobs);
|
||||
}
|
||||
|
||||
void BPendingGroup_ExecuteJob (BPendingGroup *g)
|
||||
{
|
||||
ASSERT(!BPending__List_IsEmpty(&g->jobs))
|
||||
DebugObject_Access(&g->d_obj);
|
||||
|
||||
// get a job
|
||||
BSmallPending *p = BPending__List_First(&g->jobs);
|
||||
ASSERT(!BPending__ListIsRemoved(p))
|
||||
ASSERT(p->pending)
|
||||
|
||||
// remove from jobs list
|
||||
BPending__List_RemoveFirst(&g->jobs);
|
||||
|
||||
// set not pending
|
||||
BPending__ListMarkRemoved(p);
|
||||
#ifndef NDEBUG
|
||||
p->pending = 0;
|
||||
#endif
|
||||
|
||||
// execute job
|
||||
p->handler(p->user);
|
||||
return;
|
||||
}
|
||||
|
||||
BSmallPending * BPendingGroup_PeekJob (BPendingGroup *g)
|
||||
{
|
||||
DebugObject_Access(&g->d_obj);
|
||||
|
||||
return BPending__List_First(&g->jobs);
|
||||
}
|
||||
|
||||
void BSmallPending_Init (BSmallPending *o, BPendingGroup *g, BSmallPending_handler handler, void *user)
|
||||
{
|
||||
// init arguments
|
||||
o->handler = handler;
|
||||
o->user = user;
|
||||
|
||||
// set not pending
|
||||
BPending__ListMarkRemoved(o);
|
||||
#ifndef NDEBUG
|
||||
o->pending = 0;
|
||||
#endif
|
||||
|
||||
// increment pending counter
|
||||
DebugCounter_Increment(&g->pending_ctr);
|
||||
|
||||
// init debug object
|
||||
DebugObject_Init(&o->d_obj);
|
||||
}
|
||||
|
||||
void BSmallPending_Free (BSmallPending *o, BPendingGroup *g)
|
||||
{
|
||||
DebugCounter_Decrement(&g->pending_ctr);
|
||||
DebugObject_Free(&o->d_obj);
|
||||
ASSERT(o->pending == !BPending__ListIsRemoved(o))
|
||||
|
||||
// remove from jobs list
|
||||
if (!BPending__ListIsRemoved(o)) {
|
||||
BPending__List_Remove(&g->jobs, o);
|
||||
}
|
||||
}
|
||||
|
||||
void BSmallPending_SetHandler (BSmallPending *o, BSmallPending_handler handler, void *user)
|
||||
{
|
||||
DebugObject_Access(&o->d_obj);
|
||||
|
||||
// set handler
|
||||
o->handler = handler;
|
||||
o->user = user;
|
||||
}
|
||||
|
||||
void BSmallPending_Set (BSmallPending *o, BPendingGroup *g)
|
||||
{
|
||||
DebugObject_Access(&o->d_obj);
|
||||
ASSERT(o->pending == !BPending__ListIsRemoved(o))
|
||||
|
||||
// remove from jobs list
|
||||
if (!BPending__ListIsRemoved(o)) {
|
||||
BPending__List_Remove(&g->jobs, o);
|
||||
}
|
||||
|
||||
// insert to jobs list
|
||||
BPending__List_Prepend(&g->jobs, o);
|
||||
|
||||
// set pending
|
||||
#ifndef NDEBUG
|
||||
o->pending = 1;
|
||||
#endif
|
||||
}
|
||||
|
||||
void BSmallPending_Unset (BSmallPending *o, BPendingGroup *g)
|
||||
{
|
||||
DebugObject_Access(&o->d_obj);
|
||||
ASSERT(o->pending == !BPending__ListIsRemoved(o))
|
||||
|
||||
if (!BPending__ListIsRemoved(o)) {
|
||||
// remove from jobs list
|
||||
BPending__List_Remove(&g->jobs, o);
|
||||
|
||||
// set not pending
|
||||
BPending__ListMarkRemoved(o);
|
||||
#ifndef NDEBUG
|
||||
o->pending = 0;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
int BSmallPending_IsSet (BSmallPending *o)
|
||||
{
|
||||
DebugObject_Access(&o->d_obj);
|
||||
ASSERT(o->pending == !BPending__ListIsRemoved(o))
|
||||
|
||||
return !BPending__ListIsRemoved(o);
|
||||
}
|
||||
|
||||
void BPending_Init (BPending *o, BPendingGroup *g, BPending_handler handler, void *user)
|
||||
{
|
||||
BSmallPending_Init(&o->base, g, handler, user);
|
||||
o->g = g;
|
||||
}
|
||||
|
||||
void BPending_Free (BPending *o)
|
||||
{
|
||||
BSmallPending_Free(&o->base, o->g);
|
||||
}
|
||||
|
||||
void BPending_Set (BPending *o)
|
||||
{
|
||||
BSmallPending_Set(&o->base, o->g);
|
||||
}
|
||||
|
||||
void BPending_Unset (BPending *o)
|
||||
{
|
||||
BSmallPending_Unset(&o->base, o->g);
|
||||
}
|
||||
|
||||
int BPending_IsSet (BPending *o)
|
||||
{
|
||||
return BSmallPending_IsSet(&o->base);
|
||||
}
|
||||
@@ -1,250 +0,0 @@
|
||||
/**
|
||||
* @file BPending.h
|
||||
* @author Ambroz Bizjak <ambrop7@gmail.com>
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @section DESCRIPTION
|
||||
*
|
||||
* Module for managing a queue of jobs pending execution.
|
||||
*/
|
||||
|
||||
#ifndef BADVPN_BPENDING_H
|
||||
#define BADVPN_BPENDING_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "misc/debugcounter.h"
|
||||
#include "structure/SLinkedList.h"
|
||||
#include "base/DebugObject.h"
|
||||
|
||||
struct BSmallPending_s;
|
||||
|
||||
#include "BPending_list.h"
|
||||
#include "structure/SLinkedList_decl.h"
|
||||
|
||||
/**
|
||||
* Job execution handler.
|
||||
* It is guaranteed that the associated {@link BSmallPending} object was
|
||||
* in set state.
|
||||
* The {@link BSmallPending} object enters not set state before the handler
|
||||
* is called.
|
||||
*
|
||||
* @param user as in {@link BSmallPending_Init}
|
||||
*/
|
||||
typedef void (*BSmallPending_handler) (void *user);
|
||||
|
||||
/**
|
||||
* Job execution handler.
|
||||
* It is guaranteed that the associated {@link BPending} object was
|
||||
* in set state.
|
||||
* The {@link BPending} object enters not set state before the handler
|
||||
* is called.
|
||||
*
|
||||
* @param user as in {@link BPending_Init}
|
||||
*/
|
||||
typedef void (*BPending_handler) (void *user);
|
||||
|
||||
/**
|
||||
* Object that contains a list of jobs pending execution.
|
||||
*/
|
||||
typedef struct {
|
||||
BPending__List jobs;
|
||||
DebugCounter pending_ctr;
|
||||
DebugObject d_obj;
|
||||
} BPendingGroup;
|
||||
|
||||
/**
|
||||
* Object for queuing a job for execution.
|
||||
*/
|
||||
typedef struct BSmallPending_s {
|
||||
BPending_handler handler;
|
||||
void *user;
|
||||
BPending__ListNode pending_node; // optimization: if not pending, .next is this
|
||||
#ifndef NDEBUG
|
||||
uint8_t pending;
|
||||
#endif
|
||||
DebugObject d_obj;
|
||||
} BSmallPending;
|
||||
|
||||
/**
|
||||
* Object for queuing a job for execution. This is a convenience wrapper
|
||||
* around {@link BSmallPending} with an extra field to remember the
|
||||
* {@link BPendingGroup} being used.
|
||||
*/
|
||||
typedef struct {
|
||||
BSmallPending base;
|
||||
BPendingGroup *g;
|
||||
} BPending;
|
||||
|
||||
/**
|
||||
* Initializes the object.
|
||||
*
|
||||
* @param g the object
|
||||
*/
|
||||
void BPendingGroup_Init (BPendingGroup *g);
|
||||
|
||||
/**
|
||||
* Frees the object.
|
||||
* There must be no {@link BPending} or {@link BSmallPending} objects using
|
||||
* this group.
|
||||
*
|
||||
* @param g the object
|
||||
*/
|
||||
void BPendingGroup_Free (BPendingGroup *g);
|
||||
|
||||
/**
|
||||
* Checks if there is at least one job in the queue.
|
||||
*
|
||||
* @param g the object
|
||||
* @return 1 if there is at least one job, 0 if not
|
||||
*/
|
||||
int BPendingGroup_HasJobs (BPendingGroup *g);
|
||||
|
||||
/**
|
||||
* Executes the top job on the job list.
|
||||
* The job is removed from the list and enters
|
||||
* not set state before being executed.
|
||||
* There must be at least one job in job list.
|
||||
*
|
||||
* @param g the object
|
||||
*/
|
||||
void BPendingGroup_ExecuteJob (BPendingGroup *g);
|
||||
|
||||
/**
|
||||
* Returns the top job on the job list, or NULL if there are none.
|
||||
*
|
||||
* @param g the object
|
||||
* @return the top job if there is at least one job, NULL if not
|
||||
*/
|
||||
BSmallPending * BPendingGroup_PeekJob (BPendingGroup *g);
|
||||
|
||||
/**
|
||||
* Initializes the object.
|
||||
* The object is initialized in not set state.
|
||||
*
|
||||
* @param o the object
|
||||
* @param g pending group to use
|
||||
* @param handler job execution handler
|
||||
* @param user value to pass to handler
|
||||
*/
|
||||
void BSmallPending_Init (BSmallPending *o, BPendingGroup *g, BSmallPending_handler handler, void *user);
|
||||
|
||||
/**
|
||||
* Frees the object.
|
||||
* The execution handler will not be called after the object
|
||||
* is freed.
|
||||
*
|
||||
* @param o the object
|
||||
* @param g pending group. Must be the same as was used in {@link BSmallPending_Init}.
|
||||
*/
|
||||
void BSmallPending_Free (BSmallPending *o, BPendingGroup *g);
|
||||
|
||||
/**
|
||||
* Changes the job execution handler.
|
||||
*
|
||||
* @param o the object
|
||||
* @param handler job execution handler
|
||||
* @param user value to pass to handler
|
||||
*/
|
||||
void BSmallPending_SetHandler (BSmallPending *o, BSmallPending_handler handler, void *user);
|
||||
|
||||
/**
|
||||
* Enables the job, pushing it to the top of the job list.
|
||||
* If the object was already in set state, the job is removed from its
|
||||
* current position in the list before being pushed.
|
||||
* The object enters set state.
|
||||
*
|
||||
* @param o the object
|
||||
* @param g pending group. Must be the same as was used in {@link BSmallPending_Init}.
|
||||
*/
|
||||
void BSmallPending_Set (BSmallPending *o, BPendingGroup *g);
|
||||
|
||||
/**
|
||||
* Disables the job, removing it from the job list.
|
||||
* If the object was not in set state, nothing is done.
|
||||
* The object enters not set state.
|
||||
*
|
||||
* @param o the object
|
||||
* @param g pending group. Must be the same as was used in {@link BSmallPending_Init}.
|
||||
*/
|
||||
void BSmallPending_Unset (BSmallPending *o, BPendingGroup *g);
|
||||
|
||||
/**
|
||||
* Checks if the job is in set state.
|
||||
*
|
||||
* @param o the object
|
||||
* @return 1 if in set state, 0 if not
|
||||
*/
|
||||
int BSmallPending_IsSet (BSmallPending *o);
|
||||
|
||||
/**
|
||||
* Initializes the object.
|
||||
* The object is initialized in not set state.
|
||||
*
|
||||
* @param o the object
|
||||
* @param g pending group to use
|
||||
* @param handler job execution handler
|
||||
* @param user value to pass to handler
|
||||
*/
|
||||
void BPending_Init (BPending *o, BPendingGroup *g, BPending_handler handler, void *user);
|
||||
|
||||
/**
|
||||
* Frees the object.
|
||||
* The execution handler will not be called after the object
|
||||
* is freed.
|
||||
*
|
||||
* @param o the object
|
||||
*/
|
||||
void BPending_Free (BPending *o);
|
||||
|
||||
/**
|
||||
* Enables the job, pushing it to the top of the job list.
|
||||
* If the object was already in set state, the job is removed from its
|
||||
* current position in the list before being pushed.
|
||||
* The object enters set state.
|
||||
*
|
||||
* @param o the object
|
||||
*/
|
||||
void BPending_Set (BPending *o);
|
||||
|
||||
/**
|
||||
* Disables the job, removing it from the job list.
|
||||
* If the object was not in set state, nothing is done.
|
||||
* The object enters not set state.
|
||||
*
|
||||
* @param o the object
|
||||
*/
|
||||
void BPending_Unset (BPending *o);
|
||||
|
||||
/**
|
||||
* Checks if the job is in set state.
|
||||
*
|
||||
* @param o the object
|
||||
* @return 1 if in set state, 0 if not
|
||||
*/
|
||||
int BPending_IsSet (BPending *o);
|
||||
|
||||
#endif
|
||||
@@ -1,4 +0,0 @@
|
||||
#define SLINKEDLIST_PARAM_NAME BPending__List
|
||||
#define SLINKEDLIST_PARAM_FEATURE_LAST 0
|
||||
#define SLINKEDLIST_PARAM_TYPE_ENTRY struct BSmallPending_s
|
||||
#define SLINKEDLIST_PARAM_MEMBER_NODE pending_node
|
||||
@@ -1,39 +0,0 @@
|
||||
/**
|
||||
* @file DebugObject.c
|
||||
* @author Ambroz Bizjak <ambrop7@gmail.com>
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "DebugObject.h"
|
||||
|
||||
#ifndef BADVPN_PLUGIN
|
||||
#ifndef NDEBUG
|
||||
DebugCounter debugobject_counter = DEBUGCOUNTER_STATIC;
|
||||
#if BADVPN_THREAD_SAFE
|
||||
pthread_mutex_t debugobject_mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
@@ -1,147 +0,0 @@
|
||||
/**
|
||||
* @file DebugObject.h
|
||||
* @author Ambroz Bizjak <ambrop7@gmail.com>
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @section DESCRIPTION
|
||||
*
|
||||
* Object used for detecting leaks.
|
||||
*/
|
||||
|
||||
#ifndef BADVPN_DEBUGOBJECT_H
|
||||
#define BADVPN_DEBUGOBJECT_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#if !defined(BADVPN_THREAD_SAFE) || (BADVPN_THREAD_SAFE != 0 && BADVPN_THREAD_SAFE != 1)
|
||||
#error BADVPN_THREAD_SAFE is not defined or incorrect
|
||||
#endif
|
||||
|
||||
#if BADVPN_THREAD_SAFE
|
||||
#include <pthread.h>
|
||||
#endif
|
||||
|
||||
#include "misc/debug.h"
|
||||
#include "misc/debugcounter.h"
|
||||
|
||||
#define DEBUGOBJECT_VALID UINT32_C(0x31415926)
|
||||
|
||||
/**
|
||||
* Object used for detecting leaks.
|
||||
*/
|
||||
typedef struct {
|
||||
#ifndef NDEBUG
|
||||
uint32_t c;
|
||||
#endif
|
||||
} DebugObject;
|
||||
|
||||
/**
|
||||
* Initializes the object.
|
||||
*
|
||||
* @param obj the object
|
||||
*/
|
||||
static void DebugObject_Init (DebugObject *obj);
|
||||
|
||||
/**
|
||||
* Frees the object.
|
||||
*
|
||||
* @param obj the object
|
||||
*/
|
||||
static void DebugObject_Free (DebugObject *obj);
|
||||
|
||||
/**
|
||||
* Does nothing.
|
||||
*
|
||||
* @param obj the object
|
||||
*/
|
||||
static void DebugObject_Access (const DebugObject *obj);
|
||||
|
||||
/**
|
||||
* Does nothing.
|
||||
* There must be no {@link DebugObject}'s initialized.
|
||||
*/
|
||||
static void DebugObjectGlobal_Finish (void);
|
||||
|
||||
#ifndef NDEBUG
|
||||
extern DebugCounter debugobject_counter;
|
||||
#if BADVPN_THREAD_SAFE
|
||||
extern pthread_mutex_t debugobject_mutex;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void DebugObject_Init (DebugObject *obj)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
|
||||
obj->c = DEBUGOBJECT_VALID;
|
||||
|
||||
#if BADVPN_THREAD_SAFE
|
||||
ASSERT_FORCE(pthread_mutex_lock(&debugobject_mutex) == 0)
|
||||
#endif
|
||||
|
||||
DebugCounter_Increment(&debugobject_counter);
|
||||
|
||||
#if BADVPN_THREAD_SAFE
|
||||
ASSERT_FORCE(pthread_mutex_unlock(&debugobject_mutex) == 0)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void DebugObject_Free (DebugObject *obj)
|
||||
{
|
||||
ASSERT(obj->c == DEBUGOBJECT_VALID)
|
||||
|
||||
#ifndef NDEBUG
|
||||
|
||||
obj->c = 0;
|
||||
|
||||
#if BADVPN_THREAD_SAFE
|
||||
ASSERT_FORCE(pthread_mutex_lock(&debugobject_mutex) == 0)
|
||||
#endif
|
||||
|
||||
DebugCounter_Decrement(&debugobject_counter);
|
||||
|
||||
#if BADVPN_THREAD_SAFE
|
||||
ASSERT_FORCE(pthread_mutex_unlock(&debugobject_mutex) == 0)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void DebugObject_Access (const DebugObject *obj)
|
||||
{
|
||||
ASSERT(obj->c == DEBUGOBJECT_VALID)
|
||||
}
|
||||
|
||||
void DebugObjectGlobal_Finish (void)
|
||||
{
|
||||
#ifndef NDEBUG
|
||||
DebugCounter_Free(&debugobject_counter);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,112 +0,0 @@
|
||||
/**
|
||||
* @file BufferWriter.c
|
||||
* @author Ambroz Bizjak <ambrop7@gmail.com>
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "misc/debug.h"
|
||||
|
||||
#include "flow/BufferWriter.h"
|
||||
|
||||
static void output_handler_recv (BufferWriter *o, uint8_t *data)
|
||||
{
|
||||
ASSERT(!o->out_have)
|
||||
|
||||
// set output packet
|
||||
o->out_have = 1;
|
||||
o->out = data;
|
||||
}
|
||||
|
||||
void BufferWriter_Init (BufferWriter *o, int mtu, BPendingGroup *pg)
|
||||
{
|
||||
ASSERT(mtu >= 0)
|
||||
|
||||
// init output
|
||||
PacketRecvInterface_Init(&o->recv_interface, mtu, (PacketRecvInterface_handler_recv)output_handler_recv, o, pg);
|
||||
|
||||
// set no output packet
|
||||
o->out_have = 0;
|
||||
|
||||
DebugObject_Init(&o->d_obj);
|
||||
#ifndef NDEBUG
|
||||
o->d_mtu = mtu;
|
||||
o->d_writing = 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
void BufferWriter_Free (BufferWriter *o)
|
||||
{
|
||||
DebugObject_Free(&o->d_obj);
|
||||
|
||||
// free output
|
||||
PacketRecvInterface_Free(&o->recv_interface);
|
||||
}
|
||||
|
||||
PacketRecvInterface * BufferWriter_GetOutput (BufferWriter *o)
|
||||
{
|
||||
DebugObject_Access(&o->d_obj);
|
||||
|
||||
return &o->recv_interface;
|
||||
}
|
||||
|
||||
int BufferWriter_StartPacket (BufferWriter *o, uint8_t **buf)
|
||||
{
|
||||
ASSERT(!o->d_writing)
|
||||
DebugObject_Access(&o->d_obj);
|
||||
|
||||
if (!o->out_have) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (buf) {
|
||||
*buf = o->out;
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
o->d_writing = 1;
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
void BufferWriter_EndPacket (BufferWriter *o, int len)
|
||||
{
|
||||
ASSERT(len >= 0)
|
||||
ASSERT(len <= o->d_mtu)
|
||||
ASSERT(o->out_have)
|
||||
ASSERT(o->d_writing)
|
||||
DebugObject_Access(&o->d_obj);
|
||||
|
||||
// set no output packet
|
||||
o->out_have = 0;
|
||||
|
||||
// finish packet
|
||||
PacketRecvInterface_Done(&o->recv_interface, len);
|
||||
|
||||
#ifndef NDEBUG
|
||||
o->d_writing = 0;
|
||||
#endif
|
||||
}
|
||||
@@ -1,107 +0,0 @@
|
||||
/**
|
||||
* @file BufferWriter.h
|
||||
* @author Ambroz Bizjak <ambrop7@gmail.com>
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @section DESCRIPTION
|
||||
*
|
||||
* Object for writing packets to a {@link PacketRecvInterface} client
|
||||
* in a best-effort fashion.
|
||||
*/
|
||||
|
||||
#ifndef BADVPN_FLOW_BUFFERWRITER_H
|
||||
#define BADVPN_FLOW_BUFFERWRITER_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "misc/debug.h"
|
||||
#include "base/DebugObject.h"
|
||||
#include "flow/PacketRecvInterface.h"
|
||||
|
||||
/**
|
||||
* Object for writing packets to a {@link PacketRecvInterface} client
|
||||
* in a best-effort fashion.
|
||||
*/
|
||||
typedef struct {
|
||||
PacketRecvInterface recv_interface;
|
||||
int out_have;
|
||||
uint8_t *out;
|
||||
DebugObject d_obj;
|
||||
#ifndef NDEBUG
|
||||
int d_mtu;
|
||||
int d_writing;
|
||||
#endif
|
||||
} BufferWriter;
|
||||
|
||||
/**
|
||||
* Initializes the object.
|
||||
* The object is initialized in not writing state.
|
||||
*
|
||||
* @param o the object
|
||||
* @param mtu maximum input packet length
|
||||
* @param pg pending group
|
||||
*/
|
||||
void BufferWriter_Init (BufferWriter *o, int mtu, BPendingGroup *pg);
|
||||
|
||||
/**
|
||||
* Frees the object.
|
||||
*
|
||||
* @param o the object
|
||||
*/
|
||||
void BufferWriter_Free (BufferWriter *o);
|
||||
|
||||
/**
|
||||
* Returns the output interface.
|
||||
*
|
||||
* @param o the object
|
||||
* @return output interface
|
||||
*/
|
||||
PacketRecvInterface * BufferWriter_GetOutput (BufferWriter *o);
|
||||
|
||||
/**
|
||||
* Attempts to provide a memory location for writing a packet.
|
||||
* The object must be in not writing state.
|
||||
* On success, the object enters writing state.
|
||||
*
|
||||
* @param o the object
|
||||
* @param buf if not NULL, on success, the memory location will be stored here.
|
||||
* It will have space for MTU bytes.
|
||||
* @return 1 on success, 0 on failure
|
||||
*/
|
||||
int BufferWriter_StartPacket (BufferWriter *o, uint8_t **buf) WARN_UNUSED;
|
||||
|
||||
/**
|
||||
* Submits a packet written to the buffer.
|
||||
* The object must be in writing state.
|
||||
* Yhe object enters not writing state.
|
||||
*
|
||||
* @param o the object
|
||||
* @param len length of the packet that was written. Must be >=0 and
|
||||
* <=MTU.
|
||||
*/
|
||||
void BufferWriter_EndPacket (BufferWriter *o, int len);
|
||||
|
||||
#endif
|
||||
@@ -1,131 +0,0 @@
|
||||
/**
|
||||
* @file PacketBuffer.c
|
||||
* @author Ambroz Bizjak <ambrop7@gmail.com>
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "misc/debug.h"
|
||||
#include "misc/balloc.h"
|
||||
|
||||
#include "flow/PacketBuffer.h"
|
||||
|
||||
static void input_handler_done (PacketBuffer *buf, int in_len);
|
||||
static void output_handler_done (PacketBuffer *buf);
|
||||
|
||||
void input_handler_done (PacketBuffer *buf, int in_len)
|
||||
{
|
||||
ASSERT(in_len >= 0)
|
||||
ASSERT(in_len <= buf->input_mtu)
|
||||
DebugObject_Access(&buf->d_obj);
|
||||
|
||||
// remember if buffer is empty
|
||||
int was_empty = (buf->buf.output_avail < 0);
|
||||
|
||||
// submit packet to buffer
|
||||
ChunkBuffer2_SubmitPacket(&buf->buf, in_len);
|
||||
|
||||
// if there is space, schedule receive
|
||||
if (buf->buf.input_avail >= buf->input_mtu) {
|
||||
PacketRecvInterface_Receiver_Recv(buf->input, buf->buf.input_dest);
|
||||
}
|
||||
|
||||
// if buffer was empty, schedule send
|
||||
if (was_empty) {
|
||||
PacketPassInterface_Sender_Send(buf->output, buf->buf.output_dest, buf->buf.output_avail);
|
||||
}
|
||||
}
|
||||
|
||||
void output_handler_done (PacketBuffer *buf)
|
||||
{
|
||||
DebugObject_Access(&buf->d_obj);
|
||||
|
||||
// remember if buffer is full
|
||||
int was_full = (buf->buf.input_avail < buf->input_mtu);
|
||||
|
||||
// remove packet from buffer
|
||||
ChunkBuffer2_ConsumePacket(&buf->buf);
|
||||
|
||||
// if buffer was full and there is space, schedule receive
|
||||
if (was_full && buf->buf.input_avail >= buf->input_mtu) {
|
||||
PacketRecvInterface_Receiver_Recv(buf->input, buf->buf.input_dest);
|
||||
}
|
||||
|
||||
// if there is more data, schedule send
|
||||
if (buf->buf.output_avail >= 0) {
|
||||
PacketPassInterface_Sender_Send(buf->output, buf->buf.output_dest, buf->buf.output_avail);
|
||||
}
|
||||
}
|
||||
|
||||
int PacketBuffer_Init (PacketBuffer *buf, PacketRecvInterface *input, PacketPassInterface *output, int num_packets, BPendingGroup *pg)
|
||||
{
|
||||
ASSERT(PacketPassInterface_GetMTU(output) >= PacketRecvInterface_GetMTU(input))
|
||||
ASSERT(num_packets > 0)
|
||||
|
||||
// init arguments
|
||||
buf->input = input;
|
||||
buf->output = output;
|
||||
|
||||
// init input
|
||||
PacketRecvInterface_Receiver_Init(buf->input, (PacketRecvInterface_handler_done)input_handler_done, buf);
|
||||
|
||||
// set input MTU
|
||||
buf->input_mtu = PacketRecvInterface_GetMTU(buf->input);
|
||||
|
||||
// init output
|
||||
PacketPassInterface_Sender_Init(buf->output, (PacketPassInterface_handler_done)output_handler_done, buf);
|
||||
|
||||
// allocate buffer
|
||||
int num_blocks = ChunkBuffer2_calc_blocks(buf->input_mtu, num_packets);
|
||||
if (num_blocks < 0) {
|
||||
goto fail0;
|
||||
}
|
||||
if (!(buf->buf_data = (struct ChunkBuffer2_block *)BAllocArray(num_blocks, sizeof(buf->buf_data[0])))) {
|
||||
goto fail0;
|
||||
}
|
||||
|
||||
// init buffer
|
||||
ChunkBuffer2_Init(&buf->buf, buf->buf_data, num_blocks, buf->input_mtu);
|
||||
|
||||
// schedule receive
|
||||
PacketRecvInterface_Receiver_Recv(buf->input, buf->buf.input_dest);
|
||||
|
||||
DebugObject_Init(&buf->d_obj);
|
||||
|
||||
return 1;
|
||||
|
||||
fail0:
|
||||
return 0;
|
||||
}
|
||||
|
||||
void PacketBuffer_Free (PacketBuffer *buf)
|
||||
{
|
||||
DebugObject_Free(&buf->d_obj);
|
||||
|
||||
// free buffer
|
||||
BFree(buf->buf_data);
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
/**
|
||||
* @file PacketBuffer.h
|
||||
* @author Ambroz Bizjak <ambrop7@gmail.com>
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @section DESCRIPTION
|
||||
*
|
||||
* Packet buffer with {@link PacketRecvInterface} input and {@link PacketPassInterface} output.
|
||||
*/
|
||||
|
||||
#ifndef BADVPN_FLOW_PACKETBUFFER_H
|
||||
#define BADVPN_FLOW_PACKETBUFFER_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "misc/debug.h"
|
||||
#include "base/DebugObject.h"
|
||||
#include "structure/ChunkBuffer2.h"
|
||||
#include "flow/PacketRecvInterface.h"
|
||||
#include "flow/PacketPassInterface.h"
|
||||
|
||||
/**
|
||||
* Packet buffer with {@link PacketRecvInterface} input and {@link PacketPassInterface} output.
|
||||
*/
|
||||
typedef struct {
|
||||
DebugObject d_obj;
|
||||
PacketRecvInterface *input;
|
||||
int input_mtu;
|
||||
PacketPassInterface *output;
|
||||
struct ChunkBuffer2_block *buf_data;
|
||||
ChunkBuffer2 buf;
|
||||
} PacketBuffer;
|
||||
|
||||
/**
|
||||
* Initializes the buffer.
|
||||
* Output MTU must be >= input MTU.
|
||||
*
|
||||
* @param buf the object
|
||||
* @param input input interface
|
||||
* @param output output interface
|
||||
* @param num_packets minimum number of packets the buffer must hold. Must be >0.
|
||||
* @param pg pending group
|
||||
* @return 1 on success, 0 on failure
|
||||
*/
|
||||
int PacketBuffer_Init (PacketBuffer *buf, PacketRecvInterface *input, PacketPassInterface *output, int num_packets, BPendingGroup *pg) WARN_UNUSED;
|
||||
|
||||
/**
|
||||
* Frees the buffer.
|
||||
*
|
||||
* @param buf the object
|
||||
*/
|
||||
void PacketBuffer_Free (PacketBuffer *buf);
|
||||
|
||||
#endif
|
||||
@@ -1,125 +0,0 @@
|
||||
/**
|
||||
* @file PacketPassConnector.c
|
||||
* @author Ambroz Bizjak <ambrop7@gmail.com>
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "misc/debug.h"
|
||||
|
||||
#include "flow/PacketPassConnector.h"
|
||||
|
||||
static void input_handler_send (PacketPassConnector *o, uint8_t *data, int data_len)
|
||||
{
|
||||
ASSERT(data_len >= 0)
|
||||
ASSERT(data_len <= o->input_mtu)
|
||||
ASSERT(o->in_len == -1)
|
||||
DebugObject_Access(&o->d_obj);
|
||||
|
||||
// remember input packet
|
||||
o->in_len = data_len;
|
||||
o->in = data;
|
||||
|
||||
if (o->output) {
|
||||
// schedule send
|
||||
PacketPassInterface_Sender_Send(o->output, o->in, o->in_len);
|
||||
}
|
||||
}
|
||||
|
||||
static void output_handler_done (PacketPassConnector *o)
|
||||
{
|
||||
ASSERT(o->in_len >= 0)
|
||||
ASSERT(o->output)
|
||||
DebugObject_Access(&o->d_obj);
|
||||
|
||||
// have no input packet
|
||||
o->in_len = -1;
|
||||
|
||||
// allow input to send more packets
|
||||
PacketPassInterface_Done(&o->input);
|
||||
}
|
||||
|
||||
void PacketPassConnector_Init (PacketPassConnector *o, int mtu, BPendingGroup *pg)
|
||||
{
|
||||
ASSERT(mtu >= 0)
|
||||
|
||||
// init arguments
|
||||
o->input_mtu = mtu;
|
||||
|
||||
// init input
|
||||
PacketPassInterface_Init(&o->input, o->input_mtu, (PacketPassInterface_handler_send)input_handler_send, o, pg);
|
||||
|
||||
// have no input packet
|
||||
o->in_len = -1;
|
||||
|
||||
// have no output
|
||||
o->output = NULL;
|
||||
|
||||
DebugObject_Init(&o->d_obj);
|
||||
}
|
||||
|
||||
void PacketPassConnector_Free (PacketPassConnector *o)
|
||||
{
|
||||
DebugObject_Free(&o->d_obj);
|
||||
|
||||
// free input
|
||||
PacketPassInterface_Free(&o->input);
|
||||
}
|
||||
|
||||
PacketPassInterface * PacketPassConnector_GetInput (PacketPassConnector *o)
|
||||
{
|
||||
DebugObject_Access(&o->d_obj);
|
||||
|
||||
return &o->input;
|
||||
}
|
||||
|
||||
void PacketPassConnector_ConnectOutput (PacketPassConnector *o, PacketPassInterface *output)
|
||||
{
|
||||
ASSERT(!o->output)
|
||||
ASSERT(PacketPassInterface_GetMTU(output) >= o->input_mtu)
|
||||
DebugObject_Access(&o->d_obj);
|
||||
|
||||
// set output
|
||||
o->output = output;
|
||||
|
||||
// init output
|
||||
PacketPassInterface_Sender_Init(o->output, (PacketPassInterface_handler_done)output_handler_done, o);
|
||||
|
||||
// if we have an input packet, schedule send
|
||||
if (o->in_len >= 0) {
|
||||
PacketPassInterface_Sender_Send(o->output, o->in, o->in_len);
|
||||
}
|
||||
}
|
||||
|
||||
void PacketPassConnector_DisconnectOutput (PacketPassConnector *o)
|
||||
{
|
||||
ASSERT(o->output)
|
||||
DebugObject_Access(&o->d_obj);
|
||||
|
||||
// set no output
|
||||
o->output = NULL;
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
/**
|
||||
* @file PacketPassConnector.h
|
||||
* @author Ambroz Bizjak <ambrop7@gmail.com>
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @section DESCRIPTION
|
||||
*
|
||||
* A {@link PacketPassInterface} layer which allows the output to be
|
||||
* connected and disconnected on the fly.
|
||||
*/
|
||||
|
||||
#ifndef BADVPN_FLOW_PACKETPASSCONNECTOR_H
|
||||
#define BADVPN_FLOW_PACKETPASSCONNECTOR_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "base/DebugObject.h"
|
||||
#include "flow/PacketPassInterface.h"
|
||||
|
||||
/**
|
||||
* A {@link PacketPassInterface} layer which allows the output to be
|
||||
* connected and disconnected on the fly.
|
||||
*/
|
||||
typedef struct {
|
||||
PacketPassInterface input;
|
||||
int input_mtu;
|
||||
int in_len;
|
||||
uint8_t *in;
|
||||
PacketPassInterface *output;
|
||||
DebugObject d_obj;
|
||||
} PacketPassConnector;
|
||||
|
||||
/**
|
||||
* Initializes the object.
|
||||
* The object is initialized in not connected state.
|
||||
*
|
||||
* @param o the object
|
||||
* @param mtu maximum input packet size. Must be >=0.
|
||||
* @param pg pending group
|
||||
*/
|
||||
void PacketPassConnector_Init (PacketPassConnector *o, int mtu, BPendingGroup *pg);
|
||||
|
||||
/**
|
||||
* Frees the object.
|
||||
*
|
||||
* @param o the object
|
||||
*/
|
||||
void PacketPassConnector_Free (PacketPassConnector *o);
|
||||
|
||||
/**
|
||||
* Returns the input interface.
|
||||
* The MTU of the interface will be as in {@link PacketPassConnector_Init}.
|
||||
*
|
||||
* @param o the object
|
||||
* @return input interface
|
||||
*/
|
||||
PacketPassInterface * PacketPassConnector_GetInput (PacketPassConnector *o);
|
||||
|
||||
/**
|
||||
* Connects output.
|
||||
* The object must be in not connected state.
|
||||
* The object enters connected state.
|
||||
*
|
||||
* @param o the object
|
||||
* @param output output to connect. Its MTU must be >= MTU specified in
|
||||
* {@link PacketPassConnector_Init}.
|
||||
*/
|
||||
void PacketPassConnector_ConnectOutput (PacketPassConnector *o, PacketPassInterface *output);
|
||||
|
||||
/**
|
||||
* Disconnects output.
|
||||
* The object must be in connected state.
|
||||
* The object enters not connected state.
|
||||
*
|
||||
* @param o the object
|
||||
*/
|
||||
void PacketPassConnector_DisconnectOutput (PacketPassConnector *o);
|
||||
|
||||
#endif
|
||||
@@ -1,405 +0,0 @@
|
||||
/**
|
||||
* @file PacketPassFairQueue.c
|
||||
* @author Ambroz Bizjak <ambrop7@gmail.com>
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "misc/debug.h"
|
||||
#include "misc/offset.h"
|
||||
#include "misc/minmax.h"
|
||||
#include "misc/compare.h"
|
||||
|
||||
#include "flow/PacketPassFairQueue.h"
|
||||
|
||||
static int compare_flows (PacketPassFairQueueFlow *f1, PacketPassFairQueueFlow *f2)
|
||||
{
|
||||
int cmp = B_COMPARE(f1->time, f2->time);
|
||||
if (cmp) {
|
||||
return cmp;
|
||||
}
|
||||
|
||||
return B_COMPARE((uintptr_t)f1, (uintptr_t)f2);
|
||||
}
|
||||
|
||||
#include "PacketPassFairQueue_tree.h"
|
||||
#include "structure/SAvl_impl.h"
|
||||
|
||||
static uint64_t get_current_time (PacketPassFairQueue *m)
|
||||
{
|
||||
if (m->sending_flow) {
|
||||
return m->sending_flow->time;
|
||||
}
|
||||
|
||||
uint64_t time = 0; // to remove warning
|
||||
int have = 0;
|
||||
|
||||
PacketPassFairQueueFlow *first_flow = PacketPassFairQueue__Tree_GetFirst(&m->queued_tree, 0);
|
||||
if (first_flow) {
|
||||
ASSERT(first_flow->is_queued)
|
||||
|
||||
time = first_flow->time;
|
||||
have = 1;
|
||||
}
|
||||
|
||||
if (m->previous_flow) {
|
||||
if (!have || m->previous_flow->time < time) {
|
||||
time = m->previous_flow->time;
|
||||
have = 1;
|
||||
}
|
||||
}
|
||||
|
||||
return (have ? time : 0);
|
||||
}
|
||||
|
||||
static void increment_sent_flow (PacketPassFairQueueFlow *flow, uint64_t amount)
|
||||
{
|
||||
PacketPassFairQueue *m = flow->m;
|
||||
|
||||
ASSERT(amount <= FAIRQUEUE_MAX_TIME)
|
||||
ASSERT(!flow->is_queued)
|
||||
ASSERT(!m->sending_flow)
|
||||
|
||||
// does time overflow?
|
||||
if (amount > FAIRQUEUE_MAX_TIME - flow->time) {
|
||||
// get time to subtract
|
||||
uint64_t subtract;
|
||||
PacketPassFairQueueFlow *first_flow = PacketPassFairQueue__Tree_GetFirst(&m->queued_tree, 0);
|
||||
if (!first_flow) {
|
||||
subtract = flow->time;
|
||||
} else {
|
||||
ASSERT(first_flow->is_queued)
|
||||
subtract = first_flow->time;
|
||||
}
|
||||
|
||||
// subtract time from all flows
|
||||
for (LinkedList1Node *list_node = LinkedList1_GetFirst(&m->flows_list); list_node; list_node = LinkedList1Node_Next(list_node)) {
|
||||
PacketPassFairQueueFlow *someflow = UPPER_OBJECT(list_node, PacketPassFairQueueFlow, list_node);
|
||||
|
||||
// don't subtract more time than there is, except for the just finished flow,
|
||||
// where we allow time to underflow and then overflow to the correct value after adding to it
|
||||
if (subtract > someflow->time && someflow != flow) {
|
||||
ASSERT(!someflow->is_queued)
|
||||
someflow->time = 0;
|
||||
} else {
|
||||
someflow->time -= subtract;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// add time to flow
|
||||
flow->time += amount;
|
||||
}
|
||||
|
||||
static void schedule (PacketPassFairQueue *m)
|
||||
{
|
||||
ASSERT(!m->sending_flow)
|
||||
ASSERT(!m->previous_flow)
|
||||
ASSERT(!m->freeing)
|
||||
ASSERT(!PacketPassFairQueue__Tree_IsEmpty(&m->queued_tree))
|
||||
|
||||
// get first queued flow
|
||||
PacketPassFairQueueFlow *qflow = PacketPassFairQueue__Tree_GetFirst(&m->queued_tree, 0);
|
||||
ASSERT(qflow->is_queued)
|
||||
|
||||
// remove flow from queue
|
||||
PacketPassFairQueue__Tree_Remove(&m->queued_tree, 0, qflow);
|
||||
qflow->is_queued = 0;
|
||||
|
||||
// schedule send
|
||||
PacketPassInterface_Sender_Send(m->output, qflow->queued.data, qflow->queued.data_len);
|
||||
m->sending_flow = qflow;
|
||||
m->sending_len = qflow->queued.data_len;
|
||||
}
|
||||
|
||||
static void schedule_job_handler (PacketPassFairQueue *m)
|
||||
{
|
||||
ASSERT(!m->sending_flow)
|
||||
ASSERT(!m->freeing)
|
||||
DebugObject_Access(&m->d_obj);
|
||||
|
||||
// remove previous flow
|
||||
m->previous_flow = NULL;
|
||||
|
||||
if (!PacketPassFairQueue__Tree_IsEmpty(&m->queued_tree)) {
|
||||
schedule(m);
|
||||
}
|
||||
}
|
||||
|
||||
static void input_handler_send (PacketPassFairQueueFlow *flow, uint8_t *data, int data_len)
|
||||
{
|
||||
PacketPassFairQueue *m = flow->m;
|
||||
|
||||
ASSERT(flow != m->sending_flow)
|
||||
ASSERT(!flow->is_queued)
|
||||
ASSERT(!m->freeing)
|
||||
DebugObject_Access(&flow->d_obj);
|
||||
|
||||
if (flow == m->previous_flow) {
|
||||
// remove from previous flow
|
||||
m->previous_flow = NULL;
|
||||
} else {
|
||||
// raise time
|
||||
flow->time = bmax_uint64(flow->time, get_current_time(m));
|
||||
}
|
||||
|
||||
// queue flow
|
||||
flow->queued.data = data;
|
||||
flow->queued.data_len = data_len;
|
||||
int res = PacketPassFairQueue__Tree_Insert(&m->queued_tree, 0, flow, NULL);
|
||||
ASSERT_EXECUTE(res)
|
||||
flow->is_queued = 1;
|
||||
|
||||
if (!m->sending_flow && !BPending_IsSet(&m->schedule_job)) {
|
||||
schedule(m);
|
||||
}
|
||||
}
|
||||
|
||||
static void output_handler_done (PacketPassFairQueue *m)
|
||||
{
|
||||
ASSERT(m->sending_flow)
|
||||
ASSERT(!m->previous_flow)
|
||||
ASSERT(!BPending_IsSet(&m->schedule_job))
|
||||
ASSERT(!m->freeing)
|
||||
ASSERT(!m->sending_flow->is_queued)
|
||||
|
||||
PacketPassFairQueueFlow *flow = m->sending_flow;
|
||||
|
||||
// sending finished
|
||||
m->sending_flow = NULL;
|
||||
|
||||
// remember this flow so the schedule job can remove its time if it didn's send
|
||||
m->previous_flow = flow;
|
||||
|
||||
// update flow time by packet size
|
||||
increment_sent_flow(flow, (uint64_t)m->packet_weight + m->sending_len);
|
||||
|
||||
// schedule schedule
|
||||
BPending_Set(&m->schedule_job);
|
||||
|
||||
// finish flow packet
|
||||
PacketPassInterface_Done(&flow->input);
|
||||
|
||||
// call busy handler if set
|
||||
if (flow->handler_busy) {
|
||||
// handler is one-shot, unset it before calling
|
||||
PacketPassFairQueue_handler_busy handler = flow->handler_busy;
|
||||
flow->handler_busy = NULL;
|
||||
|
||||
// call handler
|
||||
handler(flow->user);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
int PacketPassFairQueue_Init (PacketPassFairQueue *m, PacketPassInterface *output, BPendingGroup *pg, int use_cancel, int packet_weight)
|
||||
{
|
||||
ASSERT(packet_weight > 0)
|
||||
ASSERT(use_cancel == 0 || use_cancel == 1)
|
||||
ASSERT(!use_cancel || PacketPassInterface_HasCancel(output))
|
||||
|
||||
// init arguments
|
||||
m->output = output;
|
||||
m->pg = pg;
|
||||
m->use_cancel = use_cancel;
|
||||
m->packet_weight = packet_weight;
|
||||
|
||||
// make sure that (output MTU + packet_weight <= FAIRQUEUE_MAX_TIME)
|
||||
if (!(
|
||||
(PacketPassInterface_GetMTU(output) <= FAIRQUEUE_MAX_TIME) &&
|
||||
(packet_weight <= FAIRQUEUE_MAX_TIME - PacketPassInterface_GetMTU(output))
|
||||
)) {
|
||||
goto fail0;
|
||||
}
|
||||
|
||||
// init output
|
||||
PacketPassInterface_Sender_Init(m->output, (PacketPassInterface_handler_done)output_handler_done, m);
|
||||
|
||||
// not sending
|
||||
m->sending_flow = NULL;
|
||||
|
||||
// no previous flow
|
||||
m->previous_flow = NULL;
|
||||
|
||||
// init queued tree
|
||||
PacketPassFairQueue__Tree_Init(&m->queued_tree);
|
||||
|
||||
// init flows list
|
||||
LinkedList1_Init(&m->flows_list);
|
||||
|
||||
// not freeing
|
||||
m->freeing = 0;
|
||||
|
||||
// init schedule job
|
||||
BPending_Init(&m->schedule_job, m->pg, (BPending_handler)schedule_job_handler, m);
|
||||
|
||||
DebugObject_Init(&m->d_obj);
|
||||
DebugCounter_Init(&m->d_ctr);
|
||||
return 1;
|
||||
|
||||
fail0:
|
||||
return 0;
|
||||
}
|
||||
|
||||
void PacketPassFairQueue_Free (PacketPassFairQueue *m)
|
||||
{
|
||||
ASSERT(LinkedList1_IsEmpty(&m->flows_list))
|
||||
ASSERT(PacketPassFairQueue__Tree_IsEmpty(&m->queued_tree))
|
||||
ASSERT(!m->previous_flow)
|
||||
ASSERT(!m->sending_flow)
|
||||
DebugCounter_Free(&m->d_ctr);
|
||||
DebugObject_Free(&m->d_obj);
|
||||
|
||||
// free schedule job
|
||||
BPending_Free(&m->schedule_job);
|
||||
}
|
||||
|
||||
void PacketPassFairQueue_PrepareFree (PacketPassFairQueue *m)
|
||||
{
|
||||
DebugObject_Access(&m->d_obj);
|
||||
|
||||
// set freeing
|
||||
m->freeing = 1;
|
||||
}
|
||||
|
||||
int PacketPassFairQueue_GetMTU (PacketPassFairQueue *m)
|
||||
{
|
||||
DebugObject_Access(&m->d_obj);
|
||||
|
||||
return PacketPassInterface_GetMTU(m->output);
|
||||
}
|
||||
|
||||
void PacketPassFairQueueFlow_Init (PacketPassFairQueueFlow *flow, PacketPassFairQueue *m)
|
||||
{
|
||||
ASSERT(!m->freeing)
|
||||
DebugObject_Access(&m->d_obj);
|
||||
|
||||
// init arguments
|
||||
flow->m = m;
|
||||
|
||||
// have no canfree handler
|
||||
flow->handler_busy = NULL;
|
||||
|
||||
// init input
|
||||
PacketPassInterface_Init(&flow->input, PacketPassInterface_GetMTU(flow->m->output), (PacketPassInterface_handler_send)input_handler_send, flow, m->pg);
|
||||
|
||||
// set time
|
||||
flow->time = 0;
|
||||
|
||||
// add to flows list
|
||||
LinkedList1_Append(&m->flows_list, &flow->list_node);
|
||||
|
||||
// is not queued
|
||||
flow->is_queued = 0;
|
||||
|
||||
DebugObject_Init(&flow->d_obj);
|
||||
DebugCounter_Increment(&m->d_ctr);
|
||||
}
|
||||
|
||||
void PacketPassFairQueueFlow_Free (PacketPassFairQueueFlow *flow)
|
||||
{
|
||||
PacketPassFairQueue *m = flow->m;
|
||||
|
||||
ASSERT(m->freeing || flow != m->sending_flow)
|
||||
DebugCounter_Decrement(&m->d_ctr);
|
||||
DebugObject_Free(&flow->d_obj);
|
||||
|
||||
// remove from current flow
|
||||
if (flow == m->sending_flow) {
|
||||
m->sending_flow = NULL;
|
||||
}
|
||||
|
||||
// remove from previous flow
|
||||
if (flow == m->previous_flow) {
|
||||
m->previous_flow = NULL;
|
||||
}
|
||||
|
||||
// remove from queue
|
||||
if (flow->is_queued) {
|
||||
PacketPassFairQueue__Tree_Remove(&m->queued_tree, 0, flow);
|
||||
}
|
||||
|
||||
// remove from flows list
|
||||
LinkedList1_Remove(&m->flows_list, &flow->list_node);
|
||||
|
||||
// free input
|
||||
PacketPassInterface_Free(&flow->input);
|
||||
}
|
||||
|
||||
void PacketPassFairQueueFlow_AssertFree (PacketPassFairQueueFlow *flow)
|
||||
{
|
||||
PacketPassFairQueue *m = flow->m;
|
||||
B_USE(m)
|
||||
|
||||
ASSERT(m->freeing || flow != m->sending_flow)
|
||||
DebugObject_Access(&flow->d_obj);
|
||||
}
|
||||
|
||||
int PacketPassFairQueueFlow_IsBusy (PacketPassFairQueueFlow *flow)
|
||||
{
|
||||
PacketPassFairQueue *m = flow->m;
|
||||
|
||||
ASSERT(!m->freeing)
|
||||
DebugObject_Access(&flow->d_obj);
|
||||
|
||||
return (flow == m->sending_flow);
|
||||
}
|
||||
|
||||
void PacketPassFairQueueFlow_RequestCancel (PacketPassFairQueueFlow *flow)
|
||||
{
|
||||
PacketPassFairQueue *m = flow->m;
|
||||
|
||||
ASSERT(flow == m->sending_flow)
|
||||
ASSERT(m->use_cancel)
|
||||
ASSERT(!m->freeing)
|
||||
ASSERT(!BPending_IsSet(&m->schedule_job))
|
||||
DebugObject_Access(&flow->d_obj);
|
||||
|
||||
// request cancel
|
||||
PacketPassInterface_Sender_RequestCancel(m->output);
|
||||
}
|
||||
|
||||
void PacketPassFairQueueFlow_SetBusyHandler (PacketPassFairQueueFlow *flow, PacketPassFairQueue_handler_busy handler, void *user)
|
||||
{
|
||||
PacketPassFairQueue *m = flow->m;
|
||||
B_USE(m)
|
||||
|
||||
ASSERT(flow == m->sending_flow)
|
||||
ASSERT(!m->freeing)
|
||||
DebugObject_Access(&flow->d_obj);
|
||||
|
||||
// set handler
|
||||
flow->handler_busy = handler;
|
||||
flow->user = user;
|
||||
}
|
||||
|
||||
PacketPassInterface * PacketPassFairQueueFlow_GetInput (PacketPassFairQueueFlow *flow)
|
||||
{
|
||||
DebugObject_Access(&flow->d_obj);
|
||||
|
||||
return &flow->input;
|
||||
}
|
||||
@@ -1,204 +0,0 @@
|
||||
/**
|
||||
* @file PacketPassFairQueue.h
|
||||
* @author Ambroz Bizjak <ambrop7@gmail.com>
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @section DESCRIPTION
|
||||
*
|
||||
* Fair queue using {@link PacketPassInterface}.
|
||||
*/
|
||||
|
||||
#ifndef BADVPN_FLOW_PACKETPASSFAIRQUEUE_H
|
||||
#define BADVPN_FLOW_PACKETPASSFAIRQUEUE_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "misc/debug.h"
|
||||
#include "misc/debugcounter.h"
|
||||
#include "structure/SAvl.h"
|
||||
#include "structure/LinkedList1.h"
|
||||
#include "base/DebugObject.h"
|
||||
#include "base/BPending.h"
|
||||
#include "flow/PacketPassInterface.h"
|
||||
|
||||
// reduce this to test time overflow handling
|
||||
#define FAIRQUEUE_MAX_TIME UINT64_MAX
|
||||
|
||||
typedef void (*PacketPassFairQueue_handler_busy) (void *user);
|
||||
|
||||
struct PacketPassFairQueueFlow_s;
|
||||
|
||||
#include "PacketPassFairQueue_tree.h"
|
||||
#include "structure/SAvl_decl.h"
|
||||
|
||||
typedef struct PacketPassFairQueueFlow_s {
|
||||
struct PacketPassFairQueue_s *m;
|
||||
PacketPassFairQueue_handler_busy handler_busy;
|
||||
void *user;
|
||||
PacketPassInterface input;
|
||||
uint64_t time;
|
||||
LinkedList1Node list_node;
|
||||
int is_queued;
|
||||
struct {
|
||||
PacketPassFairQueue__TreeNode tree_node;
|
||||
uint8_t *data;
|
||||
int data_len;
|
||||
} queued;
|
||||
DebugObject d_obj;
|
||||
} PacketPassFairQueueFlow;
|
||||
|
||||
/**
|
||||
* Fair queue using {@link PacketPassInterface}.
|
||||
*/
|
||||
typedef struct PacketPassFairQueue_s {
|
||||
PacketPassInterface *output;
|
||||
BPendingGroup *pg;
|
||||
int use_cancel;
|
||||
int packet_weight;
|
||||
struct PacketPassFairQueueFlow_s *sending_flow;
|
||||
int sending_len;
|
||||
struct PacketPassFairQueueFlow_s *previous_flow;
|
||||
PacketPassFairQueue__Tree queued_tree;
|
||||
LinkedList1 flows_list;
|
||||
int freeing;
|
||||
BPending schedule_job;
|
||||
DebugObject d_obj;
|
||||
DebugCounter d_ctr;
|
||||
} PacketPassFairQueue;
|
||||
|
||||
/**
|
||||
* Initializes the queue.
|
||||
*
|
||||
* @param m the object
|
||||
* @param output output interface
|
||||
* @param pg pending group
|
||||
* @param use_cancel whether cancel functionality is required. Must be 0 or 1.
|
||||
* If 1, output must support cancel functionality.
|
||||
* @param packet_weight additional weight a packet bears. Must be >0, to keep
|
||||
* the queue fair for zero size packets.
|
||||
* @return 1 on success, 0 on failure (because output MTU is too large)
|
||||
*/
|
||||
int PacketPassFairQueue_Init (PacketPassFairQueue *m, PacketPassInterface *output, BPendingGroup *pg, int use_cancel, int packet_weight) WARN_UNUSED;
|
||||
|
||||
/**
|
||||
* Frees the queue.
|
||||
* All flows must have been freed.
|
||||
*
|
||||
* @param m the object
|
||||
*/
|
||||
void PacketPassFairQueue_Free (PacketPassFairQueue *m);
|
||||
|
||||
/**
|
||||
* Prepares for freeing the entire queue. Must be called to allow freeing
|
||||
* the flows in the process of freeing the entire queue.
|
||||
* After this function is called, flows and the queue must be freed
|
||||
* before any further I/O.
|
||||
* May be called multiple times.
|
||||
* The queue enters freeing state.
|
||||
*
|
||||
* @param m the object
|
||||
*/
|
||||
void PacketPassFairQueue_PrepareFree (PacketPassFairQueue *m);
|
||||
|
||||
/**
|
||||
* Returns the MTU of the queue.
|
||||
*
|
||||
* @param m the object
|
||||
*/
|
||||
int PacketPassFairQueue_GetMTU (PacketPassFairQueue *m);
|
||||
|
||||
/**
|
||||
* Initializes a queue flow.
|
||||
* Queue must not be in freeing state.
|
||||
* Must not be called from queue calls to output.
|
||||
*
|
||||
* @param flow the object
|
||||
* @param m queue to attach to
|
||||
*/
|
||||
void PacketPassFairQueueFlow_Init (PacketPassFairQueueFlow *flow, PacketPassFairQueue *m);
|
||||
|
||||
/**
|
||||
* Frees a queue flow.
|
||||
* Unless the queue is in freeing state:
|
||||
* - The flow must not be busy as indicated by {@link PacketPassFairQueueFlow_IsBusy}.
|
||||
* - Must not be called from queue calls to output.
|
||||
*
|
||||
* @param flow the object
|
||||
*/
|
||||
void PacketPassFairQueueFlow_Free (PacketPassFairQueueFlow *flow);
|
||||
|
||||
/**
|
||||
* Does nothing.
|
||||
* It must be possible to free the flow (see {@link PacketPassFairQueueFlow_Free}).
|
||||
*
|
||||
* @param flow the object
|
||||
*/
|
||||
void PacketPassFairQueueFlow_AssertFree (PacketPassFairQueueFlow *flow);
|
||||
|
||||
/**
|
||||
* Determines if the flow is busy. If the flow is considered busy, it must not
|
||||
* be freed. At any given time, at most one flow will be indicated as busy.
|
||||
* Queue must not be in freeing state.
|
||||
* Must not be called from queue calls to output.
|
||||
*
|
||||
* @param flow the object
|
||||
* @return 0 if not busy, 1 is busy
|
||||
*/
|
||||
int PacketPassFairQueueFlow_IsBusy (PacketPassFairQueueFlow *flow);
|
||||
|
||||
/**
|
||||
* Requests the output to stop processing the current packet as soon as possible.
|
||||
* Cancel functionality must be enabled for the queue.
|
||||
* The flow must be busy as indicated by {@link PacketPassFairQueueFlow_IsBusy}.
|
||||
* Queue must not be in freeing state.
|
||||
*
|
||||
* @param flow the object
|
||||
*/
|
||||
void PacketPassFairQueueFlow_RequestCancel (PacketPassFairQueueFlow *flow);
|
||||
|
||||
/**
|
||||
* Sets up a callback to be called when the flow is no longer busy.
|
||||
* The handler will be called as soon as the flow is no longer busy, i.e. it is not
|
||||
* possible that this flow is no longer busy before the handler is called.
|
||||
* The flow must be busy as indicated by {@link PacketPassFairQueueFlow_IsBusy}.
|
||||
* Queue must not be in freeing state.
|
||||
* Must not be called from queue calls to output.
|
||||
*
|
||||
* @param flow the object
|
||||
* @param handler callback function. NULL to disable.
|
||||
* @param user value passed to callback function. Ignored if handler is NULL.
|
||||
*/
|
||||
void PacketPassFairQueueFlow_SetBusyHandler (PacketPassFairQueueFlow *flow, PacketPassFairQueue_handler_busy handler, void *user);
|
||||
|
||||
/**
|
||||
* Returns the input interface of the flow.
|
||||
*
|
||||
* @param flow the object
|
||||
* @return input interface
|
||||
*/
|
||||
PacketPassInterface * PacketPassFairQueueFlow_GetInput (PacketPassFairQueueFlow *flow);
|
||||
|
||||
#endif
|
||||
@@ -1,7 +0,0 @@
|
||||
#define SAVL_PARAM_NAME PacketPassFairQueue__Tree
|
||||
#define SAVL_PARAM_FEATURE_COUNTS 0
|
||||
#define SAVL_PARAM_FEATURE_NOKEYS 1
|
||||
#define SAVL_PARAM_TYPE_ENTRY struct PacketPassFairQueueFlow_s
|
||||
#define SAVL_PARAM_TYPE_ARG int
|
||||
#define SAVL_PARAM_FUN_COMPARE_ENTRIES(arg, entry1, entry2) compare_flows((entry1), (entry2))
|
||||
#define SAVL_PARAM_MEMBER_NODE queued.tree_node
|
||||
@@ -1,68 +0,0 @@
|
||||
/**
|
||||
* @file PacketPassInterface.c
|
||||
* @author Ambroz Bizjak <ambrop7@gmail.com>
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "flow/PacketPassInterface.h"
|
||||
|
||||
void _PacketPassInterface_job_operation (PacketPassInterface *i)
|
||||
{
|
||||
ASSERT(i->state == PPI_STATE_OPERATION_PENDING)
|
||||
DebugObject_Access(&i->d_obj);
|
||||
|
||||
// set state
|
||||
i->state = PPI_STATE_BUSY;
|
||||
|
||||
// call handler
|
||||
i->handler_operation(i->user_provider, i->job_operation_data, i->job_operation_len);
|
||||
return;
|
||||
}
|
||||
|
||||
void _PacketPassInterface_job_requestcancel (PacketPassInterface *i)
|
||||
{
|
||||
ASSERT(i->state == PPI_STATE_BUSY)
|
||||
ASSERT(i->cancel_requested)
|
||||
ASSERT(i->handler_requestcancel)
|
||||
DebugObject_Access(&i->d_obj);
|
||||
|
||||
// call handler
|
||||
i->handler_requestcancel(i->user_provider);
|
||||
return;
|
||||
}
|
||||
|
||||
void _PacketPassInterface_job_done (PacketPassInterface *i)
|
||||
{
|
||||
ASSERT(i->state == PPI_STATE_DONE_PENDING)
|
||||
DebugObject_Access(&i->d_obj);
|
||||
|
||||
// set state
|
||||
i->state = PPI_STATE_NONE;
|
||||
|
||||
// call handler
|
||||
i->handler_done(i->user_user);
|
||||
return;
|
||||
}
|
||||
@@ -1,236 +0,0 @@
|
||||
/**
|
||||
* @file PacketPassInterface.h
|
||||
* @author Ambroz Bizjak <ambrop7@gmail.com>
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @section DESCRIPTION
|
||||
*
|
||||
* Interface allowing a packet sender to pass data packets to a packet receiver.
|
||||
*/
|
||||
|
||||
#ifndef BADVPN_FLOW_PACKETPASSINTERFACE_H
|
||||
#define BADVPN_FLOW_PACKETPASSINTERFACE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "misc/debug.h"
|
||||
#include "base/DebugObject.h"
|
||||
#include "base/BPending.h"
|
||||
|
||||
#define PPI_STATE_NONE 1
|
||||
#define PPI_STATE_OPERATION_PENDING 2
|
||||
#define PPI_STATE_BUSY 3
|
||||
#define PPI_STATE_DONE_PENDING 4
|
||||
|
||||
typedef void (*PacketPassInterface_handler_send) (void *user, uint8_t *data, int data_len);
|
||||
|
||||
typedef void (*PacketPassInterface_handler_requestcancel) (void *user);
|
||||
|
||||
typedef void (*PacketPassInterface_handler_done) (void *user);
|
||||
|
||||
typedef struct {
|
||||
// provider data
|
||||
int mtu;
|
||||
PacketPassInterface_handler_send handler_operation;
|
||||
PacketPassInterface_handler_requestcancel handler_requestcancel;
|
||||
void *user_provider;
|
||||
|
||||
// user data
|
||||
PacketPassInterface_handler_done handler_done;
|
||||
void *user_user;
|
||||
|
||||
// operation job
|
||||
BPending job_operation;
|
||||
uint8_t *job_operation_data;
|
||||
int job_operation_len;
|
||||
|
||||
// requestcancel job
|
||||
BPending job_requestcancel;
|
||||
|
||||
// done job
|
||||
BPending job_done;
|
||||
|
||||
// state
|
||||
int state;
|
||||
int cancel_requested;
|
||||
|
||||
DebugObject d_obj;
|
||||
} PacketPassInterface;
|
||||
|
||||
static void PacketPassInterface_Init (PacketPassInterface *i, int mtu, PacketPassInterface_handler_send handler_operation, void *user, BPendingGroup *pg);
|
||||
|
||||
static void PacketPassInterface_Free (PacketPassInterface *i);
|
||||
|
||||
static void PacketPassInterface_EnableCancel (PacketPassInterface *i, PacketPassInterface_handler_requestcancel handler_requestcancel);
|
||||
|
||||
static void PacketPassInterface_Done (PacketPassInterface *i);
|
||||
|
||||
static int PacketPassInterface_GetMTU (PacketPassInterface *i);
|
||||
|
||||
static void PacketPassInterface_Sender_Init (PacketPassInterface *i, PacketPassInterface_handler_done handler_done, void *user);
|
||||
|
||||
static void PacketPassInterface_Sender_Send (PacketPassInterface *i, uint8_t *data, int data_len);
|
||||
|
||||
static void PacketPassInterface_Sender_RequestCancel (PacketPassInterface *i);
|
||||
|
||||
static int PacketPassInterface_HasCancel (PacketPassInterface *i);
|
||||
|
||||
void _PacketPassInterface_job_operation (PacketPassInterface *i);
|
||||
void _PacketPassInterface_job_requestcancel (PacketPassInterface *i);
|
||||
void _PacketPassInterface_job_done (PacketPassInterface *i);
|
||||
|
||||
void PacketPassInterface_Init (PacketPassInterface *i, int mtu, PacketPassInterface_handler_send handler_operation, void *user, BPendingGroup *pg)
|
||||
{
|
||||
ASSERT(mtu >= 0)
|
||||
|
||||
// init arguments
|
||||
i->mtu = mtu;
|
||||
i->handler_operation = handler_operation;
|
||||
i->handler_requestcancel = NULL;
|
||||
i->user_provider = user;
|
||||
|
||||
// set no user
|
||||
i->handler_done = NULL;
|
||||
|
||||
// init jobs
|
||||
BPending_Init(&i->job_operation, pg, (BPending_handler)_PacketPassInterface_job_operation, i);
|
||||
BPending_Init(&i->job_requestcancel, pg, (BPending_handler)_PacketPassInterface_job_requestcancel, i);
|
||||
BPending_Init(&i->job_done, pg, (BPending_handler)_PacketPassInterface_job_done, i);
|
||||
|
||||
// set state
|
||||
i->state = PPI_STATE_NONE;
|
||||
|
||||
DebugObject_Init(&i->d_obj);
|
||||
}
|
||||
|
||||
void PacketPassInterface_Free (PacketPassInterface *i)
|
||||
{
|
||||
DebugObject_Free(&i->d_obj);
|
||||
|
||||
// free jobs
|
||||
BPending_Free(&i->job_done);
|
||||
BPending_Free(&i->job_requestcancel);
|
||||
BPending_Free(&i->job_operation);
|
||||
}
|
||||
|
||||
void PacketPassInterface_EnableCancel (PacketPassInterface *i, PacketPassInterface_handler_requestcancel handler_requestcancel)
|
||||
{
|
||||
ASSERT(!i->handler_requestcancel)
|
||||
ASSERT(!i->handler_done)
|
||||
ASSERT(handler_requestcancel)
|
||||
|
||||
i->handler_requestcancel = handler_requestcancel;
|
||||
}
|
||||
|
||||
void PacketPassInterface_Done (PacketPassInterface *i)
|
||||
{
|
||||
ASSERT(i->state == PPI_STATE_BUSY)
|
||||
DebugObject_Access(&i->d_obj);
|
||||
|
||||
// unset requestcancel job
|
||||
BPending_Unset(&i->job_requestcancel);
|
||||
|
||||
// schedule done
|
||||
BPending_Set(&i->job_done);
|
||||
|
||||
// set state
|
||||
i->state = PPI_STATE_DONE_PENDING;
|
||||
}
|
||||
|
||||
int PacketPassInterface_GetMTU (PacketPassInterface *i)
|
||||
{
|
||||
DebugObject_Access(&i->d_obj);
|
||||
|
||||
return i->mtu;
|
||||
}
|
||||
|
||||
void PacketPassInterface_Sender_Init (PacketPassInterface *i, PacketPassInterface_handler_done handler_done, void *user)
|
||||
{
|
||||
ASSERT(handler_done)
|
||||
ASSERT(!i->handler_done)
|
||||
DebugObject_Access(&i->d_obj);
|
||||
|
||||
i->handler_done = handler_done;
|
||||
i->user_user = user;
|
||||
}
|
||||
|
||||
void PacketPassInterface_Sender_Send (PacketPassInterface *i, uint8_t *data, int data_len)
|
||||
{
|
||||
ASSERT(data_len >= 0)
|
||||
ASSERT(data_len <= i->mtu)
|
||||
ASSERT(!(data_len > 0) || data)
|
||||
ASSERT(i->state == PPI_STATE_NONE)
|
||||
ASSERT(i->handler_done)
|
||||
DebugObject_Access(&i->d_obj);
|
||||
|
||||
// schedule operation
|
||||
i->job_operation_data = data;
|
||||
i->job_operation_len = data_len;
|
||||
BPending_Set(&i->job_operation);
|
||||
|
||||
// set state
|
||||
i->state = PPI_STATE_OPERATION_PENDING;
|
||||
i->cancel_requested = 0;
|
||||
}
|
||||
|
||||
void PacketPassInterface_Sender_RequestCancel (PacketPassInterface *i)
|
||||
{
|
||||
ASSERT(i->state == PPI_STATE_OPERATION_PENDING || i->state == PPI_STATE_BUSY || i->state == PPI_STATE_DONE_PENDING)
|
||||
ASSERT(i->handler_requestcancel)
|
||||
DebugObject_Access(&i->d_obj);
|
||||
|
||||
// ignore multiple cancel requests
|
||||
if (i->cancel_requested) {
|
||||
return;
|
||||
}
|
||||
|
||||
// remember we requested cancel
|
||||
i->cancel_requested = 1;
|
||||
|
||||
if (i->state == PPI_STATE_OPERATION_PENDING) {
|
||||
// unset operation job
|
||||
BPending_Unset(&i->job_operation);
|
||||
|
||||
// set done job
|
||||
BPending_Set(&i->job_done);
|
||||
|
||||
// set state
|
||||
i->state = PPI_STATE_DONE_PENDING;
|
||||
} else if (i->state == PPI_STATE_BUSY) {
|
||||
// set requestcancel job
|
||||
BPending_Set(&i->job_requestcancel);
|
||||
}
|
||||
}
|
||||
|
||||
int PacketPassInterface_HasCancel (PacketPassInterface *i)
|
||||
{
|
||||
DebugObject_Access(&i->d_obj);
|
||||
|
||||
return !!i->handler_requestcancel;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,182 +0,0 @@
|
||||
/**
|
||||
* @file PacketProtoDecoder.c
|
||||
* @author Ambroz Bizjak <ambrop7@gmail.com>
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "misc/debug.h"
|
||||
#include "misc/byteorder.h"
|
||||
#include "misc/minmax.h"
|
||||
#include "base/BLog.h"
|
||||
|
||||
#include "flow/PacketProtoDecoder.h"
|
||||
|
||||
#include "generated/blog_channel_PacketProtoDecoder.h"
|
||||
|
||||
static void process_data (PacketProtoDecoder *enc);
|
||||
static void input_handler_done (PacketProtoDecoder *enc, int data_len);
|
||||
static void output_handler_done (PacketProtoDecoder *enc);
|
||||
|
||||
void process_data (PacketProtoDecoder *enc)
|
||||
{
|
||||
int was_error = 0;
|
||||
|
||||
do {
|
||||
uint8_t *data = enc->buf + enc->buf_start;
|
||||
int left = enc->buf_used;
|
||||
|
||||
// check if header was received
|
||||
if (left < sizeof(struct packetproto_header)) {
|
||||
break;
|
||||
}
|
||||
struct packetproto_header header;
|
||||
memcpy(&header, data, sizeof(header));
|
||||
data += sizeof(struct packetproto_header);
|
||||
left -= sizeof(struct packetproto_header);
|
||||
int data_len = ltoh16(header.len);
|
||||
|
||||
// check data length
|
||||
if (data_len > enc->output_mtu) {
|
||||
BLog(BLOG_NOTICE, "error: packet too large");
|
||||
was_error = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
// check if whole packet was received
|
||||
if (left < data_len) {
|
||||
break;
|
||||
}
|
||||
|
||||
// update buffer
|
||||
enc->buf_start += sizeof(struct packetproto_header) + data_len;
|
||||
enc->buf_used -= sizeof(struct packetproto_header) + data_len;
|
||||
|
||||
// submit packet
|
||||
PacketPassInterface_Sender_Send(enc->output, data, data_len);
|
||||
return;
|
||||
} while (0);
|
||||
|
||||
if (was_error) {
|
||||
// reset buffer
|
||||
enc->buf_start = 0;
|
||||
enc->buf_used = 0;
|
||||
} else {
|
||||
// if we reached the end of the buffer, wrap around to allow more data to be received
|
||||
if (enc->buf_start + enc->buf_used == enc->buf_size) {
|
||||
memmove(enc->buf, enc->buf + enc->buf_start, enc->buf_used);
|
||||
enc->buf_start = 0;
|
||||
}
|
||||
}
|
||||
|
||||
// receive data
|
||||
StreamRecvInterface_Receiver_Recv(enc->input, enc->buf + (enc->buf_start + enc->buf_used), enc->buf_size - (enc->buf_start + enc->buf_used));
|
||||
|
||||
// if we had error, report it
|
||||
if (was_error) {
|
||||
enc->handler_error(enc->user);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
static void input_handler_done (PacketProtoDecoder *enc, int data_len)
|
||||
{
|
||||
ASSERT(data_len > 0)
|
||||
ASSERT(data_len <= enc->buf_size - (enc->buf_start + enc->buf_used))
|
||||
DebugObject_Access(&enc->d_obj);
|
||||
|
||||
// update buffer
|
||||
enc->buf_used += data_len;
|
||||
|
||||
// process data
|
||||
process_data(enc);
|
||||
return;
|
||||
}
|
||||
|
||||
void output_handler_done (PacketProtoDecoder *enc)
|
||||
{
|
||||
DebugObject_Access(&enc->d_obj);
|
||||
|
||||
// process data
|
||||
process_data(enc);
|
||||
return;
|
||||
}
|
||||
|
||||
int PacketProtoDecoder_Init (PacketProtoDecoder *enc, StreamRecvInterface *input, PacketPassInterface *output, BPendingGroup *pg, void *user, PacketProtoDecoder_handler_error handler_error)
|
||||
{
|
||||
// init arguments
|
||||
enc->input = input;
|
||||
enc->output = output;
|
||||
enc->user = user;
|
||||
enc->handler_error = handler_error;
|
||||
|
||||
// init input
|
||||
StreamRecvInterface_Receiver_Init(enc->input, (StreamRecvInterface_handler_done)input_handler_done, enc);
|
||||
|
||||
// init output
|
||||
PacketPassInterface_Sender_Init(enc->output, (PacketPassInterface_handler_done)output_handler_done, enc);
|
||||
|
||||
// set output MTU, limit by maximum payload size
|
||||
enc->output_mtu = bmin_int(PacketPassInterface_GetMTU(enc->output), PACKETPROTO_MAXPAYLOAD);
|
||||
|
||||
// init buffer state
|
||||
enc->buf_size = PACKETPROTO_ENCLEN(enc->output_mtu);
|
||||
enc->buf_start = 0;
|
||||
enc->buf_used = 0;
|
||||
|
||||
// allocate buffer
|
||||
if (!(enc->buf = (uint8_t *)malloc(enc->buf_size))) {
|
||||
goto fail0;
|
||||
}
|
||||
|
||||
// start receiving
|
||||
StreamRecvInterface_Receiver_Recv(enc->input, enc->buf, enc->buf_size);
|
||||
|
||||
DebugObject_Init(&enc->d_obj);
|
||||
|
||||
return 1;
|
||||
|
||||
fail0:
|
||||
return 0;
|
||||
}
|
||||
|
||||
void PacketProtoDecoder_Free (PacketProtoDecoder *enc)
|
||||
{
|
||||
DebugObject_Free(&enc->d_obj);
|
||||
|
||||
// free buffer
|
||||
free(enc->buf);
|
||||
}
|
||||
|
||||
void PacketProtoDecoder_Reset (PacketProtoDecoder *enc)
|
||||
{
|
||||
DebugObject_Access(&enc->d_obj);
|
||||
|
||||
enc->buf_start += enc->buf_used;
|
||||
enc->buf_used = 0;
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
/**
|
||||
* @file PacketProtoDecoder.h
|
||||
* @author Ambroz Bizjak <ambrop7@gmail.com>
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @section DESCRIPTION
|
||||
*
|
||||
* Object which decodes a stream according to PacketProto.
|
||||
*/
|
||||
|
||||
#ifndef BADVPN_FLOW_PACKETPROTODECODER_H
|
||||
#define BADVPN_FLOW_PACKETPROTODECODER_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "protocol/packetproto.h"
|
||||
#include "misc/debug.h"
|
||||
#include "base/DebugObject.h"
|
||||
#include "flow/StreamRecvInterface.h"
|
||||
#include "flow/PacketPassInterface.h"
|
||||
|
||||
/**
|
||||
* Handler called when a protocol error occurs.
|
||||
* When an error occurs, the decoder is reset to the initial state.
|
||||
*
|
||||
* @param user as in {@link PacketProtoDecoder_Init}
|
||||
*/
|
||||
typedef void (*PacketProtoDecoder_handler_error) (void *user);
|
||||
|
||||
typedef struct {
|
||||
StreamRecvInterface *input;
|
||||
PacketPassInterface *output;
|
||||
void *user;
|
||||
PacketProtoDecoder_handler_error handler_error;
|
||||
int output_mtu;
|
||||
int buf_size;
|
||||
int buf_start;
|
||||
int buf_used;
|
||||
uint8_t *buf;
|
||||
DebugObject d_obj;
|
||||
} PacketProtoDecoder;
|
||||
|
||||
/**
|
||||
* Initializes the object.
|
||||
*
|
||||
* @param enc the object
|
||||
* @param input input interface. The decoder will accept packets with payload size up to its MTU
|
||||
* (but the payload can never be more than PACKETPROTO_MAXPAYLOAD).
|
||||
* @param output output interface
|
||||
* @param pg pending group
|
||||
* @param user argument to handlers
|
||||
* @param handler_error error handler
|
||||
* @return 1 on success, 0 on failure
|
||||
*/
|
||||
int PacketProtoDecoder_Init (PacketProtoDecoder *enc, StreamRecvInterface *input, PacketPassInterface *output, BPendingGroup *pg, void *user, PacketProtoDecoder_handler_error handler_error) WARN_UNUSED;
|
||||
|
||||
/**
|
||||
* Frees the object.
|
||||
*
|
||||
* @param enc the object
|
||||
*/
|
||||
void PacketProtoDecoder_Free (PacketProtoDecoder *enc);
|
||||
|
||||
/**
|
||||
* Clears the internal buffer.
|
||||
* The next data received from the input will be treated as a new
|
||||
* PacketProto stream.
|
||||
*
|
||||
* @param enc the object
|
||||
*/
|
||||
void PacketProtoDecoder_Reset (PacketProtoDecoder *enc);
|
||||
|
||||
#endif
|
||||
@@ -1,101 +0,0 @@
|
||||
/**
|
||||
* @file PacketProtoEncoder.c
|
||||
* @author Ambroz Bizjak <ambrop7@gmail.com>
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "protocol/packetproto.h"
|
||||
#include "misc/balign.h"
|
||||
#include "misc/debug.h"
|
||||
#include "misc/byteorder.h"
|
||||
|
||||
#include "flow/PacketProtoEncoder.h"
|
||||
|
||||
static void output_handler_recv (PacketProtoEncoder *enc, uint8_t *data)
|
||||
{
|
||||
ASSERT(!enc->output_packet)
|
||||
ASSERT(data)
|
||||
DebugObject_Access(&enc->d_obj);
|
||||
|
||||
// schedule receive
|
||||
enc->output_packet = data;
|
||||
PacketRecvInterface_Receiver_Recv(enc->input, enc->output_packet + sizeof(struct packetproto_header));
|
||||
}
|
||||
|
||||
static void input_handler_done (PacketProtoEncoder *enc, int in_len)
|
||||
{
|
||||
ASSERT(enc->output_packet)
|
||||
DebugObject_Access(&enc->d_obj);
|
||||
|
||||
// write length
|
||||
struct packetproto_header pp;
|
||||
pp.len = htol16(in_len);
|
||||
memcpy(enc->output_packet, &pp, sizeof(pp));
|
||||
|
||||
// finish output packet
|
||||
enc->output_packet = NULL;
|
||||
PacketRecvInterface_Done(&enc->output, PACKETPROTO_ENCLEN(in_len));
|
||||
}
|
||||
|
||||
void PacketProtoEncoder_Init (PacketProtoEncoder *enc, PacketRecvInterface *input, BPendingGroup *pg)
|
||||
{
|
||||
ASSERT(PacketRecvInterface_GetMTU(input) <= PACKETPROTO_MAXPAYLOAD)
|
||||
|
||||
// init arguments
|
||||
enc->input = input;
|
||||
|
||||
// init input
|
||||
PacketRecvInterface_Receiver_Init(enc->input, (PacketRecvInterface_handler_done)input_handler_done, enc);
|
||||
|
||||
// init output
|
||||
PacketRecvInterface_Init(
|
||||
&enc->output, PACKETPROTO_ENCLEN(PacketRecvInterface_GetMTU(enc->input)),
|
||||
(PacketRecvInterface_handler_recv)output_handler_recv, enc, pg
|
||||
);
|
||||
|
||||
// set no output packet
|
||||
enc->output_packet = NULL;
|
||||
|
||||
DebugObject_Init(&enc->d_obj);
|
||||
}
|
||||
|
||||
void PacketProtoEncoder_Free (PacketProtoEncoder *enc)
|
||||
{
|
||||
DebugObject_Free(&enc->d_obj);
|
||||
|
||||
// free input
|
||||
PacketRecvInterface_Free(&enc->output);
|
||||
}
|
||||
|
||||
PacketRecvInterface * PacketProtoEncoder_GetOutput (PacketProtoEncoder *enc)
|
||||
{
|
||||
DebugObject_Access(&enc->d_obj);
|
||||
|
||||
return &enc->output;
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
/**
|
||||
* @file PacketProtoEncoder.h
|
||||
* @author Ambroz Bizjak <ambrop7@gmail.com>
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @section DESCRIPTION
|
||||
*
|
||||
* Object which encodes packets according to PacketProto.
|
||||
*/
|
||||
|
||||
#ifndef BADVPN_FLOW_PACKETPROTOENCODER_H
|
||||
#define BADVPN_FLOW_PACKETPROTOENCODER_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "base/DebugObject.h"
|
||||
#include "flow/PacketRecvInterface.h"
|
||||
|
||||
/**
|
||||
* Object which encodes packets according to PacketProto.
|
||||
*
|
||||
* Input is with {@link PacketRecvInterface}.
|
||||
* Output is with {@link PacketRecvInterface}.
|
||||
*/
|
||||
typedef struct {
|
||||
PacketRecvInterface *input;
|
||||
PacketRecvInterface output;
|
||||
uint8_t *output_packet;
|
||||
DebugObject d_obj;
|
||||
} PacketProtoEncoder;
|
||||
|
||||
/**
|
||||
* Initializes the object.
|
||||
*
|
||||
* @param enc the object
|
||||
* @param input input interface. Its MTU must be <=PACKETPROTO_MAXPAYLOAD.
|
||||
* @param pg pending group
|
||||
*/
|
||||
void PacketProtoEncoder_Init (PacketProtoEncoder *enc, PacketRecvInterface *input, BPendingGroup *pg);
|
||||
|
||||
/**
|
||||
* Frees the object.
|
||||
*
|
||||
* @param enc the object
|
||||
*/
|
||||
void PacketProtoEncoder_Free (PacketProtoEncoder *enc);
|
||||
|
||||
/**
|
||||
* Returns the output interface.
|
||||
* The MTU of the output interface is PACKETPROTO_ENCLEN(MTU of input interface).
|
||||
*
|
||||
* @param enc the object
|
||||
* @return output interface
|
||||
*/
|
||||
PacketRecvInterface * PacketProtoEncoder_GetOutput (PacketProtoEncoder *enc);
|
||||
|
||||
#endif
|
||||
@@ -1,82 +0,0 @@
|
||||
/**
|
||||
* @file PacketProtoFlow.c
|
||||
* @author Ambroz Bizjak <ambrop7@gmail.com>
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "protocol/packetproto.h"
|
||||
#include "misc/debug.h"
|
||||
|
||||
#include "flow/PacketProtoFlow.h"
|
||||
|
||||
int PacketProtoFlow_Init (PacketProtoFlow *o, int input_mtu, int num_packets, PacketPassInterface *output, BPendingGroup *pg)
|
||||
{
|
||||
ASSERT(input_mtu >= 0)
|
||||
ASSERT(input_mtu <= PACKETPROTO_MAXPAYLOAD)
|
||||
ASSERT(num_packets > 0)
|
||||
ASSERT(PacketPassInterface_GetMTU(output) >= PACKETPROTO_ENCLEN(input_mtu))
|
||||
|
||||
// init async input
|
||||
BufferWriter_Init(&o->ainput, input_mtu, pg);
|
||||
|
||||
// init encoder
|
||||
PacketProtoEncoder_Init(&o->encoder, BufferWriter_GetOutput(&o->ainput), pg);
|
||||
|
||||
// init buffer
|
||||
if (!PacketBuffer_Init(&o->buffer, PacketProtoEncoder_GetOutput(&o->encoder), output, num_packets, pg)) {
|
||||
goto fail0;
|
||||
}
|
||||
|
||||
DebugObject_Init(&o->d_obj);
|
||||
|
||||
return 1;
|
||||
|
||||
fail0:
|
||||
PacketProtoEncoder_Free(&o->encoder);
|
||||
BufferWriter_Free(&o->ainput);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void PacketProtoFlow_Free (PacketProtoFlow *o)
|
||||
{
|
||||
DebugObject_Free(&o->d_obj);
|
||||
|
||||
// free buffer
|
||||
PacketBuffer_Free(&o->buffer);
|
||||
|
||||
// free encoder
|
||||
PacketProtoEncoder_Free(&o->encoder);
|
||||
|
||||
// free async input
|
||||
BufferWriter_Free(&o->ainput);
|
||||
}
|
||||
|
||||
BufferWriter * PacketProtoFlow_GetInput (PacketProtoFlow *o)
|
||||
{
|
||||
DebugObject_Access(&o->d_obj);
|
||||
|
||||
return &o->ainput;
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
/**
|
||||
* @file PacketProtoFlow.h
|
||||
* @author Ambroz Bizjak <ambrop7@gmail.com>
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @section DESCRIPTION
|
||||
*
|
||||
* Buffer which encodes packets with PacketProto, with {@link BufferWriter}
|
||||
* input and {@link PacketPassInterface} output.
|
||||
*/
|
||||
|
||||
#ifndef BADVPN_FLOW_PACKETPROTOFLOW_H
|
||||
#define BADVPN_FLOW_PACKETPROTOFLOW_H
|
||||
|
||||
#include "misc/debug.h"
|
||||
|
||||
#include "base/DebugObject.h"
|
||||
#include "flow/BufferWriter.h"
|
||||
#include "flow/PacketProtoEncoder.h"
|
||||
#include "flow/PacketBuffer.h"
|
||||
|
||||
/**
|
||||
* Buffer which encodes packets with PacketProto, with {@link BufferWriter}
|
||||
* input and {@link PacketPassInterface} output.
|
||||
*/
|
||||
typedef struct {
|
||||
BufferWriter ainput;
|
||||
PacketProtoEncoder encoder;
|
||||
PacketBuffer buffer;
|
||||
DebugObject d_obj;
|
||||
} PacketProtoFlow;
|
||||
|
||||
/**
|
||||
* Initializes the object.
|
||||
*
|
||||
* @param o the object
|
||||
* @param input_mtu maximum input packet size. Must be >=0 and <=PACKETPROTO_MAXPAYLOAD.
|
||||
* @param num_packets minimum number of packets the buffer should hold. Must be >0.
|
||||
* @param output output interface. Its MTU must be >=PACKETPROTO_ENCLEN(input_mtu).
|
||||
* @param pg pending group
|
||||
* @return 1 on success, 0 on failure
|
||||
*/
|
||||
int PacketProtoFlow_Init (PacketProtoFlow *o, int input_mtu, int num_packets, PacketPassInterface *output, BPendingGroup *pg) WARN_UNUSED;
|
||||
|
||||
/**
|
||||
* Frees the object.
|
||||
*
|
||||
* @param o the object
|
||||
*/
|
||||
void PacketProtoFlow_Free (PacketProtoFlow *o);
|
||||
|
||||
/**
|
||||
* Returns the input interface.
|
||||
*
|
||||
* @param o the object
|
||||
* @return input interface
|
||||
*/
|
||||
BufferWriter * PacketProtoFlow_GetInput (PacketProtoFlow *o);
|
||||
|
||||
#endif
|
||||
@@ -1,56 +0,0 @@
|
||||
/**
|
||||
* @file PacketRecvInterface.c
|
||||
* @author Ambroz Bizjak <ambrop7@gmail.com>
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "flow/PacketRecvInterface.h"
|
||||
|
||||
void _PacketRecvInterface_job_operation (PacketRecvInterface *i)
|
||||
{
|
||||
ASSERT(i->state == PRI_STATE_OPERATION_PENDING)
|
||||
DebugObject_Access(&i->d_obj);
|
||||
|
||||
// set state
|
||||
i->state = PRI_STATE_BUSY;
|
||||
|
||||
// call handler
|
||||
i->handler_operation(i->user_provider, i->job_operation_data);
|
||||
return;
|
||||
}
|
||||
|
||||
void _PacketRecvInterface_job_done (PacketRecvInterface *i)
|
||||
{
|
||||
ASSERT(i->state == PRI_STATE_DONE_PENDING)
|
||||
DebugObject_Access(&i->d_obj);
|
||||
|
||||
// set state
|
||||
i->state = PRI_STATE_NONE;
|
||||
|
||||
// call handler
|
||||
i->handler_done(i->user_user, i->job_done_len);
|
||||
return;
|
||||
}
|
||||
@@ -1,170 +0,0 @@
|
||||
/**
|
||||
* @file PacketRecvInterface.h
|
||||
* @author Ambroz Bizjak <ambrop7@gmail.com>
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @section DESCRIPTION
|
||||
*
|
||||
* Interface allowing a packet receiver to receive data packets from a packet sender.
|
||||
*/
|
||||
|
||||
#ifndef BADVPN_FLOW_PACKETRECVINTERFACE_H
|
||||
#define BADVPN_FLOW_PACKETRECVINTERFACE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "misc/debug.h"
|
||||
#include "base/DebugObject.h"
|
||||
#include "base/BPending.h"
|
||||
|
||||
#define PRI_STATE_NONE 1
|
||||
#define PRI_STATE_OPERATION_PENDING 2
|
||||
#define PRI_STATE_BUSY 3
|
||||
#define PRI_STATE_DONE_PENDING 4
|
||||
|
||||
typedef void (*PacketRecvInterface_handler_recv) (void *user, uint8_t *data);
|
||||
|
||||
typedef void (*PacketRecvInterface_handler_done) (void *user, int data_len);
|
||||
|
||||
typedef struct {
|
||||
// provider data
|
||||
int mtu;
|
||||
PacketRecvInterface_handler_recv handler_operation;
|
||||
void *user_provider;
|
||||
|
||||
// user data
|
||||
PacketRecvInterface_handler_done handler_done;
|
||||
void *user_user;
|
||||
|
||||
// operation job
|
||||
BPending job_operation;
|
||||
uint8_t *job_operation_data;
|
||||
|
||||
// done job
|
||||
BPending job_done;
|
||||
int job_done_len;
|
||||
|
||||
// state
|
||||
int state;
|
||||
|
||||
DebugObject d_obj;
|
||||
} PacketRecvInterface;
|
||||
|
||||
static void PacketRecvInterface_Init (PacketRecvInterface *i, int mtu, PacketRecvInterface_handler_recv handler_operation, void *user, BPendingGroup *pg);
|
||||
|
||||
static void PacketRecvInterface_Free (PacketRecvInterface *i);
|
||||
|
||||
static void PacketRecvInterface_Done (PacketRecvInterface *i, int data_len);
|
||||
|
||||
static int PacketRecvInterface_GetMTU (PacketRecvInterface *i);
|
||||
|
||||
static void PacketRecvInterface_Receiver_Init (PacketRecvInterface *i, PacketRecvInterface_handler_done handler_done, void *user);
|
||||
|
||||
static void PacketRecvInterface_Receiver_Recv (PacketRecvInterface *i, uint8_t *data);
|
||||
|
||||
void _PacketRecvInterface_job_operation (PacketRecvInterface *i);
|
||||
void _PacketRecvInterface_job_done (PacketRecvInterface *i);
|
||||
|
||||
void PacketRecvInterface_Init (PacketRecvInterface *i, int mtu, PacketRecvInterface_handler_recv handler_operation, void *user, BPendingGroup *pg)
|
||||
{
|
||||
ASSERT(mtu >= 0)
|
||||
|
||||
// init arguments
|
||||
i->mtu = mtu;
|
||||
i->handler_operation = handler_operation;
|
||||
i->user_provider = user;
|
||||
|
||||
// set no user
|
||||
i->handler_done = NULL;
|
||||
|
||||
// init jobs
|
||||
BPending_Init(&i->job_operation, pg, (BPending_handler)_PacketRecvInterface_job_operation, i);
|
||||
BPending_Init(&i->job_done, pg, (BPending_handler)_PacketRecvInterface_job_done, i);
|
||||
|
||||
// set state
|
||||
i->state = PRI_STATE_NONE;
|
||||
|
||||
DebugObject_Init(&i->d_obj);
|
||||
}
|
||||
|
||||
void PacketRecvInterface_Free (PacketRecvInterface *i)
|
||||
{
|
||||
DebugObject_Free(&i->d_obj);
|
||||
|
||||
// free jobs
|
||||
BPending_Free(&i->job_done);
|
||||
BPending_Free(&i->job_operation);
|
||||
}
|
||||
|
||||
void PacketRecvInterface_Done (PacketRecvInterface *i, int data_len)
|
||||
{
|
||||
ASSERT(data_len >= 0)
|
||||
ASSERT(data_len <= i->mtu)
|
||||
ASSERT(i->state == PRI_STATE_BUSY)
|
||||
DebugObject_Access(&i->d_obj);
|
||||
|
||||
// schedule done
|
||||
i->job_done_len = data_len;
|
||||
BPending_Set(&i->job_done);
|
||||
|
||||
// set state
|
||||
i->state = PRI_STATE_DONE_PENDING;
|
||||
}
|
||||
|
||||
int PacketRecvInterface_GetMTU (PacketRecvInterface *i)
|
||||
{
|
||||
DebugObject_Access(&i->d_obj);
|
||||
|
||||
return i->mtu;
|
||||
}
|
||||
|
||||
void PacketRecvInterface_Receiver_Init (PacketRecvInterface *i, PacketRecvInterface_handler_done handler_done, void *user)
|
||||
{
|
||||
ASSERT(handler_done)
|
||||
ASSERT(!i->handler_done)
|
||||
DebugObject_Access(&i->d_obj);
|
||||
|
||||
i->handler_done = handler_done;
|
||||
i->user_user = user;
|
||||
}
|
||||
|
||||
void PacketRecvInterface_Receiver_Recv (PacketRecvInterface *i, uint8_t *data)
|
||||
{
|
||||
ASSERT(!(i->mtu > 0) || data)
|
||||
ASSERT(i->state == PRI_STATE_NONE)
|
||||
ASSERT(i->handler_done)
|
||||
DebugObject_Access(&i->d_obj);
|
||||
|
||||
// schedule operation
|
||||
i->job_operation_data = data;
|
||||
BPending_Set(&i->job_operation);
|
||||
|
||||
// set state
|
||||
i->state = PRI_STATE_OPERATION_PENDING;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,111 +0,0 @@
|
||||
/**
|
||||
* @file PacketStreamSender.c
|
||||
* @author Ambroz Bizjak <ambrop7@gmail.com>
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "misc/debug.h"
|
||||
|
||||
#include "flow/PacketStreamSender.h"
|
||||
|
||||
static void send_data (PacketStreamSender *s)
|
||||
{
|
||||
ASSERT(s->in_len >= 0)
|
||||
|
||||
if (s->in_used < s->in_len) {
|
||||
// send more data
|
||||
StreamPassInterface_Sender_Send(s->output, s->in + s->in_used, s->in_len - s->in_used);
|
||||
} else {
|
||||
// finish input packet
|
||||
s->in_len = -1;
|
||||
PacketPassInterface_Done(&s->input);
|
||||
}
|
||||
}
|
||||
|
||||
static void input_handler_send (PacketStreamSender *s, uint8_t *data, int data_len)
|
||||
{
|
||||
ASSERT(s->in_len == -1)
|
||||
ASSERT(data_len >= 0)
|
||||
DebugObject_Access(&s->d_obj);
|
||||
|
||||
// set input packet
|
||||
s->in_len = data_len;
|
||||
s->in = data;
|
||||
s->in_used = 0;
|
||||
|
||||
// send
|
||||
send_data(s);
|
||||
}
|
||||
|
||||
static void output_handler_done (PacketStreamSender *s, int data_len)
|
||||
{
|
||||
ASSERT(s->in_len >= 0)
|
||||
ASSERT(data_len > 0)
|
||||
ASSERT(data_len <= s->in_len - s->in_used)
|
||||
DebugObject_Access(&s->d_obj);
|
||||
|
||||
// update number of bytes sent
|
||||
s->in_used += data_len;
|
||||
|
||||
// send
|
||||
send_data(s);
|
||||
}
|
||||
|
||||
void PacketStreamSender_Init (PacketStreamSender *s, StreamPassInterface *output, int mtu, BPendingGroup *pg)
|
||||
{
|
||||
ASSERT(mtu >= 0)
|
||||
|
||||
// init arguments
|
||||
s->output = output;
|
||||
|
||||
// init input
|
||||
PacketPassInterface_Init(&s->input, mtu, (PacketPassInterface_handler_send)input_handler_send, s, pg);
|
||||
|
||||
// init output
|
||||
StreamPassInterface_Sender_Init(s->output, (StreamPassInterface_handler_done)output_handler_done, s);
|
||||
|
||||
// have no input packet
|
||||
s->in_len = -1;
|
||||
|
||||
DebugObject_Init(&s->d_obj);
|
||||
}
|
||||
|
||||
void PacketStreamSender_Free (PacketStreamSender *s)
|
||||
{
|
||||
DebugObject_Free(&s->d_obj);
|
||||
|
||||
// free input
|
||||
PacketPassInterface_Free(&s->input);
|
||||
}
|
||||
|
||||
PacketPassInterface * PacketStreamSender_GetInput (PacketStreamSender *s)
|
||||
{
|
||||
DebugObject_Access(&s->d_obj);
|
||||
|
||||
return &s->input;
|
||||
}
|
||||
@@ -1,83 +0,0 @@
|
||||
/**
|
||||
* @file PacketStreamSender.h
|
||||
* @author Ambroz Bizjak <ambrop7@gmail.com>
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @section DESCRIPTION
|
||||
*
|
||||
* Object which forwards packets obtained with {@link PacketPassInterface}
|
||||
* as a stream with {@link StreamPassInterface} (i.e. it concatenates them).
|
||||
*/
|
||||
|
||||
#ifndef BADVPN_FLOW_PACKETSTREAMSENDER_H
|
||||
#define BADVPN_FLOW_PACKETSTREAMSENDER_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "base/DebugObject.h"
|
||||
#include "flow/PacketPassInterface.h"
|
||||
#include "flow/StreamPassInterface.h"
|
||||
|
||||
/**
|
||||
* Object which forwards packets obtained with {@link PacketPassInterface}
|
||||
* as a stream with {@link StreamPassInterface} (i.e. it concatenates them).
|
||||
*/
|
||||
typedef struct {
|
||||
DebugObject d_obj;
|
||||
PacketPassInterface input;
|
||||
StreamPassInterface *output;
|
||||
int in_len;
|
||||
uint8_t *in;
|
||||
int in_used;
|
||||
} PacketStreamSender;
|
||||
|
||||
/**
|
||||
* Initializes the object.
|
||||
*
|
||||
* @param s the object
|
||||
* @param output output interface
|
||||
* @param mtu input MTU. Must be >=0.
|
||||
* @param pg pending group
|
||||
*/
|
||||
void PacketStreamSender_Init (PacketStreamSender *s, StreamPassInterface *output, int mtu, BPendingGroup *pg);
|
||||
|
||||
/**
|
||||
* Frees the object.
|
||||
*
|
||||
* @param s the object
|
||||
*/
|
||||
void PacketStreamSender_Free (PacketStreamSender *s);
|
||||
|
||||
/**
|
||||
* Returns the input interface.
|
||||
* Its MTU will be as in {@link PacketStreamSender_Init}.
|
||||
*
|
||||
* @param s the object
|
||||
* @return input interface
|
||||
*/
|
||||
PacketPassInterface * PacketStreamSender_GetInput (PacketStreamSender *s);
|
||||
|
||||
#endif
|
||||
@@ -1,87 +0,0 @@
|
||||
/**
|
||||
* @file SinglePacketBuffer.c
|
||||
* @author Ambroz Bizjak <ambrop7@gmail.com>
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "misc/debug.h"
|
||||
#include "misc/balloc.h"
|
||||
|
||||
#include "flow/SinglePacketBuffer.h"
|
||||
|
||||
static void input_handler_done (SinglePacketBuffer *o, int in_len)
|
||||
{
|
||||
DebugObject_Access(&o->d_obj);
|
||||
|
||||
PacketPassInterface_Sender_Send(o->output, o->buf, in_len);
|
||||
}
|
||||
|
||||
static void output_handler_done (SinglePacketBuffer *o)
|
||||
{
|
||||
DebugObject_Access(&o->d_obj);
|
||||
|
||||
PacketRecvInterface_Receiver_Recv(o->input, o->buf);
|
||||
}
|
||||
|
||||
int SinglePacketBuffer_Init (SinglePacketBuffer *o, PacketRecvInterface *input, PacketPassInterface *output, BPendingGroup *pg)
|
||||
{
|
||||
ASSERT(PacketPassInterface_GetMTU(output) >= PacketRecvInterface_GetMTU(input))
|
||||
|
||||
// init arguments
|
||||
o->input = input;
|
||||
o->output = output;
|
||||
|
||||
// init input
|
||||
PacketRecvInterface_Receiver_Init(o->input, (PacketRecvInterface_handler_done)input_handler_done, o);
|
||||
|
||||
// init output
|
||||
PacketPassInterface_Sender_Init(o->output, (PacketPassInterface_handler_done)output_handler_done, o);
|
||||
|
||||
// init buffer
|
||||
if (!(o->buf = (uint8_t *)BAlloc(PacketRecvInterface_GetMTU(o->input)))) {
|
||||
goto fail1;
|
||||
}
|
||||
|
||||
// schedule receive
|
||||
PacketRecvInterface_Receiver_Recv(o->input, o->buf);
|
||||
|
||||
DebugObject_Init(&o->d_obj);
|
||||
|
||||
return 1;
|
||||
|
||||
fail1:
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SinglePacketBuffer_Free (SinglePacketBuffer *o)
|
||||
{
|
||||
DebugObject_Free(&o->d_obj);
|
||||
|
||||
// free buffer
|
||||
BFree(o->buf);
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
/**
|
||||
* @file SinglePacketBuffer.h
|
||||
* @author Ambroz Bizjak <ambrop7@gmail.com>
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @section DESCRIPTION
|
||||
*
|
||||
* Packet buffer with {@link PacketRecvInterface} input and {@link PacketPassInterface} output
|
||||
* than can store only a single packet.
|
||||
*/
|
||||
|
||||
#ifndef BADVPN_FLOW_SINGLEPACKETBUFFER_H
|
||||
#define BADVPN_FLOW_SINGLEPACKETBUFFER_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "misc/debug.h"
|
||||
#include "base/DebugObject.h"
|
||||
#include "flow/PacketRecvInterface.h"
|
||||
#include "flow/PacketPassInterface.h"
|
||||
|
||||
/**
|
||||
* Packet buffer with {@link PacketRecvInterface} input and {@link PacketPassInterface} output
|
||||
* than can store only a single packet.
|
||||
*/
|
||||
typedef struct {
|
||||
DebugObject d_obj;
|
||||
PacketRecvInterface *input;
|
||||
PacketPassInterface *output;
|
||||
uint8_t *buf;
|
||||
} SinglePacketBuffer;
|
||||
|
||||
/**
|
||||
* Initializes the object.
|
||||
* Output MTU must be >= input MTU.
|
||||
*
|
||||
* @param o the object
|
||||
* @param input input interface
|
||||
* @param output output interface
|
||||
* @param pg pending group
|
||||
* @return 1 on success, 0 on failure
|
||||
*/
|
||||
int SinglePacketBuffer_Init (SinglePacketBuffer *o, PacketRecvInterface *input, PacketPassInterface *output, BPendingGroup *pg) WARN_UNUSED;
|
||||
|
||||
/**
|
||||
* Frees the object
|
||||
*
|
||||
* @param o the object
|
||||
*/
|
||||
void SinglePacketBuffer_Free (SinglePacketBuffer *o);
|
||||
|
||||
#endif
|
||||
@@ -1,56 +0,0 @@
|
||||
/**
|
||||
* @file StreamPassInterface.c
|
||||
* @author Ambroz Bizjak <ambrop7@gmail.com>
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "flow/StreamPassInterface.h"
|
||||
|
||||
void _StreamPassInterface_job_operation (StreamPassInterface *i)
|
||||
{
|
||||
ASSERT(i->state == SPI_STATE_OPERATION_PENDING)
|
||||
DebugObject_Access(&i->d_obj);
|
||||
|
||||
// set state
|
||||
i->state = SPI_STATE_BUSY;
|
||||
|
||||
// call handler
|
||||
i->handler_operation(i->user_provider, i->job_operation_data, i->job_operation_len);
|
||||
return;
|
||||
}
|
||||
|
||||
void _StreamPassInterface_job_done (StreamPassInterface *i)
|
||||
{
|
||||
ASSERT(i->state == SPI_STATE_DONE_PENDING)
|
||||
DebugObject_Access(&i->d_obj);
|
||||
|
||||
// set state
|
||||
i->state = SPI_STATE_NONE;
|
||||
|
||||
// call handler
|
||||
i->handler_done(i->user_user, i->job_done_len);
|
||||
return;
|
||||
}
|
||||
@@ -1,165 +0,0 @@
|
||||
/**
|
||||
* @file StreamPassInterface.h
|
||||
* @author Ambroz Bizjak <ambrop7@gmail.com>
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @section DESCRIPTION
|
||||
*
|
||||
* Interface allowing a stream sender to pass stream data to a stream receiver.
|
||||
*
|
||||
* Note that this interface behaves exactly the same and has the same code as
|
||||
* {@link StreamRecvInterface} if names and its external semantics are disregarded.
|
||||
* If you modify this file, you should probably modify {@link StreamRecvInterface}
|
||||
* too.
|
||||
*/
|
||||
|
||||
#ifndef BADVPN_FLOW_STREAMPASSINTERFACE_H
|
||||
#define BADVPN_FLOW_STREAMPASSINTERFACE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "misc/debug.h"
|
||||
#include "base/DebugObject.h"
|
||||
#include "base/BPending.h"
|
||||
|
||||
#define SPI_STATE_NONE 1
|
||||
#define SPI_STATE_OPERATION_PENDING 2
|
||||
#define SPI_STATE_BUSY 3
|
||||
#define SPI_STATE_DONE_PENDING 4
|
||||
|
||||
typedef void (*StreamPassInterface_handler_send) (void *user, uint8_t *data, int data_len);
|
||||
|
||||
typedef void (*StreamPassInterface_handler_done) (void *user, int data_len);
|
||||
|
||||
typedef struct {
|
||||
// provider data
|
||||
StreamPassInterface_handler_send handler_operation;
|
||||
void *user_provider;
|
||||
|
||||
// user data
|
||||
StreamPassInterface_handler_done handler_done;
|
||||
void *user_user;
|
||||
|
||||
// operation job
|
||||
BPending job_operation;
|
||||
uint8_t *job_operation_data;
|
||||
int job_operation_len;
|
||||
|
||||
// done job
|
||||
BPending job_done;
|
||||
int job_done_len;
|
||||
|
||||
// state
|
||||
int state;
|
||||
|
||||
DebugObject d_obj;
|
||||
} StreamPassInterface;
|
||||
|
||||
static void StreamPassInterface_Init (StreamPassInterface *i, StreamPassInterface_handler_send handler_operation, void *user, BPendingGroup *pg);
|
||||
|
||||
static void StreamPassInterface_Free (StreamPassInterface *i);
|
||||
|
||||
static void StreamPassInterface_Done (StreamPassInterface *i, int data_len);
|
||||
|
||||
static void StreamPassInterface_Sender_Init (StreamPassInterface *i, StreamPassInterface_handler_done handler_done, void *user);
|
||||
|
||||
static void StreamPassInterface_Sender_Send (StreamPassInterface *i, uint8_t *data, int data_len);
|
||||
|
||||
void _StreamPassInterface_job_operation (StreamPassInterface *i);
|
||||
void _StreamPassInterface_job_done (StreamPassInterface *i);
|
||||
|
||||
void StreamPassInterface_Init (StreamPassInterface *i, StreamPassInterface_handler_send handler_operation, void *user, BPendingGroup *pg)
|
||||
{
|
||||
// init arguments
|
||||
i->handler_operation = handler_operation;
|
||||
i->user_provider = user;
|
||||
|
||||
// set no user
|
||||
i->handler_done = NULL;
|
||||
|
||||
// init jobs
|
||||
BPending_Init(&i->job_operation, pg, (BPending_handler)_StreamPassInterface_job_operation, i);
|
||||
BPending_Init(&i->job_done, pg, (BPending_handler)_StreamPassInterface_job_done, i);
|
||||
|
||||
// set state
|
||||
i->state = SPI_STATE_NONE;
|
||||
|
||||
DebugObject_Init(&i->d_obj);
|
||||
}
|
||||
|
||||
void StreamPassInterface_Free (StreamPassInterface *i)
|
||||
{
|
||||
DebugObject_Free(&i->d_obj);
|
||||
|
||||
// free jobs
|
||||
BPending_Free(&i->job_done);
|
||||
BPending_Free(&i->job_operation);
|
||||
}
|
||||
|
||||
void StreamPassInterface_Done (StreamPassInterface *i, int data_len)
|
||||
{
|
||||
ASSERT(i->state == SPI_STATE_BUSY)
|
||||
ASSERT(data_len > 0)
|
||||
ASSERT(data_len <= i->job_operation_len)
|
||||
DebugObject_Access(&i->d_obj);
|
||||
|
||||
// schedule done
|
||||
i->job_done_len = data_len;
|
||||
BPending_Set(&i->job_done);
|
||||
|
||||
// set state
|
||||
i->state = SPI_STATE_DONE_PENDING;
|
||||
}
|
||||
|
||||
void StreamPassInterface_Sender_Init (StreamPassInterface *i, StreamPassInterface_handler_done handler_done, void *user)
|
||||
{
|
||||
ASSERT(handler_done)
|
||||
ASSERT(!i->handler_done)
|
||||
DebugObject_Access(&i->d_obj);
|
||||
|
||||
i->handler_done = handler_done;
|
||||
i->user_user = user;
|
||||
}
|
||||
|
||||
void StreamPassInterface_Sender_Send (StreamPassInterface *i, uint8_t *data, int data_len)
|
||||
{
|
||||
ASSERT(data_len > 0)
|
||||
ASSERT(data)
|
||||
ASSERT(i->state == SPI_STATE_NONE)
|
||||
ASSERT(i->handler_done)
|
||||
DebugObject_Access(&i->d_obj);
|
||||
|
||||
// schedule operation
|
||||
i->job_operation_data = data;
|
||||
i->job_operation_len = data_len;
|
||||
BPending_Set(&i->job_operation);
|
||||
|
||||
// set state
|
||||
i->state = SPI_STATE_OPERATION_PENDING;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,56 +0,0 @@
|
||||
/**
|
||||
* @file StreamRecvInterface.c
|
||||
* @author Ambroz Bizjak <ambrop7@gmail.com>
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "flow/StreamRecvInterface.h"
|
||||
|
||||
void _StreamRecvInterface_job_operation (StreamRecvInterface *i)
|
||||
{
|
||||
ASSERT(i->state == SRI_STATE_OPERATION_PENDING)
|
||||
DebugObject_Access(&i->d_obj);
|
||||
|
||||
// set state
|
||||
i->state = SRI_STATE_BUSY;
|
||||
|
||||
// call handler
|
||||
i->handler_operation(i->user_provider, i->job_operation_data, i->job_operation_len);
|
||||
return;
|
||||
}
|
||||
|
||||
void _StreamRecvInterface_job_done (StreamRecvInterface *i)
|
||||
{
|
||||
ASSERT(i->state == SRI_STATE_DONE_PENDING)
|
||||
DebugObject_Access(&i->d_obj);
|
||||
|
||||
// set state
|
||||
i->state = SRI_STATE_NONE;
|
||||
|
||||
// call handler
|
||||
i->handler_done(i->user_user, i->job_done_len);
|
||||
return;
|
||||
}
|
||||
@@ -1,165 +0,0 @@
|
||||
/**
|
||||
* @file StreamRecvInterface.h
|
||||
* @author Ambroz Bizjak <ambrop7@gmail.com>
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @section DESCRIPTION
|
||||
*
|
||||
* Interface allowing a stream receiver to receive stream data from a stream sender.
|
||||
*
|
||||
* Note that this interface behaves exactly the same and has the same code as
|
||||
* {@link StreamPassInterface} if names and its external semantics are disregarded.
|
||||
* If you modify this file, you should probably modify {@link StreamPassInterface}
|
||||
* too.
|
||||
*/
|
||||
|
||||
#ifndef BADVPN_FLOW_STREAMRECVINTERFACE_H
|
||||
#define BADVPN_FLOW_STREAMRECVINTERFACE_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "misc/debug.h"
|
||||
#include "base/DebugObject.h"
|
||||
#include "base/BPending.h"
|
||||
|
||||
#define SRI_STATE_NONE 1
|
||||
#define SRI_STATE_OPERATION_PENDING 2
|
||||
#define SRI_STATE_BUSY 3
|
||||
#define SRI_STATE_DONE_PENDING 4
|
||||
|
||||
typedef void (*StreamRecvInterface_handler_recv) (void *user, uint8_t *data, int data_len);
|
||||
|
||||
typedef void (*StreamRecvInterface_handler_done) (void *user, int data_len);
|
||||
|
||||
typedef struct {
|
||||
// provider data
|
||||
StreamRecvInterface_handler_recv handler_operation;
|
||||
void *user_provider;
|
||||
|
||||
// user data
|
||||
StreamRecvInterface_handler_done handler_done;
|
||||
void *user_user;
|
||||
|
||||
// operation job
|
||||
BPending job_operation;
|
||||
uint8_t *job_operation_data;
|
||||
int job_operation_len;
|
||||
|
||||
// done job
|
||||
BPending job_done;
|
||||
int job_done_len;
|
||||
|
||||
// state
|
||||
int state;
|
||||
|
||||
DebugObject d_obj;
|
||||
} StreamRecvInterface;
|
||||
|
||||
static void StreamRecvInterface_Init (StreamRecvInterface *i, StreamRecvInterface_handler_recv handler_operation, void *user, BPendingGroup *pg);
|
||||
|
||||
static void StreamRecvInterface_Free (StreamRecvInterface *i);
|
||||
|
||||
static void StreamRecvInterface_Done (StreamRecvInterface *i, int data_len);
|
||||
|
||||
static void StreamRecvInterface_Receiver_Init (StreamRecvInterface *i, StreamRecvInterface_handler_done handler_done, void *user);
|
||||
|
||||
static void StreamRecvInterface_Receiver_Recv (StreamRecvInterface *i, uint8_t *data, int data_len);
|
||||
|
||||
void _StreamRecvInterface_job_operation (StreamRecvInterface *i);
|
||||
void _StreamRecvInterface_job_done (StreamRecvInterface *i);
|
||||
|
||||
void StreamRecvInterface_Init (StreamRecvInterface *i, StreamRecvInterface_handler_recv handler_operation, void *user, BPendingGroup *pg)
|
||||
{
|
||||
// init arguments
|
||||
i->handler_operation = handler_operation;
|
||||
i->user_provider = user;
|
||||
|
||||
// set no user
|
||||
i->handler_done = NULL;
|
||||
|
||||
// init jobs
|
||||
BPending_Init(&i->job_operation, pg, (BPending_handler)_StreamRecvInterface_job_operation, i);
|
||||
BPending_Init(&i->job_done, pg, (BPending_handler)_StreamRecvInterface_job_done, i);
|
||||
|
||||
// set state
|
||||
i->state = SRI_STATE_NONE;
|
||||
|
||||
DebugObject_Init(&i->d_obj);
|
||||
}
|
||||
|
||||
void StreamRecvInterface_Free (StreamRecvInterface *i)
|
||||
{
|
||||
DebugObject_Free(&i->d_obj);
|
||||
|
||||
// free jobs
|
||||
BPending_Free(&i->job_done);
|
||||
BPending_Free(&i->job_operation);
|
||||
}
|
||||
|
||||
void StreamRecvInterface_Done (StreamRecvInterface *i, int data_len)
|
||||
{
|
||||
ASSERT(i->state == SRI_STATE_BUSY)
|
||||
ASSERT(data_len > 0)
|
||||
ASSERT(data_len <= i->job_operation_len)
|
||||
DebugObject_Access(&i->d_obj);
|
||||
|
||||
// schedule done
|
||||
i->job_done_len = data_len;
|
||||
BPending_Set(&i->job_done);
|
||||
|
||||
// set state
|
||||
i->state = SRI_STATE_DONE_PENDING;
|
||||
}
|
||||
|
||||
void StreamRecvInterface_Receiver_Init (StreamRecvInterface *i, StreamRecvInterface_handler_done handler_done, void *user)
|
||||
{
|
||||
ASSERT(handler_done)
|
||||
ASSERT(!i->handler_done)
|
||||
DebugObject_Access(&i->d_obj);
|
||||
|
||||
i->handler_done = handler_done;
|
||||
i->user_user = user;
|
||||
}
|
||||
|
||||
void StreamRecvInterface_Receiver_Recv (StreamRecvInterface *i, uint8_t *data, int data_len)
|
||||
{
|
||||
ASSERT(data_len > 0)
|
||||
ASSERT(data)
|
||||
ASSERT(i->state == SRI_STATE_NONE)
|
||||
ASSERT(i->handler_done)
|
||||
DebugObject_Access(&i->d_obj);
|
||||
|
||||
// schedule operation
|
||||
i->job_operation_data = data;
|
||||
i->job_operation_len = data_len;
|
||||
BPending_Set(&i->job_operation);
|
||||
|
||||
// set state
|
||||
i->state = SRI_STATE_OPERATION_PENDING;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,131 +0,0 @@
|
||||
/**
|
||||
* @file PacketPassInactivityMonitor.c
|
||||
* @author Ambroz Bizjak <ambrop7@gmail.com>
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include "PacketPassInactivityMonitor.h"
|
||||
|
||||
static void input_handler_send (PacketPassInactivityMonitor *o, uint8_t *data, int data_len)
|
||||
{
|
||||
DebugObject_Access(&o->d_obj);
|
||||
|
||||
// schedule send
|
||||
PacketPassInterface_Sender_Send(o->output, data, data_len);
|
||||
|
||||
// stop timer
|
||||
BReactor_RemoveTimer(o->reactor, &o->timer);
|
||||
}
|
||||
|
||||
static void input_handler_requestcancel (PacketPassInactivityMonitor *o)
|
||||
{
|
||||
DebugObject_Access(&o->d_obj);
|
||||
|
||||
// request cancel
|
||||
PacketPassInterface_Sender_RequestCancel(o->output);
|
||||
}
|
||||
|
||||
static void output_handler_done (PacketPassInactivityMonitor *o)
|
||||
{
|
||||
DebugObject_Access(&o->d_obj);
|
||||
|
||||
// output no longer busy, restart timer
|
||||
BReactor_SetTimer(o->reactor, &o->timer);
|
||||
|
||||
// call done
|
||||
PacketPassInterface_Done(&o->input);
|
||||
}
|
||||
|
||||
static void timer_handler (PacketPassInactivityMonitor *o)
|
||||
{
|
||||
DebugObject_Access(&o->d_obj);
|
||||
|
||||
// restart timer
|
||||
BReactor_SetTimer(o->reactor, &o->timer);
|
||||
|
||||
// call handler
|
||||
if (o->handler) {
|
||||
o->handler(o->user);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void PacketPassInactivityMonitor_Init (PacketPassInactivityMonitor *o, PacketPassInterface *output, BReactor *reactor, btime_t interval, PacketPassInactivityMonitor_handler handler, void *user)
|
||||
{
|
||||
// init arguments
|
||||
o->output = output;
|
||||
o->reactor = reactor;
|
||||
o->handler = handler;
|
||||
o->user = user;
|
||||
|
||||
// init input
|
||||
PacketPassInterface_Init(&o->input, PacketPassInterface_GetMTU(o->output), (PacketPassInterface_handler_send)input_handler_send, o, BReactor_PendingGroup(o->reactor));
|
||||
if (PacketPassInterface_HasCancel(o->output)) {
|
||||
PacketPassInterface_EnableCancel(&o->input, (PacketPassInterface_handler_requestcancel)input_handler_requestcancel);
|
||||
}
|
||||
|
||||
// init output
|
||||
PacketPassInterface_Sender_Init(o->output, (PacketPassInterface_handler_done)output_handler_done, o);
|
||||
|
||||
// init timer
|
||||
BTimer_Init(&o->timer, interval, (BTimer_handler)timer_handler, o);
|
||||
BReactor_SetTimer(o->reactor, &o->timer);
|
||||
|
||||
DebugObject_Init(&o->d_obj);
|
||||
}
|
||||
|
||||
void PacketPassInactivityMonitor_Free (PacketPassInactivityMonitor *o)
|
||||
{
|
||||
DebugObject_Free(&o->d_obj);
|
||||
|
||||
// free timer
|
||||
BReactor_RemoveTimer(o->reactor, &o->timer);
|
||||
|
||||
// free input
|
||||
PacketPassInterface_Free(&o->input);
|
||||
}
|
||||
|
||||
PacketPassInterface * PacketPassInactivityMonitor_GetInput (PacketPassInactivityMonitor *o)
|
||||
{
|
||||
DebugObject_Access(&o->d_obj);
|
||||
|
||||
return &o->input;
|
||||
}
|
||||
|
||||
void PacketPassInactivityMonitor_SetHandler (PacketPassInactivityMonitor *o, PacketPassInactivityMonitor_handler handler, void *user)
|
||||
{
|
||||
DebugObject_Access(&o->d_obj);
|
||||
|
||||
o->handler = handler;
|
||||
o->user = user;
|
||||
}
|
||||
|
||||
void PacketPassInactivityMonitor_Force (PacketPassInactivityMonitor *o)
|
||||
{
|
||||
DebugObject_Access(&o->d_obj);
|
||||
|
||||
BReactor_SetTimerAfter(o->reactor, &o->timer, 0);
|
||||
}
|
||||
@@ -1,124 +0,0 @@
|
||||
/**
|
||||
* @file PacketPassInactivityMonitor.h
|
||||
* @author Ambroz Bizjak <ambrop7@gmail.com>
|
||||
*
|
||||
* @section LICENSE
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the author nor the
|
||||
* names of its contributors may be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
|
||||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
* @section DESCRIPTION
|
||||
*
|
||||
* A {@link PacketPassInterface} layer for detecting inactivity.
|
||||
*/
|
||||
|
||||
#ifndef BADVPN_PACKETPASSINACTIVITYMONITOR_H
|
||||
#define BADVPN_PACKETPASSINACTIVITYMONITOR_H
|
||||
|
||||
#include "base/DebugObject.h"
|
||||
#include "system/BReactor.h"
|
||||
#include "flow/PacketPassInterface.h"
|
||||
|
||||
/**
|
||||
* Handler function invoked when inactivity is detected.
|
||||
* It is guaranteed that the interfaces are in not sending state.
|
||||
*
|
||||
* @param user value given to {@link PacketPassInactivityMonitor_Init}
|
||||
*/
|
||||
typedef void (*PacketPassInactivityMonitor_handler) (void *user);
|
||||
|
||||
/**
|
||||
* A {@link PacketPassInterface} layer for detecting inactivity.
|
||||
* It reports inactivity to a user provided handler function.
|
||||
*
|
||||
* The object behaves like that:
|
||||
* ("timer set" means started with the given timeout whether if was running or not,
|
||||
* "timer unset" means stopped if it was running)
|
||||
* - There is a timer.
|
||||
* - The timer is set when the object is initialized.
|
||||
* - When the input calls Send, the call is passed on to the output.
|
||||
* If the output accepted the packet, the timer is set. If the output
|
||||
* blocked the packet, the timer is unset.
|
||||
* - When the output calls Done, the timer is set, and the call is
|
||||
* passed on to the input.
|
||||
* - When the input calls Cancel, the timer is set, and the call is
|
||||
* passed on to the output.
|
||||
* - When the timer expires, the timer is set, ant the user's handler
|
||||
* function is invoked.
|
||||
*/
|
||||
typedef struct {
|
||||
DebugObject d_obj;
|
||||
PacketPassInterface *output;
|
||||
BReactor *reactor;
|
||||
PacketPassInactivityMonitor_handler handler;
|
||||
void *user;
|
||||
PacketPassInterface input;
|
||||
BTimer timer;
|
||||
} PacketPassInactivityMonitor;
|
||||
|
||||
/**
|
||||
* Initializes the object.
|
||||
* See {@link PacketPassInactivityMonitor} for details.
|
||||
*
|
||||
* @param o the object
|
||||
* @param output output interface
|
||||
* @param reactor reactor we live in
|
||||
* @param interval timer value in milliseconds
|
||||
* @param handler handler function for reporting inactivity, or NULL to disable
|
||||
* @param user value passed to handler functions
|
||||
*/
|
||||
void PacketPassInactivityMonitor_Init (PacketPassInactivityMonitor *o, PacketPassInterface *output, BReactor *reactor, btime_t interval, PacketPassInactivityMonitor_handler handler, void *user);
|
||||
|
||||
/**
|
||||
* Frees the object.
|
||||
*
|
||||
* @param o the object
|
||||
*/
|
||||
void PacketPassInactivityMonitor_Free (PacketPassInactivityMonitor *o);
|
||||
|
||||
/**
|
||||
* Returns the input interface.
|
||||
* The MTU of the interface will be the same as of the output interface.
|
||||
* The interface supports cancel functionality if the output interface supports it.
|
||||
*
|
||||
* @param o the object
|
||||
* @return input interface
|
||||
*/
|
||||
PacketPassInterface * PacketPassInactivityMonitor_GetInput (PacketPassInactivityMonitor *o);
|
||||
|
||||
/**
|
||||
* Sets or removes the inactivity handler.
|
||||
*
|
||||
* @param o the object
|
||||
* @param handler handler function for reporting inactivity, or NULL to disable
|
||||
* @param user value passed to handler functions
|
||||
*/
|
||||
void PacketPassInactivityMonitor_SetHandler (PacketPassInactivityMonitor *o, PacketPassInactivityMonitor_handler handler, void *user);
|
||||
|
||||
/**
|
||||
* Sets the timer to expire immediately in order to force an inactivity report.
|
||||
*
|
||||
* @param o the object
|
||||
*/
|
||||
void PacketPassInactivityMonitor_Force (PacketPassInactivityMonitor *o);
|
||||
|
||||
#endif
|
||||
@@ -1,4 +0,0 @@
|
||||
#ifdef BLOG_CURRENT_CHANNEL
|
||||
#undef BLOG_CURRENT_CHANNEL
|
||||
#endif
|
||||
#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_BArpProbe
|
||||
@@ -1,4 +0,0 @@
|
||||
#ifdef BLOG_CURRENT_CHANNEL
|
||||
#undef BLOG_CURRENT_CHANNEL
|
||||
#endif
|
||||
#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_BConnection
|
||||
@@ -1,4 +0,0 @@
|
||||
#ifdef BLOG_CURRENT_CHANNEL
|
||||
#undef BLOG_CURRENT_CHANNEL
|
||||
#endif
|
||||
#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_BDHCPClient
|
||||
@@ -1,4 +0,0 @@
|
||||
#ifdef BLOG_CURRENT_CHANNEL
|
||||
#undef BLOG_CURRENT_CHANNEL
|
||||
#endif
|
||||
#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_BDHCPClientCore
|
||||
@@ -1,4 +0,0 @@
|
||||
#ifdef BLOG_CURRENT_CHANNEL
|
||||
#undef BLOG_CURRENT_CHANNEL
|
||||
#endif
|
||||
#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_BDatagram
|
||||
@@ -1,4 +0,0 @@
|
||||
#ifdef BLOG_CURRENT_CHANNEL
|
||||
#undef BLOG_CURRENT_CHANNEL
|
||||
#endif
|
||||
#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_BEncryption
|
||||
@@ -1,4 +0,0 @@
|
||||
#ifdef BLOG_CURRENT_CHANNEL
|
||||
#undef BLOG_CURRENT_CHANNEL
|
||||
#endif
|
||||
#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_BInputProcess
|
||||
@@ -1,4 +0,0 @@
|
||||
#ifdef BLOG_CURRENT_CHANNEL
|
||||
#undef BLOG_CURRENT_CHANNEL
|
||||
#endif
|
||||
#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_BLockReactor
|
||||
@@ -1,4 +0,0 @@
|
||||
#ifdef BLOG_CURRENT_CHANNEL
|
||||
#undef BLOG_CURRENT_CHANNEL
|
||||
#endif
|
||||
#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_BNetwork
|
||||
@@ -1,4 +0,0 @@
|
||||
#ifdef BLOG_CURRENT_CHANNEL
|
||||
#undef BLOG_CURRENT_CHANNEL
|
||||
#endif
|
||||
#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_BPredicate
|
||||
@@ -1,4 +0,0 @@
|
||||
#ifdef BLOG_CURRENT_CHANNEL
|
||||
#undef BLOG_CURRENT_CHANNEL
|
||||
#endif
|
||||
#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_BProcess
|
||||
@@ -1,4 +0,0 @@
|
||||
#ifdef BLOG_CURRENT_CHANNEL
|
||||
#undef BLOG_CURRENT_CHANNEL
|
||||
#endif
|
||||
#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_BReactor
|
||||
@@ -1,4 +0,0 @@
|
||||
#ifdef BLOG_CURRENT_CHANNEL
|
||||
#undef BLOG_CURRENT_CHANNEL
|
||||
#endif
|
||||
#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_BSSLConnection
|
||||
@@ -1,4 +0,0 @@
|
||||
#ifdef BLOG_CURRENT_CHANNEL
|
||||
#undef BLOG_CURRENT_CHANNEL
|
||||
#endif
|
||||
#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_BSignal
|
||||
@@ -1,4 +0,0 @@
|
||||
#ifdef BLOG_CURRENT_CHANNEL
|
||||
#undef BLOG_CURRENT_CHANNEL
|
||||
#endif
|
||||
#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_BSocksClient
|
||||
@@ -1,4 +0,0 @@
|
||||
#ifdef BLOG_CURRENT_CHANNEL
|
||||
#undef BLOG_CURRENT_CHANNEL
|
||||
#endif
|
||||
#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_BTap
|
||||
@@ -1,4 +0,0 @@
|
||||
#ifdef BLOG_CURRENT_CHANNEL
|
||||
#undef BLOG_CURRENT_CHANNEL
|
||||
#endif
|
||||
#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_BThreadSignal
|
||||
@@ -1,4 +0,0 @@
|
||||
#ifdef BLOG_CURRENT_CHANNEL
|
||||
#undef BLOG_CURRENT_CHANNEL
|
||||
#endif
|
||||
#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_BThreadWork
|
||||
@@ -1,4 +0,0 @@
|
||||
#ifdef BLOG_CURRENT_CHANNEL
|
||||
#undef BLOG_CURRENT_CHANNEL
|
||||
#endif
|
||||
#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_BTime
|
||||
@@ -1,4 +0,0 @@
|
||||
#ifdef BLOG_CURRENT_CHANNEL
|
||||
#undef BLOG_CURRENT_CHANNEL
|
||||
#endif
|
||||
#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_BUnixSignal
|
||||
@@ -1,4 +0,0 @@
|
||||
#ifdef BLOG_CURRENT_CHANNEL
|
||||
#undef BLOG_CURRENT_CHANNEL
|
||||
#endif
|
||||
#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_DPReceive
|
||||
@@ -1,4 +0,0 @@
|
||||
#ifdef BLOG_CURRENT_CHANNEL
|
||||
#undef BLOG_CURRENT_CHANNEL
|
||||
#endif
|
||||
#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_DPRelay
|
||||
@@ -1,4 +0,0 @@
|
||||
#ifdef BLOG_CURRENT_CHANNEL
|
||||
#undef BLOG_CURRENT_CHANNEL
|
||||
#endif
|
||||
#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_DataProto
|
||||
@@ -1,4 +0,0 @@
|
||||
#ifdef BLOG_CURRENT_CHANNEL
|
||||
#undef BLOG_CURRENT_CHANNEL
|
||||
#endif
|
||||
#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_DatagramPeerIO
|
||||
@@ -1,4 +0,0 @@
|
||||
#ifdef BLOG_CURRENT_CHANNEL
|
||||
#undef BLOG_CURRENT_CHANNEL
|
||||
#endif
|
||||
#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_FragmentProtoAssembler
|
||||
@@ -1,4 +0,0 @@
|
||||
#ifdef BLOG_CURRENT_CHANNEL
|
||||
#undef BLOG_CURRENT_CHANNEL
|
||||
#endif
|
||||
#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_FrameDecider
|
||||
@@ -1,4 +0,0 @@
|
||||
#ifdef BLOG_CURRENT_CHANNEL
|
||||
#undef BLOG_CURRENT_CHANNEL
|
||||
#endif
|
||||
#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_LineBuffer
|
||||
@@ -1,4 +0,0 @@
|
||||
#ifdef BLOG_CURRENT_CHANNEL
|
||||
#undef BLOG_CURRENT_CHANNEL
|
||||
#endif
|
||||
#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_Listener
|
||||
@@ -1,4 +0,0 @@
|
||||
#ifdef BLOG_CURRENT_CHANNEL
|
||||
#undef BLOG_CURRENT_CHANNEL
|
||||
#endif
|
||||
#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_NCDBuildProgram
|
||||
@@ -1,4 +0,0 @@
|
||||
#ifdef BLOG_CURRENT_CHANNEL
|
||||
#undef BLOG_CURRENT_CHANNEL
|
||||
#endif
|
||||
#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_NCDConfigParser
|
||||
@@ -1,4 +0,0 @@
|
||||
#ifdef BLOG_CURRENT_CHANNEL
|
||||
#undef BLOG_CURRENT_CHANNEL
|
||||
#endif
|
||||
#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_NCDConfigTokenizer
|
||||
@@ -1,4 +0,0 @@
|
||||
#ifdef BLOG_CURRENT_CHANNEL
|
||||
#undef BLOG_CURRENT_CHANNEL
|
||||
#endif
|
||||
#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_NCDIfConfig
|
||||
@@ -1,4 +0,0 @@
|
||||
#ifdef BLOG_CURRENT_CHANNEL
|
||||
#undef BLOG_CURRENT_CHANNEL
|
||||
#endif
|
||||
#define BLOG_CURRENT_CHANNEL BLOG_CHANNEL_NCDInterfaceMonitor
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user