Make format

pull/945/head
Stephen Shelton 5 years ago
parent eb5184ee09
commit 66a058a2af

@ -21,8 +21,7 @@ curl_RecvIdentKey(char *ptr, size_t, size_t nmemb, void *userdata)
namespace llarp
{
KeyManager::KeyManager()
: m_initialized(false)
KeyManager::KeyManager() : m_initialized(false)
{
}
@ -42,7 +41,6 @@ namespace llarp
m_lokidRPCUser = config.lokid.lokidRPCUser;
m_lokidRPCPassword = config.lokid.lokidRPCPassword;
RouterContact rc;
bool exists = rc.Read(m_rcPath.c_str());
if(not exists and not genIfAbsent)
@ -68,7 +66,8 @@ namespace llarp
if(!backupKeyFilesByMoving())
{
LogError("Could not mv some key files, please ensure key files"
LogError(
"Could not mv some key files, please ensure key files"
" are backed up if needed and remove");
return false;
}
@ -78,8 +77,7 @@ namespace llarp
if(not m_usingLokid)
{
// load identity key or create if needed
auto identityKeygen = [](llarp::SecretKey& key)
{
auto identityKeygen = [](llarp::SecretKey& key) {
// TODO: handle generating from service node seed
llarp::CryptoManager::instance()->identity_keygen(key);
};
@ -93,16 +91,14 @@ namespace llarp
}
// load encryption key
auto encryptionKeygen = [](llarp::SecretKey& key)
{
auto encryptionKeygen = [](llarp::SecretKey& key) {
llarp::CryptoManager::instance()->encryption_keygen(key);
};
if(not loadOrCreateKey(m_encKeyPath, m_encKey, encryptionKeygen))
return false;
// TODO: transport key (currently done in LinkLayer)
auto transportKeygen = [](llarp::SecretKey& key)
{
auto transportKeygen = [](llarp::SecretKey& key) {
key.Zero();
CryptoManager::instance()->encryption_keygen(key);
};
@ -165,12 +161,8 @@ namespace llarp
return fs::path();
};
std::vector<std::string> files = {
m_rcPath,
m_idKeyPath,
m_encKeyPath,
m_transportKeyPath
};
std::vector< std::string > files = {m_rcPath, m_idKeyPath, m_encKeyPath,
m_transportKeyPath};
for(auto& filepath : files)
{
@ -178,7 +170,8 @@ namespace llarp
bool exists = fs::exists(filepath, ec);
if(ec)
{
LogError("Could not determine status of file ", filepath, ": ", ec.message());
LogError("Could not determine status of file ", filepath, ": ",
ec.message());
return false;
}
@ -195,10 +188,12 @@ namespace llarp
return false;
}
LogInfo("Backing up (moving) key file ", filepath, " to ", newFilepath, "...");
LogInfo("Backing up (moving) key file ", filepath, " to ", newFilepath,
"...");
fs::rename(filepath, newFilepath, ec);
if (ec) {
if(ec)
{
LogError("Failed to move key file ", ec.message());
return false;
}
@ -209,8 +204,7 @@ namespace llarp
bool
KeyManager::loadOrCreateKey(
const std::string& filepath,
llarp::SecretKey& key,
const std::string& filepath, llarp::SecretKey& key,
std::function< void(llarp::SecretKey& key) > keygen)
{
fs::path path(filepath);
@ -318,7 +312,8 @@ namespace llarp
}
if(ret)
{
LogInfo("Got Identity Keys from lokid: ", RouterID(seckey_topublic(m_idKey)));
LogInfo("Got Identity Keys from lokid: ",
RouterID(seckey_topublic(m_idKey)));
break;
}
else

@ -8,30 +8,31 @@
namespace llarp
{
/// KeyManager manages the cryptographic keys stored on disk for the local node.
/// This includes private keys as well as the self-signed router contact file
/// (e.g. "self.signed").
/// KeyManager manages the cryptographic keys stored on disk for the local
/// node. This includes private keys as well as the self-signed router contact
/// file (e.g. "self.signed").
///
/// Keys are either read from disk if they exist and are valid (see below) or are
/// generated and written to disk.
/// Keys are either read from disk if they exist and are valid (see below) or
/// are generated and written to disk.
///
/// In addition, the KeyManager detects when the keys obsolete (e.g. as a result
/// of a software upgrade) and backs up existing keys before writing out new ones.
struct KeyManager {
/// In addition, the KeyManager detects when the keys obsolete (e.g. as a
/// result of a software upgrade) and backs up existing keys before writing
/// out new ones.
struct KeyManager
{
/// Constructor
KeyManager();
/// Initializes keys using the provided config, loading from disk and/or lokid
/// via HTTP request.
/// Initializes keys using the provided config, loading from disk and/or
/// lokid via HTTP request.
///
/// NOTE: Must be called prior to obtaining any keys.
/// NOTE: blocks on I/O
///
/// @param config should be a prepared config object
/// @param genIfAbsent determines whether or not we will create files if they
/// @param genIfAbsent determines whether or not we will create files if
/// they
/// do not exist.
/// @return true on success, false otherwise
bool
@ -81,7 +82,6 @@ namespace llarp
getRouterContact(llarp::RouterContact& rc) const;
private:
std::string m_rcPath;
std::string m_idKeyPath;
std::string m_encKeyPath;
@ -105,9 +105,7 @@ namespace llarp
///
/// @param keygen is a function that will generate the key if needed
static bool
loadOrCreateKey(
const std::string& filepath,
llarp::SecretKey& key,
loadOrCreateKey(const std::string& filepath, llarp::SecretKey& key,
std::function< void(llarp::SecretKey& key) > keygen);
/// Requests the identity key from lokid via HTTP (curl)

@ -71,8 +71,8 @@ namespace llarp
return bencode_read_integer(val, &txid);
}
bool read = false;
if(!BEncodeMaybeVerifyVersion("V", version, LLARP_PROTO_VERSION, read, key,
val))
if(!BEncodeMaybeVerifyVersion("V", version, LLARP_PROTO_VERSION, read,
key, val))
return false;
return read;

@ -143,8 +143,8 @@ tun_ev_loop(void* unused)
while(true)
{
alert =
GetQueuedCompletionStatus(tun_event_queue, &size, &listener, &ovl, EV_TICK_INTERVAL);
alert = GetQueuedCompletionStatus(tun_event_queue, &size, &listener, &ovl,
EV_TICK_INTERVAL);
if(!alert)
{

@ -8,14 +8,14 @@ namespace llarp
{
namespace iwp
{
LinkLayer::LinkLayer(std::shared_ptr<KeyManager> keyManager, GetRCFunc getrc,
LinkMessageHandler h, SignBufferFunc sign,
SessionEstablishedHandler est,
LinkLayer::LinkLayer(std::shared_ptr< KeyManager > keyManager,
GetRCFunc getrc, LinkMessageHandler h,
SignBufferFunc sign, SessionEstablishedHandler est,
SessionRenegotiateHandler reneg,
TimeoutHandler timeout, SessionClosedHandler closed,
PumpDoneHandler pumpDone, bool allowInbound)
: ILinkLayer(keyManager, getrc, h, sign, est, reneg, timeout,
closed, pumpDone)
: ILinkLayer(keyManager, getrc, h, sign, est, reneg, timeout, closed,
pumpDone)
, permitInbound{allowInbound}
{
}

@ -29,7 +29,6 @@ namespace llarp
NewOutboundSession(const RouterContact &rc,
const AddressInfo &ai) override;
const char *
Name() const override;

@ -22,9 +22,9 @@ namespace llarp
};
using Factory = std::function< LinkLayer_ptr(
std::shared_ptr<KeyManager>, GetRCFunc, LinkMessageHandler, SignBufferFunc,
SessionEstablishedHandler, SessionRenegotiateHandler, TimeoutHandler,
SessionClosedHandler, PumpDoneHandler) >;
std::shared_ptr< KeyManager >, GetRCFunc, LinkMessageHandler,
SignBufferFunc, SessionEstablishedHandler, SessionRenegotiateHandler,
TimeoutHandler, SessionClosedHandler, PumpDoneHandler) >;
/// get link type by name string
/// if invalid returns eLinkUnspec

@ -11,8 +11,9 @@ namespace llarp
{
static constexpr size_t MaxSessionsPerKey = 16;
ILinkLayer::ILinkLayer(std::shared_ptr<KeyManager> keyManager, GetRCFunc getrc,
LinkMessageHandler handler, SignBufferFunc signbuf,
ILinkLayer::ILinkLayer(std::shared_ptr< KeyManager > keyManager,
GetRCFunc getrc, LinkMessageHandler handler,
SignBufferFunc signbuf,
SessionEstablishedHandler establishedSession,
SessionRenegotiateHandler reneg,
TimeoutHandler timeout, SessionClosedHandler closed,

@ -76,8 +76,8 @@ namespace llarp
}
else if(key == "v")
{
if(!BEncodeMaybeVerifyVersion("v", version, LLARP_PROTO_VERSION, read, key,
buf))
if(!BEncodeMaybeVerifyVersion("v", version, LLARP_PROTO_VERSION, read,
key, buf))
{
return false;
}

@ -195,7 +195,6 @@ namespace llarp
bool
Router::EnsureIdentity()
{
if(whitelistRouters)
{
#if defined(ANDROID) || defined(IOS)
@ -524,8 +523,7 @@ namespace llarp
util::memFn(&IOutboundSessionMaker::OnConnectTimeout,
&_outboundSessionMaker),
util::memFn(&AbstractRouter::SessionClosed, this),
util::memFn(&AbstractRouter::PumpLL, this)
);
util::memFn(&AbstractRouter::PumpLL, this));
const auto &key = std::get< LinksConfig::Interface >(serverConfig);
int af = std::get< LinksConfig::AddressFamily >(serverConfig);
@ -1161,8 +1159,7 @@ namespace llarp
util::memFn(&IOutboundSessionMaker::OnConnectTimeout,
&_outboundSessionMaker),
util::memFn(&AbstractRouter::SessionClosed, this),
util::memFn(&AbstractRouter::PumpLL, this)
);
util::memFn(&AbstractRouter::PumpLL, this));
if(!link)
return false;

@ -163,8 +163,8 @@ namespace llarp
return false;
if(!BEncodeMaybeReadDictEntry("T", T, read, key, val))
return false;
if(!BEncodeMaybeVerifyVersion("V", version, LLARP_PROTO_VERSION, read, key,
val))
if(!BEncodeMaybeVerifyVersion("V", version, LLARP_PROTO_VERSION, read,
key, val))
return false;
if(!BEncodeMaybeReadDictEntry("Z", Z, read, key, val))
return false;

@ -139,7 +139,8 @@ bencode_discard(llarp_buffer_t* buf)
}
bool
bencode_write_uint64_entry(llarp_buffer_t* buff, const void* name, size_t sz, uint64_t i)
bencode_write_uint64_entry(llarp_buffer_t* buff, const void* name, size_t sz,
uint64_t i)
{
if(!bencode_write_bytestring(buff, name, sz))
return false;

@ -31,7 +31,8 @@ bencode_write_uint64(llarp_buffer_t* buff, uint64_t i);
/// Write a dictionary entry with a uint64_t value
bool
bencode_write_uint64_entry(llarp_buffer_t* buff, const void* name, size_t sz, uint64_t i);
bencode_write_uint64_entry(llarp_buffer_t* buff, const void* name, size_t sz,
uint64_t i);
bool
bencode_start_list(llarp_buffer_t* buff);

Loading…
Cancel
Save