-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
subsys: net: download_client rework #17481
base: main
Are you sure you want to change the base?
subsys: net: download_client rework #17481
Conversation
CI InformationTo view the history of this post, clich the 'edited' button above Inputs:Sources:sdk-nrf: PR head: 761cfb8d85fbd80059f100b174816fee76d2f4ff more detailssdk-nrf:
Github labels
List of changed files detected by CI (116)
Outputs:ToolchainVersion: Test Spec & Results: ✅ Success; ❌ Failure; 🟠 Queued; 🟡 Progress; ◻️ Skipped;
|
include/net/download_client.h
Outdated
struct download_client_host_cfg { | ||
/** Server hosting the file, null-terminated. | ||
* The host name must be kept in scope while download is going on. | ||
*/ | ||
const char *hostname; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since you are so heavily refactoring, I would propose that we get rid of this separation of host and path.
Just use URI on the API.
It is actually very rare that any interfaces would give us host and path separately. I only know nRF Cloud to do so on some REST APIs. It is more common that we receive full URI where to fetch the data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh.. and also now host is provided inside a struct and path is provided as a function parameter. This emphasizes the separation even further.
It feels like cleanest API would just take URI as one parameter, or field inside this struct. Let the HTTP parser to split protocol, host, port and path.
3af4cbb
to
3e9412e
Compare
6573c1d
to
2666f2d
Compare
272b2de
to
c058985
Compare
c058985
to
49e7000
Compare
Marking ready for review to trigger CI. |
doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst
Outdated
Show resolved
Hide resolved
doc/nrf/releases_and_maturity/migration/migration_guide_2.9.rst
Outdated
Show resolved
Hide resolved
doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst
Outdated
Show resolved
Hide resolved
doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst
Outdated
Show resolved
Hide resolved
doc/nrf/releases_and_maturity/migration/migration_guide_2.9.rst
Outdated
Show resolved
Hide resolved
.. code-block:: C | ||
#include <net/download_client.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.. code-block:: C | |
#include <net/download_client.h> | |
.. code-block:: C | |
#include <net/download_client.h> |
.. code-block:: C | ||
#include <net/downloader.h> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.. code-block:: C | |
#include <net/downloader.h> | |
.. code-block:: C | |
#include <net/downloader.h> |
* Remove: | ||
|
||
.. code-block:: C | ||
static struct download_client dlc; | ||
static int callback(const struct download_client_evt *event); | ||
download_client_init(&dlc, callback) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Remove: | |
.. code-block:: C | |
static struct download_client dlc; | |
static int callback(const struct download_client_evt *event); | |
download_client_init(&dlc, callback) | |
* Remove: | |
.. code-block:: C | |
static struct download_client dlc; | |
static int callback(const struct download_client_evt *event); | |
download_client_init(&dlc, callback) |
* Remove: | ||
|
||
.. code-block:: C | ||
int err; | ||
const struct download_client_cfg dlc_config = { | ||
... | ||
}; | ||
err = download_client_set_host(&dlc, dl_host, &dlc_config); | ||
err = download_client_start(&dlc, dl_file, offset); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Remove: | |
.. code-block:: C | |
int err; | |
const struct download_client_cfg dlc_config = { | |
... | |
}; | |
err = download_client_set_host(&dlc, dl_host, &dlc_config); | |
err = download_client_start(&dlc, dl_file, offset); | |
* Remove: | |
.. code-block:: C | |
int err; | |
const struct download_client_cfg dlc_config = { | |
... | |
}; | |
err = download_client_set_host(&dlc, dl_host, &dlc_config); | |
err = download_client_start(&dlc, dl_file, offset); |
* Add: | ||
|
||
.. code-block:: C | ||
/* Note: All configuration of the downloader is done through the config structs. | ||
* The downloader struct should not be modified by the application. | ||
*/ | ||
static struct downloader_host_cfg host_config = { | ||
... | ||
/* Note: | ||
* .frag_size_override is replaced by .range_override. | ||
* .set_tls_hostname is replaced by .set_native_tls. | ||
* dlc.close_when_done is moved here and inverted(.keep_connection). | ||
* Set .cid if CONFIG_DOWNLOAD_CLIENT_CID was enabled in download client. | ||
*/ | ||
}; | ||
int err = downloader_get_with_host_and_path(&dl, &host_config, dl_host, dl_file, offset); | ||
.. note:: The new downloader has an API to download the file using the URI directly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Add: | |
.. code-block:: C | |
/* Note: All configuration of the downloader is done through the config structs. | |
* The downloader struct should not be modified by the application. | |
*/ | |
static struct downloader_host_cfg host_config = { | |
... | |
/* Note: | |
* .frag_size_override is replaced by .range_override. | |
* .set_tls_hostname is replaced by .set_native_tls. | |
* dlc.close_when_done is moved here and inverted(.keep_connection). | |
* Set .cid if CONFIG_DOWNLOAD_CLIENT_CID was enabled in download client. | |
*/ | |
}; | |
int err = downloader_get_with_host_and_path(&dl, &host_config, dl_host, dl_file, offset); | |
.. note:: The new downloader has an API to download the file using the URI directly. | |
* Add: | |
.. code-block:: C | |
/* Note: All configuration of the downloader is done through the config structs. | |
* The downloader struct should not be modified by the application. | |
*/ | |
static struct downloader_host_cfg host_config = { | |
... | |
/* Note: | |
* .frag_size_override is replaced by .range_override. | |
* .set_tls_hostname is replaced by .set_native_tls. | |
* dlc.close_when_done is moved here and inverted(.keep_connection). | |
* Set .cid if CONFIG_DOWNLOAD_CLIENT_CID was enabled in download client. | |
*/ | |
}; | |
int err = downloader_get_with_host_and_path(&dl, &host_config, dl_host, dl_file, offset); | |
.. note:: | |
The new downloader has an API to download the file using the URI directly. |
* Add: | ||
|
||
.. code-block:: C | ||
err = downloader_deinit(&dl); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* Add: | |
.. code-block:: C | |
err = downloader_deinit(&dl); | |
* Add: | |
.. code-block:: C | |
err = downloader_deinit(&dl); |
@@ -3512,7 +3512,7 @@ Jobs not received after reset | |||
|
|||
.. rst-class:: v2-6-2 v2-6-1 v2-6-0 v2-5-3 v2-5-2 v2-5-1 v2-5-0 | |||
|
|||
NCSDK-24305: fota_download library sends FOTA_DOWNLOAD_EVT_FINISHED when unable to connect | |||
NCSDK-24305: fota_download and fota_download libraries sends FOTA_DOWNLOAD_EVT_FINISHED and FOTA_DOWNLOAD_EVT_FINISHED events, respectively, when unable to connect |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why 2 entries for the same library and same event? Isn't this about the FOTA download library that is not changed as part of the PR?
@@ -3521,9 +3521,9 @@ NCSDK-24305: fota_download library sends FOTA_DOWNLOAD_EVT_FINISHED when unable | |||
.. rst-class:: v1-1-0 | |||
|
|||
Stalled download | |||
:ref:`lib_fota_download` does not resume a download if the device loses the connection. | |||
:ref:`lib_fota_download` and :ref:`lib_fota_download` does not resume a download if the device loses the connection. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why 2 entries for the same library? Isn't this about the FOTA download library that is not changed as part of the PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, I missed to review this file during the initial review. Also, line nos: 3501, 3502, and 3516 would require an update to :ref:lib_downloader
, which mentions :ref:lib_download_client
.
|
||
**Workaround:** Call :cpp:func:`fota_download_start` again with the same arguments when the connection is re-established to resume the download. | ||
**Workaround:** Call :cpp:func:`fota_download_start` or :cpp:func:`fota_download_start` again with the same arguments when the connection is re-established to resume the download. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicate entry for the same function
doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst
Outdated
Show resolved
Hide resolved
doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst
Outdated
Show resolved
Hide resolved
doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst
Outdated
Show resolved
Hide resolved
aee34a9
to
8f2d185
Compare
doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst
Outdated
Show resolved
Hide resolved
doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst
Outdated
Show resolved
Hide resolved
doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst
Outdated
Show resolved
Hide resolved
ad19a95
to
8441121
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very good job, Eivind. First round of comments, a lot more to come.
|
||
#include "dl_parse.h" | ||
|
||
static int swallow(const char **str, const char *swallow) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest trim
(or strip
), I had to go into the code to see what it actually does because it wasn't obvious from the name. Also, generally not recommended to have names that shadow each other (the function swallow
and the parameter swallow
in the same scope) even though the compiler can figure it out.
static int swallow(const char **str, const char *swallow) | |
static int trim(const char **str, const char *substr) |
{ | ||
switch (state) { | ||
case DOWNLOADER_IDLE: | ||
return "IDLE"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use the Zephyr macro STRINGIFY
here instead of hardcoding a string, same for the other ones.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, though I would like to avoid logging the full name. For some logs there are multiple states in the same line, so it will be quite long.
} | ||
} | ||
|
||
int downloader_init(struct downloader *const dl, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
int downloader_init(struct downloader *const dl, | |
int downloader_init(struct downloader *const dl, struct downloader_cfg *config) |
/* The thread is spawned now, but it will suspend itself; | ||
* it is resumed when the download is started via the API. | ||
*/ | ||
dl->tid = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strange line formatting here.
return 0; | ||
} | ||
|
||
int downloader_deinit(struct downloader *const dl) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if we pass an uninitialized downloader?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question, I've added some checks for the state, event_sem and thread to be set.
int downloader_cancel(struct downloader *const dl) | ||
{ | ||
if (dl == NULL || | ||
is_state(dl, DOWNLOADER_IDLE) || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to be explicit about which states are permitted rather than the opposite. From looking at the code here I wouldn't know which states are permitted and would have to see the list of all states and eliminate the ones here. Also, this permits the state DOWNLOADER_STOPPING
to be canceled, which seems strange. If it's on purpose, why?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
{ | ||
int rc; | ||
|
||
if (dl == NULL || uri == NULL) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
host_config
not checked. Yes, it's checked later in downloader_start
but now you have coupling between the two functions.
return -EINVAL; | ||
} | ||
|
||
k_mutex_lock(&dl->mutex, K_FOREVER); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On one hand host_config
is not checked because it's done in downloader_start
, but then the same should apply to the mutex lock: there is no need to lock here because it is locked inside downloader_start
. I think that this lock/unlock can be removed.
return rc; | ||
} | ||
|
||
int downloader_get_with_host_and_path(struct downloader *dl, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
host_and_file
perhaps since the other argument is file
?
return -EINVAL; | ||
} | ||
|
||
sprintf(dl->config.buf, "%s/%s", host, file); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would prefer the more secure snprintf
.
8441121
to
effe299
Compare
@@ -56,7 +55,9 @@ SHELL_STATIC_SUBCMD_SET_CREATE( | |||
sub_fota, | |||
SHELL_CMD_ARG( | |||
download, NULL, | |||
"<server> <filename>\nDownload and install a FOTA update. Available servers are \"eu\", \"us\", \"jpn\" and \"au\".", | |||
"[<server> <filename>]\nDownload and install a FOTA update. " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"[<server> <filename>]\nDownload and install a FOTA update. " | |
"<server> <filename>\nDownload and install a FOTA update. " |
53bde3d
to
9b9b914
Compare
@@ -3520,7 +3520,7 @@ Jobs not received after reset | |||
.. rst-class:: v2-6-2 v2-6-1 v2-6-0 v2-5-3 v2-5-2 v2-5-1 v2-5-0 | |||
|
|||
NCSDK-24305: fota_download library sends FOTA_DOWNLOAD_EVT_FINISHED when unable to connect | |||
The :ref:`lib_download_client` library does not resume a download if the device cannot connect to a target server. | |||
The :ref:`lib_download_client` and :ref:`lib_downloader` libraries does not resume a download if the device cannot connect to a target server. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The :ref:`lib_download_client` and :ref:`lib_downloader` libraries does not resume a download if the device cannot connect to a target server. | |
The :ref:`lib_download_client` and :ref:`lib_downloader` libraries do not resume a download if the device cannot connect to a target server. |
@@ -38,7 +38,7 @@ HTTPS downloads | |||
The FOTA download library is used in the :ref:`http_application_update_sample` sample. | |||
|
|||
By default, the FOTA download library uses HTTP for downloading the firmware file. | |||
To use HTTPS, apply the changes described in :ref:`the HTTPS section of the download client documentation <download_client_https>` to the library. | |||
To use HTTPS, apply the changes described in :ref:`the HTTPS section of the download client documentation <downloader_https>` to the library. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To use HTTPS, apply the changes described in :ref:`the HTTPS section of the download client documentation <downloader_https>` to the library. | |
To use HTTPS, apply the changes described in :ref:`the HTTPS section of the Downloader library documentation <downloader_https>` to the library. |
.. note:: | ||
The new downloader has an API to download the file using the URI directly. | ||
|
||
#. [optional] Deinitlaize the downloader after use: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#. [optional] Deinitlaize the downloader after use: | |
#. [optional] Deinitialize the downloader after use: |
@@ -3520,7 +3520,7 @@ Jobs not received after reset | |||
.. rst-class:: v2-6-2 v2-6-1 v2-6-0 v2-5-3 v2-5-2 v2-5-1 v2-5-0 | |||
|
|||
NCSDK-24305: fota_download library sends FOTA_DOWNLOAD_EVT_FINISHED when unable to connect | |||
The :ref:`lib_download_client` library does not resume a download if the device cannot connect to a target server. | |||
The :ref:`lib_download_client` and :ref:`lib_downloader` libraries does not resume a download if the device cannot connect to a target server. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The :ref:`lib_download_client` and :ref:`lib_downloader` libraries does not resume a download if the device cannot connect to a target server. | |
The :ref:`lib_download_client` and :ref:`lib_downloader` libraries do not resume a download if the device cannot connect to a target server. |
@@ -3505,10 +3505,10 @@ NCSDK-11432: DFU: Erasing secondary slot returns error response | |||
.. rst-class:: v1-7-1 v1-7-0 v1-6-1 v1-6-0 v1-5-2 v1-5-1 v1-5-0 v1-4-2 v1-4-1 v1-4-0 | |||
|
|||
NCSDK-6238: Socket API calls might hang when using Download client | |||
When using the :ref:`lib_download_client` library with HTTP (without TLS), the application might not process incoming fragments fast enough, which can starve the :ref:`nrfxlib:nrf_modem` buffers and make calls to the Modem library hang. | |||
When using the :ref:`lib_download_client` and :ref:`lib_downloader` libraries with HTTP (without TLS), the application might not process incoming fragments fast enough, which can starve the :ref:`nrfxlib:nrf_modem` buffers and make calls to the Modem library hang. | |||
Samples and applications that are affected include those that use :ref:`lib_download_client` to download files through HTTP, or those that use :ref:`lib_fota_download` with modem updates enabled. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Samples and applications that are affected include those that use :ref:`lib_download_client` to download files through HTTP, or those that use :ref:`lib_fota_download` with modem updates enabled. | |
Samples and applications that are affected include those that use :ref:`lib_download_client` and :ref:`lib_downloader` libraries to download files through HTTP, or those that use :ref:`lib_fota_download` with modem updates enabled. |
Samples and applications that are affected include those that use :ref:`lib_download_client` to download files through HTTP, or those that use :ref:`lib_fota_download` with modem updates enabled. | ||
|
||
**Workaround:** Set :kconfig:option:`CONFIG_DOWNLOAD_CLIENT_RANGE_REQUESTS`. | ||
**Workaround:** Set :kconfig:option:`CONFIG_DOWNLOAD_CLIENT_RANGE_REQUESTS` with the :ref:`lib_download_client` library. Set ``range_override`` in :c:struct:`downloader_host_cfg` with the :ref:`lib_downloader` library. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
**Workaround:** Set :kconfig:option:`CONFIG_DOWNLOAD_CLIENT_RANGE_REQUESTS` with the :ref:`lib_download_client` library. Set ``range_override`` in :c:struct:`downloader_host_cfg` with the :ref:`lib_downloader` library. | |
**Workaround:** Set :kconfig:option:`CONFIG_DOWNLOAD_CLIENT_RANGE_REQUESTS` for the :ref:`lib_download_client` library. | |
Set ``range_override`` in :c:struct:`downloader_host_cfg` for the :ref:`lib_downloader` library. |
9b9b914
to
670cb2d
Compare
REQUIRED = 2, | ||
}; | ||
|
||
verify = REQUIRED; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The size of enum is system dependent, I would stick to int
which is the type expected by setsockopt
.
Instead use:
int verify = TLS_PEER_VERIFY_REQUIRED
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, updated.
return 0; | ||
} | ||
|
||
static int socket_tls_hostname_set(int fd, const char * const host) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static int socket_tls_hostname_set(int fd, const char * const host) | |
static int socket_tls_hostname_set(int fd, const char * const hostname) |
For consistency since there are other functions that have a hostname parameter named hostname
.
if (err) { | ||
err = -errno; | ||
/* Make sure that ECONNRESET is not returned as it has a special meaning | ||
* in the download client API |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps?
* in the download client API | |
* in the downloader API |
return -EINVAL; | ||
} | ||
|
||
timeo.tv_sec = (timeout_ms / 1000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This logic is shared with send_timeout_set
, maybe it can be abstracted?
*/ | ||
|
||
BUILD_ASSERT( | ||
STACK_SIZE - (HOSTNAME_SIZE + FILENAME_SIZE) >= 512, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this 512 defined somewhere?
} | ||
|
||
static int cmd_host_config_sec_tag(const struct shell *shell, size_t argc, | ||
char **argv) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting
} | ||
|
||
static int cmd_host_config_pdn_id(const struct shell *shell, size_t argc, | ||
char **argv) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Formatting
SHELL_STATIC_SUBCMD_SET_CREATE(host_config_options, | ||
SHELL_CMD(sec_tag, NULL, "Set security tag", cmd_host_config_sec_tag), | ||
SHELL_CMD(pdn_id, NULL, "Set PDN ID", cmd_host_config_pdn_id), | ||
SHELL_CMD(sec_tag, NULL, "Set security tag", cmd_host_config_sec_tag), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This appears twice
|
||
static int dl_callback(const struct downloader_evt *event); | ||
|
||
static char dl_buf[2048]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment on the 2048 here too like in transports/http.c
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is not the same.
http->sock.proto = IPPROTO_TCP; | ||
http->sock.type = SOCK_STREAM; | ||
|
||
if (strncmp(uri, "https://", 8) == 0 || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
strlen
|
||
static bool dl_http_proto_supported(struct downloader *dl, const char *uri) | ||
{ | ||
if (strncmp(uri, "https://", 8) == 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two strings and their length are used in multiple places, I would define them at the top and use strlen
.
* Length of data payload left to process on success | ||
* Negative errno on error. | ||
*/ | ||
static int http_parse(struct downloader *dl, size_t len) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you checked if there is already an http parser in Zephyr?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is, I'll leave it as a future task to see if that can be used.
https://docs.zephyrproject.org/apidoc/latest/parser_8h.html
return -EBADMSG; | ||
} | ||
|
||
expected_status = (http->ranged || dl->progress) ? 206 : 200; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These two http status codes can be defined too, mostly for their name/use. For example, I know from the top of my head that 200 is success, but don't remember 206.
if (err) { | ||
switch (http->sock.proto) { | ||
case IPPROTO_TLS_1_2: | ||
http->sock.port = 443; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would define these two too
12781ef
to
2db381f
Compare
The new downloader is replacing the download_client library and is based on that. Internal restructuring: * Restructuring of socket functions and files. * Parse HTTP header line for line. This reduces the size requirement for the download client recv buffer. * Change TLS range override logic. * Use range requests for nRF91 TLS only, and when specified by app. API updates: * Let application provide client buffer. This allows for multiple download clients with different buffer sizes. * Add downloader_deinit() * Add downloader_stop() * Remove downloader_disconnect() * Changed signature of downloader_init(), downloader_start() and downloader_get() to take a URI. * Added downloader_get_with_host_and_path() for downloads where host and path are separate arguments to keep backwards compatibility. * The transports (http, coap) are now separated out of the download client with its own API. Future work: * Take uri as input param to fota_download library and use URI in other relevant libaries and structures. * Curent download client is deprecated and will be removed later. Signed-off-by: Eivind Jølsgard <[email protected]>
2db381f
to
761cfb8
Compare
Work in progress. No need for thorough review yet.
TODOs