From 046ab3d4535bccc6637fe2587c5363056d327d97 Mon Sep 17 00:00:00 2001 From: Jeff Becker Date: Tue, 8 Jun 2021 08:32:01 -0400 Subject: [PATCH] export functions in liblokinet for win32 dll --- cmake/win32.cmake | 2 +- include/lokinet/lokinet_addr.h | 2 +- include/lokinet/lokinet_context.h | 16 ++++++----- include/lokinet/lokinet_export.h | 7 +++++ include/lokinet/lokinet_misc.h | 8 +++--- include/lokinet/lokinet_socket.h | 4 +-- include/lokinet/lokinet_srv.h | 6 ++--- include/lokinet/lokinet_stream.h | 6 ++--- include/lokinet/lokinet_udp.h | 8 +++--- llarp/lokinet_shared.cpp | 44 +++++++++++++------------------ 10 files changed, 52 insertions(+), 51 deletions(-) create mode 100644 include/lokinet/lokinet_export.h diff --git a/cmake/win32.cmake b/cmake/win32.cmake index 5ba95cf17..2a4af72a0 100644 --- a/cmake/win32.cmake +++ b/cmake/win32.cmake @@ -14,7 +14,7 @@ if(NOT MSVC_VERSION) # GNU ld sees fit to merge *all* the .ident sections in object files # to .r[o]data section one after the other! add_compile_options(-fno-ident -Wa,-mbig-obj) - link_libraries( -lws2_32 -lshlwapi -ldbghelp -luser32 -liphlpapi -lpsapi -luserenv ) + link_libraries( -lws2_32 -lshlwapi -ldbghelp -luser32 -liphlpapi -lpsapi -luserenv) # zmq requires windows xp or higher add_definitions(-DWINVER=0x0501 -D_WIN32_WINNT=0x0501) endif() diff --git a/include/lokinet/lokinet_addr.h b/include/lokinet/lokinet_addr.h index f3a5e3690..cd36fc2e6 100644 --- a/include/lokinet/lokinet_addr.h +++ b/include/lokinet/lokinet_addr.h @@ -8,7 +8,7 @@ extern "C" /// get a free()-able null terminated string that holds our .loki address /// returns NULL if we dont have one right now - char* + char* EXPORT lokinet_address(struct lokinet_context*); #ifdef __cplusplus } diff --git a/include/lokinet/lokinet_context.h b/include/lokinet/lokinet_context.h index a7f4b9b58..f3281e28c 100644 --- a/include/lokinet/lokinet_context.h +++ b/include/lokinet/lokinet_context.h @@ -1,5 +1,7 @@ #pragma once +#include "lokinet_export.h" + #include #include #include @@ -12,40 +14,40 @@ extern "C" struct lokinet_context; /// allocate a new lokinet context - struct lokinet_context* + struct lokinet_context* EXPORT lokinet_context_new(); /// free a context allocated by lokinet_context_new - void + void EXPORT lokinet_context_free(struct lokinet_context*); /// spawn all the threads needed for operation and start running /// return 0 on success /// return non zero on fail - int + int EXPORT lokinet_context_start(struct lokinet_context*); /// return 0 if we our endpoint has published on the network and is ready to send /// return -1 if we don't have enough paths ready /// retrun -2 if we look deadlocked /// retrun -3 if context was null or not started yet - int + int EXPORT lokinet_status(struct lokinet_context*); /// wait at most N milliseconds for lokinet to build paths and get ready /// return 0 if we are ready /// return nonzero if we are not ready - int + int EXPORT lokinet_wait_for_ready(int N, struct lokinet_context*); /// stop all operations on this lokinet context - void + void EXPORT lokinet_context_stop(struct lokinet_context*); /// load a bootstrap RC from memory /// return 0 on success /// return non zero on fail - int + int EXPORT lokinet_add_bootstrap_rc(const char*, size_t, struct lokinet_context*); #ifdef __cplusplus diff --git a/include/lokinet/lokinet_export.h b/include/lokinet/lokinet_export.h new file mode 100644 index 000000000..be0459994 --- /dev/null +++ b/include/lokinet/lokinet_export.h @@ -0,0 +1,7 @@ +#pragma once + +#ifdef _WIN32 +#define EXPORT __cdecl +#else +#define EXPORT +#endif diff --git a/include/lokinet/lokinet_misc.h b/include/lokinet/lokinet_misc.h index fde288997..dea41f9ba 100644 --- a/include/lokinet/lokinet_misc.h +++ b/include/lokinet/lokinet_misc.h @@ -1,24 +1,24 @@ #pragma once - +#include "lokinet_export.h" #ifdef __cplusplus extern "C" { #endif /// change our network id globally across all contexts - void + void EXPORT lokinet_set_netid(const char*); /// get our current netid /// must be free()'d after use - const char* + const char* EXPORT lokinet_get_netid(); /// set log level /// possible values: trace, debug, info, warn, error, none /// return 0 on success /// return non zero on fail - int + int EXPORT lokinet_log_level(const char*); #ifdef __cplusplus diff --git a/include/lokinet/lokinet_socket.h b/include/lokinet/lokinet_socket.h index 20d8d509a..f8aff201d 100644 --- a/include/lokinet/lokinet_socket.h +++ b/include/lokinet/lokinet_socket.h @@ -11,11 +11,11 @@ extern "C" /// poll many sockets for activity /// each pollfd.fd should be set to the socket id /// returns 0 on sucess - int + int EXPORT lokinet_poll(struct pollfd* poll, nfds_t numsockets, struct lokinet_context* ctx); /// close a udp socket or a stream socket by its id - void + void EXPORT lokinet_close_socket(int id, struct lokinet_context* ctx); #ifdef __cplusplus diff --git a/include/lokinet/lokinet_srv.h b/include/lokinet/lokinet_srv.h index 4827b6862..27110ab78 100644 --- a/include/lokinet/lokinet_srv.h +++ b/include/lokinet/lokinet_srv.h @@ -35,7 +35,7 @@ extern "C" /// do a srv lookup on host for service /// caller MUST call lokinet_srv_lookup_done when they are done handling the result - int + int EXPORT lokinet_srv_lookup( char* host, char* service, @@ -51,12 +51,12 @@ extern "C" /// iterate over each srv record in a lookup result /// user is passes into hook and called for each result and then with NULL as the result on the /// end of iteration - void + void EXPORT lokinet_for_each_srv_record( struct lokinet_srv_lookup_result* result, lokinet_srv_record_iterator iter, void* user); /// free internal members of a srv lookup result after use of the result - void + void EXPORT lokinet_srv_lookup_done(struct lokinet_srv_lookup_result* result); #ifdef __cplusplus diff --git a/include/lokinet/lokinet_stream.h b/include/lokinet/lokinet_stream.h index 0e1d9f039..d5d97754b 100644 --- a/include/lokinet/lokinet_stream.h +++ b/include/lokinet/lokinet_stream.h @@ -28,7 +28,7 @@ extern "C" /// connect out to a remote endpoint /// remoteAddr is in the form of "name:port" /// localAddr is either NULL for any or in the form of "ip:port" to bind to an explicit address - void + void EXPORT lokinet_outbound_stream( struct lokinet_stream_result* result, const char* remoteAddr, @@ -44,13 +44,13 @@ extern "C" /// set stream accepter filter /// passes user parameter into stream filter as void * /// returns stream id - int + int EXPORT lokinet_inbound_stream_filter( lokinet_stream_filter acceptFilter, void* user, struct lokinet_context* context); /// simple stream acceptor /// simple variant of lokinet_inbound_stream_filter that maps port to localhost:port - int + int EXPORT lokinet_inbound_stream(uint16_t port, struct lokinet_context* context); #ifdef __cplusplus diff --git a/include/lokinet/lokinet_udp.h b/include/lokinet/lokinet_udp.h index 3ca68f31c..27b00c3e7 100644 --- a/include/lokinet/lokinet_udp.h +++ b/include/lokinet/lokinet_udp.h @@ -42,7 +42,7 @@ extern "C" /// localAddr is the local ip:port to bind our socket to, if localAddr is NULL then /// lokinet_udp_sendmmsg MUST be used to send packets return 0 on success return nonzero on fail, /// containing an errno value - int + int EXPORT lokinet_udp_establish( char* remoteHost, char* remotePort, @@ -66,7 +66,7 @@ extern "C" /// /// returns 0 on success /// returns nonzero on error in which it is an errno value - int + int EXPORT lokinet_udp_bind( int exposedPort, char* srv, @@ -78,7 +78,7 @@ extern "C" /// returns 0 on sucess /// /// returns non zero errno on error - int + int EXPORT lokinet_udp_poll( const int* socket_ids, size_t numsockets, @@ -93,7 +93,7 @@ extern "C" }; /// analog to recvmmsg - ssize_t + ssize_t EXPORT lokinet_udp_recvmmsg( int socket_id, struct lokinet_udp_pkt* events, diff --git a/llarp/lokinet_shared.cpp b/llarp/lokinet_shared.cpp index fbe27f089..6b285e20f 100644 --- a/llarp/lokinet_shared.cpp +++ b/llarp/lokinet_shared.cpp @@ -191,28 +191,20 @@ struct lokinet_srv_lookup_private extern "C" { - struct lokinet_context* - lokinet_default() - { - if (not g_context) - g_context = std::make_unique(); - return g_context.get(); - } - - void + void EXPORT lokinet_set_netid(const char* netid) { llarp::NetID::DefaultValue() = llarp::NetID{reinterpret_cast(netid)}; } - const char* + const char* EXPORT lokinet_get_netid() { const auto netid = llarp::NetID::DefaultValue().ToString(); return strdup(netid.c_str()); } - int + int EXPORT lokinet_log_level(const char* level) { if (auto maybe = llarp::LogLevelFromString(level)) @@ -223,7 +215,7 @@ extern "C" return -1; } - char* + char* EXPORT lokinet_address(struct lokinet_context* ctx) { if (not ctx) @@ -235,7 +227,7 @@ extern "C" return strdup(addrStr.c_str()); } - int + int EXPORT lokinet_add_bootstrap_rc(const char* data, size_t datalen, struct lokinet_context* ctx) { llarp_buffer_t buf{data, datalen}; @@ -253,20 +245,20 @@ extern "C" return 0; } - struct lokinet_context* + struct lokinet_context* EXPORT lokinet_context_new() { return new lokinet_context{}; } - void + void EXPORT lokinet_context_free(struct lokinet_context* ctx) { lokinet_context_stop(ctx); delete ctx; } - int + int EXPORT lokinet_context_start(struct lokinet_context* ctx) { if (not ctx) @@ -301,7 +293,7 @@ extern "C" return 0; } - int + int EXPORT lokinet_status(struct lokinet_context* ctx) { if (ctx == nullptr) @@ -314,7 +306,7 @@ extern "C" return ctx->endpoint()->IsReady() ? 0 : -1; } - int + int EXPORT lokinet_wait_for_ready(int ms, struct lokinet_context* ctx) { if (ctx == nullptr) @@ -335,7 +327,7 @@ extern "C" return ep->IsReady() ? 0 : -1; } - void + void EXPORT lokinet_context_stop(struct lokinet_context* ctx) { if (not ctx) @@ -354,7 +346,7 @@ extern "C" ctx->runner.reset(); } - void + void EXPORT lokinet_outbound_stream( struct lokinet_stream_result* result, const char* remote, @@ -477,14 +469,14 @@ extern "C" } } - int + int EXPORT lokinet_inbound_stream(uint16_t port, struct lokinet_context* ctx) { /// FIXME: delete pointer later return lokinet_inbound_stream_filter(&accept_port, (void*)new std::uintptr_t{port}, ctx); } - int + int EXPORT lokinet_inbound_stream_filter( lokinet_stream_filter acceptFilter, void* user, struct lokinet_context* ctx) { @@ -531,7 +523,7 @@ extern "C" return id; } - void + void EXPORT lokinet_close_stream(int stream_id, struct lokinet_context* ctx) { if (not ctx) @@ -564,7 +556,7 @@ extern "C" {} } - int + int EXPORT lokinet_srv_lookup( char* host, char* service, @@ -580,7 +572,7 @@ extern "C" return result->internal->LookupSRV(host, service, ctx); } - void + void EXPORT lokinet_for_each_srv_record( struct lokinet_srv_lookup_result* result, lokinet_srv_record_iterator iter, void* user) { @@ -594,7 +586,7 @@ extern "C" } } - void + void EXPORT lokinet_srv_lookup_done(struct lokinet_srv_lookup_result* result) { if (result == nullptr or result->internal == nullptr)