fix up win32 specific parts

pull/7/head
Jeff Becker 6 years ago
parent 1b20ba6a6c
commit 0d2bce2089

@ -278,23 +278,18 @@ main(int argc, char *argv[])
// "encryption.key")
fs::path encryption_keyfile = "encryption.key";
llarp::SecretKey encryption;
#ifdef _WIN32
llarp_findOrCreateEncryption(&crypt, encryption_keyfile.string().c_str(),
&encryption);
#else
llarp_findOrCreateEncryption(&crypt, encryption_keyfile.c_str(),
&encryption);
#endif
llarp_rc_set_pubenckey(&tmp, llarp::seckey_topublic(encryption));
// get identity public sig key
fs::path ident_keyfile = "identity.key";
byte_t identity[SECKEYSIZE];
#ifdef _WIN32
llarp_findOrCreateIdentity(&crypt, ident_keyfile.string().c_str(), identity);
#else
llarp_findOrCreateIdentity(&crypt, ident_keyfile.c_str(), identity);
#endif
llarp_findOrCreateIdentity(&crypt, ident_keyfile.string().c_str(),
identity);
llarp_rc_set_pubsigkey(&tmp, llarp::seckey_topublic(identity));
// this causes a segfault
@ -302,11 +297,8 @@ main(int argc, char *argv[])
// set filename
fs::path our_rc_file = rcfname;
// write file
#ifdef _WIN32
llarp_rc_write(&tmp, our_rc_file.string().c_str());
#else
llarp_rc_write(&tmp, our_rc_file.c_str());
#endif
// release memory for tmp lists
llarp_rc_free(&tmp);
}
@ -324,11 +316,8 @@ main(int argc, char *argv[])
llarp_crypto_libsodium_init(&crypt);
fs::path ident_keyfile = "identity.key";
byte_t identity[SECKEYSIZE];
#ifdef _WIN32
llarp_findOrCreateIdentity(&crypt, ident_keyfile.string().c_str(), identity);
#else
llarp_findOrCreateIdentity(&crypt, ident_keyfile.c_str(), identity);
#endif
llarp_findOrCreateIdentity(&crypt, ident_keyfile.string().c_str(),
identity);
// get identity public key
uint8_t *pubkey = llarp::seckey_topublic(identity);
llarp_rc_set_pubsigkey(&rc, pubkey);
@ -337,11 +326,7 @@ main(int argc, char *argv[])
// set filename
fs::path our_rc_file_out = "update_debug.rc";
// write file
#ifdef _WIN32
llarp_rc_write(&tmp, our_rc_file_out.string().c_str());
#else
llarp_rc_write(&tmp, our_rc_file_out.c_str());
#endif
}
if(listMode)
{

@ -12,6 +12,7 @@
#include "mem.hpp"
static const char skiplist_subdirs[] = "0123456789abcdef";
static const fs::path RC_FILE_EXT = ".signed";
struct llarp_nodedb
{
@ -21,7 +22,7 @@ struct llarp_nodedb
llarp_crypto *crypto;
// std::map< llarp::pubkey, llarp_rc > entries;
std::unordered_map< llarp::PubKey, llarp_rc, llarp::PubKeyHash > entries;
std::unordered_map< llarp::PubKey, llarp_rc, llarp::PubKey::Hash > entries;
fs::path nodePath;
void
@ -38,11 +39,11 @@ struct llarp_nodedb
llarp_rc *
getRC(const llarp::PubKey &pk)
{
return &entries[pk];
return &entries.at(pk);
}
bool
Has(const llarp::PubKey &pk)
Has(const llarp::PubKey &pk) const
{
return entries.find(pk) != entries.end();
}
@ -66,7 +67,7 @@ struct llarp_nodedb
*/
bool
pubKeyExists(llarp_rc *rc)
pubKeyExists(llarp_rc *rc) const
{
// extract pk from rc
llarp::PubKey pk = rc->pubkey;
@ -105,22 +106,16 @@ struct llarp_nodedb
}
std::string
getRCFilePath(const byte_t *pubkey)
getRCFilePath(const byte_t *pubkey) const
{
char ftmp[68] = {0};
const char *hexname =
llarp::HexEncode< llarp::PubKey, decltype(ftmp) >(pubkey, ftmp);
std::string hexString(hexname);
#ifdef _WIN32
std::string filepath = nodePath.string();
#else
std::string filepath = nodePath;
#endif
filepath.append(PATH_SEP);
filepath.append(&hexString[hexString.length() - 1]);
filepath.append(PATH_SEP);
filepath.append(hexname);
filepath.append(".signed");
hexString += RC_FILE_EXT;
std::string skiplistDir;
skiplistDir += hexString[hexString.length() - 1];
fs::path filepath = nodePath / skiplistDir / hexString;
return filepath;
}
@ -172,6 +167,8 @@ struct llarp_nodedb
for(const char &ch : skiplist_subdirs)
{
if(!ch)
continue;
std::string p;
p += ch;
fs::path sub = path / p;
@ -192,7 +189,7 @@ struct llarp_nodedb
auto itr = fs::begin(i);
while(itr != fs::end(i))
#else
auto itr = i.begin();
auto itr = i.begin();
while(itr != itr.end())
#endif
{
@ -207,20 +204,12 @@ struct llarp_nodedb
bool
loadfile(const fs::path &fpath)
{
#if __APPLE__ && __MACH__
// skip .DS_Store files
if(strstr(fpath.c_str(), ".DS_Store") != 0)
{
if(fpath.extension() != RC_FILE_EXT)
return false;
}
#endif
llarp_rc rc;
llarp_rc_clear(&rc);
#ifdef _WIN32
if(!llarp_rc_read(fpath.string().c_str(), &rc))
#else
if(!llarp_rc_read(fpath.c_str(), &rc))
#endif
{
llarp::LogError("Signature read failed", fpath);
return false;

@ -166,11 +166,7 @@ llarp_router::try_connect(fs::path rcfile)
{
llarp_rc remote;
llarp_rc_new(&remote);
#ifdef _WIN32
if(!llarp_rc_read(rcfile.string().c_str(), &remote))
#else
if(!llarp_rc_read(rcfile.c_str(), &remote))
#endif
{
llarp::LogError("failure to decode or verify of remote RC");
return;
@ -200,24 +196,15 @@ llarp_router::EnsureIdentity()
{
if(!EnsureEncryptionKey())
return false;
#ifdef _WIN32
return llarp_findOrCreateIdentity(&crypto, ident_keyfile.string().c_str(),
identity);
#else
return llarp_findOrCreateIdentity(&crypto, ident_keyfile.c_str(), identity);
#endif
}
bool
llarp_router::EnsureEncryptionKey()
{
#ifdef _WIN32
return llarp_findOrCreateEncryption(
&crypto, encryption_keyfile.string().c_str(), &this->encryption);
#else
return llarp_findOrCreateEncryption(&crypto, encryption_keyfile.c_str(),
&this->encryption);
#endif
}
void
@ -247,11 +234,8 @@ llarp_router::SaveRC()
if(llarp_rc_bencode(&rc, &buf))
{
#ifdef _WIN32
std::ofstream f(our_rc_file.string());
#else
std::ofstream f(our_rc_file);
#endif
if(f.is_open())
{
f.write((char *)buf.base, buf.cur - buf.base);
@ -759,27 +743,10 @@ llarp_router::InitOutboundLink()
{
if(outboundLink)
return true;
#ifdef __MINGW32__
llarp_iwp_args args = {
.crypto = &crypto,
.logic = logic,
.cryptoworker = tp,
.router = this,
.keyfile = transport_keyfile.string().c_str(),
};
#elif !defined(_MSC_VER)
llarp_iwp_args args = {
.crypto = &crypto,
.logic = logic,
.cryptoworker = tp,
.router = this,
.keyfile = transport_keyfile.c_str(),
};
#else
llarp_iwp_args args = {
&crypto, logic, tp, this, transport_keyfile.string().c_str(),
};
#endif
auto link = new(std::nothrow) llarp_link(args);
@ -931,11 +898,9 @@ llarp_rc_read(const char *fpath, llarp_rc *result)
printf("File[%s] not found\n", fpath);
return false;
}
#ifdef _WIN32
std::ifstream f(our_rc_file.string(), std::ios::binary);
#else
std::ifstream f(our_rc_file, std::ios::binary);
#endif
if(!f.is_open())
{
printf("Can't open file [%s]\n", fpath);
@ -989,11 +954,7 @@ llarp_rc_write(struct llarp_rc *rc, const char *fpath)
if(llarp_rc_bencode(rc, &buf))
{
#ifdef _WIN32
std::ofstream f(our_rc_file.string(), std::ios::binary);
#else
std::ofstream f(our_rc_file, std::ios::binary);
#endif
if(f.is_open())
{
f.write((char *)buf.base, buf.cur - buf.base);
@ -1065,21 +1026,13 @@ llarp_findOrCreateIdentity(llarp_crypto *crypto, const char *fpath,
{
llarp::LogInfo("generating new identity key");
crypto->identity_keygen(secretkey);
#ifdef _WIN32
std::ofstream f(path.string(), std::ios::binary);
#else
std::ofstream f(path, std::ios::binary);
#endif
if(f.is_open())
{
f.write((char *)secretkey, SECKEYSIZE);
}
}
#ifdef _WIN32
std::ifstream f(path.string(), std::ios::binary);
#else
std::ifstream f(path, std::ios::binary);
#endif
if(f.is_open())
{
f.read((char *)secretkey, SECKEYSIZE);
@ -1101,21 +1054,14 @@ llarp_findOrCreateEncryption(llarp_crypto *crypto, const char *fpath,
{
llarp::LogInfo("generating new encryption key");
crypto->encryption_keygen(*encryption);
#ifdef _WIN32
std::ofstream f(path.string(), std::ios::binary);
#else
std::ofstream f(path, std::ios::binary);
#endif
if(f.is_open())
{
f.write((char *)encryption, SECKEYSIZE);
}
}
#ifdef _WIN32
std::ifstream f(path.string(), std::ios::binary);
#else
std::ifstream f(path, std::ios::binary);
#endif
if(f.is_open())
{
f.read((char *)encryption, SECKEYSIZE);
@ -1172,23 +1118,7 @@ namespace llarp
if(!StrEq(key, "*"))
{
llarp::LogInfo("interface specific binding activated");
#ifdef __MINGW32__
llarp_iwp_args args = {
.crypto = &self->crypto,
.logic = self->logic,
.cryptoworker = self->tp,
.router = self,
.keyfile = self->transport_keyfile.string().c_str(),
};
#elif !defined(_MSC_VER)
llarp_iwp_args args = {
.crypto = &self->crypto,
.logic = self->logic,
.cryptoworker = self->tp,
.router = self,
.keyfile = self->transport_keyfile.c_str(),
};
#else
llarp_iwp_args args = {
&self->crypto,
self->logic,
@ -1196,7 +1126,6 @@ namespace llarp
self,
self->transport_keyfile.string().c_str(),
};
#endif
link = new(std::nothrow) llarp_link(args);

Loading…
Cancel
Save