Skip to content

Commit

Permalink
feat: Remote interface interoperate distributed computing resources
Browse files Browse the repository at this point in the history
* make BUILD_REMOTE=1 to build libdcurl.so and remote-worker
* make BUILD_REMOTE=1 check with RabbitMQ broker and remote-worker
* RPC with exclusive callback queues with TTL property
* Channel management for multiple threads but no verification
* Implement local fallback PoW when remote interface fails

Related DLTcollab#137
Related DLTcollab#139
  • Loading branch information
ajblane committed May 14, 2019
1 parent 6014715 commit e1c96ec
Show file tree
Hide file tree
Showing 12 changed files with 899 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "deps/libtuv"]
path = deps/libtuv
url = https://github.com/DLTcollab/libtuv.git
[submodule "deps/rabbitmq-c"]
path = deps/rabbitmq-c
url = https://github.com/alanxz/rabbitmq-c.git
49 changes: 46 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ ifeq ("$(BUILD_FPGA_ACCEL)","1")
CFLAGS += -DENABLE_FPGA_ACCEL
endif

ifeq ("$(BUILD_REMOTE)","1")
CFLAGS += -DENABLE_REMOTE
endif

ifeq ("$(BUILD_JNI)","1")
include mk/java.mk
endif
Expand All @@ -91,6 +95,8 @@ TESTS := $(addprefix $(OUT)/test-, $(TESTS))
LIBS = libdcurl.so
LIBS := $(addprefix $(OUT)/, $(LIBS))

LIBS += $(LIBRABBITMQ_LIBRARY)

JARS := dcurljni-$(VERSION).jar
JARS := $(addprefix $(OUT)/, $(JARS))

Expand All @@ -99,6 +105,10 @@ ifeq ("$(BUILD_JNI)","1")
PREQ += $(JARS)
endif

ifeq ("$(BUILD_REMOTE)", "1")
PREQ += $(OUT)/remote/remote-worker
endif

all: $(PREQ)
.DEFAULT_GOAL := all

Expand Down Expand Up @@ -139,23 +149,56 @@ OBJS += \
pow_fpga_accel.o
endif

ifeq ("$(BUILD_REMOTE)", "1")
OBJS += \
remote_common.o \
remote_interface.o

WORKER_OBJS := $(addprefix $(OUT)/remote/,$(filter-out remote_interface.o, $(OBJS)))
OBJS := $(addprefix $(OUT)/, $(OBJS))
LIBDCURL_OBJS := $(OBJS)
OBJS += $(WORKER_OBJS)

WORKER_CFLAGS := $(filter-out -DENABLE_REMOTE, $(CFLAGS))
else
OBJS := $(addprefix $(OUT)/, $(OBJS))
endif

$(OUT)/test-%.o: tests/test-%.c $(LIBTUV_PATH)/include
$(VECHO) " CC\t$@\n"
$(Q)$(CC) -o $@ $(CFLAGS) -I $(SRC) $(LIBTUV_INCLUDE) -c -MMD -MF $@.d $<

$(OUT)/%.o: $(SRC)/%.c $(LIBTUV_PATH)/include
$(OUT)/%.o: $(SRC)/%.c $(LIBTUV_PATH)/include $(LIBRABBITMQ_PATH)/build/include
$(VECHO) " CC\t$@\n"
$(Q)$(CC) -o $@ $(CFLAGS) $(LIBTUV_INCLUDE) -c -MMD -MF $@.d $<
$(Q)$(CC) -o $@ $(CFLAGS) $(LIBTUV_INCLUDE) $(LIBRABBITMQ_INCLUDE) -c -MMD -MF $@.d $<

$(OUT)/test-%: $(OUT)/test-%.o $(OBJS) $(LIBTUV_LIBRARY)
ifeq ("$(BUILD_REMOTE)", "1")
$(OUT)/test-%: $(OUT)/test-%.o $(LIBDCURL_OBJS) $(LIBS) $(LIBTUV_LIBRARY)
$(VECHO) " LD\t$@\n"
$(Q)$(CC) -o $@ $^ $(LDFLAGS)

$(OUT)/libdcurl.so: $(LIBDCURL_OBJS) $(LIBTUV_LIBRARY)
$(VECHO) " LD\t$@\n"
$(Q)$(CC) -shared -o $@ $^ $(LDFLAGS)
else
$(OUT)/test-%: $(OUT)/test-%.o $(OBJS) $(LIBS) $(LIBTUV_LIBRARY)
$(VECHO) " LD\t$@\n"
$(Q)$(CC) -o $@ $^ $(LDFLAGS)

$(OUT)/libdcurl.so: $(OBJS) $(LIBTUV_LIBRARY)
$(VECHO) " LD\t$@\n"
$(Q)$(CC) -shared -o $@ $^ $(LDFLAGS)
endif

ifeq ("$(BUILD_REMOTE)", "1")
$(OUT)/remote/%.o: $(SRC)/%.c $(LIBTUV_PATH)/include $(LIBRABBITMQ_PATH)/build/include
$(VECHO) " CC\t$@\n"
$(Q)$(CC) -o $@ $(WORKER_CFLAGS) $(LIBTUV_INCLUDE) $(LIBRABBITMQ_INCLUDE) -c -MMD -MF $@.d $<

$(OUT)/remote/remote-worker: $(OUT)/remote/remote_worker.o $(WORKER_OBJS) $(LIBS) $(LIBTUV_LIBRARY)
$(VECHO) " CC\t$@\n"
$(Q)$(CC) -o $@ $^ $(LDFLAGS)
endif

include mk/common.mk

Expand Down
1 change: 1 addition & 0 deletions deps/rabbitmq-c
Submodule rabbitmq-c added at 75a21e
3 changes: 3 additions & 0 deletions mk/common.mk
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Always ensure directory build exist
SHELL_HACK := $(shell mkdir -p $(OUT))
ifeq ("$(BUILD_REMOTE)", "1")
SHELL_HACK += $(shell mkdir -p $(OUT)/remote)
endif

UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
Expand Down
3 changes: 3 additions & 0 deletions mk/defs.mk
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ BUILD_GPU ?= 0
# Build FPGA backend or not
BUILD_FPGA_ACCEL ?= 0

# Build remote interface backend or not
BUILD_REMOTE ?= 0

# Build JNI glue as the bridge between dcurl and IRI
BUILD_JNI ?= 0

Expand Down
17 changes: 17 additions & 0 deletions mk/submodule.mk
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,20 @@ $(LIBTUV_PATH)/include:

$(LIBTUV_LIBRARY):
$(MAKE) -C $(LIBTUV_PATH) TUV_BUILD_TYPE=release TUV_CREATE_PIC_LIB=yes TUV_PLATFORM=$(LIBTUV_PLATFORM) TUV_BOARD=$(LIBTUV_BOARD)

# librabbitmq related variables
LIBRABBITMQ_PATH = deps/rabbitmq-c
LIBRABBITMQ_INCLUDE := -I $(LIBRABBITMQ_PATH)/build/include
LIBRABBITMQ_LIBRARY := $(LIBRABBITMQ_PATH)/build/librabbitmq/librabbitmq.a

$(LIBRABBITMQ_PATH)/build/include:
git submodule update --init $(LIBRABBITMQ_PATH)
mkdir $(LIBRABBITMQ_PATH)/build
cd $(LIBRABBITMQ_PATH)/build && \
cmake -DCMAKE_INSTALL_PREFIX=. .. && \
cmake --build . --target install

$(LIBRABBITMQ_LIBRARY):
cd $(LIBRABBITMQ_PATH)/build && \
cmake --build .

46 changes: 46 additions & 0 deletions src/dcurl.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
#if defined(ENABLE_FPGA_ACCEL)
#include "pow_fpga_accel.h"
#endif
#if defined(ENABLE_REMOTE)
#include "remote_interface.h"
#endif
#include "implcontext.h"
#include "trinary.h"
#include "uv.h"
Expand Down Expand Up @@ -48,6 +51,11 @@ extern ImplContext PoWCL_Context;
extern ImplContext PoWFPGAAccel_Context;
#endif

#if defined(ENABLE_REMOTE)
extern RemoteInterfaceContext RemoteInterface_Context;
static uv_sem_t notify_remoteinterface;
#endif

bool dcurl_init()
{
bool ret = true;
Expand All @@ -68,6 +76,11 @@ bool dcurl_init()
ret &= registerImplContext(&PoWFPGAAccel_Context);
#endif

#if defined(ENABLE_REMOTE)
ret &= initializeRemoteInterfaceContext(&RemoteInterface_Context);
uv_sem_init(&notify_remoteinterface, 0);
#endif

uv_sem_init(&notify, 0);
return isInitialized = ret;
}
Expand All @@ -77,6 +90,10 @@ void dcurl_destroy()
ImplContext *impl = NULL;
struct list_head *p;

#if defined(ENABLE_REMOTE)
destroyRemoteInterfaceContext(&RemoteInterface_Context);
#endif

list_for_each (p, &IMPL_LIST) {
impl = list_entry(p, ImplContext, list);
destroyImplContext(impl);
Expand All @@ -96,6 +113,35 @@ int8_t *dcurl_entry(int8_t *trytes, int mwm, int threads)
if (!isInitialized)
return NULL;

#if defined(ENABLE_REMOTE)

void *pow_remoteinterface_ctx = NULL;

do {
if (enterRemoteInterfaceContext(&RemoteInterface_Context)) {
pow_remoteinterface_ctx = getRemoteInterfaceContext(
&RemoteInterface_Context, trytes, mwm);
goto do_remoteinterface;
}
uv_sem_wait(&notify_remoteinterface);
} while (1);

do_remoteinterface:
if (!doRemoteInterfaceContext(&RemoteInterface_Context,
pow_remoteinterface_ctx)) {
goto local_pow;
} else {
res = getRemoteInterfaceResult(&RemoteInterface_Context,
pow_remoteinterface_ctx);
}
freeRemoteInterfaceContext(&RemoteInterface_Context,
pow_remoteinterface_ctx);
exitRemoteInterfaceContext(&RemoteInterface_Context);
uv_sem_post(&notify_remoteinterface);
return res;

local_pow:
#endif
do {
list_for_each (p, &IMPL_LIST) {
impl = list_entry(p, ImplContext, list);
Expand Down
Loading

0 comments on commit e1c96ec

Please sign in to comment.