export functions in liblokinet for win32 dll

pull/1660/head
Jeff Becker 3 years ago
parent 37a9bd768e
commit 046ab3d453
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -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()

@ -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
}

@ -1,5 +1,7 @@
#pragma once
#include "lokinet_export.h"
#include <stdbool.h>
#include <stdint.h>
#include <unistd.h>
@ -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

@ -0,0 +1,7 @@
#pragma once
#ifdef _WIN32
#define EXPORT __cdecl
#else
#define EXPORT
#endif

@ -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

@ -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

@ -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

@ -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

@ -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,

@ -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<lokinet_context>();
return g_context.get();
}
void
void EXPORT
lokinet_set_netid(const char* netid)
{
llarp::NetID::DefaultValue() = llarp::NetID{reinterpret_cast<const byte_t*>(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)

Loading…
Cancel
Save