Fix lifetime issues in llarp_findOrCreate* function calls

This commit is contained in:
Michael 2019-01-03 23:10:32 +00:00
parent a4751224d9
commit 4f90192e1a
No known key found for this signature in database
GPG Key ID: 2D51757B47E2434C
6 changed files with 174 additions and 178 deletions

View File

@ -19,7 +19,7 @@ def exit_sessions_main():
print("graph_category network")
print("graph_info This graph shows the number of exit sessions on a lokinet exit")
print("lokinet.exit.sessions.info Number of exit sessions")
print("lokinet.exit.sessions.label sessions"))
print("lokinet.exit.sessions.label sessions")
else:
count = 0
try:
@ -30,7 +30,6 @@ def exit_sessions_main():
print("lokinet.exit.sessions {}".format(outbound))
def peers_main():
if len(sys.argv) == 2 and sys.argv[1] == 'config':
print("graph_title lokinet peers")
@ -64,4 +63,5 @@ if __name__ == '__main__':
elif sys.argv[0] == 'lokinet-exit':
exit_sessions_main()
else:
print('please symlink this as `lokinet-peers` or `lokinet-exit` in munin plugins dir')
print(
'please symlink this as `lokinet-peers` or `lokinet-exit` in munin plugins dir')

View File

@ -2,23 +2,23 @@
import bencode
import sys
import libnacl
import base64
import struct
from io import BytesIO
import time
from multiprocessing import Process, Array, Value
def print_help():
print('usage: {} keyfile.private prefix numthreads'.format(sys.argv[0]))
return 1
_zalpha = ['y', 'b', 'n', 'd', 'r', 'f', 'g', '8',
'e', 'j', 'k', 'm', 'c', 'p', 'q', 'x',
'o', 't', '1', 'u', 'w', 'i', 's', 'z',
'a', '3', '4', '5', 'h', '7', '6', '9']
def zb32_encode(buf):
s = str()
bits = 0
@ -65,7 +65,8 @@ class AddrGen:
print("find ^{}.loki".format(self.prefix))
i = self._inc
while i > 0:
p = Process(target=self._gen_addr_tick, args=(self.prefix, abs(libnacl.randombytes_random()), abs(libnacl.randombytes_random()), _gen_si(self._keys)))
p = Process(target=self._gen_addr_tick, args=(self.prefix, abs(
libnacl.randombytes_random()), abs(libnacl.randombytes_random()), _gen_si(self._keys)))
p.start()
self._procs.append(p)
i -= 1
@ -132,5 +133,6 @@ def main(args):
enc = bencode.BCodec(fd)
enc.encode(keys)
if __name__ == '__main__':
main(sys.argv[1:])

View File

@ -261,8 +261,7 @@ main(int argc, char *argv[])
if(verifyMode)
{
llarp::Crypto crypto;
llarp_crypto_init(&crypto);
llarp::Crypto crypto(llarp::Crypto::sodium{});
if(!rc.Read(rcfname))
{
std::cout << "failed to read " << rcfname << std::endl;
@ -327,8 +326,7 @@ main(int argc, char *argv[])
// this is the only one...
if(listMode)
{
llarp::Crypto crypto;
llarp_crypto_init(&crypto);
llarp::Crypto crypto(llarp::Crypto::sodium{});
auto nodedb = llarp_nodedb_new(&crypto);
llarp_nodedb_iter itr;
itr.visit = [](llarp_nodedb_iter *i) -> bool {
@ -348,8 +346,7 @@ main(int argc, char *argv[])
std::cout << "no file to import" << std::endl;
return 1;
}
llarp::Crypto crypto;
llarp_crypto_init(&crypto);
llarp::Crypto crypto(llarp::Crypto::sodium{});
auto nodedb = llarp_nodedb_new(&crypto);
if(!llarp_nodedb_ensure_dir(nodesdir))
{
@ -389,24 +386,21 @@ main(int argc, char *argv[])
// set updated timestamp
rc.last_updated = llarp::time_now_ms();
// load longterm identity
llarp::Crypto crypt;
llarp_crypto_init(&crypt);
llarp::Crypto crypt(llarp::Crypto::sodium{});
// which is in daemon.ini config: router.encryption-privkey (defaults
// "encryption.key")
fs::path encryption_keyfile = "encryption.key";
llarp::SecretKey encryption;
llarp_findOrCreateEncryption(&crypt, encryption_keyfile.string().c_str(),
encryption);
llarp_findOrCreateEncryption(&crypt, encryption_keyfile, encryption);
rc.enckey = llarp::seckey_topublic(encryption);
// get identity public sig key
fs::path ident_keyfile = "identity.key";
llarp::SecretKey identity;
llarp_findOrCreateIdentity(&crypt, ident_keyfile.string().c_str(),
identity);
llarp_findOrCreateIdentity(&crypt, ident_keyfile, identity);
rc.pubkey = llarp::seckey_topublic(identity);
@ -438,15 +432,14 @@ main(int argc, char *argv[])
// set updated timestamp
rc.last_updated = llarp::time_now_ms();
// load longterm identity
llarp::Crypto crypt;
llarp::Crypto crypt(llarp::Crypto::sodium{});
// no longer used?
// llarp_crypto_libsodium_init(&crypt);
llarp::SecretKey identityKey; // FIXME: Jeff requests we use this
fs::path ident_keyfile = "identity.key";
byte_t identity[SECKEYSIZE];
llarp_findOrCreateIdentity(&crypt, ident_keyfile.string().c_str(),
identity);
llarp::SecretKey identity;
llarp_findOrCreateIdentity(&crypt, ident_keyfile, identity);
// FIXME: update RC API
// get identity public key
@ -467,10 +460,7 @@ main(int argc, char *argv[])
if(listMode)
{
llarp::Crypto crypto;
// no longer used?
// llarp_crypto_libsodium_init(&crypto);
llarp_crypto_init(&crypto);
llarp::Crypto crypto(llarp::Crypto::sodium{});
auto nodedb = llarp_nodedb_new(&crypto);
llarp_nodedb_iter itr;
itr.visit = [](llarp_nodedb_iter *i) -> bool {
@ -517,7 +507,7 @@ main(int argc, char *argv[])
job->found = false;
job->hook = &HandleDHTLocate;
// llarp_rc_new(&job->result);
memcpy(job->target, binaryPK, PUBKEYSIZE); // set job's target
job->target = binaryPK; // set job's target
// create query DHT request
check_online_request *request = new check_online_request;

View File

@ -1,4 +1,5 @@
import os, sys, time
import os
import sys
# usage: parse_log.py log-file [socket-index to focus on]
@ -7,14 +8,15 @@ socket_filter = None
if len(sys.argv) >= 3:
socket_filter = sys.argv[2].strip()
if socket_filter == None:
if socket_filter is None:
print "scanning for socket with the most packets"
file = open(sys.argv[1], 'rb')
sockets = {}
for l in file:
if not 'our_delay' in l: continue
if not 'our_delay' in l:
continue
try:
a = l.strip().split(" ")
@ -39,14 +41,15 @@ if socket_filter == None:
for i in items:
print '%s: %d' % (i[0], i[1])
count += 1
if count > 5: break
if count > 5:
break
file.close()
socket_filter = items[0][0]
print '\nfocusing on socket %s' % socket_filter
file = open(sys.argv[1], 'rb')
out_file = 'utp.out%s' % socket_filter;
out_file = 'utp.out%s' % socket_filter
out = open(out_file, 'wb')
delay_samples = 'dots lc rgb "blue"'
@ -164,12 +167,14 @@ for l in file:
if n == "our_delay":
bucket = v / histogram_quantization
delay_histogram[bucket] = 1 + delay_histogram.get(bucket, 0)
if not n in metrics: continue
if not n in metrics:
continue
if fill_columns:
columns.append(n)
if n == "max_window":
window_size[socket_index] = v
print >>out, '%f\t' % int(reduce(lambda a,b: a+b, window_size.values())),
print >>out, '%f\t' % int(
reduce(lambda a, b: a+b, window_size.values())),
else:
print >>out, '%f\t' % v,
print >>out, float(packet_loss * 8000), float(packet_timeout * 8000)
@ -180,7 +185,8 @@ out.close()
out = open('%s.histogram' % out_file, 'wb')
for d, f in delay_histogram.iteritems():
print >>out, float(d*histogram_quantization) + histogram_quantization / 2, f
print >>out, float(d*histogram_quantization) + \
histogram_quantization / 2, f
out.close()
@ -274,9 +280,11 @@ for p in plot:
print >>out, "plot",
for c in p['data']:
if not c in metrics: continue
if not c in metrics:
continue
i = columns.index(c)
print >>out, '%s"%s" using 1:%d title "%s-%s" axes %s with %s' % (comma, out_file, i + 2, metrics[c][0], metrics[c][1], metrics[c][1], metrics[c][2]),
print >>out, '%s"%s" using 1:%d title "%s-%s" axes %s with %s' % (
comma, out_file, i + 2, metrics[c][0], metrics[c][1], metrics[c][1], metrics[c][2]),
comma = ', '
print >>out, ''
@ -285,4 +293,3 @@ out.close()
os.system("gnuplot utp.gnuplot")
os.system("open %s" % files)

View File

@ -121,11 +121,10 @@ llarp_router_try_connect(llarp::Router *router,
}
bool
llarp_findOrCreateIdentity(llarp::Crypto *crypto, const char *fpath,
llarp_findOrCreateIdentity(llarp::Crypto *crypto, const fs::path &path,
llarp::SecretKey &secretkey)
{
llarp::LogDebug("find or create ", fpath);
fs::path path(fpath);
llarp::LogDebug("find or create ", path);
std::error_code ec;
if(!fs::exists(path, ec))
{
@ -151,11 +150,10 @@ llarp_findOrCreateIdentity(llarp::Crypto *crypto, const char *fpath,
// C++ ...
bool
llarp_findOrCreateEncryption(llarp::Crypto *crypto, const char *fpath,
llarp_findOrCreateEncryption(llarp::Crypto *crypto, const fs::path &path,
llarp::SecretKey &encryption)
{
llarp::LogDebug("find or create ", fpath);
fs::path path(fpath);
llarp::LogDebug("find or create ", path);
std::error_code ec;
if(!fs::exists(path, ec))
{
@ -397,15 +395,14 @@ namespace llarp
{
if(!EnsureEncryptionKey())
return false;
return llarp_findOrCreateIdentity(&crypto, ident_keyfile.string().c_str(),
identity);
return llarp_findOrCreateIdentity(&crypto, ident_keyfile, identity);
}
bool
Router::EnsureEncryptionKey()
{
return llarp_findOrCreateEncryption(
&crypto, encryption_keyfile.string().c_str(), encryption);
return llarp_findOrCreateEncryption(&crypto, encryption_keyfile,
encryption);
}
void

View File

@ -33,11 +33,11 @@
#include <unordered_map>
bool
llarp_findOrCreateEncryption(llarp::Crypto *crypto, const char *fpath,
llarp_findOrCreateEncryption(llarp::Crypto *crypto, const fs::path &fpath,
llarp::SecretKey &encryption);
bool
llarp_findOrCreateIdentity(llarp::Crypto *crypto, const char *path,
llarp_findOrCreateIdentity(llarp::Crypto *crypto, const fs::path &path,
llarp::SecretKey &secretkey);
struct TryConnectJob;