Skip to content

Commit

Permalink
Merge pull request #13502 from aabadie/pr/examples/wolfssl_cleanup
Browse files Browse the repository at this point in the history
examples/dtls-wolfssl: cleanup output messages
  • Loading branch information
MichelRottleuthner authored Mar 2, 2020
2 parents 4e92126 + 7da87a7 commit 0611920
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
14 changes: 7 additions & 7 deletions examples/dtls-wolfssl/dtls-client.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,20 @@ int dtls_client(int argc, char **argv)
else {
gnrc_netif_t *netif = gnrc_netif_get_by_pid(atoi(iface));
if (netif == NULL) {
LOG(LOG_ERROR, "ERROR: interface not valid");
LOG(LOG_ERROR, "ERROR: interface not valid\n");
usage(argv[0]);
return -1;
}
remote.netif = (uint16_t)netif->pid;
}
if (ipv6_addr_from_str((ipv6_addr_t *)remote.addr.ipv6, addr_str) == NULL) {
LOG(LOG_ERROR, "ERROR: unable to parse destination address");
LOG(LOG_ERROR, "ERROR: unable to parse destination address\n");
usage(argv[0]);
return -1;
}
remote.port = SERVER_PORT;
if (sock_dtls_create(sk, &local, &remote, 0, wolfDTLSv1_2_client_method()) != 0) {
LOG(LOG_ERROR, "ERROR: Unable to create DTLS sock");
LOG(LOG_ERROR, "ERROR: Unable to create DTLS sock\n");
return -1;
}

Expand All @@ -147,7 +147,7 @@ int dtls_client(int argc, char **argv)
if (sock_dtls_session_create(sk) < 0)
return -1;
wolfSSL_dtls_set_timeout_init(sk->ssl, 5);
LOG(LOG_INFO, "connecting to server...");
LOG(LOG_INFO, "connecting to server...\n");
/* attempt to connect until the connection is successful */
do {
ret = wolfSSL_connect(sk->ssl);
Expand Down Expand Up @@ -179,13 +179,13 @@ int dtls_client(int argc, char **argv)
/* wait for a reply, indefinitely */
do {
ret = wolfSSL_read(sk->ssl, buf, APP_DTLS_BUF_SIZE - 1);
LOG(LOG_INFO, "wolfSSL_read returned %d\r\n", ret);
LOG(LOG_INFO, "wolfSSL_read returned %d\n", ret);
} while (ret <= 0);
buf[ret] = (char)0;
LOG(LOG_INFO, "Received: '%s'\r\n", buf);
LOG(LOG_INFO, "Received: '%s'\n", buf);

/* Clean up and exit. */
LOG(LOG_INFO, "Closing connection.\r\n");
LOG(LOG_INFO, "Closing connection.\n");
sock_dtls_session_destroy(sk);
sock_dtls_close(sk);
return 0;
Expand Down
16 changes: 8 additions & 8 deletions examples/dtls-wolfssl/dtls-server.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ int dtls_server(int argc, char **argv)
(void)argv;

if (sock_dtls_create(sk, &local, NULL, 0, wolfDTLSv1_2_server_method()) != 0) {
LOG(LOG_ERROR, "ERROR: Unable to create DTLS sock\r\n");
LOG(LOG_ERROR, "ERROR: Unable to create DTLS sock\n");
return -1;
}

Expand All @@ -103,15 +103,15 @@ int dtls_server(int argc, char **argv)
if (wolfSSL_CTX_use_certificate_buffer(sk->ctx, server_cert,
server_cert_len, SSL_FILETYPE_ASN1 ) != SSL_SUCCESS)
{
LOG(LOG_ERROR, "Failed to load certificate from memory.\r\n");
LOG(LOG_ERROR, "Failed to load certificate from memory.\n");
return -1;
}

/* Load the private key */
if (wolfSSL_CTX_use_PrivateKey_buffer(sk->ctx, server_key,
server_key_len, SSL_FILETYPE_ASN1 ) != SSL_SUCCESS)
{
LOG(LOG_ERROR, "Failed to load private key from memory.\r\n");
LOG(LOG_ERROR, "Failed to load private key from memory.\n");
return -1;
}
#else
Expand All @@ -123,7 +123,7 @@ int dtls_server(int argc, char **argv)
ret = sock_dtls_session_create(sk);
if (ret < 0)
{
LOG(LOG_ERROR, "Failed to create DTLS session (err: %s)\r\n", strerror(-ret));
LOG(LOG_ERROR, "Failed to create DTLS session (err: %s)\n", strerror(-ret));
return -1;
}

Expand All @@ -141,19 +141,19 @@ int dtls_server(int argc, char **argv)
}

/* Wait until data is received */
LOG(LOG_INFO, "Connection accepted\r\n");
LOG(LOG_INFO, "Connection accepted\n");
ret = wolfSSL_read(sk->ssl, buf, APP_DTLS_BUF_SIZE);
if (ret > 0) {
buf[ret] = (char)0;
LOG(LOG_INFO, "Received '%s'\r\n", buf);
LOG(LOG_INFO, "Received '%s'\n", buf);
}

/* Send reply */
LOG(LOG_INFO, "Sending 'DTLS OK'...\r\n");
LOG(LOG_INFO, "Sending 'DTLS OK'...\n");
wolfSSL_write(sk->ssl, Test_dtls_string, sizeof(Test_dtls_string));

/* Cleanup/shutdown */
LOG(LOG_INFO, "Closing connection.\r\n");
LOG(LOG_INFO, "Closing connection.\n");
sock_dtls_session_destroy(sk);
sock_dtls_close(sk);
break;
Expand Down
4 changes: 2 additions & 2 deletions examples/dtls-wolfssl/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,12 @@ int main(void)
/* we need a message queue for the thread running the shell in order to
* receive potentially fast incoming networking packets */
msg_init_queue(_main_msg_queue, MAIN_QUEUE_SIZE);
LOG(LOG_INFO, "RIOT wolfSSL DTLS testing implementation");
LOG(LOG_INFO, "RIOT wolfSSL DTLS testing implementation\n");
wolfSSL_Init();
wolfSSL_Debugging_ON();

/* start shell */
LOG(LOG_INFO, "All up, running the shell now");
LOG(LOG_INFO, "All up, running the shell now\n");
char line_buf[SHELL_DEFAULT_BUFSIZE];
shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);

Expand Down

0 comments on commit 0611920

Please sign in to comment.