]> git.seodisparate.com - UDPConnection/commitdiff
Set pointers to const where possible in API
authorStephen Seo <seo.disparate@gmail.com>
Fri, 10 Jan 2020 11:28:08 +0000 (20:28 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Fri, 10 Jan 2020 11:28:08 +0000 (20:28 +0900)
src/UDPC.h
src/UDPC_Defines.hpp
src/UDPConnection.cpp

index 903a03938f91d40ce03ab954965dd1ad201996a6..2cb9952ce7775f635b87c2b9b2511628c45ed714 100644 (file)
@@ -446,7 +446,7 @@ void UDPC_client_initiate_connection(
  * \param size The size in bytes of the data to be sent
  */
 void UDPC_queue_send(UDPC_HContext ctx, UDPC_ConnectionId destinationId,
-                     int isChecked, void *data, uint32_t size);
+                     int isChecked, const void *data, uint32_t size);
 
 /*!
  * \brief Gets the size of the data structure holding queued packets
@@ -475,6 +475,11 @@ unsigned long UDPC_get_queue_send_current_size(UDPC_HContext ctx);
  * UDPC_update() will lock this mutex, regardless of whether or not the context
  * is using threaded update).
  *
+ * If \p exists is a non-null pointer to an \p int, and a connection to a peer
+ * identified by \p id exists, then the value of \p exists will be set to
+ * non-zero, otherwise a non-existing peer will set the value of \p exists to
+ * zero.
+ *
  * \return The size of a connection's queue
  */
 unsigned long UDPC_get_queued_size(UDPC_HContext ctx, UDPC_ConnectionId id, int *exists);
@@ -625,15 +630,15 @@ UDPC_Event UDPC_get_event(UDPC_HContext ctx, unsigned long *remaining);
 
 UDPC_PacketInfo UDPC_get_received(UDPC_HContext ctx, unsigned long *remaining);
 
-int UDPC_set_libsodium_keys(UDPC_HContext ctx, unsigned char *sk, unsigned char *pk);
+int UDPC_set_libsodium_keys(UDPC_HContext ctx, const unsigned char *sk, const unsigned char *pk);
 
-int UDPC_set_libsodium_key_easy(UDPC_HContext ctx, unsigned char *sk);
+int UDPC_set_libsodium_key_easy(UDPC_HContext ctx, const unsigned char *sk);
 
 int UDPC_unset_libsodium_keys(UDPC_HContext ctx);
 
-int UDPC_add_whitelist_pk(UDPC_HContext ctx, unsigned char *pk);
-int UDPC_has_whitelist_pk(UDPC_HContext ctx, unsigned char *pk);
-int UDPC_remove_whitelist_pk(UDPC_HContext ctx, unsigned char *pk);
+int UDPC_add_whitelist_pk(UDPC_HContext ctx, const unsigned char *pk);
+int UDPC_has_whitelist_pk(UDPC_HContext ctx, const unsigned char *pk);
+int UDPC_remove_whitelist_pk(UDPC_HContext ctx, const unsigned char *pk);
 int UDPC_clear_whitelist(UDPC_HContext ctx);
 
 int UDPC_get_auth_policy(UDPC_HContext ctx);
index 368434ea21c5bc2b1fac19d644780cf956bf6b08..e43d1898abd90005fc4a37476553474439511e14 100644 (file)
@@ -84,7 +84,7 @@ struct IPV6_Hasher {
 
 struct PKContainer {
     PKContainer();
-    PKContainer(unsigned char *pk);
+    PKContainer(const unsigned char *pk);
 
     unsigned char pk[crypto_sign_PUBLICKEYBYTES];
 
index f0bb9811262b182d5cbef094a63ee22a3c25d030..01055b05745b7e6bb5ac924a669405b7bf5d4548 100644 (file)
@@ -69,7 +69,7 @@ UDPC::PKContainer::PKContainer() {
     std::memset(pk, 0, crypto_sign_PUBLICKEYBYTES);
 }
 
-UDPC::PKContainer::PKContainer(unsigned char *pk) {
+UDPC::PKContainer::PKContainer(const unsigned char *pk) {
     std::memcpy(this->pk, pk, crypto_sign_PUBLICKEYBYTES);
 }
 
@@ -2117,7 +2117,7 @@ void UDPC_client_initiate_connection(
 }
 
 void UDPC_queue_send(UDPC_HContext ctx, UDPC_ConnectionId destinationId,
-                     int isChecked, void *data, uint32_t size) {
+                     int isChecked, const void *data, uint32_t size) {
     if(size == 0 || !data) {
         return;
     }
@@ -2325,7 +2325,7 @@ UDPC_PacketInfo UDPC_get_received(UDPC_HContext ctx, unsigned long *remaining) {
     }
 }
 
-int UDPC_set_libsodium_keys(UDPC_HContext ctx, unsigned char *sk, unsigned char *pk) {
+int UDPC_set_libsodium_keys(UDPC_HContext ctx, const unsigned char *sk, const unsigned char *pk) {
     UDPC::Context *c = UDPC::verifyContext(ctx);
     if(!c || !c->flags.test(2)) {
         return 0;
@@ -2338,7 +2338,7 @@ int UDPC_set_libsodium_keys(UDPC_HContext ctx, unsigned char *sk, unsigned char
     return 1;
 }
 
-int UDPC_set_libsodium_key_easy(UDPC_HContext ctx, unsigned char *sk) {
+int UDPC_set_libsodium_key_easy(UDPC_HContext ctx, const unsigned char *sk) {
     unsigned char pk[crypto_sign_PUBLICKEYBYTES];
     if(crypto_sign_ed25519_sk_to_pk(pk, sk) != 0) {
         return 0;
@@ -2358,7 +2358,7 @@ int UDPC_unset_libsodium_keys(UDPC_HContext ctx) {
     return 1;
 }
 
-int UDPC_add_whitelist_pk(UDPC_HContext ctx, unsigned char *pk) {
+int UDPC_add_whitelist_pk(UDPC_HContext ctx, const unsigned char *pk) {
     UDPC::Context *c = UDPC::verifyContext(ctx);
     if(!c || !c->flags.test(2)) {
         return 0;
@@ -2372,7 +2372,7 @@ int UDPC_add_whitelist_pk(UDPC_HContext ctx, unsigned char *pk) {
     return 0;
 }
 
-int UDPC_has_whitelist_pk(UDPC_HContext ctx, unsigned char *pk) {
+int UDPC_has_whitelist_pk(UDPC_HContext ctx, const unsigned char *pk) {
     UDPC::Context *c = UDPC::verifyContext(ctx);
     if(!c || !c->flags.test(2)) {
         return 0;
@@ -2385,7 +2385,7 @@ int UDPC_has_whitelist_pk(UDPC_HContext ctx, unsigned char *pk) {
     return 0;
 }
 
-int UDPC_remove_whitelist_pk(UDPC_HContext ctx, unsigned char *pk) {
+int UDPC_remove_whitelist_pk(UDPC_HContext ctx, const unsigned char *pk) {
     UDPC::Context *c = UDPC::verifyContext(ctx);
     if(!c || !c->flags.test(2)) {
         return 0;