Skip to content

Commit

Permalink
Merge pull request #270 from loki-project/dev
Browse files Browse the repository at this point in the history
Merge dev to master
  • Loading branch information
Doy-lee authored Sep 27, 2018
2 parents ffdf682 + e12ce07 commit 016a37e
Show file tree
Hide file tree
Showing 41 changed files with 1,469 additions and 388 deletions.
8 changes: 8 additions & 0 deletions contrib/epee/include/storages/portable_storage_from_bin.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ namespace epee
storage_entry load_storage_entry();
void read(section& sec);
void read(std::string& str);
void read(array_entry &ae);
private:
struct recursuion_limitation_guard
{
Expand Down Expand Up @@ -114,6 +115,7 @@ namespace epee
void throwable_buffer_reader::read(t_pod_type& pod_val)
{
RECURSION_LIMITATION();
static_assert(std::is_pod<t_pod_type>::value, "POD type expected");
read(&pod_val, sizeof(pod_val));
}

Expand Down Expand Up @@ -277,5 +279,11 @@ namespace epee
m_ptr+=len;
m_count -= len;
}
inline
void throwable_buffer_reader::read(array_entry &ae)
{
RECURSION_LIMITATION();
CHECK_AND_ASSERT_THROW_MES(false, "Reading array entry is not supported");
}
}
}
13 changes: 8 additions & 5 deletions contrib/epee/include/storages/portable_storage_from_json.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@
#include "parserse_base_utils.h"
#include "file_io_utils.h"

#define EPEE_JSON_RECURSION_LIMIT_INTERNAL 100

namespace epee
{
using namespace misc_utils::parse;
Expand All @@ -44,8 +46,9 @@ namespace epee
ASSERT_MES_AND_THROW("json parse error");
}*/
template<class t_storage>
inline void run_handler(typename t_storage::hsection current_section, std::string::const_iterator& sec_buf_begin, std::string::const_iterator buf_end, t_storage& stg)
inline void run_handler(typename t_storage::hsection current_section, std::string::const_iterator& sec_buf_begin, std::string::const_iterator buf_end, t_storage& stg, unsigned int recursion)
{
CHECK_AND_ASSERT_THROW_MES(recursion < EPEE_JSON_RECURSION_LIMIT_INTERNAL, "Wrong JSON data: recursion limitation (" << EPEE_JSON_RECURSION_LIMIT_INTERNAL << ") exceeded");

std::string::const_iterator sub_element_start;
std::string name;
Expand Down Expand Up @@ -157,7 +160,7 @@ namespace epee
//sub section here
typename t_storage::hsection new_sec = stg.open_section(name, current_section, true);
CHECK_AND_ASSERT_THROW_MES(new_sec, "Failed to insert new section in json: " << std::string(it, buf_end));
run_handler(new_sec, it, buf_end, stg);
run_handler(new_sec, it, buf_end, stg, recursion + 1);
state = match_state_wonder_after_value;
}else if(*it == '[')
{//array of something
Expand Down Expand Up @@ -186,7 +189,7 @@ namespace epee
typename t_storage::hsection new_sec = nullptr;
h_array = stg.insert_first_section(name, new_sec, current_section);
CHECK_AND_ASSERT_THROW_MES(h_array&&new_sec, "failed to create new section");
run_handler(new_sec, it, buf_end, stg);
run_handler(new_sec, it, buf_end, stg, recursion + 1);
state = match_state_array_after_value;
array_md = array_mode_sections;
}else if(*it == '"')
Expand Down Expand Up @@ -260,7 +263,7 @@ namespace epee
typename t_storage::hsection new_sec = NULL;
bool res = stg.insert_next_section(h_array, new_sec);
CHECK_AND_ASSERT_THROW_MES(res&&new_sec, "failed to insert next section");
run_handler(new_sec, it, buf_end, stg);
run_handler(new_sec, it, buf_end, stg, recursion + 1);
state = match_state_array_after_value;
}else CHECK_ISSPACE();
break;
Expand Down Expand Up @@ -362,7 +365,7 @@ namespace epee
std::string::const_iterator sec_buf_begin = buff_json.begin();
try
{
run_handler(nullptr, sec_buf_begin, buff_json.end(), stg);
run_handler(nullptr, sec_buf_begin, buff_json.end(), stg, 0);
return true;
}
catch(const std::exception& ex)
Expand Down
8 changes: 4 additions & 4 deletions src/blockchain_utilities/blockchain_import.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ int pop_blocks(cryptonote::core& core, int num_blocks)
return num_blocks;
}

int check_flush(cryptonote::core &core, std::list<block_complete_entry> &blocks, bool force)
int check_flush(cryptonote::core &core, std::vector<block_complete_entry> &blocks, bool force)
{
if (blocks.empty())
return 0;
Expand All @@ -177,7 +177,7 @@ int check_flush(cryptonote::core &core, std::list<block_complete_entry> &blocks,
if (!force && new_height % HASH_OF_HASHES_STEP)
return 0;

std::list<crypto::hash> hashes;
std::vector<crypto::hash> hashes;
for (const auto &b: blocks)
{
cryptonote::block block;
Expand Down Expand Up @@ -313,7 +313,7 @@ int import_from_file(cryptonote::core& core, const std::string& import_file_path
MINFO("Reading blockchain from bootstrap file...");
std::cout << ENDL;

std::list<block_complete_entry> blocks;
std::vector<block_complete_entry> blocks;

// Skip to start_height before we start adding.
{
Expand Down Expand Up @@ -438,7 +438,7 @@ int import_from_file(cryptonote::core& core, const std::string& import_file_path
{
cryptonote::blobdata block;
cryptonote::block_to_blob(bp.block, block);
std::list<cryptonote::blobdata> txs;
std::vector<cryptonote::blobdata> txs;
for (const auto &tx: bp.txs)
{
txs.push_back(cryptonote::blobdata());
Expand Down
11 changes: 8 additions & 3 deletions src/crypto/keccak.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include "common/int-util.h"
#include "hash-ops.h"
#include "keccak.h"

Expand Down Expand Up @@ -105,7 +106,7 @@ void keccak(const uint8_t *in, size_t inlen, uint8_t *md, int mdlen)

for ( ; inlen >= rsiz; inlen -= rsiz, in += rsiz) {
for (i = 0; i < rsizw; i++)
st[i] ^= ((uint64_t *) in)[i];
st[i] ^= swap64le(((uint64_t *) in)[i]);
keccakf(st, KECCAK_ROUNDS);
}

Expand All @@ -121,11 +122,15 @@ void keccak(const uint8_t *in, size_t inlen, uint8_t *md, int mdlen)
temp[rsiz - 1] |= 0x80;

for (i = 0; i < rsizw; i++)
st[i] ^= ((uint64_t *) temp)[i];
st[i] ^= swap64le(((uint64_t *) temp)[i]);

keccakf(st, KECCAK_ROUNDS);

memcpy(md, st, mdlen);
if (((size_t)mdlen % sizeof(uint64_t)) != 0)
{
local_abort("Bad keccak use");
}
memcpy_swap64le(md, st, mdlen/sizeof(uint64_t));
}

void keccak1600(const uint8_t *in, size_t inlen, uint8_t *md)
Expand Down
2 changes: 1 addition & 1 deletion src/cryptonote_basic/connection_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ namespace cryptonote
};

state m_state;
std::list<crypto::hash> m_needed_objects;
std::vector<crypto::hash> m_needed_objects;
std::unordered_set<crypto::hash> m_requested_objects;
uint64_t m_remote_blockchain_height;
uint64_t m_last_response_height;
Expand Down
2 changes: 1 addition & 1 deletion src/cryptonote_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ static_assert(STAKING_PORTIONS % 3 == 0, "Use a multiple of three, so that it di

#define BLOCKCHAIN_TIMESTAMP_CHECK_WINDOW 11

#define UPTIME_PROOF_BUFFER_IN_SECONDS (5*60)
#define UPTIME_PROOF_BUFFER_IN_SECONDS (5*60) // The acceptable window of time to accept a peer's uptime proof from its reported timestamp
#define UPTIME_PROOF_FREQUENCY_IN_SECONDS (60*60)
#define UPTIME_PROOF_MAX_TIME_IN_SECONDS (UPTIME_PROOF_FREQUENCY_IN_SECONDS * 2 + UPTIME_PROOF_BUFFER_IN_SECONDS)

Expand Down
Loading

0 comments on commit 016a37e

Please sign in to comment.