Skip to content

Commit

Permalink
Merge remote-tracking branch 'cjdelisle/crashey'
Browse files Browse the repository at this point in the history
  • Loading branch information
Lars Gierth committed Aug 25, 2015
2 parents b9ec981 + d9e365e commit 1f436e2
Show file tree
Hide file tree
Showing 12 changed files with 132 additions and 24 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,17 @@ it will be downloaded and installed in the source tree.

sudo apt-get install nodejs git build-essential

#### Fedora 22+ based distro:

sudo dnf install install nodejs git
sudo dnf install @development-tools

#### RHEL based distro (adds the EPEL repo):

sudo yum localinstall https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
sudo yum install install nodejs git
sudo yum install @development-tools

#### OS X:

On OS X, you must install the Command Line Developer Tools. If
Expand Down Expand Up @@ -188,7 +199,7 @@ If it says: `cat: /dev/net/tun: File descriptor in bad state` Good!

If it says: `cat: /dev/net/tun: No such file or directory`, create it using:

sudo mkdir /dev/net &&
sudo mkdir -p /dev/net &&
sudo mknod /dev/net/tun c 10 200 &&
sudo chmod 0666 /dev/net/tun

Expand Down
2 changes: 1 addition & 1 deletion README_RU.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ Cjdns поставляется с библиотекой для python, кото

# Продвинутая настройка

* [Запуск cjdns не от root](doc/non-root-user.md)
* [Запуск cjdns не от root](doc/non-root-user_ru.md)
* [Настройка ПК как cjdns NAT gateway для вашей домашней сети](doc/nat-gateway.md)
* [Установка cjdns на OpenIndiana](doc/open-indiana.md)

Expand Down
11 changes: 8 additions & 3 deletions client/Configurator.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,16 +450,21 @@ static void security(struct Allocator* tempAlloc, List* conf, struct Log* log, s
int chroot = 1;
int setupComplete = 1;
int setuser = 1;
if (Defined(win32)) {
setuser = 0;
}

int uid = -1;
int keepNetAdmin = 1;

do {
Dict* d = Dict_new(tempAlloc);
Dict_putString(d, String_CONST("user"), String_CONST("nobody"), tempAlloc);
Dict* ret = NULL;
rpcCall0(String_CONST("Security_getUser"), d, ctx, tempAlloc, &ret, true);
uid = *Dict_getInt(ret, String_CONST("uid"));
if (!Defined(win32)) {
Dict* ret = NULL;
rpcCall0(String_CONST("Security_getUser"), d, ctx, tempAlloc, &ret, true);
uid = *Dict_getInt(ret, String_CONST("uid"));
}
} while (0);

for (int i = 0; conf && i < List_size(conf); i++) {
Expand Down
11 changes: 8 additions & 3 deletions client/cjdroute2.c
Original file line number Diff line number Diff line change
Expand Up @@ -353,9 +353,14 @@ static int genconf(struct Random* rand, bool eth)
" },\n"
"\n"
" // If set to non-zero, cjdns will not fork to the background.\n"
" // Recommended for use in conjunction with \"logTo\":\"stdout\".\n"
" \"noBackground\":0,\n"
"}\n");
" // Recommended for use in conjunction with \"logTo\":\"stdout\".\n");
if (Defined(win32)) {
printf(" \"noBackground\":1,\n");
}
else {
printf(" \"noBackground\":0,\n");
}
printf("}\n");

return 0;
}
Expand Down
15 changes: 12 additions & 3 deletions contrib/android/cjdroid-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,21 @@ cd "$src_dir"
[[ ! -e "$ndk_dir" ]] \
&& ln -sf "$NDK" "$ndk_dir"

GCC=$work_dir/android-arm-toolchain/bin/arm-linux-androideabi-gcc
TOOLCHAIN=arm-linux-androideabi-4.9
COMPILER=arm-linux-androideabi-
[[ "x$TARGET_ARCH" == "xarm64" ]] \
&& GCC=$work_dir/android-arm-toolchain/bin/aarch64-linux-android-gcc \
&& TOOLCHAIN=aarch64-linux-android-4.9 \
&& COMPILER=aarch64-linux-android-


##BUILD TOOLCHAIN: build gcc toolchain
[[ ! -x "$work_dir/android-arm-toolchain/bin/arm-linux-androideabi-gcc" ]] && {
[[ ! -x "$GCC" ]] && {
cd "$src_dir"
"$ndk_dir/build/tools/make-standalone-toolchain.sh" \
--platform=android-21 \
--toolchain=arm-linux-androideabi-4.9 \
--toolchain=$TOOLCHAIN \
--install-dir="$work_dir/android-arm-toolchain/" \
--system=linux-$cpu_arch \
|| exit 1
Expand All @@ -126,7 +135,7 @@ cd "$build_dir"
export PATH="$work_dir/android-arm-toolchain/bin:$PATH"

##BUILD cjdns (without tests)
CROSS_COMPILE=arm-linux-androideabi- ./cross-do 2>&1 \
CROSS_COMPILE=$COMPILER ./cross-do 2>&1 \
| tee cjdns-build.log
[[ ! -f 'cjdroute' ]] && {
echo -e "\nBUILD FAILED :("
Expand Down
16 changes: 11 additions & 5 deletions dht/Pathfinder.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ static int incomingFromDHT(struct DHTMessage* dmessage, void* vpf)
struct Message* msg = dmessage->binMessage;
struct Address* addr = dmessage->address;

if (addr->path == 1) {
// Message to myself, can't handle this later because encrypting a message to yourself
// causes problems.
DHTModuleRegistry_handleIncoming(dmessage, pf->registry);
return 0;
}

// Sanity check (make sure the addr was actually calculated)
Assert_true(addr->ip6.bytes[0] == 0xfc);

Expand Down Expand Up @@ -370,7 +377,7 @@ static Iface_DEFUN incomingMsg(struct Message* msg, struct Pathfinder_pvt* pf)
Message_shift(msg, -(RouteHeader_SIZE + DataHeader_SIZE), NULL);
Bits_memcpyConst(addr.ip6.bytes, hdr->ip6, 16);
Bits_memcpyConst(addr.key, hdr->publicKey, 32);
int version = addr.protocolVersion = Endian_bigEndianToHost32(hdr->version_be);
addr.protocolVersion = Endian_bigEndianToHost32(hdr->version_be);
addr.padding = 0;
addr.path = Endian_bigEndianToHost64(hdr->sh.label_be);

Expand All @@ -384,10 +391,9 @@ static Iface_DEFUN incomingMsg(struct Message* msg, struct Pathfinder_pvt* pf)

DHTModuleRegistry_handleIncoming(&dht, pf->registry);

if (!version && addr.protocolVersion) {
struct Message* nodeMsg = Message_new(0, 256, msg->alloc);
Iface_CALL(sendNode, nodeMsg, &addr, 0xfffffff0u, pf);
}
struct Message* nodeMsg = Message_new(0, 256, msg->alloc);
Iface_CALL(sendNode, nodeMsg, &addr, 0xfffffff0u, pf);

if (dht.pleaseRespond) {
// what a beautiful hack, see incomingFromDHT
return Iface_next(&pf->pub.eventIf, msg);
Expand Down
2 changes: 1 addition & 1 deletion doc/admin-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ Example:
### AdminLog Functions:

Since cjdns contains so many logging locations, logging to a file would not only be inefficient
but it would fill up your disk rather quickly. Because if this, cjdns logging is only enabled on
but it would fill up your disk rather quickly. Because of this, cjdns logging is only enabled on
request, with these functions you can ask for logs to be enabled on a log level, per-file or even
per-line basis.

Expand Down
58 changes: 58 additions & 0 deletions doc/non-root-user_ru.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
Запуск cjdns не от имени суперпользователя
==========================================

Есть два способа запуска cjdns не от имени суперпользователя. Они могут вам пригодится, если вы хотите запустить cjdns на OpenVZ,
или запустить сеть от имени обычного пользователя.

Метод 1: Преждевременно настроить интерфейс tun (нужно для OpenVZ)
---------------------------------------------------------------------

Если вы используйте VPS на базе OpenVZ, вам нужно использовать этот метод,
так как OpenVZ запрещает постоянные туннели.

Создать пользователя cjdns:

sudo useradd cjdns

Создать новый интерфейс TUN и разрешить cjdns к нему обращаться:

sudo /sbin/ip tuntap add mode tun user cjdns dev cjdroute0


### 4b-1: Настройка интерфейса вручную

Запустите команды ниже для подготовки вашего устройства TUN.

sudo /sbin/ip addr add <your ipv6 address>/8 dev cjdroute0
sudo /sbin/ip link set mtu 1312 dev cjdroute0
sudo /sbin/ip link set cjdroute0 up

Эти команды следует выполнять с root-привилегиями каждый раз при перезапуске системы.
Вы можете разместить их в /etc/rc.local, если ваша система его поддерживает.

#### Старые версии iproute2

Если при запуске /sbin/ip вы ввидите ошибку, версия iproute2 может быть устаревшей.

sudo /sbin/ip tuntap add mode tun user cjdns
Object "tuntap" is unknown, try "ip help".

Исправление: На данный момент, следует скопировать новую
версию исполняемого файла ip в вашу домашнюю директорию.
Заменять системные файлы - не самая лучшая идея.

### 4b-2: Запуск!

sudo -u cjdns ./cjdroute < cjdroute.conf

Чтобы удалить туннель, используйте следующую команду:

sudo /sbin/ip tuntap del mode tun <имя туннеля>

Метод 2: Дать исполняемому файлу cjdroute полномочия для создания устройства TUN.
---------------------------------------------------------------------------------

Запустите эту команду с root-правами после сборки (и каждый раз при пересборке)

setcap "cap_net_admin+eip cap_net_raw+eip" cjdroute

21 changes: 17 additions & 4 deletions node_build/dependencies/libuv/src/unix/linux-core.c
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
int fd;
int op;
int i;
static int no_epoll_wait;

if (loop->nfds == 0) {
assert(QUEUE_EMPTY(&loop->watcher_queue));
Expand Down Expand Up @@ -184,10 +185,22 @@ void uv__io_poll(uv_loop_t* loop, int timeout) {
count = 48; /* Benchmarks suggest this gives the best throughput. */

for (;;) {
nfds = uv__epoll_wait(loop->backend_fd,
events,
ARRAY_SIZE(events),
timeout);
if (!no_epoll_wait) {
nfds = uv__epoll_wait(loop->backend_fd,
events,
ARRAY_SIZE(events),
timeout);
if (nfds == -1 && errno == ENOSYS) {
no_epoll_wait = 1;
continue;
}
} else {
nfds = uv__epoll_pwait(loop->backend_fd,
events,
ARRAY_SIZE(events),
timeout,
NULL);
}

/* Update loop->time unconditionally. It's tempting to skip the update when
* timeout == 0 (i.e. non-blocking poll) but there is no guarantee that the
Expand Down
4 changes: 2 additions & 2 deletions node_build/dependencies/libuv/src/unix/thread.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ int uv_cond_init(uv_cond_t* cond) {
if (err)
return -err;

#if !defined(__ANDROID__)
#if !(defined(__ANDROID__) && defined(HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC))
err = pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);
if (err)
goto error2;
Expand Down Expand Up @@ -338,7 +338,7 @@ int uv_cond_timedwait(uv_cond_t* cond, uv_mutex_t* mutex, uint64_t timeout) {
timeout += uv__hrtime(UV_CLOCK_PRECISE);
ts.tv_sec = timeout / NANOSEC;
ts.tv_nsec = timeout % NANOSEC;
#if defined(__ANDROID__)
#if defined(__ANDROID__) && defined(HAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC)
/*
* The bionic pthread implementation doesn't support CLOCK_MONOTONIC,
* but has this alternative function instead.
Expand Down
1 change: 1 addition & 0 deletions util/platform/netdev/NetPlatform_openbsd.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "exception/Except.h"
#include "util/platform/netdev/NetPlatform.h"
#include "util/AddrTools.h"
#include "util/platform/Sockaddr.h"

#include <errno.h>
#include <ctype.h>
Expand Down
2 changes: 1 addition & 1 deletion util/platform/netdev/NetPlatform_win32.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static NET_LUID getLuid(const char* name, struct Except* eh)
{
uint16_t ifName[IF_MAX_STRING_SIZE + 1] = {0};
WinFail_check(eh,
(!MultiByteToWideChar(CP_UTF8, 0, name, strlen(name), ifName, IF_MAX_STRING_SIZE + 1))
(!MultiByteToWideChar(CP_ACP, 0, name, strlen(name), ifName, IF_MAX_STRING_SIZE + 1))
);
NET_LUID out;
WinFail_check(eh, ConvertInterfaceAliasToLuid(ifName, &out));
Expand Down

0 comments on commit 1f436e2

Please sign in to comment.