Skip to content

Commit

Permalink
A fairly major upgrade. Many minor improvements and fixes. TANK(servi…
Browse files Browse the repository at this point in the history
…ce) now uses a new Elastic Binary Trees timers scheduler for performance and simplicity. New API for reloading a topic's partition configuration and a matching TANK CLI command for that. Cluster support(via consule integration) forthcoming.
  • Loading branch information
markpapadakis committed Sep 20, 2018
1 parent 3c35e8d commit 4c54b9f
Show file tree
Hide file tree
Showing 292 changed files with 129,343 additions and 1,757 deletions.
30 changes: 18 additions & 12 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
HOST:=$(shell hostname)


ifeq ($(HOST), origin)
# When building on our dev.system
include /home/system/Development/Switch/Makefile.dfl
CXXFLAGS:=$(CPPFLAGS_SANITY_DEBUG) #-fsanitize=address
LDFLAGS:=$(LDFLAGS_SANITY) -L$(SWITCH_BASE) -lswitch -lpthread -ldl -lcrypto -lz -lssl -ljemalloc #-fsanitize=address
CXXFLAGS:=$(CPPFLAGS_SANITY_RELEASE) #-fsanitize=address
LDFLAGS:=$(LDFLAGS_SANITY) -L$(SWITCH_BASE) -lswitch -lpthread -ldl -lcrypto -lz -lssl -ljemalloc /home/system/Development/Switch/ext/ebtree/libtree.a
SWITCH_LIB:=-lswitch
CXXFLAGS += -DTRACE_REACHABILITY_OVERSEER
#CXX:=scan-build clang++
Expand All @@ -18,31 +17,38 @@ else
-Wunused-variable -Wunused-value -Wreturn-type -Wparentheses -Wmissing-braces -Wno-invalid-source-encoding -Wno-invalid-offsetof \
-Wno-unknown-pragmas -Wno-missing-field-initializers -Wno-unused-parameter -Wno-sign-compare -Wno-invalid-offsetof \
-fno-rtti -std=c++14 -ffast-math -D_REENTRANT -DREENTRANT -g3 -ggdb -fno-omit-frame-pointer \
-fno-strict-aliasing -DLEAN_SWITCH -ISwitch/ -Wno-uninitialized -Wno-unused-function -Wno-uninitialized -funroll-loops -O3
LDFLAGS:=-ldl -ffunction-sections -lpthread -ldl -lz -LSwitch/ext_snappy/ -lsnappy
-fno-strict-aliasing -DLEAN_SWITCH -ISwitch/ -I./ -Wno-uninitialized -Wno-unused-function -Wno-uninitialized -funroll-loops -Ofast
LDFLAGS:=-ldl -ffunction-sections -lpthread -ldl -lz -LSwitch/ext_snappy/ -lsnappy ext/ebtree/libtree.a
SWITCH_LIB:=
SWITCH_DEP:=switch
EXT_DEP:=ext
# Docker complains about clang++ dep.
#CXX:=clang++
endif

all: service cli-tool
all: service cli-tool client

switch:
make -C Switch/ext_snappy/
+make -C Switch/ext_snappy/ all

ext:
+make -C ext/ebtree/ all

client: client.o $(SWITCH_DEP)
client: client.o $(SWITCH_DEP) $(EXT_DEP)
ar rcs libtank.a client.o

service: service.o $(SWITCH_DEP)
$(CXX) service.o -o ./tank $(LDFLAGS)
service: service.o $(SWITCH_DEP) $(EXT_DEP)
$(CXX) service.o -o ./tank $(LDFLAGS)

cli-tool: cli.o client $(SWITCH_DEP)
$(CXX) cli.o -o ./tank-cli -L./ -ltank $(LDFLAGS) $(SWITCH_LIB)

.o: .cpp

clean:
rm -f *.o *.a Switch/ext_snappy/*o Switch/ext_snappy/*.a
rm -f ./*.o
rm -f ./*.a
rm -f Switch/ext_snappy/*.o
rm -f ext/ebtree/*.o

.PHONY: clean
.PHONY: clean ext switch
111 changes: 111 additions & 0 deletions Switch/base64.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
#include "switch.h"
#include "base64.h"

std::size_t Base64::decoded_repr_length(const str_view32 s) {
size_t l = s.size(), padding;

if (l && s.data()[l - 1] == '=') {
if (l >= 2 && s.data()[l - 2] == '=')
padding = 2;
else
padding = 1;
}
padding = 0;

return (l * 3) / 4 - padding;
}

uint16_t b64_int(const uint8_t c) noexcept {
if (c == 43)
return 62;
else if (c == 47)
return 63;
else if (c == 61)
return 64;
else if (c > 47 && c < 58)
return c + 4;
else if (c > 64 && c < 91)
return c - 'A';
else if (c > 96 && c < 123)
return (c - 'a') + 26;
else
return 256;
}

uint32_t Base64::Encode(const uint8_t *in, size_t in_len, Buffer *out) {
static constexpr const char *b64_chr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
uint32_t s[3], j{0};
const auto saved{out->size()};

for (uint32_t i{0}; i != in_len; ++i) {
s[j++] = in[i];

if (j == 3) {
uint8_t o[4];

o[0] = b64_chr[(s[0] & 255) >> 2];
o[1] = b64_chr[((s[0] & 0x03) << 4) + ((s[1] & 0xF0) >> 4)];
o[2] = b64_chr[((s[1] & 0x0F) << 2) + ((s[2] & 0xC0) >> 6)];
o[3] = b64_chr[s[2] & 0x3F];
j = 0;

out->append(str_view32(reinterpret_cast<const char *>(o), 4));
}
}

if (j) {
uint8_t o[4];

if (j == 1)
s[1] = 0;

o[0] = b64_chr[(s[0] & 255) >> 2];
o[1] = b64_chr[((s[0] & 0x03) << 4) + ((s[1] & 0xF0) >> 4)];

if (j == 2)
o[2] = b64_chr[((s[1] & 0x0F) << 2)];
else
o[2] = '=';

o[3] = '=';

out->append(str_view32(reinterpret_cast<const char *>(o), 4));
}

return out->size() - saved;
}

int32_t Base64::Decode(const uint8_t *in, const size_t in_len, Buffer *out) {
uint32_t s[4], j{0};
const auto saved{out->size()};

for (uint32_t i{0}; i < in_len; i++) {
if (const auto v = b64_int(in[i]); v == 256)
return -1;
else
s[j++] = v;

if (j == 4) {
uint8_t k{0}, o[4];

o[0] = ((s[0] & 255) << 2) + ((s[1] & 0x30) >> 4);
if (s[2] != 64) {
o[1] = ((s[1] & 0x0F) << 4) + ((s[2] & 0x3C) >> 2);

if ((s[3] != 64)) {
o[2] = ((s[2] & 0x03) << 6) + (s[3]);
k = 3;
} else {
k = 2;
}
} else {
k = 1;
}

out->append(str_view32(reinterpret_cast<const char *>(o), k));
j = 0;
}
}

return out->size() - saved;
}
20 changes: 20 additions & 0 deletions Switch/base64.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once
#include "switch.h"
#include "buffer.h"
#include <openssl/bio.h>
#include <openssl/evp.h>

static inline bool is_base64(const uint8_t c) noexcept
{
return c == '+' || c == '/' || (c >= '0' && c <= '9') || (c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z');
}


namespace Base64
{
size_t decoded_repr_length(const str_view32 s);

uint32_t Encode(const uint8_t *in, size_t in_len, Buffer *out);

int32_t Decode(const uint8_t *in, const size_t in_len, Buffer *out);
}
Loading

0 comments on commit 4c54b9f

Please sign in to comment.