Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add TCP support to DHT-based group chats. #1448

Merged
merged 204 commits into from
May 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
204 commits
Select commit Hold shift + click to select a range
d0f9aca
fixes
IngvarX Nov 6, 2016
f5eeb05
fixes and typos
IngvarX Nov 19, 2016
1f0837a
let's have a game
IngvarX Jan 15, 2017
2e6d118
new invite system
IngvarX Jan 17, 2017
268c1a2
handshake fixes. real handshake sending
IngvarX Jan 18, 2017
603c8b2
successful invite handshake (but real handshake fails)
IngvarX Jan 18, 2017
e05b8be
new hope
IngvarX Jan 28, 2017
a3096ea
sync requests fix part 1
IngvarX Jan 28, 2017
4323a66
sync request over tcp (no peers list sharing yet)
IngvarX Jan 28, 2017
f74e4dc
successful sending sync request (without ann of new peer to others yet)
IngvarX Jan 29, 2017
2c8d55e
ignore some invites
IngvarX Jan 29, 2017
657607d
removed debug prints and fixed a bug
IngvarX Jan 29, 2017
c28c5d0
fixed bug with index
IngvarX Jan 30, 2017
77c355e
announcements of new peers during sync
IngvarX Jan 30, 2017
007d05e
empire strikes back
IngvarX Jan 30, 2017
0a97468
fixes in ann sending
IngvarX Feb 1, 2017
50cb951
some ann fixes
IngvarX Feb 2, 2017
29fcf8e
do_tcp moved to hell
IngvarX Feb 2, 2017
37eafce
typo
IngvarX Feb 2, 2017
2907a5a
segfault fix
IngvarX Feb 3, 2017
dca778b
correct handshake sending
IngvarX Feb 4, 2017
8761c5f
again segfault fix (???)
IngvarX Feb 4, 2017
8803176
sync requests fix++
IngvarX Feb 4, 2017
db007eb
correct public key sending
IngvarX Feb 4, 2017
c3b772a
some renaming
IngvarX Feb 4, 2017
840a6ad
return 0;
IngvarX Feb 5, 2017
dd8efa4
return of the jedi
IngvarX Feb 6, 2017
3a91a59
removed unsused code from old gc
IngvarX Mar 6, 2017
5a29a70
invites fix
IngvarX Mar 26, 2017
7d8dbda
ip/port sending (udp)
IngvarX Mar 26, 2017
35664a3
ip/port handling (UDP)
IngvarX Mar 26, 2017
d0e9b56
add fake friend for public gc
IngvarX Jan 1, 2018
00bfa37
add gc data to specified onion friend
IngvarX Jan 2, 2018
54865d4
sending gc data in onion announce request if needed
IngvarX Jan 6, 2018
19c8bbb
invite fix and refactoring
IngvarX Jan 6, 2018
68881ed
sending gc announces + various fixes
IngvarX Jan 7, 2018
a6bd271
old gc announces removed
IngvarX Jan 7, 2018
f5d824d
new group announces
IngvarX Jan 9, 2018
94875fa
fixed bootstrap (onion resp temp fix)
IngvarX Jan 10, 2018
2b116b2
broken madness
IngvarX Jan 12, 2018
af66a39
gc announces successfull sending. (partial info and w/o handling)
IngvarX Jan 13, 2018
df6622c
untested gc ann - peer id sending.
IngvarX Jan 13, 2018
b9eb9c3
announces exchange (still broken)
IngvarX Jan 14, 2018
a35d918
announces exchange - working version
IngvarX Jan 14, 2018
0f72a52
broken handshakes
IngvarX Jan 15, 2018
2507e95
initial almost not broken public ngc version
IngvarX Jan 15, 2018
18eab6e
oob instead of plain connection
IngvarX Jan 16, 2018
28a97f3
minor fixes - oob
IngvarX Jan 17, 2018
3335df7
some handshake updates and fixes
IngvarX Jan 20, 2018
fea9b58
second handshake is fixed. sync still doesn't work
IngvarX Jan 21, 2018
3f0a2e4
temporary fix for sync requests
IngvarX Jan 21, 2018
fa1a559
gc ann cleanup and refactoring
IngvarX Jan 25, 2018
e21841e
attempt to fix sync
IngvarX Jan 27, 2018
d5c3d68
minor updates
IngvarX Jan 27, 2018
0d96960
some changes reverted. sync now fails for user #6 in chat.
IngvarX Jan 28, 2018
ed1903d
fixed removing handshakes from sending array in case of race condition
IngvarX Feb 3, 2018
80926b4
minor fixes
IngvarX Feb 3, 2018
20770b6
fixed invites sending order. various fixes
IngvarX Feb 4, 2018
290491e
seems that now sync really fails for user #6 in chat. for small chats…
IngvarX Feb 4, 2018
14f8c0b
broken invites?
IngvarX Feb 4, 2018
b2764c1
fixed segfault on gc leaving
IngvarX Feb 5, 2018
1f705bc
announces fixes
IngvarX Feb 6, 2018
3c8b693
comments removed
IngvarX Feb 6, 2018
8b729d4
group reconnection and saving fix part #1
IngvarX Feb 10, 2018
73d3f56
minor improvements
IngvarX Feb 11, 2018
df53dd4
restoring fix
IngvarX Feb 18, 2018
a7801f1
debug inputs removed
IngvarX Feb 19, 2018
1164035
join public gc via invite - ann sending fix
IngvarX Feb 20, 2018
2a8ee6b
join group with different nick and status
IngvarX Feb 21, 2018
2e0388b
fix for public ngc restoring and leaving
IngvarX Feb 21, 2018
8676fab
temp fix for sending exit packets
IngvarX Feb 25, 2018
d38d637
fix for join large public gc
IngvarX Feb 28, 2018
e1d2bcc
small fixes
iphydf May 21, 2018
cb2e77e
Few compile issues fixes. Tests are still broken.
IngvarX May 22, 2018
fd10c1b
cast
iphydf May 22, 2018
4cb3c9d
fixed bug with public gc creation. tests are still broken
IngvarX May 25, 2018
395fec0
fixed bug with group join
IngvarX May 26, 2018
3007ede
fixed issue when chat id is public key of user
IngvarX Jun 2, 2018
7497680
minor refactoring
IngvarX Jun 3, 2018
8502183
removed unused code
IngvarX Jun 3, 2018
048dca9
add tcp relay moved, typo fixed
IngvarX Jun 17, 2018
5627a6f
Public gc announces pack && unpack added. It compiles but I didn't te…
IngvarX Jun 17, 2018
6b35d4b
ip ports handling during invites and handshakes
IngvarX Jun 20, 2018
e55a68b
initial version of sending announces in public gc
IngvarX Jun 21, 2018
ea7d3da
sending gc name in invite
IngvarX Jun 22, 2018
3810f3a
tcp invites works
IngvarX Jun 30, 2018
5bad199
group sync requests were rewritten
IngvarX Jul 4, 2018
9fecd41
various fixes for public groups announces
IngvarX Jul 8, 2018
bd9e7c3
fixed bug with public groups in udp mode
IngvarX Jul 10, 2018
3a16b9a
Fixed sync request in group
IngvarX Jul 11, 2018
d19d542
fixed > 1 announce packing
IngvarX Jul 14, 2018
6eb9e3c
update gc data on tcp connection change
IngvarX Jul 14, 2018
0c8919b
Update gc data on tcp connection status changed. try to send handshak…
IngvarX Jul 15, 2018
02fb7cc
udp groups restoring fix
IngvarX Jul 15, 2018
740fcdf
reconnection and disconnection. renaming in api
IngvarX Jul 17, 2018
2953666
group disconnection and reconnection functionality finally works
IngvarX Jul 18, 2018
0bce629
reconnection to active group
IngvarX Jul 21, 2018
d40a83a
renaming and minor fixes
IngvarX Jul 21, 2018
43fea43
renaming and refactoring
IngvarX Jul 21, 2018
81dd645
bug fixes
IngvarX Jul 22, 2018
7aa6e1c
private messages types
IngvarX Jul 22, 2018
fc22a0f
ban types api
IngvarX Jul 23, 2018
ac328cb
ban checking
IngvarX Jul 23, 2018
14470fb
fixed join gc with different name
IngvarX Jul 25, 2018
aaf3a99
minor improvements - get group numbers list, refactoring
IngvarX Jul 29, 2018
2eb50a9
fixed peer ann handling. compile errors were fixed
IngvarX Jul 29, 2018
c29e077
Minor cleanup
IngvarX Jul 31, 2018
1d7f82b
fixed few bugs. added free function for self gc info
IngvarX Jul 31, 2018
e3040e5
fixes for peers announces
IngvarX Aug 2, 2018
9fc3f6b
bans - added possibility to get ban target via api. few bugs fixed
IngvarX Aug 3, 2018
12526e5
fixed bug with peer id and ignore flag resetting
IngvarX Aug 6, 2018
de8b812
nicknames banning fix
IngvarX Aug 6, 2018
5a73803
malloc => calloc
IngvarX Aug 10, 2018
0493de1
removed ip sending in gc. fixed but with gc reconnection
IngvarX Aug 23, 2018
c798c0a
removed old unused code
IngvarX Aug 24, 2018
5595bd9
mem leaks and minor fixes
IngvarX Aug 24, 2018
61895fa
reconnection update, NULL => nullptr
IngvarX Aug 25, 2018
5443d0e
fixes for gc join/friend adding and other stuff
IngvarX Aug 27, 2018
04a3c0f
fixed bug with sending handshakes, fixed banning users by nick, gcc r…
IngvarX Aug 29, 2018
d82e3e1
announce publishing fixes, minor refactoring
IngvarX Sep 2, 2018
3a3ac4a
fixed kick/ban crash
IngvarX Sep 3, 2018
c73314a
tcp realys adding if there are no any
IngvarX Sep 3, 2018
28a27b2
handle missing handshake packet id
IngvarX Sep 5, 2018
8e3e793
fixed a bug, few debug prints removed
IngvarX Sep 5, 2018
528400c
added api for get peer list
IngvarX Sep 11, 2018
a05db4a
fixed crash with disconnected groups
IngvarX Sep 13, 2018
f75b4b4
fix up tests
iphydf Sep 18, 2018
bd2a09d
fix heap-use-after-free
iphydf Sep 18, 2018
f496091
return error correctly on group load failure
iphydf Sep 19, 2018
8ebcb19
fix groupchat_test
iphydf Sep 19, 2018
ae6052c
Fixed crash in handle_gc_sync_response
IngvarX Sep 20, 2018
d40a9da
add const in some places
iphydf Sep 20, 2018
cefe940
Make events const and remove unused argument.
tvladyslav Oct 27, 2018
8bc07a5
Revert PADDING/REQUEST/KILL reassignment.
joecrayne Nov 16, 2018
e8894b1
Fixed documentation for send_conference_invite_packet().
joecrayne Nov 18, 2018
add657f
gc announce response: Fixed accidental negation of ip_is_lan().
joecrayne Nov 18, 2018
1b96f47
Fixed id_toa() related memory leaks.
joecrayne Nov 16, 2018
a0d76b8
Fix return in function now returning void.
iphydf Jan 12, 2019
6165b51
Fix warnings
iphydf Mar 5, 2020
90bd24c
Use `crypto_` functions and constants instead of sodium.h.
iphydf Mar 6, 2020
51a4335
stuff compiles again
iphydf Mar 17, 2020
4c76382
typo: recieved
iphydf Mar 17, 2020
3e3dde5
astyle
iphydf Mar 17, 2020
65d5417
Use VLA macro for VLAs.
iphydf Mar 17, 2020
8086c6f
remove group.h dependency from Messenger.c
iphydf Mar 19, 2020
30d8916
fix up tox_group_ban_get_target
iphydf Mar 23, 2020
3302336
Fix group_private_message event
Zer0-One Apr 1, 2020
8e4ad0f
Fix group_invite event
Zer0-One Apr 1, 2020
e063b60
"Fix" Tox_Group_Peer_Info struct
Zer0-One Apr 3, 2020
f88a161
Fix TOX_GROUP_MAX_PEER_LENGTH
Zer0-One Apr 3, 2020
3115112
Fix tox_group_new
Zer0-One Apr 3, 2020
4dc0bf7
Fix TOX_ERR_GROUP_NEW_PEER_INFO
Zer0-One Apr 3, 2020
87c62d1
Fix tox_group_join
Zer0-One Apr 3, 2020
c3769b2
Fix TOX_ERR_GROUP_IS_CONNECTED
Zer0-One Apr 3, 2020
fc76c87
Fix TOX_ERR_GROUP_DISCONNECT and TOX_ERR_GROUP_RECONNECT
Zer0-One Apr 3, 2020
996db5b
Fix TOX_ERR_GROUP_PEER_LIST_QUERY
Zer0-One Apr 3, 2020
1a45d20
Fix TOX_ERR_GROUP_TOPIC_SET
Zer0-One Apr 3, 2020
6d903c4
Fix TOX_ERR_GROUP_SEND_MESSAGE
Zer0-One Apr 3, 2020
1c1fa00
Fix tox_group_send_private_message
Zer0-One Apr 3, 2020
c498b24
Fix TOX_ERR_GROUP_SEND_PRIVATE_MESSAGE
Zer0-One Apr 3, 2020
97618a0
Add GROUP_IS_DISCONNECTED value for error enums
Zer0-One Apr 3, 2020
2f25c2f
Fix tox_group_invite_accept
Zer0-One Apr 3, 2020
b03592a
Fix tox_group_mod_remove_peer
Zer0-One Apr 3, 2020
dbe22c3
Add TOX_GROUP_BAN_TYPE enum
Zer0-One Apr 3, 2020
ef1b7e9
Add TOX_ERR_GROUP_MOD_REMOVE_PEER_INVALID_BAN_TYPE
Zer0-One Apr 3, 2020
398bbfb
Added remaining missing functions for groups
Zer0-One Apr 6, 2020
ea6f3fc
fix doc comments
iphydf Apr 6, 2020
c41be44
fix tests; make tokstyle happy
iphydf Apr 9, 2020
e08f51e
fix loop iterator
iphydf Apr 18, 2020
8337e6b
friend_is_valid
iphydf Apr 20, 2020
06e9e76
rebase fixup: nick_len -> nick_length
iphydf Apr 26, 2020
b09de18
add back the "group leave on test end" stuff
iphydf Apr 26, 2020
43e506a
Fix onion autotest
JFreegman Apr 27, 2020
342ed0f
less logging
iphydf Apr 27, 2020
971c935
Fix onion autotest properly this time
JFreegman Apr 27, 2020
b86a957
Fix groupchat autotests
JFreegman Apr 28, 2020
0d29b9c
Remove group peer info struct from public API
JFreegman Apr 28, 2020
2a0ca61
Remove group peer list query API functions
JFreegman Apr 28, 2020
b331d47
Some fixes and improvements to group autotests
JFreegman Apr 28, 2020
3e1ae04
Remove all callback events initiated from API calls
JFreegman Apr 29, 2020
15acb71
Add error codes for invalid moderator actions on self
JFreegman Apr 29, 2020
65e8535
Remove ability to ban peers from groups
JFreegman Apr 29, 2020
6f68931
Remove unused code and unecessary callback
JFreegman Apr 29, 2020
4c81d80
Fix bug causing kicked peers to auto-rejoin the group
JFreegman Apr 29, 2020
09d7207
Attempt to fix some group join issues
JFreegman Apr 30, 2020
8958403
Remove unused variable
JFreegman Apr 30, 2020
e4498d8
Remove redundant groupchat tests
JFreegman Apr 30, 2020
db77c09
Separate groups from friends in Messenger.c
JFreegman May 1, 2020
a462a71
Make send_online_packet() usable for friends and groups.
JFreegman May 1, 2020
92c0c51
Format code.
iphydf May 1, 2020
ce79ce3
Make tokstyle happy.
iphydf May 1, 2020
04a798c
Remove known recursion that's now gone from check_recursion.
iphydf May 1, 2020
792fe0c
Fix C++ type error; #undef all the things at the end of tests.
iphydf May 1, 2020
b4364ce
Use a fully random public key for group friend connections
JFreegman May 1, 2020
44e1454
Refactor some Messenger code
JFreegman May 1, 2020
bed8b99
Use toktok-stack 0.0.10.
iphydf May 1, 2020
1a21fe6
Remove a pointless function and re-add a check erroneously removed
JFreegman May 1, 2020
e86d6c6
Fix TCP_test under testnet.
iphydf May 1, 2020
10c53a3
Enable testnet on cirrus-ci.
iphydf May 1, 2020
b4b92c2
Stop using hard-coded packet ids in onion_test.
iphydf May 1, 2020
3ff71e5
Fix tcp relay test: add jfreegman test node.
iphydf May 1, 2020
eaef66f
Enable testnet on travis and circle.
iphydf May 1, 2020
67fbd31
Make onion announce code work with vanilla nacl
JFreegman May 2, 2020
acc73b7
Use test network in autotools build.
iphydf May 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .circleci/cmake-asan
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ cmake -B_build -H. -GNinja \
-DSTRICT_ABI=ON \
-DTEST_TIMEOUT_SECONDS=120 \
-DUSE_IPV6=OFF \
-DUSE_TEST_NETWORK=ON \
-DAUTOTEST=ON

cd _build
Expand Down
1 change: 1 addition & 0 deletions .circleci/cmake-tsan
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ cmake -B_build -H. -GNinja \
-DSTRICT_ABI=ON \
-DTEST_TIMEOUT_SECONDS=120 \
-DUSE_IPV6=OFF \
-DUSE_TEST_NETWORK=ON \
-DAUTOTEST=ON

cd _build
Expand Down
4 changes: 2 additions & 2 deletions .cirrus.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
cirrus-ci_task:
container:
image: toxchat/toktok-stack:0.0.7
image: toxchat/toktok-stack:0.0.10
cpu: 2
memory: 2G
configure_script:
Expand All @@ -10,6 +10,6 @@ cirrus-ci_task:
- bazel test -k
--remote_http_cache=http://$CIRRUS_HTTP_CACHE_HOST
--config=ci
--config=docker
--config=release
--config=testnet
//c-toxcore/...
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -87,3 +87,5 @@ cscope.files

# rpm
tox.spec

.idea/
1 change: 1 addition & 0 deletions .travis/autotools-linux
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ travis_script() {
add_config_flag --with-nacl-libs="$CACHEDIR/lib/amd64"
add_config_flag --with-nacl-headers="$CACHEDIR/include/amd64"
add_config_flag --disable-ipv6
add_config_flag --enable-test-network
add_config_flag --enable-nacl
add_config_flag --enable-daemon
add_config_flag --enable-logging
Expand Down
1 change: 1 addition & 0 deletions .travis/cmake-linux
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ travis_script() {
-DSTRICT_ABI=ON \
-DTEST_TIMEOUT_SECONDS=120 \
-DUSE_IPV6=OFF \
-DUSE_TEST_NETWORK=ON \
-DAUTOTEST=ON

cmake --build _build --parallel "$NPROC" --target install -- -k 0
Expand Down
11 changes: 0 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -545,15 +545,4 @@ if (BUILD_MISC_TESTS)
testing/afl_toxsave.c)
target_link_modules(afl_toxsave toxcore)

add_executable(group_announce_test ${CPUFEATURES}
testing/groupchats/group_announce_test.c)
target_link_modules(group_announce_test toxcore misc_tools)

add_executable(group_bootstrap_n_chat ${CPUFEATURES}
testing/groupchats/group_bootstrap_n_chat.c)
target_link_modules(group_bootstrap_n_chat toxcore misc_tools)

add_executable(group_newpeers_dos_attack ${CPUFEATURES}
testing/groupchats/group_newpeers_dos_attack.c)
target_link_modules(group_newpeers_dos_attack toxcore misc_tools)
endif()
20 changes: 11 additions & 9 deletions auto_tests/TCP_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ START_TEST(test_basic)
memcpy(f_nonce_r, response_plain + CRYPTO_SHARED_KEY_SIZE, CRYPTO_NONCE_SIZE);

// Building a request
uint8_t r_req_p[1 + CRYPTO_PUBLIC_KEY_SIZE] = {0};
uint8_t r_req_p[1 + CRYPTO_PUBLIC_KEY_SIZE];
r_req_p[0] = TCP_PACKET_ROUTING_REQUEST;
memcpy(r_req_p + 1, f_public_key, CRYPTO_PUBLIC_KEY_SIZE);
uint8_t r_req[2 + 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE];
uint16_t size = 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE;
Expand Down Expand Up @@ -162,7 +163,8 @@ START_TEST(test_basic)
ck_assert_msg(ret != -1, "Failed to decrypt the TCP server's response.");
increment_nonce(f_nonce_r);

ck_assert_msg(packet_resp_plain[0] == 1, "Server sent the wrong packet id: %u", packet_resp_plain[0]);
ck_assert_msg(packet_resp_plain[0] == TCP_PACKET_ROUTING_RESPONSE, "Server sent the wrong packet id: %u",
packet_resp_plain[0]);
ck_assert_msg(packet_resp_plain[1] == 0, "Server did not refuse the connection.");
ck_assert_msg(public_key_cmp(packet_resp_plain + 2, f_public_key) == 0, "Server sent the wrong public key.");

Expand Down Expand Up @@ -284,7 +286,7 @@ START_TEST(test_some)
struct sec_TCP_con *con3 = new_TCP_con(tcp_s, mono_time);

uint8_t requ_p[1 + CRYPTO_PUBLIC_KEY_SIZE];
requ_p[0] = 0;
requ_p[0] = TCP_PACKET_ROUTING_REQUEST;

// Sending wrong public keys to test server response.
memcpy(requ_p + 1, con3->public_key, CRYPTO_PUBLIC_KEY_SIZE);
Expand All @@ -298,14 +300,14 @@ START_TEST(test_some)
uint8_t data[2048];
int len = read_packet_sec_TCP(con1, data, 2 + 1 + 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE);
ck_assert_msg(len == 1 + 1 + CRYPTO_PUBLIC_KEY_SIZE, "Wrong response packet length of %d.", len);
ck_assert_msg(data[0] == 1, "Wrong response packet id of %d.", data[0]);
ck_assert_msg(data[0] == TCP_PACKET_ROUTING_RESPONSE, "Wrong response packet id of %d.", data[0]);
ck_assert_msg(data[1] == 16, "Server didn't refuse connection using wrong public key.");
ck_assert_msg(public_key_cmp(data + 2, con3->public_key) == 0, "Key in response packet wrong.");

// Connection 3
len = read_packet_sec_TCP(con3, data, 2 + 1 + 1 + CRYPTO_PUBLIC_KEY_SIZE + CRYPTO_MAC_SIZE);
ck_assert_msg(len == 1 + 1 + CRYPTO_PUBLIC_KEY_SIZE, "Wrong response packet length of %d.", len);
ck_assert_msg(data[0] == 1, "Wrong response packet id of %d.", data[0]);
ck_assert_msg(data[0] == TCP_PACKET_ROUTING_RESPONSE, "Wrong response packet id of %d.", data[0]);
ck_assert_msg(data[1] == 16, "Server didn't refuse connection using wrong public key.");
ck_assert_msg(public_key_cmp(data + 2, con1->public_key) == 0, "Key in response packet wrong.");

Expand All @@ -319,11 +321,11 @@ START_TEST(test_some)

len = read_packet_sec_TCP(con1, data, 2 + 2 + CRYPTO_MAC_SIZE);
ck_assert_msg(len == 2, "wrong len %d", len);
ck_assert_msg(data[0] == 2, "wrong packet id %u", data[0]);
ck_assert_msg(data[0] == TCP_PACKET_CONNECTION_NOTIFICATION, "wrong packet id %u", data[0]);
ck_assert_msg(data[1] == 16, "wrong peer id %u", data[1]);
len = read_packet_sec_TCP(con3, data, 2 + 2 + CRYPTO_MAC_SIZE);
ck_assert_msg(len == 2, "wrong len %d", len);
ck_assert_msg(data[0] == 2, "wrong packet id %u", data[0]);
ck_assert_msg(data[0] == TCP_PACKET_CONNECTION_NOTIFICATION, "wrong packet id %u", data[0]);
ck_assert_msg(data[1] == 16, "wrong peer id %u", data[1]);
len = read_packet_sec_TCP(con1, data, 2 + sizeof(test_packet) + CRYPTO_MAC_SIZE);
ck_assert_msg(len == sizeof(test_packet), "wrong len %d", len);
Expand Down Expand Up @@ -354,14 +356,14 @@ START_TEST(test_some)
ck_assert_msg(memcmp(data, test_packet, sizeof(test_packet)) == 0, "packet is wrong %u %u %u %u", data[0], data[1],
data[sizeof(test_packet) - 2], data[sizeof(test_packet) - 1]);

uint8_t ping_packet[1 + sizeof(uint64_t)] = {4, 8, 6, 9, 67};
uint8_t ping_packet[1 + sizeof(uint64_t)] = {TCP_PACKET_PING, 8, 6, 9, 67};
write_packet_TCP_secure_connection(con1, ping_packet, sizeof(ping_packet));

do_TCP_server_delay(tcp_s, mono_time, 50);

len = read_packet_sec_TCP(con1, data, 2 + sizeof(ping_packet) + CRYPTO_MAC_SIZE);
ck_assert_msg(len == sizeof(ping_packet), "wrong len %d", len);
ck_assert_msg(data[0] == 5, "wrong packet id %u", data[0]);
ck_assert_msg(data[0] == TCP_PACKET_PONG, "wrong packet id %u", data[0]);
ck_assert_msg(memcmp(ping_packet + 1, data + 1, sizeof(uint64_t)) == 0, "wrong packet data");

// Kill off the connections
Expand Down
62 changes: 36 additions & 26 deletions auto_tests/group_announce_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@ typedef struct State {

#include "run_auto_test.h"

#define TEST_MESSAGE "The kiosk in my temporal lobe is shaped like Rosalynn Carter"
#define TEST_GROUP_NAME "NASA Headquarters"
#define PEER0_NICK "Lois"
#define PEER1_NICK "Benjamin"

static void group_invite_handler(Tox *tox, uint32_t friend_number, const uint8_t *invite_data, size_t length,
void *user_data)
const uint8_t *group_name, size_t group_name_length, void *user_data)
{
printf("invite arrived; accepting\n");
TOX_ERR_GROUP_INVITE_ACCEPT err_accept;
tox_group_invite_accept(tox, invite_data, length, nullptr, 0, &err_accept);
ck_assert(err_accept == TOX_ERR_GROUP_INVITE_ACCEPT_OK);
if (tox != nullptr) {
ck_abort_msg("we should not get invited");
}
}

static const char *tox_str_group_join_fail(TOX_GROUP_JOIN_FAIL v)
Expand Down Expand Up @@ -62,29 +66,37 @@ static void group_peer_join_handler(Tox *tox, uint32_t groupnumber, uint32_t pee
static void group_message_handler(Tox *tox, uint32_t groupnumber, uint32_t peer_id, TOX_MESSAGE_TYPE type,
const uint8_t *message, size_t length, void *user_data)
{
if (length > TOX_MAX_MESSAGE_LENGTH) {
printf("Failed to receive message. Invalid length: %zu\n", length);
return;
}

char message_buf[TOX_MAX_MESSAGE_LENGTH + 1];
memcpy(message_buf, message, length);
message_buf[length] = 0;

State *state = (State *)user_data;
printf("peer %u sent message: %s\n", peer_id, (const char *)message);
ck_assert(memcmp(message, "hello", 6) == 0);
printf("peer %u sent message: %s\n", peer_id, (const char *)message_buf);
ck_assert(memcmp(message_buf, TEST_MESSAGE, length) == 0);
state->message_received = true;
}

static void group_message_test(Tox **toxes, State *state)
{
tox_self_set_name(toxes[0], (const uint8_t *)"a", 1, nullptr);
tox_self_set_name(toxes[1], (const uint8_t *)"b", 1, nullptr);
tox_self_set_name(toxes[2], (const uint8_t *)"c", 1, nullptr);

tox_callback_group_invite(toxes[1], group_invite_handler, nullptr);
tox_callback_group_join_fail(toxes[1], group_join_fail_handler, nullptr);
tox_callback_group_peer_join(toxes[1], group_peer_join_handler, nullptr);
tox_callback_group_message(toxes[0], group_message_handler, nullptr);
tox_callback_group_invite(toxes[1], group_invite_handler);
tox_callback_group_join_fail(toxes[1], group_join_fail_handler);
tox_callback_group_peer_join(toxes[1], group_peer_join_handler);
tox_callback_group_message(toxes[0], group_message_handler);

// tox0 makes new group.
TOX_ERR_GROUP_NEW err_new;
uint32_t group_number =
tox_group_new(
toxes[0], TOX_GROUP_PRIVACY_STATE_PUBLIC,
(const uint8_t *)"my cool group", strlen("my cool group"), &err_new);
(const uint8_t *) TEST_GROUP_NAME, strlen(TEST_GROUP_NAME), (const uint8_t *)PEER0_NICK, strlen(PEER0_NICK), &err_new);
ck_assert(err_new == TOX_ERR_GROUP_NEW_OK);

// get the chat id of the new group.
Expand All @@ -93,25 +105,21 @@ static void group_message_test(Tox **toxes, State *state)
tox_group_get_chat_id(toxes[0], group_number, chat_id, &err_id);
ck_assert(err_id == TOX_ERR_GROUP_STATE_QUERIES_OK);

// tox1 and tox2 joins it.
// tox1 joins it.
TOX_ERR_GROUP_JOIN err_join;
tox_group_join(toxes[1], chat_id, nullptr, 0, &err_join);
ck_assert(err_join == TOX_ERR_GROUP_JOIN_OK);

tox_group_join(toxes[2], chat_id, nullptr, 0, &err_join);
tox_group_join(toxes[1], chat_id, (const uint8_t *)PEER1_NICK, strlen(PEER1_NICK), nullptr, 0, &err_join);
ck_assert(err_join == TOX_ERR_GROUP_JOIN_OK);

while (!state[0].message_received) {
iterate_all_wait(3, toxes, state, ITERATION_INTERVAL);
iterate_all_wait(2, toxes, state, ITERATION_INTERVAL);

if (state[1].peer_joined && !state[1].message_sent) {
TOX_ERR_GROUP_SEND_MESSAGE err_send;
tox_group_send_message(toxes[1], group_number, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)"hello", 6, &err_send);
tox_group_send_message(toxes[1], group_number, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)TEST_MESSAGE,
strlen(TEST_MESSAGE), &err_send);
ck_assert(err_send == TOX_ERR_GROUP_SEND_MESSAGE_OK);
state[1].message_sent = true;
}

c_sleep(ITERATION_INTERVAL);
}

TOX_ERR_GROUP_LEAVE err_exit;
Expand All @@ -120,15 +128,17 @@ static void group_message_test(Tox **toxes, State *state)

tox_group_leave(toxes[1], group_number, nullptr, 0, &err_exit);
ck_assert(err_exit == TOX_ERR_GROUP_LEAVE_OK);

tox_group_leave(toxes[2], group_number, nullptr, 0, &err_exit);
ck_assert(err_exit == TOX_ERR_GROUP_LEAVE_OK);
}

#undef PEER1_NICK
#undef PEER0_NICK
#undef TEST_GROUP_NAME
#undef TEST_MESSAGE

int main(void)
{
setvbuf(stdout, nullptr, _IONBF, 0);

run_auto_test(3, group_message_test, false);
run_auto_test(2, group_message_test, false);
return 0;
}
67 changes: 57 additions & 10 deletions auto_tests/group_message_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@ typedef struct State {

#include "run_auto_test.h"

#define TEST_MESSAGE "Where is it I've read that someone condemned to death says or thinks, an hour before his death, that if he had to live on some high rock, on such a narrow ledge that he'd only room to stand, and the ocean, everlasting darkness, everlasting solitude, everlasting tempest around him, if he had to remain standing on a square yard of space all his life, a thousand years, eternity, it were better to live so than to die at once. Only to live, to live and live! Life, whatever it may be!"
#define TEST_GROUP_NAME "Utah Data Center"
#define PEER0_NICK "Victor"
#define PEER1_NICK "George"

static void group_invite_handler(Tox *tox, uint32_t friend_number, const uint8_t *invite_data, size_t length,
void *user_data)
const uint8_t *group_name, size_t group_name_length, void *user_data)
{
printf("invite arrived; accepting\n");
TOX_ERR_GROUP_INVITE_ACCEPT err_accept;
tox_group_invite_accept(tox, invite_data, length, nullptr, 0, &err_accept);
tox_group_invite_accept(tox, friend_number, invite_data, length, (const uint8_t *)PEER0_NICK, strlen(PEER0_NICK),
nullptr, 0, &err_accept);
ck_assert(err_accept == TOX_ERR_GROUP_INVITE_ACCEPT_OK);
}

Expand Down Expand Up @@ -62,9 +68,44 @@ static void group_peer_join_handler(Tox *tox, uint32_t groupnumber, uint32_t pee
static void group_message_handler(Tox *tox, uint32_t groupnumber, uint32_t peer_id, TOX_MESSAGE_TYPE type,
const uint8_t *message, size_t length, void *user_data)
{
if (length > TOX_MAX_MESSAGE_LENGTH) {
printf("Failed to receive message. Invalid length: %zu\n", length);
return;
}

char message_buf[TOX_MAX_MESSAGE_LENGTH + 1];
memcpy(message_buf, message, length);
message_buf[length] = 0;

TOX_ERR_GROUP_PEER_QUERY q_err;
size_t peer_name_len = tox_group_peer_get_name_size(tox, groupnumber, peer_id, &q_err);

ck_assert(q_err == TOX_ERR_GROUP_PEER_QUERY_OK);
ck_assert(peer_name_len <= TOX_MAX_NAME_LENGTH);

char peer_name[TOX_MAX_NAME_LENGTH + 1];
tox_group_peer_get_name(tox, groupnumber, peer_id, (uint8_t *) peer_name, &q_err);
peer_name[peer_name_len] = 0;

ck_assert(q_err == TOX_ERR_GROUP_PEER_QUERY_OK);
ck_assert(memcmp(peer_name, PEER1_NICK, peer_name_len));

TOX_ERR_GROUP_SELF_QUERY s_err;
size_t self_name_len = tox_group_self_get_name_size(tox, groupnumber, &s_err);
ck_assert(s_err == TOX_ERR_GROUP_SELF_QUERY_OK);
ck_assert(self_name_len <= TOX_MAX_NAME_LENGTH);

char self_name[TOX_MAX_NAME_LENGTH + 1];
tox_group_self_get_name(tox, groupnumber, (uint8_t *) self_name, &s_err);
self_name[self_name_len] = 0;

ck_assert(s_err == TOX_ERR_GROUP_SELF_QUERY_OK);
ck_assert(memcmp(self_name, PEER0_NICK, self_name_len));

printf("%s sent message to %s: %s\n", peer_name, self_name, message_buf);
ck_assert(memcmp(message_buf, TEST_MESSAGE, length) == 0);

State *state = (State *)user_data;
printf("peer %u sent message: %s\n", peer_id, (const char *)message);
ck_assert(memcmp(message, "hello", 6) == 0);
state->message_received = true;
}

Expand All @@ -73,17 +114,17 @@ static void group_message_test(Tox **toxes, State *state)
tox_self_set_name(toxes[0], (const uint8_t *)"a", 1, nullptr);
tox_self_set_name(toxes[1], (const uint8_t *)"b", 1, nullptr);

tox_callback_group_invite(toxes[1], group_invite_handler, nullptr);
tox_callback_group_join_fail(toxes[1], group_join_fail_handler, nullptr);
tox_callback_group_peer_join(toxes[1], group_peer_join_handler, nullptr);
tox_callback_group_message(toxes[0], group_message_handler, nullptr);
tox_callback_group_invite(toxes[1], group_invite_handler);
tox_callback_group_join_fail(toxes[1], group_join_fail_handler);
tox_callback_group_peer_join(toxes[1], group_peer_join_handler);
tox_callback_group_message(toxes[0], group_message_handler);

// tox0 makes new group.
TOX_ERR_GROUP_NEW err_new;
uint32_t group_number =
tox_group_new(
toxes[0], TOX_GROUP_PRIVACY_STATE_PRIVATE,
(const uint8_t *)"my cool group", strlen("my cool group"), &err_new);
(const uint8_t *)TEST_GROUP_NAME, strlen(TEST_GROUP_NAME), (const uint8_t *)PEER1_NICK, strlen(PEER1_NICK), &err_new);
ck_assert(err_new == TOX_ERR_GROUP_NEW_OK);

// tox0 invites tox1
Expand All @@ -97,7 +138,8 @@ static void group_message_test(Tox **toxes, State *state)

if (state[1].peer_joined && !state[1].message_sent) {
TOX_ERR_GROUP_SEND_MESSAGE err_send;
tox_group_send_message(toxes[1], group_number, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)"hello", 6, &err_send);
tox_group_send_message(toxes[1], group_number, TOX_MESSAGE_TYPE_NORMAL, (const uint8_t *)TEST_MESSAGE,
strlen(TEST_MESSAGE), &err_send);
ck_assert(err_send == TOX_ERR_GROUP_SEND_MESSAGE_OK);
state[1].message_sent = true;
}
Expand All @@ -112,6 +154,11 @@ static void group_message_test(Tox **toxes, State *state)
}
}

#undef PEER1_NICK
#undef PEER0_NICK
#undef TEST_GROUP_NAME
#undef TEST_MESSAGE

int main(void)
{
setvbuf(stdout, nullptr, _IONBF, 0);
Expand Down