-
Notifications
You must be signed in to change notification settings - Fork 7k
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
Net app API #540
Net app API #540
Conversation
If we're doing this to simplify things:
|
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 there are rooms for improving net_context API first, this current attempt of an extra layer on top of net_context is not as simple as it could
For instance:
-
net_context's callbacks. The pb with those is the stack they are ran from: net's one. We could maybe move towards using kpoll objects (actually net_context was designed long before this objects appeared)..
It would also simplify a lot of things for the BSD socket layer I think. (it would not save or bloat memory though I think) -
tx_slab/data_pool: I think we will need to work on smarter buffer handling, this really needs to go away at some point.
About @lpereira's comment on type/protocol, I disagree: the base function should ask for both. But starting from that idea: nothing prevents the api to expose some dedicated and simple inline function such as net_app_init_tcp_server() or net_app_init_udp_client() etc...
include/net/net_app.h
Outdated
struct sockaddr *server_addr, | ||
u16_t port, | ||
net_pkt_get_slab_func_t tx_slab, | ||
net_pkt_get_pool_func_t data_pool, |
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.
Not sure we want to expose this tx_slab/data_pool thingy. It's very low level stuff, and in the future (hopefully) we will be able to get rid of it completely. So imo it should stay on net_context side for those who really need it, but not exposed on net_app.h
include/net/net_app.h
Outdated
u16_t peer_port, | ||
s32_t timeout, | ||
net_pkt_get_slab_func_t tx_slab, | ||
net_pkt_get_pool_func_t data_pool, |
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.
same here
include/net/net_app.h
Outdated
}; | ||
|
||
/** Network application context. */ | ||
struct net_app_ctx { |
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.
A context on top of another context. Maybe simplifying net_context first would be wiser.
Adding this net_app_init() is a good idea to simplify the examples. I wonder if we could go even one step further and have this initialization happen during boot-up automatically, say, during pre-application initialization? Something like:
perhaps its parameters can be added as Kconfig options? That way, it will hide this common initialization from all the examples, and the function call could be completely removed from all the net (and new socket) samples. Looking at the new BSD socket_echo.c example (#498), the only non-standard bit of code (other than the headers) keeping it from being a portable BSD socket app is that bit of Zephyr-specific initialization code (init_net()). Hiding the initialization could be another small step to help future porting of third party BSD socket apps and protocols to Zephyr. |
@GAnthony : Right, it's about the same idea I shared on mailing list in response to the RFC behind this patch: https://lists.zephyrproject.org/pipermail/zephyr-devel/2017-June/007799.html |
@pfalcon: Ah, yes, thanks for pointing that out. I must have overlooked that part of the email thread. In any case, I agree it would help simplify the apps to somehow hide that initialization. |
New version uploaded.
|
ef9454e
to
3612bf5
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.
include/net/net_app.h
Outdated
* | ||
* @return 0 if ok, <0 if error. | ||
*/ | ||
int net_app_wait_connection(struct net_app_ctx *ctx); |
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.
Maybe a nitpick, but from the name or a description of this function, it's not clear whether this really waits for connection (blocks until it happens), or whether it starts to listen for connections (non-blocking). Name suggests that it really waits, though description leans towards starting to listen. If so, why not call this func e.g. net_app_listen() ?
ret = net_app_init("Initializing network", flags, | ||
K_SECONDS(CONFIG_NET_APP_INIT_TIMEOUT)); | ||
if (ret < 0) { | ||
NET_ERR("Network initialization failed (%d)", ret); |
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'd suggest to make this printk() and k_panic(), to make sure this cannot be missed, regardless of logging options.
client_or_server == MBEDTLS_SSL_IS_CLIENT ? "client" : | ||
"server"); | ||
|
||
exit: |
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.
We probably need to call mbedtls_ssl_free(), mbedtls_ssl_config_free(), mbedtls_ctr_drbg_free(), and mbedtls_entropy_free() if something goes wrong.
Sent a new version. Changes:
|
The network application API is a higher level API for creating client and server type applications. Instead of applications dealing with low level details, the network application API provides services that most of the applications can use directly. This commit removes the internal net_sample_*() API and converts the existing users of it to use the new net_app API. Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit will convert echo-server to use the net app API when creating the listening service. Most of the network setup code will be removed from echo-server by this commit. Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This commit will convert echo-client to use the net app API when creating the connection to peer. Most of the network setup code will be removed from echo-client by this commit. Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Removing CONFIG_NET_APP_SETTINGS from prj.conf file as the sample does not use or need any IP addresses. Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
As the net app API is automatically initialized, there is no need to call net_app_init() by the http client and server sample applications. Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Next two commits will increase the mbedtls ram usage a bit and https client and server sample test will fail. Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Add Kconfig option that can be used to enable various debug options in mbedtls config file. Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
This changes increases content buffer length MBEDTLS_SSL_MAX_CONTENT_LEN to 1500 bytes so that we can use this config for echo-client and echo-server network sample applications which need to send bigger data than 1024 bytes. Removing MBEDTLS_PEM_PARSE_C as we do not have any cert in PEM format. Place various MBEDTLS debug options behind CONFIG_MBEDTLS_DEBUG Kconfig option which was introduced in previous commit. Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
Getting past shippable seems to be tricky for this PR. I sent a new version:
|
There has been discussion and complaints that the current net_context API that applications can use is too low level and requires lot of effort from application developer to create a bug free application. Many networking operations that various applications do, are very similar and can be provided by a library. In order to address these issues I created a higher level API that applications can use.
The API consists of two parts:
Example for the TCP server:
Example for UDP server:
Example TCP client:
Example UDP client:
So the developer needs to setup the proper callbacks that will be called in various stages of the connection flow.
I created a TLS support for TCP server in this initial pull request. The TLS support is transparent to the application, all the encryption and decryption happens inside the net_app API. Only thing the application needs to do is to setup the TLS, and prepare the certificates for mbedtls library. With this transparent TLS support, it is possible to create for example MQTT over TLS support quite easily.
In order to try the TLS support, the net-tools project have this
zephyrproject-rtos/net-tools#8
PR that provides stunnel configuration so that echo-client can be run in Linux side and it can communicate with zephyr echo-server sample over TLS.
This net_app API will replace the internal net_sample_app API that was used by some of the network sample applications found under samples/net directory.
The current patchset contains these patches:
Future plans: