Commit 06a98be5 authored by thorsten's avatar thorsten
Browse files

Merge remote-tracking branch 'origin/master'

parents 90f6fbb7 fa569b7f
......@@ -8,26 +8,26 @@
<sourceFolder url="file://$MODULE_DIR$/src/rmq_msg.c" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/relay_crypto.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/relay_source.c" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/relay_event.c" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/relay_auth.c" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/application_template.c" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/librelaymq.pc.in" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/relay_source.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/relay_protocol.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/relay_protocol.c" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/relay.c" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/relay_peer.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/relay_source.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/relay_context.c" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/peer_table.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/relay_crypto.c" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/relay_event.c" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/relay_identity.c" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/relay_target.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/peer_table.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/relay_event.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/relay.c" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/relay_peer.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/relay_target.c" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/relay_context.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/relay_context.c" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/relay_peer.c" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/relay_handle.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/relay_auth.c" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/peer_table.c" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/relay_protocol.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/relay_event.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/relay_handle.c" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/rmq_msg.h" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/Findlibzmq.cmake" isTestSource="false" />
......@@ -38,15 +38,15 @@
<orderEntry type="module-library">
<library name="Header Search Paths">
<CLASSES>
<root url="file:///usr/include" />
<root url="file:///usr/lib/gcc/x86_64-linux-gnu/5/include" />
<root url="file:///usr/lib/gcc/x86_64-linux-gnu/5/include-fixed" />
<root url="file:///usr/include" />
<root url="file:///usr/local/include" />
</CLASSES>
<SOURCES>
<root url="file:///usr/include" />
<root url="file:///usr/lib/gcc/x86_64-linux-gnu/5/include" />
<root url="file:///usr/lib/gcc/x86_64-linux-gnu/5/include-fixed" />
<root url="file:///usr/include" />
<root url="file:///usr/local/include" />
</SOURCES>
</library>
......
......@@ -11,6 +11,8 @@ project(relaymq)
enable_language(C)
enable_testing()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=c11")
set(SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}")
########################################################################
......
......@@ -204,7 +204,6 @@ private:
std::unordered_map<int, std::function<bool()>> timers;
std::unordered_map<int, std::function<void()>> tickets;
zmutex_t* mutex;
zsock_t *frontend;
void *loop; //> Reactor written in C
......@@ -296,7 +295,8 @@ public:
StartFct<T> onStart = nullptr,
CancelFct<T> onCancel = nullptr,
bool cancel_loop_on_exit=false){
zmutex_lock(this->mutex);
//zmutex_lock(this->mutex);
index++;
zsys_debug("Adding new Handler at index %i", index);
......@@ -313,7 +313,7 @@ public:
this->AddToZLoop(socket->getRaw(), index, cancel_loop_on_exit);
zmutex_unlock(this->mutex);
//zmutex_unlock(this->mutex);
return std::unique_ptr<CancelHandle>(new HandlerCancelHandle(this, index));
}
......
......@@ -598,8 +598,8 @@ verbose(verbose){
this->index = 0;
assert(this->index == 0);
this->mutex = zmutex_new();
assert(this->mutex);
// this->mutex = zmutex_new();
// assert(this->mutex);
this->handlers = {};
......@@ -633,7 +633,7 @@ void RmqLoop::CancelHandler(int handle) {
}
std::unique_ptr<TicketHandle> RmqLoop::addTicket(const std::function<void()> fn, bool ext) {
zmutex_lock(this->mutex);
//zmutex_lock(this->mutex);
index++;
if(this->verbose)zsys_debug("Adding new Ticket at index %i", index);
this->tickets[index] = fn;
......@@ -647,7 +647,7 @@ std::unique_ptr<TicketHandle> RmqLoop::addTicket(const std::function<void()> fn,
c_handle = s_add_ticket((loop_t *) loop, (void *) &tickets[index]);
}
assert(c_handle);
zmutex_unlock(this->mutex);
//zmutex_unlock(this->mutex);
if(this->verbose)
zsys_debug("Successfully added new Ticket at index %i", index);
......@@ -669,7 +669,7 @@ std::unique_ptr<CancelHandle> RmqLoop::addTimer(std::function<bool()> fn,
size_t repetitions,
bool exit_on_cancel) {
zmutex_lock(this->mutex);
// zmutex_lock(this->mutex);
index++;
if(this->verbose)
zsys_debug("Adding new Timer at index %i", index);
......@@ -678,7 +678,7 @@ std::unique_ptr<CancelHandle> RmqLoop::addTimer(std::function<bool()> fn,
assert(timer_id);
auto handle = std::unique_ptr<CancelHandle>(new TimerCancelHandle(this, index, timer_id));
zmutex_unlock(this->mutex);
// zmutex_unlock(this->mutex);
return handle;
}
......@@ -709,11 +709,11 @@ RmqLoop::add(std::shared_ptr<Socket> socket, SimpleHandlerFct handler,
SimpleCancelFct onCancel,
bool cancel_loop_on_exit) {
zmutex_lock(this->mutex);
// zmutex_lock(this->mutex);
index++;
if(this->verbose)
zsys_debug("Adding new Handler at index %i", index);
zmutex_unlock(this->mutex);
// zmutex_unlock(this->mutex);
auto wrapped = std::bind(handler, this, std::placeholders::_1);
......@@ -722,9 +722,9 @@ RmqLoop::add(std::shared_ptr<Socket> socket, SimpleHandlerFct handler,
std::function<void(std::shared_ptr<Socket>)> onCancelWrapped = nullptr;
if (onCancel) onCancelWrapped = std::bind(onCancel, this, std::placeholders::_1);
zmutex_lock(this->mutex);
// zmutex_lock(this->mutex);
auto it = handlers.emplace(index, std::unique_ptr<RmqLoopHandler>(new RmqLoopHandler(socket, wrapped, onStartWrapped, onCancelWrapped)));
zmutex_unlock(this->mutex);
// zmutex_unlock(this->mutex);
bool success = it.second;
assert(success); // TODO: Fail hard on failure ! Good ? Bad ? Ugly ?
......@@ -732,7 +732,7 @@ RmqLoop::add(std::shared_ptr<Socket> socket, SimpleHandlerFct handler,
this->AddToZLoop(socket->getRaw(), index, cancel_loop_on_exit);
auto cancelHandle = std::unique_ptr<CancelHandle>(new HandlerCancelHandle(this, index));
zmutex_unlock(this->mutex);
// zmutex_unlock(this->mutex);
return cancelHandle;
}
......
......@@ -13,37 +13,38 @@ extern "C" {
typedef struct _relay_event_handler_t relay_event_handler_t;
relay_event_handler_t*
RELAYMQ_EXPORT relay_event_handler_t*
relay_event_handler_new(relay_event_type_t event, ...);
void
RELAYMQ_EXPORT void
relay_event_handler_destroy(relay_event_handler_t** self_p);
int
RELAYMQ_EXPORT int
relay_event_handler_add(relay_event_handler_t* self,
relay_t* relay);
int
RELAYMQ_EXPORT int
relay_event_handler_remove(relay_event_handler_t* self, relay_t* relay);
int
RELAYMQ_EXPORT int
relay_event_handler_wait(relay_event_handler_t* self, int timeo);
int
RELAYMQ_EXPORT int
relay_event_handler_next(relay_event_handler_t* self);
int
RELAYMQ_EXPORT int
relay_event_handler_has_next(relay_event_handler_t* self);
relay_event_type_t
RELAYMQ_EXPORT relay_event_type_t
relay_event_handler_type(relay_event_handler_t* self);
relay_t*
RELAYMQ_EXPORT relay_t*
relay_event_handler_source(relay_event_handler_t* self);
zsock_t*
RELAYMQ_EXPORT zsock_t*
relay_event_handler_sock(relay_event_handler_t* self);
#ifdef __cplusplus
}
#endif
......
......@@ -94,7 +94,9 @@ s_send(relay_t* self, zuuid_t* sender, zhashx_t* header, zmsg_t* message, void*
if(!message) {
msg_frame = zframe_from(EMPTY_MSG);
}else{
msg_frame = zmsg_encode(message);
byte* buffer;
size_t size = zmsg_encode(message, &buffer);
msg_frame = zframe_new(buffer, size);
}
assert(msg_frame);
......
......@@ -285,12 +285,15 @@ relay_crypto_encrypt(relay_crypto_t* self,byte* key, zmsg_t** msg){
case ENCRYPTED:
clear = zframe_dup(current);//Make a copy of the data
break;
case NONE://First layer of encryption
case NONE: {//First layer of encryption
/*
* Make single frame out of message to reduce overhead.
* Otherwise we would need to iterate ver each frame and everytime and had a lot more memory allocations
*/
clear = zmsg_encode(*msg);//Creates copy
byte *buffer;
size_t size = zmsg_encode(*msg, &buffer);
clear = zframe_new(buffer, size);
}
break;
}
assert(clear);
......@@ -331,7 +334,7 @@ relay_crypto_decrypt(relay_crypto_t* self, byte* key, zmsg_t** msg){
case CLEAR:
cleartext = s_process_message (self, key, current);
assert(cleartext);
real_msg = zmsg_decode(cleartext);
real_msg = zmsg_decode(zframe_data(cleartext), zframe_size(cleartext));
break;
case ENCRYPTED://Frame is encrypted
......
......@@ -1354,7 +1354,7 @@ s_handle_introduce(relay_protocol_t *self, relay_peer_t *peer, zuuid_t* sender,
assert(payload);
zframe_t* message_frame = zmsg_pop(payload);
zmsg_t* message = zmsg_decode(message_frame);
zmsg_t* message = zmsg_decode(zframe_data(message_frame), zframe_size(message_frame));
//Decode Indentites
zlistx_t* ident_list = s_process_identities(self, payload);
......@@ -1413,7 +1413,7 @@ s_handle_message(relay_protocol_t *self, relay_peer_t *peer, zuuid_t* sender, zm
assert(payload);//There must still be something left in the message
zframe_t* message_frame = zmsg_pop(payload);
zmsg_t* message = message_frame ? zmsg_decode(message_frame) : NULL;
zmsg_t* message = message_frame ? zmsg_decode(zframe_data(message_frame), zframe_size(message_frame)) : NULL;
//Decode Indentites
zlistx_t* ident_list = s_process_identities(self, payload);
......
git stash
git pull
./autogen.sh
./configure
cmake ./
make
sudo make install
sudo ldconfg
cd ..
cd bindings
cd cpp
cmake ./
sudo make install
cd ..
cd ..
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment