mirror of
https://github.com/oxen-io/lokinet.git
synced 2024-11-03 23:15:52 +00:00
Merge branch 'master' of https://github.com/neuroscr/loki-network
This commit is contained in:
commit
6f9af33058
@ -30,7 +30,7 @@ bool printNode(struct llarp_nodedb_iter *iter) {
|
||||
const char *hexname =
|
||||
llarp::HexEncode< llarp::PubKey, decltype(ftmp) >(iter->rc->pubkey, ftmp);
|
||||
|
||||
printf("[%d]=>[%s]\n", iter->index, hexname);
|
||||
printf("[%zu]=>[%s]\n", iter->index, hexname);
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -217,7 +217,20 @@ main(int argc, char *argv[])
|
||||
}
|
||||
if (exportMode) {
|
||||
llarp_main_loadDatabase(ctx);
|
||||
// TODO: write me
|
||||
//llarp::Info("Looking for string: ", rcfname);
|
||||
|
||||
llarp::PubKey binaryPK;
|
||||
llarp::HexDecode(rcfname, binaryPK.data());
|
||||
|
||||
llarp::Info("Looking for binary: ", binaryPK);
|
||||
struct llarp_rc *rc = llarp_main_getDatabase(ctx, binaryPK.data());
|
||||
if (!rc) {
|
||||
llarp::Error("Can't load RC from database");
|
||||
}
|
||||
std::string filename(rcfname);
|
||||
filename.append(".signed");
|
||||
llarp::Info("Writing out: ", filename);
|
||||
llarp_rc_write(rc, filename.c_str());
|
||||
}
|
||||
llarp_main_free(ctx);
|
||||
return 1; // success
|
||||
|
@ -39,12 +39,15 @@ llarp_main_loadDatabase(struct llarp_main *ptr);
|
||||
int
|
||||
llarp_main_iterateDatabase(struct llarp_main *ptr, struct llarp_nodedb_iter i);
|
||||
|
||||
|
||||
|
||||
/// put RC into nodeDB
|
||||
bool
|
||||
llarp_main_putDatabase(struct llarp_main *ptr, struct llarp_rc *rc);
|
||||
|
||||
|
||||
struct llarp_rc *
|
||||
llarp_main_getDatabase(struct llarp_main *ptr, byte_t *pk);
|
||||
|
||||
|
||||
void
|
||||
llarp_main_free(struct llarp_main *ptr);
|
||||
|
||||
|
@ -42,6 +42,9 @@ namespace llarp
|
||||
bool
|
||||
PutDatabase(struct llarp_rc *rc);
|
||||
|
||||
struct llarp_rc *
|
||||
GetDatabase(const byte_t *pk);
|
||||
|
||||
int
|
||||
Run();
|
||||
|
||||
|
@ -26,6 +26,9 @@ namespace llarp
|
||||
*ptr = 0;
|
||||
return &stack[0];
|
||||
}
|
||||
|
||||
int char2int(char input);
|
||||
void HexDecode(const char* src, uint8_t* target);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@ -118,6 +118,11 @@ namespace llarp
|
||||
return llarp_nodedb_put_rc(nodedb, rc);
|
||||
}
|
||||
|
||||
struct llarp_rc *
|
||||
Context::GetDatabase(const byte_t *pk)
|
||||
{
|
||||
return llarp_nodedb_get_rc(nodedb, pk);
|
||||
}
|
||||
|
||||
int
|
||||
Context::Run()
|
||||
@ -328,6 +333,11 @@ llarp_main_putDatabase(struct llarp_main *ptr, struct llarp_rc *rc)
|
||||
return ptr->ctx->PutDatabase(rc);
|
||||
}
|
||||
|
||||
struct llarp_rc *
|
||||
llarp_main_getDatabase(struct llarp_main *ptr, byte_t *pk)
|
||||
{
|
||||
return ptr->ctx->GetDatabase(pk);
|
||||
}
|
||||
|
||||
void
|
||||
llarp_main_free(struct llarp_main *ptr)
|
||||
|
27
llarp/encode.cpp
Normal file
27
llarp/encode.cpp
Normal file
@ -0,0 +1,27 @@
|
||||
#include <llarp/encode.hpp>
|
||||
#include <stdexcept>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
|
||||
int char2int(char input)
|
||||
{
|
||||
if(input >= '0' && input <= '9')
|
||||
return input - '0';
|
||||
if(input >= 'A' && input <= 'F')
|
||||
return input - 'A' + 10;
|
||||
if(input >= 'a' && input <= 'f')
|
||||
return input - 'a' + 10;
|
||||
throw std::invalid_argument("Invalid input string");
|
||||
}
|
||||
|
||||
void HexDecode(const char* src, uint8_t* target)
|
||||
{
|
||||
while(*src && src[1])
|
||||
{
|
||||
*(target++) = char2int(*src)*16 + char2int(src[1]);
|
||||
src += 2;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -47,6 +47,24 @@ struct llarp_nodedb
|
||||
return entries.find(pk) != entries.end();
|
||||
}
|
||||
|
||||
/*
|
||||
bool
|
||||
Has(const byte_t *pk)
|
||||
{
|
||||
llarp::PubKey test(pk);
|
||||
auto itr = this->entries.begin();
|
||||
while(itr != this->entries.end())
|
||||
{
|
||||
llarp::Info("Has byte_t [", test.size(), "] vs [", itr->first.size(), "]");
|
||||
if (memcmp(test.data(), itr->first.data(), 32) == 0) {
|
||||
llarp::Info("Match");
|
||||
}
|
||||
itr++;
|
||||
}
|
||||
return entries.find(pk) != entries.end();
|
||||
}
|
||||
*/
|
||||
|
||||
bool
|
||||
pubKeyExists(llarp_rc *rc)
|
||||
{
|
||||
@ -167,8 +185,9 @@ struct llarp_nodedb
|
||||
auto itr = i.begin();
|
||||
while(itr != itr.end())
|
||||
{
|
||||
if(loadfile(*itr))
|
||||
if (fs::is_regular_file(itr->symlink_status()) && loadfile(*itr))
|
||||
sz++;
|
||||
|
||||
++itr;
|
||||
}
|
||||
return sz;
|
||||
@ -177,49 +196,26 @@ struct llarp_nodedb
|
||||
bool
|
||||
loadfile(const fs::path &fpath)
|
||||
{
|
||||
#if __APPLE__ && __MACH__
|
||||
// skip .DS_Store files
|
||||
if (strstr(fpath.c_str(), ".DS_Store") != 0) {
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
llarp_rc *rc = llarp_rc_read(fpath.c_str());
|
||||
if (rc)
|
||||
if (!rc)
|
||||
{
|
||||
if(llarp_rc_verify_sig(crypto, rc))
|
||||
{
|
||||
llarp::PubKey pk(rc->pubkey);
|
||||
entries[pk] = *rc;
|
||||
return true;
|
||||
}
|
||||
llarp::Error("Signature read failed", fpath);
|
||||
return false;
|
||||
}
|
||||
/*
|
||||
std::ifstream f(fpath, std::ios::binary);
|
||||
if(!f.is_open())
|
||||
return false;
|
||||
|
||||
byte_t tmp[MAX_RC_SIZE];
|
||||
|
||||
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
|
||||
f.seekg(0, std::ios::end);
|
||||
size_t sz = f.tellg();
|
||||
f.seekg(0, std::ios::beg);
|
||||
|
||||
if(sz > buf.sz)
|
||||
return false;
|
||||
|
||||
// TODO: error checking
|
||||
f.read((char *)buf.base, sz);
|
||||
buf.sz = sz;
|
||||
|
||||
llarp_rc rc;
|
||||
llarp::Zero(&rc, sizeof(llarp_rc));
|
||||
if(llarp_rc_bdecode(&rc, &buf))
|
||||
if(!llarp_rc_verify_sig(crypto, rc))
|
||||
{
|
||||
if(llarp_rc_verify_sig(crypto, &rc))
|
||||
{
|
||||
llarp::PubKey pk(rc.pubkey);
|
||||
entries[pk] = rc;
|
||||
return true;
|
||||
}
|
||||
llarp::Error("Signature verify failed", fpath);
|
||||
return false;
|
||||
}
|
||||
llarp_rc_free(&rc);
|
||||
*/
|
||||
return false;
|
||||
llarp::PubKey pk(rc->pubkey);
|
||||
entries[pk] = *rc;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool iterate() {
|
||||
@ -414,6 +410,7 @@ llarp_nodedb_async_load_rc(struct llarp_async_load_rc *job)
|
||||
struct llarp_rc *
|
||||
llarp_nodedb_get_rc(struct llarp_nodedb *n, const byte_t *pk)
|
||||
{
|
||||
//llarp::Info("llarp_nodedb_get_rc [", pk, "]");
|
||||
if(n->Has(pk))
|
||||
return n->getRC(pk);
|
||||
else
|
||||
|
Loading…
Reference in New Issue
Block a user