Started work on a configuration options object
This commit is contained in:
@ -42,6 +42,7 @@ LIBS = -lsam -ltomcrypt
|
|||||||
|
|
||||||
OBJS = $(OBJDIR)/bigint.o \
|
OBJS = $(OBJDIR)/bigint.o \
|
||||||
$(OBJDIR)/chk.o \
|
$(OBJDIR)/chk.o \
|
||||||
|
$(OBJDIR)/config.o \
|
||||||
$(OBJDIR)/logger.o \
|
$(OBJDIR)/logger.o \
|
||||||
$(OBJDIR)/main.o \
|
$(OBJDIR)/main.o \
|
||||||
$(OBJDIR)/peers.o \
|
$(OBJDIR)/peers.o \
|
||||||
|
30
apps/enclave/cfg/enclave.cfg
Normal file
30
apps/enclave/cfg/enclave.cfg
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#
|
||||||
|
# This is the Enclave configuration file. Lines starting with # and blank lines
|
||||||
|
# are ignored.
|
||||||
|
#
|
||||||
|
|
||||||
|
# The DNS name or IP address of the SAM server you will be using
|
||||||
|
samhost=localhost
|
||||||
|
|
||||||
|
# The TCP port the SAM server is listening on
|
||||||
|
samport=7656
|
||||||
|
|
||||||
|
# The destination name of this program. This can be anything. If you run
|
||||||
|
# multiple copies of Enclave off the same SAM server then each one has to have a
|
||||||
|
# unique mydest.
|
||||||
|
mydest=enclave
|
||||||
|
|
||||||
|
# The depth used for incoming and outgoing I2P tunnels. Using a depth of 2 is
|
||||||
|
# the default and a good choice. You can set it to 0 if you don't care about
|
||||||
|
# anonymity and just want speed.
|
||||||
|
tunneldepth=0
|
||||||
|
|
||||||
|
# The location of the peer references file
|
||||||
|
references=/home/Administrator/cvs/i2p/apps/enclave/cfg/peers.ref
|
||||||
|
|
||||||
|
# Record every log message at or above this priority level
|
||||||
|
# debug = 0, minor = 1, info = 2, warn = 3, error = 4
|
||||||
|
loglevel=1
|
||||||
|
|
||||||
|
# The location of the Enclave log file
|
||||||
|
logfile=/home/Administrator/cvs/i2p/apps/enclave/log/enclave.log
|
@ -35,7 +35,7 @@ class Chk {
|
|||||||
public:
|
public:
|
||||||
//Chk(const uchar_t* cypertext, size_t size);
|
//Chk(const uchar_t* cypertext, size_t size);
|
||||||
Chk(const uchar_t* plaintext, size_t size, const string& mime_type);
|
Chk(const uchar_t* plaintext, size_t size, const string& mime_type);
|
||||||
~Chk(void) { delete ct; }
|
~Chk(void) { delete[] ct; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const size_t CRYPT_BLOCK_SIZE = 16;
|
static const size_t CRYPT_BLOCK_SIZE = 16;
|
||||||
|
93
apps/enclave/src/config.cpp
Normal file
93
apps/enclave/src/config.cpp
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2004, Matthew P. Cashdollar <mpc@innographx.com>
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* * Neither the name of the author nor the names of any contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||||
|
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||||
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||||
|
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||||
|
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "platform.hpp"
|
||||||
|
#include "bigint.hpp"
|
||||||
|
|
||||||
|
Config::Config(const string& file)
|
||||||
|
: file(file)
|
||||||
|
{
|
||||||
|
set_defaults();
|
||||||
|
parse();
|
||||||
|
configf.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Config::parse(void)
|
||||||
|
{
|
||||||
|
configf.open(file.c_str());
|
||||||
|
if (!configf) {
|
||||||
|
cerr << "Error opening configuration file (" << file.c_str() << ")\n";
|
||||||
|
throw runtime_error("Error opening configuration file");
|
||||||
|
}
|
||||||
|
size_t line = 0;
|
||||||
|
string s;
|
||||||
|
for (getline(configf, s); configf; getline(configf, s)) {
|
||||||
|
line++;
|
||||||
|
if (s[0] == '#') // comment
|
||||||
|
continue;
|
||||||
|
size_t eqpos = s.find("=");
|
||||||
|
if (eqpos == string::npos) {
|
||||||
|
LERROR << "Error parsing line #" << line << " in " << file << ": " << s << '\n';
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
string key = s.substr(0, eqpos - 1);
|
||||||
|
string value = s.substr(eqpos + 1);
|
||||||
|
cfgmap.insert(make_pair(key, value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Looks up a configuration option in the table and returns the value
|
||||||
|
*
|
||||||
|
* key - key to lookup
|
||||||
|
*
|
||||||
|
* Returns a pointer to the value associated with the key
|
||||||
|
*/
|
||||||
|
const string* Config::get_property(const string& key) const
|
||||||
|
{
|
||||||
|
for (cfgmap_ci i = cfgmap.begin(); i != cfgmap.end(); i++) {
|
||||||
|
string s = i->first;
|
||||||
|
if (s == key)
|
||||||
|
return &(i->second);
|
||||||
|
}
|
||||||
|
assert(false);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Config::set_defaults(void)
|
||||||
|
{
|
||||||
|
cfgmap.insert(make_pair("samhost", "localhost"));
|
||||||
|
cfgmap.insert(make_pair("samport", "7656"));
|
||||||
|
cfgmap.insert(make_pair("mydest", "enclave"));
|
||||||
|
cfgmap.insert(make_pair("tunneldepth", "2"));
|
||||||
|
cfgmap.insert(make_pair("references", "cfg/peers.ref"));
|
||||||
|
cfgmap.insert(make_pair("loglevel", "1"));
|
||||||
|
cfgmap.insert(make_pair("logfile", "log/enclave.log"));
|
||||||
|
}
|
52
apps/enclave/src/config.hpp
Normal file
52
apps/enclave/src/config.hpp
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2004, Matthew P. Cashdollar <mpc@innographx.com>
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are
|
||||||
|
* met:
|
||||||
|
*
|
||||||
|
* * Redistributions of source code must retain the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer.
|
||||||
|
* * Redistributions in binary form must reproduce the above copyright
|
||||||
|
* notice, this list of conditions and the following disclaimer in the
|
||||||
|
* documentation and/or other materials provided with the distribution.
|
||||||
|
* * Neither the name of the author nor the names of any contributors
|
||||||
|
* may be used to endorse or promote products derived from this software
|
||||||
|
* without specific prior written permission.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
|
||||||
|
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||||
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
|
||||||
|
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
|
||||||
|
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||||
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
||||||
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||||
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||||||
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||||
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||||
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CONFIG_HPP
|
||||||
|
#define CONFIG_HPP
|
||||||
|
|
||||||
|
class Config {
|
||||||
|
public:
|
||||||
|
Config(const string& file);
|
||||||
|
|
||||||
|
const string* get_property(const string& key) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
typedef map<const string, string>::const_iterator cfgmap_ci;
|
||||||
|
typedef map<const string, string>::iterator cfgmap_i;
|
||||||
|
|
||||||
|
void parse(void);
|
||||||
|
void set_defaults(void);
|
||||||
|
|
||||||
|
ifstream configf;
|
||||||
|
const string file;
|
||||||
|
map<const string, string> cfgmap;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CONFIG_HPP
|
@ -31,6 +31,7 @@
|
|||||||
#include "platform.hpp"
|
#include "platform.hpp"
|
||||||
#include "main.hpp"
|
#include "main.hpp"
|
||||||
|
|
||||||
|
Config *config; // Configuration options
|
||||||
Logger logger(LOG_FILE); // Logging mechanism
|
Logger logger(LOG_FILE); // Logging mechanism
|
||||||
Random prng; // Random number generator
|
Random prng; // Random number generator
|
||||||
Sam *sam; // SAM connection
|
Sam *sam; // SAM connection
|
||||||
@ -42,7 +43,7 @@ int main(int argc, char* argv[])
|
|||||||
if (argc != 2) { // put some getopts stuff in here later
|
if (argc != 2) { // put some getopts stuff in here later
|
||||||
LERROR << "Please specify your destination name. e.g. 'bin/enclave " \
|
LERROR << "Please specify your destination name. e.g. 'bin/enclave " \
|
||||||
"enclave'\n";
|
"enclave'\n";
|
||||||
return -1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
LINFO << "Enclave DHT - Built on " << __DATE__ << ' ' << __TIME__ << '\n';
|
LINFO << "Enclave DHT - Built on " << __DATE__ << ' ' << __TIME__ << '\n';
|
||||||
|
@ -77,6 +77,7 @@ using namespace std;
|
|||||||
* Local includes
|
* Local includes
|
||||||
*/
|
*/
|
||||||
#include "logger.hpp" // Logger
|
#include "logger.hpp" // Logger
|
||||||
|
#include "config.hpp" // Config
|
||||||
#include "sam_error.hpp" // for sam.hpp
|
#include "sam_error.hpp" // for sam.hpp
|
||||||
#include "bigint.hpp" // for sha1.hpp
|
#include "bigint.hpp" // for sha1.hpp
|
||||||
#include "sha1.hpp" // for peers.hpp
|
#include "sha1.hpp" // for peers.hpp
|
||||||
@ -89,6 +90,7 @@ using namespace std;
|
|||||||
/*
|
/*
|
||||||
* Global variables
|
* Global variables
|
||||||
*/
|
*/
|
||||||
|
extern Config *config; // Configuration options
|
||||||
extern Logger logger; // Logging mechanism
|
extern Logger logger; // Logging mechanism
|
||||||
extern Random prng; // Random number generator
|
extern Random prng; // Random number generator
|
||||||
extern Sam *sam; // Sam connection
|
extern Sam *sam; // Sam connection
|
||||||
|
Reference in New Issue
Block a user