make things work mostly
This commit is contained in:
parent
02da06f69a
commit
5407702e33
|
@ -8,7 +8,7 @@ CXXFLAGS = -O3 -fexpensive-optimizations -ffast-math -fno-math-errno -Wall -I/us
|
|||
endif
|
||||
LDFLAGS = /users/m4burns/thrift/lib/libthriftnb.a /users/m4burns/thrift/lib/libthrift.a -levent
|
||||
|
||||
SOURCES = ConfigFile.cpp posdb.cpp db_if.cpp linus_sha1.c log.cpp nameserver.cpp sha1.cpp gen-cpp/pos_constants.cpp gen-cpp/Pos.cpp gen-cpp/pos_types.cpp
|
||||
SOURCES = ConfigFile.cpp posdb.cpp db_if.cpp linus_sha1.c log.cpp nameserver.cpp sha1.cpp gen-cpp/pos_constants.cpp gen-cpp/Pos.cpp gen-cpp/pos_types.cpp salt_store.cpp gen-cpp/PosBookie.cpp
|
||||
|
||||
CPPOBJECTS = $(patsubst %.cpp,%.o,$(SOURCES))
|
||||
OBJECTS = $(patsubst %.c,%.o,$(CPPOBJECTS))
|
||||
|
@ -18,12 +18,12 @@ DEPS = $(patsubst %.c,%.d,$(CPPDEPS))
|
|||
SERVER = server
|
||||
CLIENT = client
|
||||
DUMP = dump
|
||||
|
||||
BOOKIE = bookie
|
||||
##################################################################
|
||||
|
||||
.PHONY : all clean
|
||||
|
||||
all : $(SERVER) $(CLIENT) $(DUMP)
|
||||
all : $(SERVER) $(CLIENT) $(DUMP) $(BOOKIE)
|
||||
|
||||
%.d : %.cpp
|
||||
$(CXX) -MM $(CXXFLAGS) $^ > $@
|
||||
|
@ -50,6 +50,9 @@ $(CLIENT) : $(OBJECTS) client.o
|
|||
$(DUMP) : $(OBJECTS) dump.o
|
||||
$(CXX) $(CXXFLAGS) $(OBJECTS) dump.o -o $@ $(LDFLAGS)
|
||||
|
||||
$(BOOKIE) : $(OBJECTS) gen-cpp/PosBookie_server.skeleton.o
|
||||
$(CXX) $(CXXFLAGS) $(OBJECTS) gen-cpp/PosBookie_server.skeleton.o -o $@ $(LDFLAGS)
|
||||
|
||||
#################################################################
|
||||
|
||||
clean :
|
||||
|
|
|
@ -0,0 +1,6 @@
|
|||
server_host = localhost
|
||||
server_port = 9090
|
||||
listen_port = 9091
|
||||
key_lifetime = 120
|
||||
salt_size = 256
|
||||
secret = balls
|
|
@ -1,4 +1,4 @@
|
|||
key_lifetime = 120
|
||||
salt_size = 256
|
||||
secret = balls
|
||||
secret = PSK
|
||||
db_file = db
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#define PosBookie_H
|
||||
|
||||
#include <thrift/TDispatchProcessor.h>
|
||||
#include "pos-bookie_types.h"
|
||||
#include "posbookie_types.h"
|
||||
|
||||
namespace posbookie {
|
||||
|
||||
|
|
|
@ -15,6 +15,8 @@
|
|||
#include "sha1.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#include "ConfigFile.h"
|
||||
|
||||
using namespace ::apache::thrift;
|
||||
using namespace ::apache::thrift::protocol;
|
||||
using namespace ::apache::thrift::transport;
|
||||
|
@ -23,34 +25,36 @@ using namespace ::apache::thrift::server;
|
|||
using boost::shared_ptr;
|
||||
|
||||
using namespace ::posbookie;
|
||||
using namespace ::pos;
|
||||
|
||||
class PosBookieHandler : virtual public PosBookieIf {
|
||||
|
||||
shared_ptr<TTransport> socket;
|
||||
shared_ptr<TTransport> transport;
|
||||
shared_ptr<TProtocol> protocol;
|
||||
PosClient client;
|
||||
PosClient * client;
|
||||
|
||||
SaltStore * saltStore;
|
||||
|
||||
std::string getAuthString() {
|
||||
std::string s;
|
||||
this->client.getSalt(s);
|
||||
this->client->getSalt(s);
|
||||
return SHA1Hash(s+"PSK").toHex();
|
||||
}
|
||||
|
||||
public:
|
||||
PosBookieHandler(char* serverHost, int serverPort, SaltStore* saltStore)
|
||||
: socket(new TSocket(serverHost, serverPort))
|
||||
, transport(new TFramedTransport(socket))
|
||||
, protocol(new TBinaryProtocol(transport))
|
||||
, client(protocol)
|
||||
{
|
||||
socket = shared_ptr<TTransport>(new TSocket(serverHost, serverPort));
|
||||
transport = shared_ptr<TTransport>(new TFramedTransport(socket));
|
||||
protocol = shared_ptr<TProtocol>(new TBinaryProtocol(transport));
|
||||
client = new PosClient(protocol);
|
||||
this->saltStore = saltStore;
|
||||
|
||||
try{
|
||||
this->client.ping();
|
||||
} catch {
|
||||
try {
|
||||
transport->open();
|
||||
this->client->ping();
|
||||
} catch(...) {
|
||||
fprintf(stderr, "Failed to contact server '%s:%d'!\n", serverHost, serverPort);
|
||||
abort();
|
||||
}
|
||||
|
@ -66,32 +70,32 @@ class PosBookieHandler : virtual public PosBookieIf {
|
|||
if(saltStore->consumeKey(auth)) {
|
||||
try {
|
||||
int32_t total_price = 0;
|
||||
std::vector<int64_t>::iterator i;
|
||||
std::vector<int64_t>::const_iterator i;
|
||||
for(i = upcs.begin(); i != upcs.end(); i++) {
|
||||
total_price += this->getUPCPrice(*i);
|
||||
}
|
||||
|
||||
int32_t accountBalance = this->client.getHashAccountBalance(dataToHash);
|
||||
int32_t accountBalance = this->client->getHashAccountBalance(dataToHash);
|
||||
if(accountBalance < total_price) {
|
||||
this->client.performTransactionOnHash(this->getAuthString(), dataToHash, total_price * -1);
|
||||
return E_PURCHASE_STATUS::type::EPS_SUCCESS;
|
||||
this->client->doTransactionOnHash(this->getAuthString(), dataToHash, total_price * -1);
|
||||
return E_PURCHASE_STATUS::EPS_SUCCESS;
|
||||
}
|
||||
|
||||
return E_PURCHASE_STATUS::type::EPS_NOMONEY;
|
||||
return E_PURCHASE_STATUS::EPS_NOMONEY;
|
||||
} catch(...) {
|
||||
return E_PURCHASE_STATUS::type::EPS_FAIL;
|
||||
return E_PURCHASE_STATUS::EPS_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
return E_PURCHASE_STATUS::type::EPS_FAIL;
|
||||
return E_PURCHASE_STATUS::EPS_FAIL;
|
||||
}
|
||||
|
||||
int32_t getUPCPrice(const int64_t upc) {
|
||||
return this->client.getUPCPrice(upc);
|
||||
return this->client->getUPCPrice(upc);
|
||||
}
|
||||
|
||||
int32_t getStock(const int64_t upc) {
|
||||
return this->client.getStock(upc);
|
||||
return this->client->getStock(upc);
|
||||
}
|
||||
|
||||
};
|
||||
|
@ -104,13 +108,13 @@ int main(int argc, char **argv) {
|
|||
|
||||
ConfigFile conf(argv[1]);
|
||||
|
||||
char* server_host;
|
||||
const char* server_host;
|
||||
int server_port;
|
||||
int listen_port;
|
||||
SaltStore * saltStore;
|
||||
|
||||
try {
|
||||
server_host = conf.read<char*>("server_host", "localhost");
|
||||
server_host = conf.read<std::string>("server_host", "localhost").c_str();
|
||||
server_port = conf.read<int>("server_port", 9090);
|
||||
listen_port = conf.read<int>("listen_port", 9091);
|
||||
saltStore = new SaltStore(
|
||||
|
@ -126,7 +130,7 @@ int main(int argc, char **argv) {
|
|||
abort();
|
||||
}
|
||||
|
||||
shared_ptr<PosBookieHandler> handler(new PosBookieHandler(server_host, server_port, saltStore));
|
||||
shared_ptr<PosBookieHandler> handler(new PosBookieHandler((char*)server_host, server_port, saltStore));
|
||||
shared_ptr<TProcessor> processor(new PosBookieProcessor(handler));
|
||||
|
||||
TNonblockingServer server(processor, listen_port);
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
/**
|
||||
* Autogenerated by Thrift Compiler (0.9.0)
|
||||
*
|
||||
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
||||
* @generated
|
||||
*/
|
||||
#ifndef pos-bookie_CONSTANTS_H
|
||||
#define pos-bookie_CONSTANTS_H
|
||||
|
||||
#include "pos-bookie_types.h"
|
||||
|
||||
namespace posbookie {
|
||||
|
||||
class pos-bookieConstants {
|
||||
public:
|
||||
pos-bookieConstants();
|
||||
|
||||
};
|
||||
|
||||
extern const pos-bookieConstants g_pos-bookie_constants;
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif
|
|
@ -4,13 +4,13 @@
|
|||
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
||||
* @generated
|
||||
*/
|
||||
#include "pos-bookie_constants.h"
|
||||
#include "posbookie_constants.h"
|
||||
|
||||
namespace posbookie {
|
||||
|
||||
const pos-bookieConstants g_pos-bookie_constants;
|
||||
const posbookieConstants g_posbookie_constants;
|
||||
|
||||
pos-bookieConstants::pos-bookieConstants() {
|
||||
posbookieConstants::posbookieConstants() {
|
||||
}
|
||||
|
||||
} // namespace
|
|
@ -0,0 +1,24 @@
|
|||
/**
|
||||
* Autogenerated by Thrift Compiler (0.9.0)
|
||||
*
|
||||
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
||||
* @generated
|
||||
*/
|
||||
#ifndef posbookie_CONSTANTS_H
|
||||
#define posbookie_CONSTANTS_H
|
||||
|
||||
#include "posbookie_types.h"
|
||||
|
||||
namespace posbookie {
|
||||
|
||||
class posbookieConstants {
|
||||
public:
|
||||
posbookieConstants();
|
||||
|
||||
};
|
||||
|
||||
extern const posbookieConstants g_posbookie_constants;
|
||||
|
||||
} // namespace
|
||||
|
||||
#endif
|
|
@ -4,7 +4,7 @@
|
|||
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
||||
* @generated
|
||||
*/
|
||||
#include "pos-bookie_types.h"
|
||||
#include "posbookie_types.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
|
@ -4,8 +4,8 @@
|
|||
* DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
||||
* @generated
|
||||
*/
|
||||
#ifndef pos-bookie_TYPES_H
|
||||
#define pos-bookie_TYPES_H
|
||||
#ifndef posbookie_TYPES_H
|
||||
#define posbookie_TYPES_H
|
||||
|
||||
#include <thrift/Thrift.h>
|
||||
#include <thrift/TApplicationException.h>
|
|
@ -3,12 +3,12 @@
|
|||
#include "sha1.h"
|
||||
#include <string>
|
||||
#include <list>
|
||||
#include <stdint.h>
|
||||
|
||||
class SaltStore {
|
||||
|
||||
public:
|
||||
SaltStore(uint64_t key_lifetime, size_t salt_size, std::string secret);
|
||||
~SaltStore();
|
||||
std::string getSalt();
|
||||
bool consumeKey(std::string key);
|
||||
|
||||
|
|
Loading…
Reference in New Issue