Merge branch 'master' into debian/sid

ubuntu/groovy
Jason Rhinelander 5 years ago
commit 823d86875a

@ -209,6 +209,15 @@ if(SHADOW)
include(cmake/shadow.cmake) include(cmake/shadow.cmake)
endif(SHADOW) endif(SHADOW)
unset(GIT_VERSION)
unset(GIT_VERSION_REAL)
if(NOT GIT_VERSION)
exec_program("git" ${CMAKE_CURRENT_SOURCE_DIR} ARGS "rev-parse --short HEAD" OUTPUT_VARIABLE GIT_VERSION_UNSTRIP)
string(STRIP "${GIT_VERSION_UNSTRIP}" GIT_VERSION)
endif(NOT GIT_VERSION)
string(REGEX REPLACE "^fatal.*$" nogit GIT_VERSION_REAL "${GIT_VERSION}")
# HeapAlloc(2) on Windows was significantly revamped in 2009 # HeapAlloc(2) on Windows was significantly revamped in 2009
# but the old algorithm isn't too bad either # but the old algorithm isn't too bad either

@ -78,13 +78,13 @@ if (UNIX)
endif() endif()
find_path(sodium_INCLUDE_DIR sodium.h find_path(sodium_INCLUDE_DIR sodium.h
HINTS ${${XPREFIX}_INCLUDE_DIRS} HINTS ${${XPREFIX}_INCLUDE_DIRS} /usr/local/include
) )
find_library(sodium_LIBRARY_DEBUG NAMES ${${XPREFIX}_LIBRARIES} find_library(sodium_LIBRARY_DEBUG NAMES ${${XPREFIX}_LIBRARIES}
HINTS ${${XPREFIX}_LIBRARY_DIRS} HINTS ${${XPREFIX}_LIBRARY_DIRS} /usr/local/lib
) )
find_library(sodium_LIBRARY_RELEASE NAMES ${${XPREFIX}_LIBRARIES} find_library(sodium_LIBRARY_RELEASE NAMES ${${XPREFIX}_LIBRARIES}
HINTS ${${XPREFIX}_LIBRARY_DIRS} HINTS ${${XPREFIX}_LIBRARY_DIRS} /usr/local/lib
) )
@ -285,4 +285,4 @@ else()
) )
endif() endif()
endif() endif()
endif() endif()

@ -20,7 +20,7 @@ if(NOT MSVC_VERSION)
# GNU ld sees fit to merge *all* the .ident sections in object files # GNU ld sees fit to merge *all* the .ident sections in object files
# to .r[o]data section one after the other! # to .r[o]data section one after the other!
add_compile_options(-fno-ident -Wa,-mbig-obj) add_compile_options(-fno-ident -Wa,-mbig-obj)
link_libraries( -lws2_32 -liphlpapi -lshlwapi -ldbghelp ) link_libraries( -lws2_32 -lshlwapi -ldbghelp -luser32 -liphlpapi -lpsapi -luserenv )
add_definitions(-DWINVER=0x0500 -D_WIN32_WINNT=0x0500) add_definitions(-DWINVER=0x0500 -D_WIN32_WINNT=0x0500)
endif() endif()

@ -48,13 +48,13 @@ add_library(${CRYPTOGRAPHY_LIB} STATIC ${CRYPTOGRAPHY_SRC})
add_log_tag(${CRYPTOGRAPHY_LIB}) add_log_tag(${CRYPTOGRAPHY_LIB})
if(NOT VENDOR_LIBSODIUM) if(NOT VENDOR_LIBSODIUM)
find_package(Sodium 1.0.17) find_package(Sodium 1.0.17 REQUIRED)
endif() endif()
if(NOT sodium_FOUND) if(NOT sodium_FOUND)
message("Could not find libsodium >= 1.0.17 so we'll grab it from the web") message("Could not find libsodium >= 1.0.17")
include(DownloadLibSodium) #include(DownloadLibSodium)
target_link_libraries(${CRYPTOGRAPHY_LIB} sodium_vendor) #target_link_libraries(${CRYPTOGRAPHY_LIB} sodium_vendor)
else() else()
target_include_directories(${CRYPTOGRAPHY_LIB} PUBLIC ${sodium_INCLUDE_DIR}) target_include_directories(${CRYPTOGRAPHY_LIB} PUBLIC ${sodium_INCLUDE_DIR})
target_link_libraries(${CRYPTOGRAPHY_LIB} sodium) target_link_libraries(${CRYPTOGRAPHY_LIB} sodium)

@ -15,15 +15,15 @@ if(SHADOW)
target_include_directories(${LOKINET_SHADOW} PUBLIC ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/llarp ${PROJECT_SOURCE_DIR}/crypto/include) target_include_directories(${LOKINET_SHADOW} PUBLIC ${PROJECT_SOURCE_DIR}/include ${PROJECT_SOURCE_DIR}/llarp ${PROJECT_SOURCE_DIR}/crypto/include)
else() else()
if(WIN32 AND NOT MSVC_VERSION) if(WIN32 AND NOT MSVC_VERSION)
list(APPEND ${EXE_SRC} ../llarp/win32/version.rc) list(APPEND EXE_SRC ../llarp/win32/version.rc)
list(APPEND ${CTL_SRC} ../llarp/win32/version.rc) list(APPEND CTL_SRC ../llarp/win32/version.rc)
endif() endif()
add_executable(${EXE} ${EXE_SRC}) add_executable(${EXE} ${EXE_SRC})
add_executable(${CTL} ${CTL_SRC}) add_executable(${CTL} ${CTL_SRC})
target_compile_definitions(${EXE} PRIVATE -DVERSIONTAG=${VERSIONTAG}) target_compile_definitions(${EXE} PRIVATE -DVERSIONTAG=${GIT_VERSION_REAL})
target_compile_definitions(${CTL} PRIVATE -DVERSIONTAG=${VERSIONTAG}) target_compile_definitions(${CTL} PRIVATE -DVERSIONTAG=${GIT_VERSION_REAL})
add_log_tag(${EXE}) add_log_tag(${EXE})
add_log_tag(${CTL}) add_log_tag(${CTL})
@ -31,7 +31,7 @@ else()
install(TARGETS ${EXE} RUNTIME DESTINATION bin) install(TARGETS ${EXE} RUNTIME DESTINATION bin)
install(TARGETS ${CTL} RUNTIME DESTINATION bin) install(TARGETS ${CTL} RUNTIME DESTINATION bin)
if(WIN32) if(WIN32)
install(PROGRAMS ${CMAKE_SOURCE_DIR}/lokinet-bootstrap.exe DESTINATION bin) install(PROGRAMS ${CMAKE_SOURCE_DIR}/win32-setup/lokinet-bootstrap.exe DESTINATION bin)
else() else()
install(PROGRAMS ${CMAKE_SOURCE_DIR}/lokinet-bootstrap DESTINATION bin) install(PROGRAMS ${CMAKE_SOURCE_DIR}/lokinet-bootstrap DESTINATION bin)
endif() endif()

@ -8,7 +8,6 @@ target_link_libraries(${ABYSS_LIB} PUBLIC ${PLATFORM_LIB})
# for freebsd # for freebsd
if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") if(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
target_link_directories(${ABYSS_EXE} PRIVATE /usr/local/lib)
target_include_directories(${ABYSS_LIB} SYSTEM PUBLIC /usr/local/include) target_include_directories(${ABYSS_LIB} SYSTEM PUBLIC /usr/local/include)
endif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD") endif(${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")

@ -105,8 +105,7 @@ if (WIN32)
ev/ev_win32.cpp ev/ev_win32.cpp
${LIB_PLATFORM_SRC} ${LIB_PLATFORM_SRC}
win32/win32_inet.c win32/win32_inet.c
win32/win32_intrnl.c win32/win32_intrnl.c)
win32/win32_upoll.c)
endif(WIN32) endif(WIN32)
add_library(${PLATFORM_LIB} STATIC ${LIB_PLATFORM_SRC}) add_library(${PLATFORM_LIB} STATIC ${LIB_PLATFORM_SRC})

@ -10,7 +10,7 @@
#define LLARP_VERSION_MIN 6 #define LLARP_VERSION_MIN 6
#define LLARP_VERSION_PATCH 0 #define LLARP_VERSION_PATCH 0
#define LLARP_DEFAULT_NETID "gamma" #define LLARP_DEFAULT_NETID "lokinet"
#ifndef LLARP_RELEASE_MOTTO #ifndef LLARP_RELEASE_MOTTO
#define LLARP_RELEASE_MOTTO "(dev build)" #define LLARP_RELEASE_MOTTO "(dev build)"

@ -20,8 +20,6 @@
#include <utility> #include <utility>
#ifdef _WIN32 #ifdef _WIN32
#include <win32/win32_up.h>
#include <win32/win32_upoll.h>
// From the preview SDK, should take a look at that // From the preview SDK, should take a look at that
// periodically in case its definition changes // periodically in case its definition changes
#define UNIX_PATH_MAX 108 #define UNIX_PATH_MAX 108
@ -184,7 +182,7 @@ namespace llarp
virtual ssize_t virtual ssize_t
do_write(void* data, size_t sz) do_write(void* data, size_t sz)
{ {
return uwrite(fd, (char*)data, sz); return send(fd, (char*)data, sz, 0);
} }
bool bool
@ -272,7 +270,7 @@ namespace llarp
virtual ~win32_ev_io() virtual ~win32_ev_io()
{ {
uclose(fd); closesocket(fd);
}; };
}; };
#else #else

@ -234,7 +234,7 @@ exit_tun_loop()
DeleteCriticalSection(&HandlerMtx); DeleteCriticalSection(&HandlerMtx);
} }
} }
/*
// now zero-copy // now zero-copy
ssize_t ssize_t
TCPWrite(llarp_tcp_conn* conn, const byte_t* ptr, size_t sz) TCPWrite(llarp_tcp_conn* conn, const byte_t* ptr, size_t sz)
@ -730,5 +730,5 @@ llarp_win32_loop::tick_listeners()
for(auto& func : m_Tickers) for(auto& func : m_Tickers)
LogicCall(m_Logic, func); LogicCall(m_Logic, func);
} }
*/
#endif #endif

@ -100,8 +100,20 @@ struct win32_tun_io
} }
}; };
// UDP event loop (we use select(3SOCKET) because linux) // UDP event loop (no longer used, we libuv for now)
struct llarp_win32_loop : public llarp_ev_loop // PLEASE convert me to IOCPs so we don't have to use that
// EXTREMELY CURSED libuv event loop and its llarp_vpn_io_pipe
//
// For you see, on Windows, we have enough local user permissions to set
// up a VPN tunnel interface internally, and have lokinet consume this
// file descriptor directly. See win32_tun_io for this impl. llarp_vpn_io
// assumes that an external entity or process is required to inject packets
// into the VPN interface provided by the OS.
//
// Not only that, the win32 IOCP facility handles timing on its own, you can
// specify an interval to tick directly into the call to
// GetQueuedCompletionStatus(2)
/*struct llarp_win32_loop : public llarp_ev_loop
{ {
upoll_t* upollfd; upoll_t* upollfd;
std::shared_ptr< llarp::Logic > m_Logic; std::shared_ptr< llarp::Logic > m_Logic;
@ -172,6 +184,6 @@ struct llarp_win32_loop : public llarp_ev_loop
void void
tick_listeners() override; tick_listeners() override;
}; };
*/
#endif #endif
#endif #endif

@ -28,7 +28,13 @@ namespace llarp
{ {
/// aligned buffer that is sz bytes long and aligns to the nearest Alignment /// aligned buffer that is sz bytes long and aligns to the nearest Alignment
template < size_t sz > template < size_t sz >
#ifdef _WIN32
// We CANNOT align on a 128-bit boundary, malloc(3C) on win32
// only hands out 64-bit aligned pointers
struct alignas(uint64_t) AlignedBuffer
#else
struct alignas(std::max_align_t) AlignedBuffer struct alignas(std::max_align_t) AlignedBuffer
#endif
{ {
static constexpr size_t SIZE = sz; static constexpr size_t SIZE = sz;

@ -23,9 +23,11 @@ namespace llarp
bool bool
FeedData(const char* buf, size_t sz) override FeedData(const char* buf, size_t sz) override
{ {
if(sz == 0)
return true;
if(m_Offset + sz > m_Buf.size() - 1) if(m_Offset + sz > m_Buf.size() - 1)
return false; return false;
std::copy(buf, buf + sz, m_Buf.begin()); std::copy_n(buf, sz, m_Buf.data() + m_Offset);
m_Offset += sz; m_Offset += sz;
m_Buf[m_Offset] = 0; m_Buf[m_Offset] = 0;
return true; return true;

@ -95,7 +95,8 @@ END
// RT_MANIFEST // RT_MANIFEST
// //
3 RT_MANIFEST "app.xml" // Uncomment if your toolchain does not provide a default-manifest.o
//3 RT_MANIFEST "app.xml"
#endif // English (United States) resources #endif // English (United States) resources
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////

@ -1,69 +0,0 @@
#ifndef _UP_H_
#define _UP_H_
#ifdef __cplusplus
extern "C"
{
#endif
#include <stdlib.h>
#include <stddef.h>
#include <stdint.h>
#define UPOLL_CTL_ADD 1
#define UPOLL_CTL_DEL 2
#define UPOLL_CTL_MOD 3
#define UPOLLIN 0x01
#define UPOLLOUT 0x02
#define UPOLLERR 0x04
#define UPOLLET 0x08
typedef struct upoll upoll_t;
typedef union upoll_data {
void* ptr;
intptr_t fd;
uint32_t u32;
uint64_t u64;
} upoll_data_t;
typedef struct upoll_event
{
uint32_t events;
upoll_data_t data;
} upoll_event_t;
upoll_t*
upoll_create(uint32_t size);
int
upoll_ctl(upoll_t* upq, int op, intptr_t fd, upoll_event_t* event);
int
upoll_wait(upoll_t* upq, upoll_event_t* events, int maxevents, int timeout);
void
upoll_destroy(upoll_t* upq);
intptr_t
usocket(int domain, int type, int proto);
intptr_t
uaccept(intptr_t sock);
int
ubind(intptr_t sock, const char* name, const char* serv);
int
ulisten(intptr_t sock, int backlog);
int
uconnect(intptr_t sock, const char* name, const char* serv);
int
uclose(intptr_t sock);
/* TCP sockets */
int
uread(intptr_t fd, char* buf, size_t len);
int
uwrite(intptr_t fd, const char* buf, size_t len);
int
usocketpair(intptr_t socks[2], int async);
#ifdef __cplusplus
}
#endif
#endif /* _UP_H_ */

@ -1,524 +0,0 @@
#ifdef _WIN32
/* wake me up inside */
#pragma GCC diagnostic ignored "-Wvla"
/* emulated epoll, because the native async event system does not do
* particularly well with notification
* update: now win32-exclusive
*/
#include "win32_upoll.h"
#define uhash_slot(K, S) (((K) ^ (K >> 8)) & (S - 1))
static uhash_t*
uhash_create(uint32_t size)
{
unsigned int i;
size--;
size |= size >> 1;
size |= size >> 2;
size |= size >> 4;
size |= size >> 8;
size |= size >> 16;
size++;
uhash_t* hash = (uhash_t*)calloc(1, sizeof(uhash_t) + size * sizeof(ulist_t));
hash->count = 0;
hash->size = size;
hash->items = (ulist_t*)(((char*)hash) + sizeof(uhash_t));
for(i = 0; i < size; i++)
{
ulist_init(&hash->items[i]);
}
return hash;
}
static void*
uhash_lookup(uhash_t* hash, intptr_t key)
{
uint32_t slot = uhash_slot(key, hash->size);
ulist_t* q;
ulist_scan(q, &hash->items[slot])
{
uitem_t* i = ulist_data(q, uitem_t, list);
if(i->key == key)
return i->val;
}
return NULL;
}
static void
uhash_insert(uhash_t* hash, intptr_t key, void* val)
{
uint32_t slot = uhash_slot(key, hash->size);
uitem_t* item = (uitem_t*)calloc(1, sizeof(uitem_t));
ulist_init(&item->list);
item->key = key;
item->val = val;
ulist_append(&hash->items[slot], &item->list);
}
static int
uhash_delete(uhash_t* hash, intptr_t key)
{
uint32_t slot = uhash_slot(key, hash->size);
ulist_t* q;
ulist_scan(q, &hash->items[slot])
{
uitem_t* i = ulist_data(q, uitem_t, list);
if(i->key == key)
{
ulist_remove(q);
free(q);
q = NULL;
return 1;
}
}
return 0;
}
static int
uhash_destroy(uhash_t* hash)
{
int i;
for(i = 0; i < hash->size; i++)
{
while(!ulist_empty(&hash->items[i]))
{
ulist_t* q = ulist_next(&hash->items[i]);
uitem_t* n = ulist_data(q, uitem_t, list);
ulist_remove(q);
free(n);
n = NULL;
}
}
return 0;
}
upoll_t*
upoll_create(uint32_t size)
{
assert(size > 0);
upoll_t* upq = (upoll_t*)calloc(1, sizeof(upoll_t));
ulist_init(&upq->alive);
upq->table = uhash_create(size);
return upq;
}
void
upoll_destroy(upoll_t* upq)
{
assert(upq != NULL);
uhash_destroy(upq->table);
ulist_t* q = NULL;
unote_t* n = NULL;
while(!ulist_empty(&upq->alive))
{
q = ulist_next(&upq->alive);
n = ulist_data(n, unote_t, queue);
ulist_remove(q);
free(n);
n = NULL;
}
free(upq);
upq = NULL;
}
int
upoll_ctl(upoll_t* upq, int op, intptr_t fd, upoll_event_t* event)
{
if(fd < 0)
return -EBADF;
unote_t* note = NULL;
switch(op)
{
case UPOLL_CTL_ADD:
{
note = (unote_t*)uhash_lookup(upq->table, fd);
if(!note)
{
note = (unote_t*)calloc(1, sizeof(unote_t));
note->upoll = upq;
ulist_init(&note->queue);
note->event = *event;
note->fd = fd;
ulist_append(&upq->alive, &note->queue);
uhash_insert(upq->table, fd, (void*)note);
}
break;
}
case UPOLL_CTL_DEL:
{
note = (unote_t*)uhash_lookup(upq->table, fd);
if(!note)
return -ENOENT;
event = &note->event;
ulist_remove(&note->queue);
uhash_delete(upq->table, fd);
free(note);
note = NULL;
break;
}
case UPOLL_CTL_MOD:
{
note = (unote_t*)uhash_lookup(upq->table, fd);
if(!note)
return -ENOENT;
note->event = *event;
break;
}
default:
{
return -EINVAL;
}
}
return 0;
}
int
upoll_wait_select(upoll_t* upq, upoll_event_t* evs, int nev, int timeout)
{
if(nev > FD_SETSIZE)
nev = FD_SETSIZE;
unote_t** nvec = calloc(nev, sizeof(unote_t*));
int i, maxfd = 0, e = 0, nfds = 0;
fd_set pollin, pollout, pollerr;
FD_ZERO(&pollin);
FD_ZERO(&pollout);
FD_ZERO(&pollerr);
struct timeval tv;
struct timeval* tvp = &tv;
tv.tv_usec = 0;
if(timeout < 0)
{
tvp = NULL;
}
else if(timeout == 0)
tv.tv_sec = 0;
else
{
tv.tv_sec = (timeout / 1000);
tv.tv_usec = (timeout % 1000) * 1000;
}
unote_t* n = NULL;
ulist_t* s = ulist_mark(&upq->alive);
ulist_t* q = ulist_next(&upq->alive);
while(q != s && nfds < nev)
{
n = ulist_data(q, unote_t, queue);
q = ulist_next(q);
ulist_remove(&n->queue);
ulist_insert(&upq->alive, &n->queue);
nvec[nfds] = n;
if(n->event.events & UPOLLIN)
{
FD_SET((SOCKET)n->fd, &pollin);
}
if(n->event.events & UPOLLOUT)
{
FD_SET((SOCKET)n->fd, &pollout);
}
FD_SET((SOCKET)n->fd, &pollerr);
if(maxfd < n->fd)
maxfd = n->fd;
nfds++;
}
int rc = select(0, &pollin, &pollout, &pollerr, tvp);
if(rc == SOCKET_ERROR)
{
assert(WSAGetLastError() == WSAENOTSOCK);
free(nvec);
return -WSAGetLastError();
}
e = 0;
for(i = 0; i < nfds && e < nev; i++)
{
uint32_t hint = 0;
unote_t* n = nvec[i];
if(FD_ISSET(n->fd, &pollin))
{
hint |= UPOLLIN;
}
if(FD_ISSET(n->fd, &pollerr))
{
hint |= (UPOLLERR | UPOLLIN);
}
else if(FD_ISSET(n->fd, &pollout))
{
hint |= UPOLLOUT;
}
if(hint)
{
evs[e].data = n->event.data;
evs[e].events = hint;
++e;
}
}
free(nvec);
return e;
}
int
upoll_wait(upoll_t* upq, upoll_event_t* evs, int nev, int timeout)
{
int r = 0;
r = upoll_wait_select(upq, evs, nev, timeout);
return r;
}
intptr_t
usocket(int domain, int type, int proto)
{
intptr_t fd = (intptr_t)socket(domain, type, proto);
if(fd < 0)
return -WSAGetLastError();
unsigned long flags = 1;
int rc = ioctlsocket((SOCKET)fd, FIONBIO, &flags);
if(rc < 0)
return -WSAGetLastError();
return fd;
}
int
ubind(intptr_t fd, const char* host, const char* serv)
{
struct addrinfo* info;
struct addrinfo hint;
memset(&hint, 0, sizeof(hint));
int optval = 0;
unsigned int optlen = sizeof(optval);
int rc = getsockopt((SOCKET)fd, SOL_SOCKET, SO_TYPE, (char*)&optval,
(int*)&optlen);
hint.ai_family = AF_INET;
hint.ai_socktype = optval;
rc = getaddrinfo(host, serv, &hint, &info);
optval = 1;
if(!rc)
{
rc = setsockopt((SOCKET)fd, SOL_SOCKET, SO_REUSEADDR, (char*)&optval,
sizeof(optval));
if(!rc)
rc = bind(fd, info->ai_addr, info->ai_addrlen);
}
freeaddrinfo(info);
if(rc)
return WSAGetLastError();
return 0;
}
int
uconnect(intptr_t fd, const char* host, const char* serv)
{
struct addrinfo* info;
struct addrinfo hint;
memset(&hint, 0, sizeof(hint));
int optval = 0;
unsigned int optlen;
int rc = getsockopt(fd, SOL_SOCKET, SO_TYPE, (char*)&optval, (int*)&optlen);
hint.ai_family = AF_INET;
hint.ai_socktype = optval;
rc = getaddrinfo(host, serv, &hint, &info);
if(!rc)
rc = connect((SOCKET)fd, info->ai_addr, info->ai_addrlen);
freeaddrinfo(info);
if(rc)
{
if(WSAGetLastError() != WSAEWOULDBLOCK)
return WSAGetLastError();
}
return 0;
}
int
ulisten(intptr_t sock, int backlog)
{
return listen(sock, backlog);
}
intptr_t
uaccept(intptr_t sock)
{
struct sockaddr addr;
addr.sa_family = AF_INET;
socklen_t addr_len;
intptr_t fd = (intptr_t)accept((SOCKET)sock, &addr, &addr_len);
if(fd == -1)
return WSAGetLastError();
return fd;
}
int
uclose(intptr_t sock)
{
return closesocket((SOCKET)sock);
}
int
uread(intptr_t fd, char* buf, size_t len)
{
return recv(fd, buf, len, 0);
}
int
uwrite(intptr_t fd, const char* buf, size_t len)
{
return send(fd, buf, len, 0);
}
/* adapted from (renamed make_overlapped to async for allergy reasons): */
/* socketpair.c
Copyright 2007, 2010 by Nathan C. Myers <ncm@cantrip.org>
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
The name of the author must not be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/* Changes:
* 2014-02-12: merge David Woodhouse, Ger Hobbelt improvements
* git.infradead.org/users/dwmw2/openconnect.git/commitdiff/bdeefa54
* github.com/GerHobbelt/selectable-socketpair
* always init the socks[] to -1/INVALID_SOCKET on error, both on Win32/64
* and UNIX/other platforms
* 2013-07-18: Change to BSD 3-clause license
* 2010-03-31:
* set addr to 127.0.0.1 because win32 getsockname does not always set it.
* 2010-02-25:
* set SO_REUSEADDR option to avoid leaking some windows resource.
* Windows System Error 10049, "Event ID 4226 TCP/IP has reached
* the security limit imposed on the number of concurrent TCP connect
* attempts." Bleah.
* 2007-04-25:
* preserve value of WSAGetLastError() on all error returns.
* 2007-04-22: (Thanks to Matthew Gregan <kinetik@flim.org>)
* s/EINVAL/WSAEINVAL/ fix trivial compile failure
* s/socket/WSASocket/ enable creation of sockets suitable as stdin/stdout
* of a child process.
* add argument make_overlapped
*/
int
usocketpair(intptr_t socks[2], int async)
{
union {
struct sockaddr_in inaddr;
struct sockaddr addr;
} a;
SOCKET listener;
int e;
socklen_t addrlen = sizeof(a.inaddr);
DWORD flags = (async ? WSA_FLAG_OVERLAPPED : 0);
int reuse = 1;
if(socks == 0)
{
WSASetLastError(WSAEINVAL);
return SOCKET_ERROR;
}
socks[0] = socks[1] = -1;
listener = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if(listener == INVALID_SOCKET)
return SOCKET_ERROR;
memset(&a, 0, sizeof(a));
a.inaddr.sin_family = AF_INET;
a.inaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
a.inaddr.sin_port = 0;
for(;;)
{
if(setsockopt(listener, SOL_SOCKET, SO_REUSEADDR, (char*)&reuse,
(socklen_t)sizeof(reuse))
== -1)
break;
if(bind(listener, &a.addr, sizeof(a.inaddr)) == SOCKET_ERROR)
break;
memset(&a, 0, sizeof(a));
if(getsockname(listener, &a.addr, &addrlen) == SOCKET_ERROR)
break;
// win32 getsockname may only set the port number, p=0.0005.
// ( http://msdn.microsoft.com/library/ms738543.aspx ):
a.inaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
a.inaddr.sin_family = AF_INET;
if(listen(listener, 1) == SOCKET_ERROR)
break;
socks[0] = (intptr_t)WSASocket(AF_INET, SOCK_STREAM, 0, NULL, 0, flags);
if(socks[0] == -1)
break;
if(connect((SOCKET)socks[0], &a.addr, sizeof(a.inaddr)) == SOCKET_ERROR)
break;
socks[1] = (intptr_t)accept(listener, NULL, NULL);
if(socks[1] == -1)
break;
closesocket(listener);
return 0;
}
e = WSAGetLastError();
closesocket(listener);
closesocket((SOCKET)socks[0]);
closesocket((SOCKET)socks[1]);
WSASetLastError(e);
socks[0] = socks[1] = -1;
return SOCKET_ERROR;
}
#endif

@ -1,126 +0,0 @@
#ifndef _UPOLL_H_
#define _UPOLL_H_
#include "win32_up.h"
#if(defined(__64BIT__) || defined(__x86_64__))
#define __IS_64BIT__
#else
#define __IS_32BIT__
#endif
#if(defined WIN32 || defined _WIN32)
#undef __WINDOWS__
#define __WINDOWS__
#undef _WIN32_WINNT
#define _WIN32_WINNT 0x0500
#endif
#include <sys/types.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <assert.h>
#include <stdio.h>
#include <stdint.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/stat.h>
// this is probably big enough to get
// the lesser of 4096 sockets or whatever
// the system allows
#ifndef FD_SETSIZE
#define FD_SETSIZE 4096
#endif
#include <io.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <wspiapi.h>
#undef HAVE_SELECT
#define HAVE_SELECT 1
typedef struct unote unote_t;
typedef struct ulist ulist_t;
typedef struct uitem uitem_t;
typedef struct uhash uhash_t;
struct ulist
{
ulist_t* next;
ulist_t* prev;
};
struct uitem
{
ulist_t list;
intptr_t key;
void* val;
};
struct uhash
{
uint16_t count;
uint16_t size;
ulist_t* items;
};
struct upoll
{
int fd; /* backend fd (epoll, kqueue) */
ulist_t alive; /* all notes this queue knows about */
uhash_t* table;
};
struct unote
{
upoll_event_t event;
intptr_t fd;
ulist_t queue; /* handle for the queue's notes */
upoll_t* upoll;
};
#define container_of(ptr, type, member) \
((type*)((char*)(ptr)-offsetof(type, member)))
#define ulist_init(q) \
(q)->prev = q; \
(q)->next = q
#define ulist_head(h) (h)->next
#define ulist_next(q) (q)->next
#define ulist_tail(h) (h)->prev
#define ulist_prev(q) (q)->prev
#define ulist_empty(h) (h == (h)->prev)
#define ulist_append(h, x) \
(x)->prev = (h)->prev; \
(x)->prev->next = x; \
(x)->next = h; \
(h)->prev = x
#define ulist_insert(h, x) \
(x)->next = (h)->next; \
(x)->next->prev = x; \
(x)->prev = h; \
(h)->next = x
#define ulist_remove(x) \
(x)->next->prev = (x)->prev; \
(x)->prev->next = (x)->next; \
(x)->prev = x; \
(x)->next = x
#define ulist_mark(h) (h)
#define ulist_scan(q, h) \
for((q) = ulist_head(h); (q) != ulist_mark(h); (q) = ulist_next(q))
#define ulist_data(q, type, link) container_of(q, type, link)
#endif /* _UPOLL_H_ */

@ -171,11 +171,13 @@ install (root):
build: build:
$ pkg install cmake git curl libuv-1.27.0 libsodium $ pkg install cmake git curl libuv libsodium pkgconf
$ git clone https://github.com/loki-project/loki-network $ git clone https://github.com/loki-project/loki-network
$ cd loki-network $ cd loki-network
$ gmake -j8 $ mkdir build
$ cmake -DCMAKE_BUILD_TYPE=Release ..
$ make
install (root): install (root):
# gmake install # make install

@ -7,7 +7,7 @@
// Microsoft Visual C++ generated resource script. // Microsoft Visual C++ generated resource script.
// //
#include <win32/resource.h> #include <win32/resource.h>
#include <constants/version.hpp> #include <constants/version.h>
#ifdef __GNUC__ #ifdef __GNUC__
#include <winresrc.h> #include <winresrc.h>
#endif #endif
@ -80,28 +80,12 @@ BEGIN
VALUE "Comments", "LokiNET test suite" VALUE "Comments", "LokiNET test suite"
VALUE "CompanyName", "Loki Foundation" VALUE "CompanyName", "Loki Foundation"
VALUE "FileDescription", "LokiNET for Microsoft® Windows® NT™" VALUE "FileDescription", "LokiNET for Microsoft® Windows® NT™"
#ifdef LLARP_RELEASE_MOTTO VALUE "FileVersion", VERSION_STRING(LLARP_VERSION_TRIPLET, LLARP_RELEASE_MOTTO, VERSIONTAG)
VALUE "FileVersion", VERSION_STRING(0.5.2, RELEASE_MOTTO, GIT_REV)
#else
#ifdef __GNUC__
VALUE "FileVersion", VERSION_STRING(0.5.2-dev-, GIT_REV)
#else
VALUE "FileVersion", "0.5.2-dev"
#endif
#endif
VALUE "InternalName", "llarpd" VALUE "InternalName", "llarpd"
VALUE "LegalCopyright", "Copyright ©2018-2019 Jeff Becker, Rick V for the Loki Foundation. All rights reserved. This software is provided under the terms of the zlib-libpng licence; see the file LICENSE for details." VALUE "LegalCopyright", "Copyright ©2018-2019 Jeff Becker, Rick V for the Loki Foundation. All rights reserved. This software is provided under the terms of the zlib-libpng licence; see the file LICENSE for details."
VALUE "OriginalFilename", "llarpd.exe" VALUE "OriginalFilename", "llarpd.exe"
VALUE "ProductName", "LokiNET for Windows" VALUE "ProductName", "LokiNET for Windows"
#ifdef LLARP_RELEASE_MOTTO VALUE "ProductVersion", VERSION_STRING(LLARP_VERSION_TRIPLET, LLARP_RELEASE_MOTTO, VERSIONTAG)
VALUE "ProductVersion", VERSION_STRING(0.5.2, RELEASE_MOTTO, GIT_REV)
#else
#ifdef __GNUC__
VALUE "ProductVersion", VERSION_STRING(0.5.2-dev-, GIT_REV)
#else
VALUE "ProductVersion", "0.5.2-dev"
#endif
#endif
END END
END END
BLOCK "VarFileInfo" BLOCK "VarFileInfo"
@ -116,7 +100,8 @@ END
// RT_MANIFEST // RT_MANIFEST
// //
4 RT_MANIFEST "app.xml" // Uncomment if your toolchain does not provide a default-manifest.o
//4 RT_MANIFEST "app.xml"
#endif // English (United States) resources #endif // English (United States) resources
///////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////

@ -33,19 +33,19 @@
this.StatusLabel = new System.Windows.Forms.Label(); this.StatusLabel = new System.Windows.Forms.Label();
this.lokinetd_fd1 = new System.Windows.Forms.TextBox(); this.lokinetd_fd1 = new System.Windows.Forms.TextBox();
this.NotificationTrayIcon = new System.Windows.Forms.NotifyIcon(this.components); this.NotificationTrayIcon = new System.Windows.Forms.NotifyIcon(this.components);
this.btnHide = new System.Windows.Forms.Button();
this.UIVersionLabel = new System.Windows.Forms.Label();
this.btnConnect = new System.Windows.Forms.Button();
this.btnDrop = new System.Windows.Forms.Button();
this.btnConfigProfile = new System.Windows.Forms.Button();
this.btnAbout = new System.Windows.Forms.Button();
this.TrayMenu = new System.Windows.Forms.ContextMenuStrip(this.components); this.TrayMenu = new System.Windows.Forms.ContextMenuStrip(this.components);
this.showToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.TrayConnect = new System.Windows.Forms.ToolStripMenuItem(); this.TrayConnect = new System.Windows.Forms.ToolStripMenuItem();
this.TrayDisconnect = new System.Windows.Forms.ToolStripMenuItem(); this.TrayDisconnect = new System.Windows.Forms.ToolStripMenuItem();
this.saveLogToFileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.saveLogToFileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.aboutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.exitToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.showToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.btnHide = new System.Windows.Forms.Button();
this.UIVersionLabel = new System.Windows.Forms.Label();
this.btnConnect = new System.Windows.Forms.Button();
this.btnDrop = new System.Windows.Forms.Button();
this.btnConfigProfile = new System.Windows.Forms.Button();
this.btnAbout = new System.Windows.Forms.Button();
this.TrayMenu.SuspendLayout(); this.TrayMenu.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
@ -86,6 +86,60 @@
this.NotificationTrayIcon.Visible = true; this.NotificationTrayIcon.Visible = true;
this.NotificationTrayIcon.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.NotificationTrayIcon_MouseDoubleClick); this.NotificationTrayIcon.MouseDoubleClick += new System.Windows.Forms.MouseEventHandler(this.NotificationTrayIcon_MouseDoubleClick);
// //
// TrayMenu
//
this.TrayMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.showToolStripMenuItem,
this.TrayConnect,
this.TrayDisconnect,
this.saveLogToFileToolStripMenuItem,
this.aboutToolStripMenuItem,
this.exitToolStripMenuItem});
this.TrayMenu.Name = "TrayMenu";
this.TrayMenu.Size = new System.Drawing.Size(166, 136);
//
// showToolStripMenuItem
//
this.showToolStripMenuItem.Name = "showToolStripMenuItem";
this.showToolStripMenuItem.Size = new System.Drawing.Size(165, 22);
this.showToolStripMenuItem.Text = "Show";
this.showToolStripMenuItem.Click += new System.EventHandler(this.showToolStripMenuItem_Click);
//
// TrayConnect
//
this.TrayConnect.Name = "TrayConnect";
this.TrayConnect.Size = new System.Drawing.Size(165, 22);
this.TrayConnect.Text = "Connect";
this.TrayConnect.Click += new System.EventHandler(this.TrayConnect_Click);
//
// TrayDisconnect
//
this.TrayDisconnect.Name = "TrayDisconnect";
this.TrayDisconnect.Size = new System.Drawing.Size(165, 22);
this.TrayDisconnect.Text = "Disconnect";
this.TrayDisconnect.Click += new System.EventHandler(this.TrayDisconnect_Click);
//
// saveLogToFileToolStripMenuItem
//
this.saveLogToFileToolStripMenuItem.Name = "saveLogToFileToolStripMenuItem";
this.saveLogToFileToolStripMenuItem.Size = new System.Drawing.Size(165, 22);
this.saveLogToFileToolStripMenuItem.Text = "Save Log to File...";
this.saveLogToFileToolStripMenuItem.Click += new System.EventHandler(this.saveLogToFileToolStripMenuItem_Click);
//
// aboutToolStripMenuItem
//
this.aboutToolStripMenuItem.Name = "aboutToolStripMenuItem";
this.aboutToolStripMenuItem.Size = new System.Drawing.Size(165, 22);
this.aboutToolStripMenuItem.Text = "About...";
this.aboutToolStripMenuItem.Click += new System.EventHandler(this.aboutToolStripMenuItem_Click);
//
// exitToolStripMenuItem
//
this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
this.exitToolStripMenuItem.Size = new System.Drawing.Size(165, 22);
this.exitToolStripMenuItem.Text = "Exit";
this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
//
// btnHide // btnHide
// //
this.btnHide.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.btnHide.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
@ -152,60 +206,6 @@
this.btnAbout.UseVisualStyleBackColor = true; this.btnAbout.UseVisualStyleBackColor = true;
this.btnAbout.Click += new System.EventHandler(this.btnAbout_Click); this.btnAbout.Click += new System.EventHandler(this.btnAbout_Click);
// //
// TrayMenu
//
this.TrayMenu.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.showToolStripMenuItem,
this.TrayConnect,
this.TrayDisconnect,
this.saveLogToFileToolStripMenuItem,
this.aboutToolStripMenuItem,
this.exitToolStripMenuItem});
this.TrayMenu.Name = "TrayMenu";
this.TrayMenu.Size = new System.Drawing.Size(181, 158);
//
// TrayConnect
//
this.TrayConnect.Name = "TrayConnect";
this.TrayConnect.Size = new System.Drawing.Size(180, 22);
this.TrayConnect.Text = "Connect";
this.TrayConnect.Click += new System.EventHandler(this.TrayConnect_Click);
//
// TrayDisconnect
//
this.TrayDisconnect.Name = "TrayDisconnect";
this.TrayDisconnect.Size = new System.Drawing.Size(180, 22);
this.TrayDisconnect.Text = "Disconnect";
this.TrayDisconnect.Click += new System.EventHandler(this.TrayDisconnect_Click);
//
// saveLogToFileToolStripMenuItem
//
this.saveLogToFileToolStripMenuItem.Name = "saveLogToFileToolStripMenuItem";
this.saveLogToFileToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.saveLogToFileToolStripMenuItem.Text = "Save Log to File...";
this.saveLogToFileToolStripMenuItem.Click += new System.EventHandler(this.saveLogToFileToolStripMenuItem_Click);
//
// aboutToolStripMenuItem
//
this.aboutToolStripMenuItem.Name = "aboutToolStripMenuItem";
this.aboutToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.aboutToolStripMenuItem.Text = "About...";
this.aboutToolStripMenuItem.Click += new System.EventHandler(this.aboutToolStripMenuItem_Click);
//
// exitToolStripMenuItem
//
this.exitToolStripMenuItem.Name = "exitToolStripMenuItem";
this.exitToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.exitToolStripMenuItem.Text = "Exit";
this.exitToolStripMenuItem.Click += new System.EventHandler(this.exitToolStripMenuItem_Click);
//
// showToolStripMenuItem
//
this.showToolStripMenuItem.Name = "showToolStripMenuItem";
this.showToolStripMenuItem.Size = new System.Drawing.Size(180, 22);
this.showToolStripMenuItem.Text = "Show";
this.showToolStripMenuItem.Click += new System.EventHandler(this.showToolStripMenuItem_Click);
//
// main_frame // main_frame
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@ -223,7 +223,7 @@
this.Name = "main_frame"; this.Name = "main_frame";
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide; this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "LokiNET Launcher"; this.Text = "Lokinet Launcher";
this.TrayMenu.ResumeLayout(false); this.TrayMenu.ResumeLayout(false);
this.ResumeLayout(false); this.ResumeLayout(false);
this.PerformLayout(); this.PerformLayout();

@ -31,7 +31,7 @@ namespace network.loki.lokinet.win32.ui
.GetAssembly(typeof(main_frame)) .GetAssembly(typeof(main_frame))
.GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false)[0]) .GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false)[0])
.InformationalVersion; .InformationalVersion;
UIVersionLabel.Text = String.Format("LokiNET version {0}", build); UIVersionLabel.Text = String.Format("Lokinet version {0}", build);
lokinetd_fd1.Text = string.Empty; lokinetd_fd1.Text = string.Empty;
logText = string.Empty; logText = string.Empty;
lokiNetDaemon.OutputDataReceived += new DataReceivedEventHandler((s, ev) => lokiNetDaemon.OutputDataReceived += new DataReceivedEventHandler((s, ev) =>
@ -71,10 +71,10 @@ namespace network.loki.lokinet.win32.ui
TrayConnect.Enabled = false; TrayConnect.Enabled = false;
StatusLabel.Text = "Connected"; StatusLabel.Text = "Connected";
isConnected = true; isConnected = true;
NotificationTrayIcon.Text = "LokiNET - connected"; NotificationTrayIcon.Text = "Lokinet - connected";
btnDrop.Enabled = true; btnDrop.Enabled = true;
TrayDisconnect.Enabled = true; TrayDisconnect.Enabled = true;
NotificationTrayIcon.ShowBalloonTip(5, "LokiNET", "Connected to network.", ToolTipIcon.Info); NotificationTrayIcon.ShowBalloonTip(5, "Lokinet", "Connected to network.", ToolTipIcon.Info);
} }
private void btnDrop_Click(object sender, EventArgs e) private void btnDrop_Click(object sender, EventArgs e)
@ -86,11 +86,11 @@ namespace network.loki.lokinet.win32.ui
btnDrop.Enabled = false; btnDrop.Enabled = false;
TrayDisconnect.Enabled = false; TrayDisconnect.Enabled = false;
StatusLabel.Text = "Disconnected"; StatusLabel.Text = "Disconnected";
NotificationTrayIcon.Text = "LokiNET - disconnected"; NotificationTrayIcon.Text = "Lokinet - disconnected";
isConnected = false; isConnected = false;
logText = lokinetd_fd1.Text; logText = lokinetd_fd1.Text;
lokinetd_fd1.Text = string.Empty; lokinetd_fd1.Text = string.Empty;
NotificationTrayIcon.ShowBalloonTip(5, "LokiNET", "Disconnected from network.", ToolTipIcon.Info); NotificationTrayIcon.ShowBalloonTip(5, "Lokinet", "Disconnected from network.", ToolTipIcon.Info);
} }
@ -106,9 +106,9 @@ namespace network.loki.lokinet.win32.ui
{ {
Hide(); Hide();
if (isConnected) if (isConnected)
NotificationTrayIcon.ShowBalloonTip(5, "LokiNET", "Currently connected.", ToolTipIcon.Info); NotificationTrayIcon.ShowBalloonTip(5, "Lokinet", "Currently connected.", ToolTipIcon.Info);
else else
NotificationTrayIcon.ShowBalloonTip(5, "LokiNET", "Currently disconnected.", ToolTipIcon.Info); NotificationTrayIcon.ShowBalloonTip(5, "Lokinet", "Currently disconnected.", ToolTipIcon.Info);
} }
private void NotificationTrayIcon_MouseDoubleClick(object sender, MouseEventArgs e) private void NotificationTrayIcon_MouseDoubleClick(object sender, MouseEventArgs e)
@ -143,7 +143,7 @@ namespace network.loki.lokinet.win32.ui
ld.setText(logText); ld.setText(logText);
ld.CreateLog(config_path); ld.CreateLog(config_path);
MessageBox.Show(string.Format("Wrote log to {0}, previous log rotated", ld.getLogPath()), "LokiNET", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show(string.Format("Wrote log to {0}, previous log rotated", ld.getLogPath()), "Lokinet", MessageBoxButtons.OK, MessageBoxIcon.Information);
logText = string.Empty; logText = string.Empty;
} }
} }

@ -14,16 +14,19 @@ namespace network.loki.lokinet.win32.ui
{ {
InitializeComponent(); InitializeComponent();
if (Program.platform == PlatformID.Win32NT) if (Program.platform == PlatformID.Win32NT)
default_path = Environment.ExpandEnvironmentVariables("%APPDATA%\\.lokinet\\bootstrap.signed"); default_path = Environment.ExpandEnvironmentVariables("%APPDATA%\\.lokinet");
else else
default_path = Environment.ExpandEnvironmentVariables("%HOME%/.lokinet/bootstrap.signed"); default_path = Environment.ExpandEnvironmentVariables("%HOME%/.lokinet");
label2.Text = String.Format("This file is automatically saved as {0}.", default_path); label2.Text = String.Format("This file is automatically saved as {0}{1}{2}.", default_path, Path.DirectorySeparatorChar, rcName);
} }
private WebClient wc; private WebClient wc;
private string default_path; private string default_path;
private const string rcName = "bootstrap.signed";
private void button1_Click(object sender, EventArgs e) private void button1_Click(object sender, EventArgs e)
{ {
Directory.CreateDirectory(default_path);
// add something more unique, this is the IE 5.0 default string // add something more unique, this is the IE 5.0 default string
try try
{ {
@ -31,7 +34,7 @@ namespace network.loki.lokinet.win32.ui
ServicePointManager.SecurityProtocol = (SecurityProtocolType)48 | 0 | (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072; ServicePointManager.SecurityProtocol = (SecurityProtocolType)48 | 0 | (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;
wc = new WebClient(); wc = new WebClient();
wc.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT 5.0)"); wc.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT 5.0)");
wc.DownloadFile(uriBox.Text, default_path); wc.DownloadFile(uriBox.Text, string.Format("{0}{1}{2}", default_path, Path.DirectorySeparatorChar, rcName));
MessageBox.Show("LokiNET node bootstrapped", "LokiNET", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show("LokiNET node bootstrapped", "LokiNET", MessageBoxButtons.OK, MessageBoxIcon.Information);
DialogResult = DialogResult.OK; DialogResult = DialogResult.OK;
} }
@ -49,7 +52,7 @@ namespace network.loki.lokinet.win32.ui
lokinet_bootstrap.StartInfo.CreateNoWindow = true; lokinet_bootstrap.StartInfo.CreateNoWindow = true;
lokinet_bootstrap.StartInfo.WorkingDirectory = Directory.GetCurrentDirectory(); lokinet_bootstrap.StartInfo.WorkingDirectory = Directory.GetCurrentDirectory();
lokinet_bootstrap.StartInfo.FileName = lokinetExeString; lokinet_bootstrap.StartInfo.FileName = lokinetExeString;
lokinet_bootstrap.StartInfo.Arguments = string.Format("--cacert rootcerts.pem -L {0} --output \"{1}\"", uriBox.Text, default_path); lokinet_bootstrap.StartInfo.Arguments = string.Format("--cacert rootcerts.pem -L {0} --output \"{1}{2}{3}\"", uriBox.Text, default_path, Path.DirectorySeparatorChar, rcName);
lokinet_bootstrap.Start(); lokinet_bootstrap.Start();
lokinet_bootstrap.WaitForExit(); lokinet_bootstrap.WaitForExit();
if (lokinet_bootstrap.ExitCode == 0) if (lokinet_bootstrap.ExitCode == 0)

@ -48,10 +48,16 @@
#ifndef GHC_FILESYSTEM_H #ifndef GHC_FILESYSTEM_H
#define GHC_FILESYSTEM_H #define GHC_FILESYSTEM_H
// #define BSD manifest constant only in
// sys/param.h
#ifndef _WIN32
#include <sys/param.h>
#endif
#ifndef GHC_OS_DETECTED #ifndef GHC_OS_DETECTED
#if defined(__APPLE__) && defined(__MACH__) #if defined(__APPLE__) && defined(__MACH__)
#define GHC_OS_MACOS #define GHC_OS_MACOS
#elif defined(__linux__) #elif defined(__linux__) || defined(__FreeBSD__)
#define GHC_OS_LINUX #define GHC_OS_LINUX
#if defined(__ANDROID__) #if defined(__ANDROID__)
#define GHC_OS_ANDROID #define GHC_OS_ANDROID
@ -62,6 +68,10 @@
#elif defined(_WIN32) #elif defined(_WIN32)
#define GHC_OS_WINDOWS #define GHC_OS_WINDOWS
#define GHC_OS_WIN32 #define GHC_OS_WIN32
#elif defined(__svr4__)
#define GHC_OS_SYS5R4
#elif defined(BSD)
#define GHC_OS_BSD
#else #else
#error "Operating system currently not supported!" #error "Operating system currently not supported!"
#endif #endif
@ -114,6 +124,7 @@
#include <sys/time.h> #include <sys/time.h>
#include <sys/types.h> #include <sys/types.h>
#include <unistd.h> #include <unistd.h>
#include <limits.h>
#ifdef GHC_OS_ANDROID #ifdef GHC_OS_ANDROID
#include <android/api-level.h> #include <android/api-level.h>
#endif #endif
@ -192,7 +203,7 @@ public:
} }
}; };
template<typename char_type> template <typename char_type>
class path_helper_base class path_helper_base
{ {
public: public:
@ -204,11 +215,11 @@ public:
#endif #endif
}; };
#if __cplusplus < 201703L #if __cplusplus < 201703L
template <typename char_type> template <typename char_type>
constexpr char_type path_helper_base<char_type>::preferred_separator; constexpr char_type path_helper_base<char_type>::preferred_separator;
#endif #endif
// 30.10.8 class path // 30.10.8 class path
class GHC_FS_API_CLASS path class GHC_FS_API_CLASS path
#if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_WSTRING_STRING_TYPE) #if defined(GHC_OS_WINDOWS) && defined(GHC_WIN_WSTRING_STRING_TYPE)
@ -225,7 +236,7 @@ public:
#endif #endif
using string_type = std::basic_string<value_type>; using string_type = std::basic_string<value_type>;
using path_helper_base<value_type>::preferred_separator; using path_helper_base<value_type>::preferred_separator;
// 30.10.10.1 enumeration format // 30.10.10.1 enumeration format
/// The path format in wich the constructor argument is given. /// The path format in wich the constructor argument is given.
enum format { enum format {
@ -427,7 +438,7 @@ private:
#else #else
const impl_string_type& native_impl() const; const impl_string_type& native_impl() const;
#endif #endif
}; }; // namespace filesystem
// 30.10.8.6 path non-member functions // 30.10.8.6 path non-member functions
GHC_FS_API void swap(path& lhs, path& rhs) noexcept; GHC_FS_API void swap(path& lhs, path& rhs) noexcept;
@ -1151,7 +1162,7 @@ GHC_INLINE std::error_code make_system_error(int err)
return std::error_code(err ? err : errno, std::system_category()); return std::error_code(err ? err : errno, std::system_category());
} }
#endif #endif
#endif // GHC_EXPAND_IMPL #endif // GHC_EXPAND_IMPL
template <typename Enum> template <typename Enum>
@ -1274,7 +1285,7 @@ GHC_INLINE unsigned consumeUtf8Fragment(const unsigned state, const uint8_t frag
codepoint = (state ? (codepoint << 6) | (fragment & 0x3fu) : (0xffu >> category) & fragment); codepoint = (state ? (codepoint << 6) | (fragment & 0x3fu) : (0xffu >> category) & fragment);
return state == S_RJCT ? static_cast<unsigned>(S_RJCT) : static_cast<unsigned>((utf8_state_info[category + 16] >> (state << 2)) & 0xf); return state == S_RJCT ? static_cast<unsigned>(S_RJCT) : static_cast<unsigned>((utf8_state_info[category + 16] >> (state << 2)) & 0xf);
} }
GHC_INLINE bool validUtf8(const std::string& utf8String) GHC_INLINE bool validUtf8(const std::string& utf8String)
{ {
std::string::const_iterator iter = utf8String.begin(); std::string::const_iterator iter = utf8String.begin();
@ -1292,9 +1303,9 @@ GHC_INLINE bool validUtf8(const std::string& utf8String)
} }
} // namespace detail } // namespace detail
#endif #endif
namespace detail { namespace detail {
template <class StringType, typename std::enable_if<(sizeof(typename StringType::value_type) == 1)>::type* = nullptr> template <class StringType, typename std::enable_if<(sizeof(typename StringType::value_type) == 1)>::type* = nullptr>
@ -1398,7 +1409,7 @@ inline std::string toUtf8(const std::basic_string<charT, traits, Alloc>& unicode
throw filesystem_error("Illegal code point for unicode character.", result, std::make_error_code(std::errc::illegal_byte_sequence)); throw filesystem_error("Illegal code point for unicode character.", result, std::make_error_code(std::errc::illegal_byte_sequence));
#else #else
appendUTF8(result, 0xfffd); appendUTF8(result, 0xfffd);
if(iter == unicodeString.end()) { if (iter == unicodeString.end()) {
break; break;
} }
#endif #endif
@ -1443,7 +1454,7 @@ GHC_INLINE bool startsWith(const std::string& what, const std::string& with)
GHC_INLINE void path::postprocess_path_with_format(path::impl_string_type& p, path::format fmt) GHC_INLINE void path::postprocess_path_with_format(path::impl_string_type& p, path::format fmt)
{ {
#ifdef GHC_RAISE_UNICODE_ERRORS #ifdef GHC_RAISE_UNICODE_ERRORS
if(!detail::validUtf8(p)) { if (!detail::validUtf8(p)) {
path t; path t;
t._path = p; t._path = p;
throw filesystem_error("Illegal byte sequence for unicode character.", t, std::make_error_code(std::errc::illegal_byte_sequence)); throw filesystem_error("Illegal byte sequence for unicode character.", t, std::make_error_code(std::errc::illegal_byte_sequence));
@ -1568,7 +1579,7 @@ GHC_INLINE const char* strerror_adapter(char* gnu, char*)
GHC_INLINE const char* strerror_adapter(int posix, char* buffer) GHC_INLINE const char* strerror_adapter(int posix, char* buffer)
{ {
if(posix) { if (posix) {
return "Error in strerror_r!"; return "Error in strerror_r!";
} }
return buffer; return buffer;
@ -3408,7 +3419,8 @@ GHC_INLINE bool create_directories(const path& p, std::error_code& ec) noexcept
std::error_code tmp_ec; std::error_code tmp_ec;
if (is_directory(current, tmp_ec)) { if (is_directory(current, tmp_ec)) {
ec.clear(); ec.clear();
} else { }
else {
return false; return false;
} }
} }
@ -4218,7 +4230,7 @@ GHC_INLINE void resize_file(const path& p, uintmax_t size, std::error_code& ec)
#ifdef GHC_OS_WINDOWS #ifdef GHC_OS_WINDOWS
LARGE_INTEGER lisize; LARGE_INTEGER lisize;
lisize.QuadPart = static_cast<LONGLONG>(size); lisize.QuadPart = static_cast<LONGLONG>(size);
if(lisize.QuadPart < 0) { if (lisize.QuadPart < 0) {
ec = detail::make_system_error(ERROR_FILE_TOO_LARGE); ec = detail::make_system_error(ERROR_FILE_TOO_LARGE);
return; return;
} }
@ -4794,7 +4806,7 @@ public:
try { try {
_current.append_name(detail::toUtf8(_findData.cFileName).c_str()); _current.append_name(detail::toUtf8(_findData.cFileName).c_str());
} }
catch(filesystem_error& fe) { catch (filesystem_error& fe) {
ec = fe.code(); ec = fe.code();
return; return;
} }
@ -4802,7 +4814,7 @@ public:
} }
else { else {
auto err = ::GetLastError(); auto err = ::GetLastError();
if(err != ERROR_NO_MORE_FILES) { if (err != ERROR_NO_MORE_FILES) {
_ec = ec = detail::make_system_error(err); _ec = ec = detail::make_system_error(err);
} }
FindClose(_dirHandle); FindClose(_dirHandle);

@ -2,6 +2,8 @@
CC=i686-w64-mingw32-gcc CC=i686-w64-mingw32-gcc
CXX=i686-w64-mingw32-g++ CXX=i686-w64-mingw32-g++
CC64=x86_64-w64-mingw32-gcc
CXX64=x86_64-w64-mingw32-g++
CFLAGS=-Ofast -march=nocona -mfpmath=sse CFLAGS=-Ofast -march=nocona -mfpmath=sse
LIBS=-lws2_32 LIBS=-lws2_32
LDFLAGS=-static LDFLAGS=-static
@ -11,7 +13,7 @@ default: all
ifndef RELEASE ifndef RELEASE
regdbhelper.dll: regdbhelper.dll:
i686-w64-mingw32-gcc regdb_helper.c -o $@ -shared -Os -s $(CC) regdb_helper.c -o $@ -shared -Os -s
mbedtls: mbedtls:
wget https://tls.mbed.org/download/mbedtls-2.16.3-apache.tgz wget https://tls.mbed.org/download/mbedtls-2.16.3-apache.tgz
@ -26,11 +28,11 @@ curl:
wget https://curl.haxx.se/download/curl-7.66.0.tar.xz wget https://curl.haxx.se/download/curl-7.66.0.tar.xz
tar xvf curl-7.66.0.tar.xz tar xvf curl-7.66.0.tar.xz
patch -p1 < curl-win32.patch patch -p1 < curl-win32.patch
cd curl-7.66.0; ./configure --host=i686-w64-mingw32 --target=i686-w64-mingw32 CC=$(CC) CXX=$(CXX) CFLAGS="$(CFLAGS)" LIBS=$(LIBS) --disable-shared --without-zlib --without-ssl --with-mbedtls=$(PWD) --enable-optimize --enable-http --disable-ftp --disable-file --disable-ldap --disable-ldaps --disable-rtsp --enable-proxy --disable-dict --disable-telnet --disable-tftp --disable-pop3 --disable-imap --disable-smb --disable-smtp --disable-gopher --enable-manual cd curl-7.66.0; ./configure --host=i686-w64-mingw32 --target=i686-w64-mingw32 CC=$(CC) CXX=$(CXX) CFLAGS="$(CFLAGS)" LIBS=$(LIBS) --disable-shared --without-zlib --without-ssl --with-mbedtls=$(PWD) --enable-optimize --enable-http --disable-ftp --prefix=$(PWD) --disable-file --disable-ldap --disable-ldaps --disable-rtsp --enable-proxy --disable-dict --disable-telnet --disable-tftp --disable-pop3 --disable-imap --disable-smb --disable-smtp --disable-gopher --enable-manual
$(MAKE) -j4 -C curl-7.66.0 $(MAKE) -j4 -C curl-7.66.0 install
lokinet-bootstrap.exe: mbedtls curl dbghelp lokinet-bootstrap.exe: mbedtls curl dbghelp
cp curl-7.66.0/src/curl.exe $@ cp bin/curl.exe $@
wget -O rootcerts.pem https://curl.haxx.se/ca/cacert.pem wget -O rootcerts.pem https://curl.haxx.se/ca/cacert.pem
cp ../LICENSE .;unix2dos LICENSE LICENSE cp ../LICENSE .;unix2dos LICENSE LICENSE
@ -65,6 +67,15 @@ tap-win32:
mv tap-windows-9.21.2.7z tuntapv9_n6.7z mv tap-windows-9.21.2.7z tuntapv9_n6.7z
wget https://snowlight.net/loki/win32-dist/tap-windows-9.9.2_3.7z wget https://snowlight.net/loki/win32-dist/tap-windows-9.9.2_3.7z
mv tap-windows-9.9.2_3.7z tuntapv9.7z mv tap-windows-9.9.2_3.7z tuntapv9.7z
libuv:
git clone https://github.com/libuv/libuv.git
cd libuv; ./autogen.sh; ./configure --host=i686-w64-mingw32 --target=i686-w64-mingw32 CC=$(CC) CXX=$(CXX) CFLAGS="$(CFLAGS)" --disable-shared --prefix=$(PWD)
make -C libuv -j4 install
make -C libuv -j4 distclean
cd libuv; ./configure --host=x86_64-w64-mingw32 --target=x86_64-w64-mingw32 CC=$(CC64) CXX=$(CXX64) CFLAGS="$(CFLAGS)" --disable-shared
make -C libuv -j4
cp libuv/.libs/libuv.a $(PWD)/lib64
clean: clean:
-rm -rf curl-7* include lib mbedtls-2* *.exe *.dll *.pem *.7z -rm -rf curl-7* include lib mbedtls-2* *.exe *.dll *.pem *.7z

@ -2,7 +2,7 @@
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES! ; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
#define MyAppName "Lokinet" #define MyAppName "Lokinet"
#define MyAppVersion "0.5.2" #define MyAppVersion "0.6.0"
#define MyAppPublisher "Loki Project" #define MyAppPublisher "Loki Project"
#define MyAppURL "https://lokinet.org" #define MyAppURL "https://lokinet.org"
#define MyAppExeName "lokinetui.exe" #define MyAppExeName "lokinetui.exe"
@ -38,18 +38,18 @@ OutputDir={#DevPath}win32-setup
OutputBaseFilename=lokinet-win32 OutputBaseFilename=lokinet-win32
Compression=lzma2/ultra64 Compression=lzma2/ultra64
SolidCompression=yes SolidCompression=yes
VersionInfoVersion=0.5.2 VersionInfoVersion=0.6.0
VersionInfoCompany=Loki Project VersionInfoCompany=Loki Project
VersionInfoDescription=Lokinet for Microsoft® Windows® NT™ VersionInfoDescription=Lokinet for Microsoft® Windows® NT™
#ifndef RELEASE #ifndef RELEASE
VersionInfoTextVersion=0.5.2-dev-{#VCSRev} VersionInfoTextVersion=0.6.0-dev-{#VCSRev}
VersionInfoProductTextVersion=0.5.2-dev-{#VCSRev} VersionInfoProductTextVersion=0.6.0-dev-{#VCSRev}
#else #else
VersionInfoTextVersion=0.5.2 VersionInfoTextVersion=0.6.0
VersionInfoProductTextVersion=0.5.2 ({#Codename}) VersionInfoProductTextVersion=0.6.0 ({#Codename})
#endif #endif
VersionInfoProductName=Lokinet VersionInfoProductName=Lokinet
VersionInfoProductVersion=0.5.2 VersionInfoProductVersion=0.6.0
InternalCompressLevel=ultra64 InternalCompressLevel=ultra64
MinVersion=0,5.0 MinVersion=0,5.0
ArchitecturesInstallIn64BitMode=x64 ArchitecturesInstallIn64BitMode=x64
@ -66,14 +66,15 @@ Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescrip
; only one of these is installed ; only one of these is installed
#ifdef SINGLE_ARCH #ifdef SINGLE_ARCH
Source: "{#DevPath}build\lokinet.exe"; DestDir: "{app}"; Flags: ignoreversion Source: "{#DevPath}build\lokinet.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#DevPath}build\liblokinet-shared.dll"; DestDir: "{app}"; Flags: ignoreversion ; don't ship it, we don't have a public api yet!
;Source: "{#DevPath}build\liblokinet-shared.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "dbghelp64.dll"; DestName: "dbghelp.dll"; DestDir: "{app}"; Flags: ignoreversion Source: "dbghelp64.dll"; DestName: "dbghelp.dll"; DestDir: "{app}"; Flags: ignoreversion
#else #else
Source: "{#DevPath}build\lokinet.exe"; DestDir: "{app}"; Flags: ignoreversion 32bit; Check: not IsWin64 Source: "{#DevPath}build\lokinet.exe"; DestDir: "{app}"; Flags: ignoreversion 32bit; Check: not IsWin64
Source: "{#DevPath}build\liblokinet-shared.dll"; DestDir: "{app}"; Flags: ignoreversion 32bit; Check: not IsWin64 ;Source: "{#DevPath}build\liblokinet-shared.dll"; DestDir: "{app}"; Flags: ignoreversion 32bit; Check: not IsWin64
Source: "dbghelp32.dll"; DestName: "dbghelp.dll"; DestDir: "{app}"; Flags: ignoreversion; Check: not IsWin64 Source: "dbghelp32.dll"; DestName: "dbghelp.dll"; DestDir: "{app}"; Flags: ignoreversion; Check: not IsWin64
Source: "{#DevPath}build64\lokinet.exe"; DestDir: "{app}"; Flags: ignoreversion 64bit; Check: IsWin64 Source: "{#DevPath}build64\lokinet.exe"; DestDir: "{app}"; Flags: ignoreversion 64bit; Check: IsWin64
Source: "{#DevPath}build64\liblokinet-shared.dll"; DestDir: "{app}"; Flags: ignoreversion 64bit; Check: IsWin64 ;Source: "{#DevPath}build64\liblokinet-shared.dll"; DestDir: "{app}"; Flags: ignoreversion 64bit; Check: IsWin64
Source: "dbghelp64.dll"; DestDir: "{app}"; DestName: "dbghelp.dll"; Flags: ignoreversion; Check: IsWin64 Source: "dbghelp64.dll"; DestDir: "{app}"; DestName: "dbghelp.dll"; Flags: ignoreversion; Check: IsWin64
#endif #endif
; UI has landed! ; UI has landed!
@ -93,7 +94,6 @@ Source: "LICENSE"; DestDir: "{app}"; Flags: ignoreversion
Source: "lokinet-bootstrap.exe"; DestDir: "{app}"; Flags: ignoreversion Source: "lokinet-bootstrap.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "rootcerts.pem"; DestDir: "{app}"; Flags: ignoreversion Source: "rootcerts.pem"; DestDir: "{app}"; Flags: ignoreversion
Source: "7z.exe"; DestDir: "{tmp}"; Flags: deleteafterinstall Source: "7z.exe"; DestDir: "{tmp}"; Flags: deleteafterinstall
; if nonexistent, then inet6 was already installed
Source: "inet6.7z"; DestDir: "{app}"; Flags: ignoreversion deleteafterinstall skipifsourcedoesntexist; MinVersion: 0,5.0; OnlyBelowVersion: 0,5.1; Check: not IsTcp6Installed Source: "inet6.7z"; DestDir: "{app}"; Flags: ignoreversion deleteafterinstall skipifsourcedoesntexist; MinVersion: 0,5.0; OnlyBelowVersion: 0,5.1; Check: not IsTcp6Installed
; Copy the correct tuntap driver for the selected platform ; Copy the correct tuntap driver for the selected platform
Source: "tuntapv9.7z"; DestDir: "{app}"; Flags: ignoreversion deleteafterinstall; OnlyBelowVersion: 0, 6.0; Check: not IsTapInstalled Source: "tuntapv9.7z"; DestDir: "{app}"; Flags: ignoreversion deleteafterinstall; OnlyBelowVersion: 0, 6.0; Check: not IsTapInstalled
@ -143,7 +143,6 @@ Name: "{userappdata}\.lokinet"
[Code] [Code]
var var
TapInstalled: Boolean; TapInstalled: Boolean;
TCP6Installed: Boolean;
Version: TWindowsVersion; Version: TWindowsVersion;
function reg_query_helper(): Integer; function reg_query_helper(): Integer;
external 'reg_query_helper@files:regdbhelper.dll cdecl setuponly'; external 'reg_query_helper@files:regdbhelper.dll cdecl setuponly';
@ -165,7 +164,7 @@ end;
function IsTcp6Installed(): Boolean; function IsTcp6Installed(): Boolean;
begin begin
if (FileExists(ExpandConstant('{sys}\drivers\tcpip6.sys')) = false) and (Version.Major = 5) and (Version.Minor = 0) then if (FileExists(ExpandConstant('{sys}\drivers\tcpip6.sys')) = false) then
begin begin
Result := true; Result := true;
end end

Loading…
Cancel
Save