]> git.meshlink.io Git - meshlink/blobdiff - src/meshlink.c
Find first available descriptor in bit array
[meshlink] / src / meshlink.c
index e5982721d533aadd2cafb8e775f6dcb7b1555916..538a9e5c5d84440b8f39531db92a94ee4216b644 100644 (file)
@@ -1370,6 +1370,28 @@ void meshlink_blacklist(meshlink_handle_t *mesh, meshlink_node_t *node) {
 
 }
 
+meshlink_connection_t* meshlink_open_rchannel(meshlink_handle_t *mesh, meshlink_node_t *destination, uint16_t dport) {
+
+//TODO: check in mesh->socketsbitmap for a free descriptor and allocate a source port for this connection
+
+       int descriptor=-1;
+
+       for (int i=0; i < 1024 ;i++) {
+               if (mesh->socketsbitmap.bitValues[i].bit == 0) {
+                       mesh->socketsbitmap.bitValues[i].bit=1;
+                       descriptor=i;
+                       break;
+               }
+       }
+
+       if (descriptor == -1 ) return NULL;
+
+//TODO: register a callback for the data that will be received from this connection
+
+//TODO: return a description value that the user will use to write on this channel
+
+}
+
 static void __attribute__((constructor)) meshlink_init(void) {
        crypto_init();
 }