Permalink
Browse files

vaultd v0.0.1

  • Loading branch information...
CodeShark committed Apr 12, 2014
1 parent ee78579 commit 0c12822f7e48dab6cec990baba6a845ccac4e6a2
Showing with 148 additions and 3 deletions.
  1. +100 −0 vaultd/Makefile
  2. +48 −3 vaultd/src/main.cpp
@@ -0,0 +1,100 @@
ODB_DB = -DDATABASE_SQLITE
LOGGER_DIR = ../deps/logger
COINCLASSES_DIR = ../deps/CoinClasses
COINQ_DIR = ../deps/CoinQ
COINDB_DIR = ../deps/CoinDB
CLI_DIR = ../deps/cli
INCLUDE_PATH += \
-I$(COINDB_DIR)/src \
-I$(COINDB_DIR)/odb \
-I$(COINDB_DIR)/tools/src \
-I$(COINQ_DIR)/src \
-I$(COINCLASSES_DIR)/src \
-I$(LOGGER_DIR)/src \
-I$(CLI_DIR)/src
LIB_PATH += \
-L$(COINDB_DIR)/lib \
-L$(COINQ_DIR)/lib \
-L$(COINCLASSES_DIR)/lib \
-L$(LOGGER_DIR)/lib
CXXFLAGS += -Wall -O3
ifndef OS
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S), Linux)
OS = linux
else ifeq ($(UNAME_S), Darwin)
OS = osx
endif
endif
ifeq ($(OS), linux)
CXX = g++
CC = gcc
CXXFLAGS += -Wno-unknown-pragmas -std=c++0x -DBOOST_SYSTEM_NOEXCEPT=""
ARCHIVER = ar
else ifeq ($(OS), mingw64)
CXX = x86_64-w64-mingw32-g++
CC = x86_64-w64-mingw32-gcc
CXXFLAGS += -Wno-unknown-pragmas -Wno-strict-aliasing -std=c++0x -DBOOST_SYSTEM_NOEXCEPT=""
MINGW64_ROOT = /usr/x86_64-w64-mingw32
INCLUDE_PATH += -I$(MINGW64_ROOT)/include
ARCHIVER = x86_64-w64-mingw32-ar
BOOST_THREAD_SUFFIX = _win32
BOOST_SUFFIX = -mt-s
PLATFORM_LIBS += \
-static-libgcc -static-libstdc++ \
-lws2_32 \
-lmswsock
EXE_EXT = .exe
else ifeq ($(OS), osx)
CXX = clang++
CC = clang
CXXFLAGS += -Wno-unknown-pragmas -Wno-unneeded-internal-declaration -std=c++11 -stdlib=libc++ -DBOOST_THREAD_DONT_USE_CHRONO -DMAC_OS_X_VERSION_MIN_REQUIRED=MAC_OS_X_VERSION_10_6 -mmacosx-version-min=10.7
INCLUDE_PATH += -I/usr/local/include
ARCHIVER = ar
BOOST_SUFFIX = -mt
else ifneq ($(MAKECMDGOALS), clean)
$(error OS must be set to linux, mingw64, or osx)
endif
LIBS += \
-lCoinDB \
-lCoinQ \
-lCoinClasses \
-lWebSocketServer \
-llogger \
-lboost_system$(BOOST_SUFFIX) \
-lboost_filesystem$(BOOST_SUFFIX) \
-lboost_regex$(BOOST_SUFFIX) \
-lboost_thread$(BOOST_THREAD_SUFFIX)$(BOOST_SUFFIX) \
-lboost_serialization$(BOOST_SUFFIX) \
-lcrypto \
-lodb-sqlite \
-lodb
all: build/vaultd${EXE_EXT}
build/vaultd${EXE_EXT}: src/main.cpp
$(CXX) $(CXXFLAGS) $(ODB_DB) $(INCLUDE_PATH) $(LIB_PATH) $< -o $@ $(LIBS)
clean:
-rm -f build/vaultd${EXE_EXT}
@@ -12,6 +12,8 @@
#include <WebSocketServer.h>
#include <cli.hpp>
#include <formatting.h>
#include <Vault.h>
#include <Schema-odb.hxx>
@@ -21,6 +23,9 @@
#include <Base58Check.h>
#include <thread>
#include <chrono>
#include <iostream>
#include <sstream>
#include <ctime>
@@ -741,16 +746,34 @@ void closeCallback(WebSocket::Server& server, websocketpp::connection_hdl hdl)
}
using namespace cli;
Shell shell("CoinDB by Eric Lombrozo v0.2.5");
Shell shell("vaultd by Eric Lombrozo v0.0.1");
void requestCallback(WebSocket::Server& server, const WebSocket::Server::client_request_t& req)
{
JsonRpc::Response response;
const string& cmdname = req.second.getMethod();
params_t params;
for (auto& param: req.second.getParams()) { params.push_back(param.get_str()); }
try
{
result_t result = shell.exec(cmdname, params);
response.setResult(result, req.second.getId());
}
catch (const std::exception& e)
{
response.setError(e.what(), req.second.getId());
}
server.send(req.first, response);
}
int main(int argc, char* argv[])
{
INIT_LOGGER("vaultd.log");
signal(SIGINT, &finish);
// Global operations
shell.add(command(&cmd_create, "create", "create a new vault", command::params(1, "db file")));
shell.add(command(&cmd_info, "info", "display general information about file", command::params(1, "db file")));
@@ -807,15 +830,37 @@ int main(int argc, char* argv[])
// Miscellaneous
shell.add(command(&cmd_randombytes, "randombytes", "output random bytes in hex", command::params(1, "length")));
WebSocket::Server wsServer(WS_PORT);
wsServer.setOpenCallback(&openCallback);
wsServer.setCloseCallback(&closeCallback);
wsServer.setRequestCallback(&requestCallback);
try
{
return shell.exec(argc, argv);
LOGGER(debug) << "Starting websocket server on port " << WS_PORT << "..." << endl;
wsServer.start();
LOGGER(debug) << "Websocket server started." << endl;
}
catch (const std::exception& e)
{
cerr << e.what() << endl;
LOGGER(error) << "Error starting websocket server: " << e.what() << endl;
return 1;
}
while (!g_bShutdown) { std::this_thread::sleep_for(std::chrono::microseconds(200)); }
try
{
LOGGER(debug) << "Stopping websocket server..." << endl;
wsServer.stop();
LOGGER(debug) << "Websocket server stopped." << endl;
}
catch (const std::exception& e)
{
LOGGER(error) << "Error stopping websocket server: " << e.what() << endl;
return 2;
}
return 0;
}

0 comments on commit 0c12822

Please sign in to comment.