From be1c46ef271b6fd44a9ff95a7e560f00edb99af7 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Wed, 12 Oct 2022 00:45:28 +0200 Subject: [PATCH 1/2] gcoap_fileserver: don't abort on duplicate packet --- sys/net/application_layer/gcoap/fileserver.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sys/net/application_layer/gcoap/fileserver.c b/sys/net/application_layer/gcoap/fileserver.c index 130ccf0400e2..9ce01516cbb1 100644 --- a/sys/net/application_layer/gcoap/fileserver.c +++ b/sys/net/application_layer/gcoap/fileserver.c @@ -275,7 +275,13 @@ static ssize_t _put_file(coap_pkt_t *pdu, uint8_t *buf, size_t len, if ((ret = vfs_lseek(fd, 0, SEEK_END)) < 0) { goto close_on_error; } - if (block1.offset != (unsigned)ret) { + if (block1.offset < (unsigned)ret) { + /* ignore duplicate packet */ + create = false; /* don't delete file */ + ret = COAP_CODE_CONTINUE; + goto close_on_error; + } + if (block1.offset > (unsigned)ret) { /* expect block to be in the correct order during initial creation */ ret = COAP_CODE_REQUEST_ENTITY_INCOMPLETE; goto close_on_error; From 7e0aeb3186a92620d215cecb05a98894e650de49 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Wed, 12 Oct 2022 00:46:13 +0200 Subject: [PATCH 2/2] tests/gcoap_fileserver: add test for PUT --- tests/gcoap_fileserver/Makefile | 2 ++ tests/gcoap_fileserver/Makefile.ci | 1 + tests/gcoap_fileserver/main.c | 13 ++++++++++++- tests/gcoap_fileserver/tests/01-run.py | 7 +++++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/tests/gcoap_fileserver/Makefile b/tests/gcoap_fileserver/Makefile index 90f0de5ac3f0..375773c24fef 100644 --- a/tests/gcoap_fileserver/Makefile +++ b/tests/gcoap_fileserver/Makefile @@ -10,6 +10,8 @@ USEMODULE += shell USEMODULE += shell_commands USEMODULE += gcoap_fileserver +USEMODULE += gcoap_fileserver_put + USEMODULE += nanocoap_vfs USEMODULE += constfs diff --git a/tests/gcoap_fileserver/Makefile.ci b/tests/gcoap_fileserver/Makefile.ci index 6ff479fbaa07..a2a48fffd29a 100644 --- a/tests/gcoap_fileserver/Makefile.ci +++ b/tests/gcoap_fileserver/Makefile.ci @@ -7,6 +7,7 @@ BOARD_INSUFFICIENT_MEMORY := \ atmega1284p \ atmega328p \ atmega328p-xplained-mini \ + atxmega-a1-xplained \ atxmega-a3bu-xplained \ blackpill \ bluepill \ diff --git a/tests/gcoap_fileserver/main.c b/tests/gcoap_fileserver/main.c index c336b1eadca9..750b22738cb9 100644 --- a/tests/gcoap_fileserver/main.c +++ b/tests/gcoap_fileserver/main.c @@ -28,7 +28,18 @@ static msg_t _main_msg_queue[MAIN_QUEUE_SIZE]; /* CoAP resources. Must be sorted by path (ASCII order). */ static const coap_resource_t _resources[] = { - { "/const", COAP_GET | COAP_MATCH_SUBTREE, gcoap_fileserver_handler, "/const" }, + { + .path = "/const", + .methods = COAP_GET | COAP_MATCH_SUBTREE, + .handler = gcoap_fileserver_handler, + .context = "/const" + }, + { + .path = "/vfs", + .methods = COAP_GET | COAP_PUT | COAP_MATCH_SUBTREE, + .handler = gcoap_fileserver_handler, + .context = VFS_DEFAULT_DATA + }, }; static gcoap_listener_t _listener = { diff --git a/tests/gcoap_fileserver/tests/01-run.py b/tests/gcoap_fileserver/tests/01-run.py index 17412e311d73..049fdc042688 100755 --- a/tests/gcoap_fileserver/tests/01-run.py +++ b/tests/gcoap_fileserver/tests/01-run.py @@ -98,11 +98,18 @@ def test_linear_topology(factory, zep_dispatch): # Download file from CoAP server B.cmd("vfs rm /nvm0/song.txt") + B.cmd("vfs rm /nvm0/song2.txt") B.cmd("ncget coap://[2001:db8::1]/const/song.txt", timeout=60) # make sure the content matches assert A.cmd("md5sum /const/song.txt").split()[2] == B.cmd("md5sum /nvm0/song.txt").split()[2] + # upload the file to node B (only one node should write MEMORY.bin) + A.cmd("ncput /const/song.txt coap://[" + global_addr(B.cmd("ifconfig 7"))[1] + "]/vfs/song2.txt", timeout=60) + + # make sure the content matches + assert B.cmd("md5sum /nvm0/song.txt").split()[2] == B.cmd("md5sum /nvm0/song2.txt").split()[2] + # terminate nodes for n in nodes: n.stop_term()