forked from servalproject/serval-dna
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dnaprotocol
executable file
·214 lines (194 loc) · 6.73 KB
/
dnaprotocol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/bin/bash
# Tests for Serval DNA server operations.
#
# Copyright 2012 Paul Gardner-Stephen
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
source "${0%/*}/../testframework.sh"
source "${0%/*}/../testdefs.sh"
instances_reach_each_other() {
local I J
for I; do
for J; do
[ $I = $J ] && continue
local logvar=LOG${I#+}
local sidvar=SID${J#+}
if ! grep "PEER REACHABLE, sid=${!sidvar}" "${!logvar}"; then
return 1
fi
done
done
return 0
}
setup() {
setup_servald
assert_no_servald_processes
foreach_instance +A +B create_single_identity
configure_servald_server() { set_server_vars; }
start_servald_instances +A +B
wait_until --sleep=0.25 instances_reach_each_other +A +B
set_instance +A
executeOk_servald config set debug.all Yes
}
finally() {
stop_all_servald_servers
}
teardown() {
kill_all_servald_processes
assert_no_servald_processes
report_all_servald_servers
}
set_server_vars() {
executeOk_servald config set log.show_pid on
executeOk_servald config set log.show_time on
executeOk_servald config set mdp.wifi.tick_ms 100
executeOk_servald config set mdp.selfannounce.ticks_per_full_address 1
executeOk_servald config set debug.interfaces Yes
executeOk_servald config set debug.packetformats No
executeOk_servald config set debug.routing No
executeOk_servald config set debug.tx No
executeOk_servald config set debug.rx No
executeOk_servald config set debug.mdprequests Yes
executeOk_servald config set debug.keyring Yes
}
doc_LookupWildcard="Lookup by wildcard"
test_LookupWildcard() {
executeOk_servald dna lookup "*"
assertStdoutLineCount '==' 2
assertStdoutGrep --matches=1 "^sid://$SIDA/local/$DIDA:$DIDA:$NAMEA\$"
assertStdoutGrep --matches=1 "^sid://$SIDB/local/$DIDB:$DIDB:$NAMEB\$"
}
doc_LookupEmpty="Lookup by empty string"
test_LookupEmpty() {
executeOk_servald dna lookup ""
assertStdoutLineCount '==' 2
assertStdoutGrep --matches=1 "^sid://$SIDA/local/$DIDA:$DIDA:$NAMEA\$"
assertStdoutGrep --matches=1 "^sid://$SIDB/local/$DIDB:$DIDB:$NAMEB\$"
}
doc_LookupNonExistent="Lookup non-existent phone number"
test_LookupNonExistent() {
executeOk_servald dna lookup "5551234"
assertStdoutLineCount '==' 0
}
doc_LookupLocal="Lookup local phone number"
test_LookupLocal() {
executeOk_servald dna lookup "$DIDA"
assertStdoutLineCount '==' 1
assertStdoutGrep --matches=1 "^sid://$SIDA/local/$DIDA:$DIDA:$NAMEA\$"
}
doc_LookupRemote="Lookup remote phone number"
test_LookupRemote() {
executeOk_servald dna lookup "$DIDB"
assertStdoutLineCount '==' 1
assertStdoutGrep --matches=1 "^sid://$SIDB/local/$DIDB:$DIDB:$NAMEB\$"
}
doc_ReverseLookup="Resolve a remote identity"
test_ReverseLookup() {
executeOk_servald reverse lookup $SIDB
assertStdoutGrep --matches=1 ":$DIDB"
assertStdoutGrep --matches=1 ":$NAMEB"
}
doc_NodeinfoLocal="Node info auto-resolves for local identities"
test_NodeinfoLocal() {
# node info for a local identity returns DID/Name since it is free, even
# if it isn't asked for.
executeOk_servald node info $SIDA
assertStdoutLineCount '==' 1
assertStdoutGrep --matches=1 ":$SIDA:"
assertStdoutGrep --matches=1 ":$DIDA:"
assertStdoutGrep --matches=1 ":$NAMEA"
assertStdoutGrep --matches=0 "did-not-resolved"
}
doc_NodeinfoRemote="Node info resolves remote identities"
test_NodeinfoRemote() {
# if resolvedid is not specified for a remote identity, then don't resolve it.
executeOk_servald node info $SIDB
assertStdoutLineCount '==' 1
assertStdoutGrep --matches=1 ":$SIDB:"
assertStdoutGrep --matches=0 ":$DIDB:"
assertStdoutGrep --matches=0 ":$NAMEB"
assertStdoutGrep --matches=1 "did-not-resolved"
# But if it resolvedid is specified, then do resolve it using DNA
executeOk_servald node info $SIDB resolvedid
assertStdoutLineCount '==' 1
assertStdoutGrep --matches=1 ":$SIDB:"
assertStdoutGrep --matches=1 ":$DIDB:"
assertStdoutGrep --matches=1 ":$NAMEB"
assertStdoutGrep --matches=0 "did-not-resolved"
}
setup_multi_helper() {
setup_servald
assert_no_servald_processes
dnahelper="$TFWTMP/dnahelper"
echo "#!$BASH" >"$dnahelper"
cat >>"$dnahelper" <<'EOF'
echo STARTED
while read line
do
token="${line%%|*}"
case "$1:$line" in
A:*'|00003|') echo "$token|uri:A1|00003|Name One|";;
A:*'|00002|') echo "$token|uri:A2|00002|Name Two|";;
B:*'|00003|') echo "$token|uri:B1|00003|Name Three|";;
B:*'|00002|') echo "$token|uri:B2|00002|Name Four|";;
B:*'|00001|') echo "$token|uri:B3|00001|Name Five|";;
C:*'|00003|') echo "$token|uri:C1|00003|Name Six|";;
esac
echo DONE
done
EOF
chmod 0755 "$dnahelper"
foreach_instance +A +B +C +D create_single_identity
configure_servald_server() {
set_server_vars
executeOk_servald config set debug.dnahelper on
executeOk_servald config set dna.helper.executable "$dnahelper"
executeOk_servald config set dna.helper.argv.1 "$instance_name"
}
start_servald_instances +A +B +C +D
wait_until --sleep=0.25 instances_reach_each_other +A +B +C +D
set_instance +D
}
doc_MultiLookupHelperThree="Lookup phone number three nodes reply"
setup_MultiLookupHelperThree() {
setup_multi_helper
}
test_MultiLookupHelperThree() {
executeOk_servald dna lookup 00003
assertStdoutLineCount '==' 3
assertStdoutGrep --matches=1 "uri:A1:00003:Name One$"
assertStdoutGrep --matches=1 "uri:B1:00003:Name Three$"
assertStdoutGrep --matches=1 "uri:C1:00003:Name Six$"
}
doc_MultiLookupHelperTwo="Lookup phone number two nodes reply"
setup_MultiLookupHelperTwo() {
setup_multi_helper
}
test_MultiLookupHelperTwo() {
executeOk_servald dna lookup 00002
assertStdoutLineCount '==' 2
assertStdoutGrep --matches=1 "uri:A2:00002:Name Two\$"
assertStdoutGrep --matches=1 "uri:B2:00002:Name Four\$"
}
doc_MultiLookupHelperOne="Lookup phone number one node replies"
setup_MultiLookupHelperOne() {
setup_multi_helper
}
test_MultiLookupHelperOne() {
executeOk_servald dna lookup 00001
assertStdoutLineCount '==' 1
assertStdoutGrep --matches=1 "uri:B3:00001:Name Five\$"
}
runTests "$@"