2018-02-01 17:07:01 +00:00
|
|
|
#include "router.hpp"
|
2018-05-17 20:00:58 +00:00
|
|
|
#include <llarp/dtls.h>
|
2018-05-22 15:54:19 +00:00
|
|
|
#include <llarp/ibfq.h>
|
2018-05-18 12:39:17 +00:00
|
|
|
#include <llarp/iwp.h>
|
2018-04-05 14:43:16 +00:00
|
|
|
#include <llarp/link.h>
|
2018-04-05 14:23:14 +00:00
|
|
|
#include <llarp/proto.h>
|
2018-04-05 14:43:16 +00:00
|
|
|
#include <llarp/router.h>
|
2018-05-21 13:17:07 +00:00
|
|
|
#include "buffer.hpp"
|
2018-05-22 15:54:19 +00:00
|
|
|
#include "net.hpp"
|
|
|
|
#include "str.hpp"
|
2017-11-28 14:05:31 +00:00
|
|
|
|
2018-05-20 17:45:47 +00:00
|
|
|
#include <fstream>
|
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
namespace llarp
|
|
|
|
{
|
|
|
|
void
|
|
|
|
router_iter_config(llarp_config_iterator *iter, const char *section,
|
|
|
|
const char *key, const char *val);
|
2018-02-01 13:21:00 +00:00
|
|
|
} // namespace llarp
|
2017-11-28 14:05:31 +00:00
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
llarp_router::llarp_router(struct llarp_alloc *m) : ready(false), mem(m)
|
|
|
|
{
|
2018-05-22 19:19:06 +00:00
|
|
|
llarp_rc_clear(&rc);
|
2018-05-22 15:54:19 +00:00
|
|
|
llarp_msg_muxer_init(&muxer);
|
|
|
|
}
|
2018-01-29 14:27:24 +00:00
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
llarp_router::~llarp_router()
|
|
|
|
{
|
2018-05-22 19:19:06 +00:00
|
|
|
llarp_rc_free(&rc);
|
2018-05-22 15:54:19 +00:00
|
|
|
}
|
2018-02-01 17:07:01 +00:00
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
void
|
|
|
|
llarp_router::try_connect(fs::path rcfile)
|
|
|
|
{
|
|
|
|
byte_t tmp[MAX_RC_SIZE];
|
|
|
|
llarp_rc remote = {0};
|
|
|
|
llarp_buffer_t buf;
|
|
|
|
llarp::StackBuffer< decltype(tmp) >(buf, tmp);
|
|
|
|
// open file
|
|
|
|
{
|
|
|
|
std::ifstream f(rcfile, std::ios::binary);
|
|
|
|
if(f.is_open())
|
|
|
|
{
|
|
|
|
f.seekg(0, std::ios::end);
|
|
|
|
size_t sz = f.tellg();
|
|
|
|
f.seekg(0, std::ios::beg);
|
|
|
|
if(sz <= buf.sz)
|
|
|
|
{
|
|
|
|
f.read((char *)buf.base, sz);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
printf("file too large\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-05-23 13:49:00 +00:00
|
|
|
printf("failed to open %s\n", rcfile.c_str());
|
2018-05-22 15:54:19 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(llarp_rc_bdecode(mem, &remote, &buf))
|
2018-05-16 18:13:18 +00:00
|
|
|
{
|
2018-05-22 15:54:19 +00:00
|
|
|
if(llarp_rc_verify_sig(&crypto, &remote))
|
|
|
|
{
|
|
|
|
printf("signature valided\n");
|
|
|
|
if(llarp_router_try_connect(this, &remote))
|
|
|
|
{
|
|
|
|
printf("session attempt started\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
printf("session already pending\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
printf("failed to verify signature\n");
|
2018-05-16 18:13:18 +00:00
|
|
|
}
|
2018-02-01 17:06:49 +00:00
|
|
|
else
|
2018-05-22 15:54:19 +00:00
|
|
|
printf("failed to decode buffer, read=%ld\n", buf.cur - buf.base);
|
2018-04-05 14:23:14 +00:00
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
llarp_rc_free(&remote);
|
|
|
|
}
|
|
|
|
|
2018-05-22 18:41:38 +00:00
|
|
|
bool
|
|
|
|
llarp_router::EnsureIdentity()
|
2018-05-20 17:45:47 +00:00
|
|
|
{
|
2018-05-22 19:19:06 +00:00
|
|
|
return llarp_findOrCreateIdentity(&crypto, ident_keyfile.c_str(), identity);
|
2018-05-20 17:45:47 +00:00
|
|
|
}
|
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
void
|
|
|
|
llarp_router::AddLink(struct llarp_link *link)
|
|
|
|
{
|
|
|
|
links.push_back(link);
|
2018-04-05 14:23:14 +00:00
|
|
|
ready = true;
|
|
|
|
}
|
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
bool
|
|
|
|
llarp_router::Ready()
|
|
|
|
{
|
|
|
|
return ready;
|
|
|
|
}
|
2018-01-29 14:27:24 +00:00
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
bool
|
|
|
|
llarp_router::SaveRC()
|
2018-05-20 17:45:47 +00:00
|
|
|
{
|
|
|
|
printf("verify rc signature... ");
|
|
|
|
if(!llarp_rc_verify_sig(&crypto, &rc))
|
|
|
|
{
|
|
|
|
printf(" BAD!\n");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
printf(" OK.\n");
|
2018-05-22 15:54:19 +00:00
|
|
|
|
|
|
|
byte_t tmp[MAX_RC_SIZE];
|
2018-05-22 18:41:38 +00:00
|
|
|
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
|
2018-05-22 15:54:19 +00:00
|
|
|
|
2018-05-20 17:45:47 +00:00
|
|
|
if(llarp_rc_bencode(&rc, &buf))
|
|
|
|
{
|
2018-05-22 15:54:19 +00:00
|
|
|
std::ofstream f(our_rc_file);
|
2018-05-20 17:45:47 +00:00
|
|
|
if(f.is_open())
|
|
|
|
{
|
2018-05-22 15:54:19 +00:00
|
|
|
f.write((char *)buf.base, buf.cur - buf.base);
|
2018-05-20 17:45:47 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
void
|
|
|
|
llarp_router::Close()
|
|
|
|
{
|
|
|
|
for(auto link : links)
|
|
|
|
{
|
|
|
|
link->stop_link(link);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
llarp_router::on_try_connect_result(llarp_link_establish_job *job)
|
|
|
|
{
|
|
|
|
printf("on_try_connect_result\n");
|
|
|
|
if(job->session)
|
|
|
|
printf("session made\n");
|
|
|
|
else
|
|
|
|
printf("session not made\n");
|
2018-05-22 19:19:06 +00:00
|
|
|
delete job;
|
2018-05-22 15:54:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
llarp_router::Run()
|
|
|
|
{
|
|
|
|
// zero out router contact
|
|
|
|
llarp::Zero(&rc, sizeof(llarp_rc));
|
|
|
|
// fill our address list
|
|
|
|
rc.addrs = llarp_ai_list_new(mem);
|
|
|
|
for(auto link : links)
|
|
|
|
{
|
2018-05-22 19:19:06 +00:00
|
|
|
llarp_ai addr;
|
2018-05-22 15:54:19 +00:00
|
|
|
link->get_our_address(link, &addr);
|
|
|
|
llarp_ai_list_pushback(rc.addrs, &addr);
|
|
|
|
};
|
|
|
|
// set public key
|
2018-05-22 19:19:06 +00:00
|
|
|
llarp_rc_set_pubkey(&rc, pubkey());
|
2018-05-22 15:54:19 +00:00
|
|
|
|
2018-05-22 19:19:06 +00:00
|
|
|
llarp_rc_sign(&crypto, identity, &rc);
|
2018-05-22 15:54:19 +00:00
|
|
|
|
|
|
|
if(!SaveRC())
|
2018-05-22 19:19:06 +00:00
|
|
|
{
|
|
|
|
printf("failed to save rc\n");
|
2018-05-22 15:54:19 +00:00
|
|
|
return;
|
2018-05-22 19:19:06 +00:00
|
|
|
}
|
2018-05-22 15:54:19 +00:00
|
|
|
|
|
|
|
printf("saved router contact\n");
|
|
|
|
// start links
|
|
|
|
for(auto link : links)
|
|
|
|
{
|
|
|
|
int result = link->start_link(link, logic);
|
|
|
|
if(result == -1)
|
|
|
|
printf("link %s failed to start\n", link->name());
|
|
|
|
else
|
|
|
|
printf("link %s started\n", link->name());
|
|
|
|
}
|
|
|
|
|
|
|
|
printf("connecting to routers\n");
|
|
|
|
for(const auto &itr : connect)
|
|
|
|
{
|
|
|
|
printf("try connecting to %s\n", itr.first.c_str());
|
|
|
|
try_connect(itr.second);
|
|
|
|
}
|
2018-02-01 17:07:01 +00:00
|
|
|
}
|
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
bool
|
|
|
|
llarp_router::iter_try_connect(llarp_router_link_iter *iter,
|
|
|
|
llarp_router *router, llarp_link *link)
|
|
|
|
{
|
|
|
|
if(!link)
|
2018-05-23 20:37:43 +00:00
|
|
|
return true;
|
2018-05-22 15:54:19 +00:00
|
|
|
|
2018-05-22 19:19:06 +00:00
|
|
|
llarp_link_establish_job *job = new llarp_link_establish_job;
|
2018-05-22 15:54:19 +00:00
|
|
|
|
|
|
|
if(!job)
|
2018-05-23 20:37:43 +00:00
|
|
|
return true;
|
2018-05-22 15:54:19 +00:00
|
|
|
llarp_ai *ai = static_cast< llarp_ai * >(iter->user);
|
|
|
|
llarp_ai_copy(&job->ai, ai);
|
|
|
|
job->timeout = 5000;
|
|
|
|
job->result = &llarp_router::on_try_connect_result;
|
|
|
|
// give router as user pointer
|
|
|
|
job->user = router;
|
|
|
|
printf("try_establish\n");
|
|
|
|
link->try_establish(link, job);
|
|
|
|
printf("return true\n");
|
|
|
|
return true;
|
2018-04-05 14:43:16 +00:00
|
|
|
}
|
2018-05-22 15:54:19 +00:00
|
|
|
|
2018-01-27 01:18:10 +00:00
|
|
|
extern "C" {
|
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
struct llarp_router *
|
|
|
|
llarp_init_router(struct llarp_alloc *mem, struct llarp_threadpool *tp,
|
|
|
|
struct llarp_ev_loop *netloop, struct llarp_logic *logic)
|
|
|
|
{
|
|
|
|
llarp_router *router = new llarp_router(mem);
|
2018-05-16 18:13:18 +00:00
|
|
|
if(router)
|
|
|
|
{
|
|
|
|
router->netloop = netloop;
|
2018-05-22 15:54:19 +00:00
|
|
|
router->tp = tp;
|
|
|
|
router->logic = logic;
|
2018-05-16 18:13:18 +00:00
|
|
|
llarp_crypto_libsodium_init(&router->crypto);
|
2018-05-22 15:54:19 +00:00
|
|
|
llarp_msg_muxer_init(&router->muxer);
|
2018-05-16 18:13:18 +00:00
|
|
|
}
|
2018-01-29 14:27:24 +00:00
|
|
|
return router;
|
|
|
|
}
|
2018-01-08 13:49:05 +00:00
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
bool
|
|
|
|
llarp_configure_router(struct llarp_router *router, struct llarp_config *conf)
|
|
|
|
{
|
2018-01-29 14:27:24 +00:00
|
|
|
llarp_config_iterator iter;
|
2018-05-22 15:54:19 +00:00
|
|
|
iter.user = router;
|
2018-01-29 14:27:24 +00:00
|
|
|
iter.visit = llarp::router_iter_config;
|
|
|
|
llarp_config_iter(conf, &iter);
|
2018-05-22 15:54:19 +00:00
|
|
|
if(!router->Ready())
|
|
|
|
{
|
|
|
|
printf("router not ready\n");
|
|
|
|
return false;
|
|
|
|
}
|
2018-05-20 17:45:47 +00:00
|
|
|
return router->EnsureIdentity();
|
2018-01-29 14:27:24 +00:00
|
|
|
}
|
2018-01-08 13:49:05 +00:00
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
void
|
|
|
|
llarp_run_router(struct llarp_router *router)
|
|
|
|
{
|
|
|
|
router->Run();
|
|
|
|
}
|
2018-05-20 17:45:47 +00:00
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
bool
|
|
|
|
llarp_router_try_connect(struct llarp_router *router, struct llarp_rc *remote)
|
|
|
|
{
|
|
|
|
// try first address only
|
|
|
|
llarp_ai addr;
|
|
|
|
if(llarp_ai_list_index(remote->addrs, 0, &addr))
|
2018-05-20 17:45:47 +00:00
|
|
|
{
|
2018-05-22 15:54:19 +00:00
|
|
|
printf("try connect to first address\n");
|
|
|
|
llarp_router_iterate_links(router,
|
|
|
|
{&addr, &llarp_router::iter_try_connect});
|
|
|
|
return true;
|
2018-05-20 17:45:47 +00:00
|
|
|
}
|
2018-05-22 15:54:19 +00:00
|
|
|
else
|
|
|
|
printf("router has no addresses?\n");
|
|
|
|
return false;
|
2018-01-29 14:27:24 +00:00
|
|
|
}
|
2018-01-08 13:49:05 +00:00
|
|
|
|
2018-05-22 18:41:38 +00:00
|
|
|
void
|
|
|
|
llarp_rc_clear(struct llarp_rc *rc)
|
|
|
|
{
|
2018-05-21 12:43:32 +00:00
|
|
|
// zero out router contact
|
|
|
|
llarp::Zero(rc, sizeof(llarp_rc));
|
|
|
|
}
|
|
|
|
|
2018-05-22 18:41:38 +00:00
|
|
|
bool
|
|
|
|
llarp_rc_addr_list_iter(struct llarp_ai_list_iter *iter, struct llarp_ai *ai)
|
|
|
|
{
|
2018-05-21 12:43:32 +00:00
|
|
|
struct llarp_rc *rc = (llarp_rc *)iter->user;
|
2018-05-22 18:41:38 +00:00
|
|
|
llarp_ai_list_pushback(rc->addrs, ai);
|
2018-05-21 12:43:32 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2018-05-22 18:41:38 +00:00
|
|
|
void
|
|
|
|
llarp_rc_set_addrs(struct llarp_rc *rc, struct llarp_alloc *mem,
|
|
|
|
struct llarp_ai_list *addr)
|
|
|
|
{
|
2018-05-21 12:43:32 +00:00
|
|
|
rc->addrs = llarp_ai_list_new(mem);
|
|
|
|
struct llarp_ai_list_iter ai_itr;
|
2018-05-22 18:41:38 +00:00
|
|
|
ai_itr.user = rc;
|
2018-05-21 12:43:32 +00:00
|
|
|
ai_itr.visit = &llarp_rc_addr_list_iter;
|
|
|
|
llarp_ai_list_iterate(addr, &ai_itr);
|
|
|
|
}
|
|
|
|
|
2018-05-22 18:41:38 +00:00
|
|
|
void
|
|
|
|
llarp_rc_set_pubkey(struct llarp_rc *rc, uint8_t *pubkey)
|
|
|
|
{
|
2018-05-21 12:43:32 +00:00
|
|
|
// set public key
|
|
|
|
memcpy(rc->pubkey, pubkey, 32);
|
|
|
|
}
|
|
|
|
|
2018-05-22 18:41:38 +00:00
|
|
|
bool
|
|
|
|
llarp_findOrCreateIdentity(llarp_crypto *crypto, const char *fpath,
|
2018-05-22 19:19:06 +00:00
|
|
|
byte_t *secretkey)
|
2018-05-22 18:41:38 +00:00
|
|
|
{
|
|
|
|
fs::path path(fpath);
|
|
|
|
std::error_code ec;
|
|
|
|
if(!fs::exists(path, ec))
|
2018-05-21 12:43:32 +00:00
|
|
|
{
|
2018-05-23 20:37:43 +00:00
|
|
|
crypto->identity_keygen(secretkey);
|
2018-05-22 18:41:38 +00:00
|
|
|
std::ofstream f(path, std::ios::binary);
|
|
|
|
if(f.is_open())
|
|
|
|
{
|
2018-05-22 19:19:06 +00:00
|
|
|
f.write((char *)secretkey, sizeof(llarp_seckey_t));
|
2018-05-22 18:41:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
std::ifstream f(path, std::ios::binary);
|
|
|
|
if(f.is_open())
|
|
|
|
{
|
2018-05-22 19:19:06 +00:00
|
|
|
f.read((char *)secretkey, sizeof(llarp_seckey_t));
|
2018-05-22 18:41:38 +00:00
|
|
|
return true;
|
2018-05-21 12:43:32 +00:00
|
|
|
}
|
2018-05-22 18:41:38 +00:00
|
|
|
return false;
|
2018-05-21 12:43:32 +00:00
|
|
|
}
|
|
|
|
|
2018-05-22 18:41:38 +00:00
|
|
|
bool
|
|
|
|
llarp_rc_write(struct llarp_rc *rc, const char *fpath)
|
|
|
|
{
|
|
|
|
fs::path our_rc_file(fpath);
|
|
|
|
byte_t tmp[MAX_RC_SIZE];
|
|
|
|
auto buf = llarp::StackBuffer< decltype(tmp) >(tmp);
|
2018-05-20 17:45:47 +00:00
|
|
|
|
2018-05-22 18:41:38 +00:00
|
|
|
if(llarp_rc_bencode(rc, &buf))
|
|
|
|
{
|
|
|
|
std::ofstream f(our_rc_file, std::ios::binary);
|
|
|
|
if(f.is_open())
|
|
|
|
{
|
|
|
|
f.write((char *)buf.base, buf.cur - buf.base);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2018-05-21 12:43:32 +00:00
|
|
|
|
2018-05-22 18:41:38 +00:00
|
|
|
void
|
2018-05-22 19:19:06 +00:00
|
|
|
llarp_rc_sign(llarp_crypto *crypto, const byte_t *seckey, struct llarp_rc *rc)
|
2018-05-22 18:41:38 +00:00
|
|
|
{
|
|
|
|
byte_t buf[MAX_RC_SIZE];
|
|
|
|
auto signbuf = llarp::StackBuffer< decltype(buf) >(buf);
|
2018-05-22 19:19:06 +00:00
|
|
|
// zero out previous signature
|
|
|
|
llarp::Zero(rc->signature, sizeof(rc->signature));
|
2018-05-20 17:45:47 +00:00
|
|
|
// encode
|
2018-05-22 18:41:38 +00:00
|
|
|
if(llarp_rc_bencode(rc, &signbuf))
|
2018-05-20 17:45:47 +00:00
|
|
|
{
|
|
|
|
// sign
|
|
|
|
signbuf.sz = signbuf.cur - signbuf.base;
|
2018-05-22 18:41:38 +00:00
|
|
|
printf("router.cpp::llarp_rc_sign - sized [%zu/%zu]\n", signbuf.sz,
|
|
|
|
MAX_RC_SIZE);
|
2018-05-22 19:19:06 +00:00
|
|
|
crypto->sign(rc->signature, seckey, signbuf);
|
2018-05-22 18:41:38 +00:00
|
|
|
printf("router.cpp::llarp_rc_sign - signed\n");
|
2018-05-20 17:45:47 +00:00
|
|
|
}
|
2018-01-29 14:27:24 +00:00
|
|
|
}
|
2018-01-08 13:49:05 +00:00
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
void
|
|
|
|
llarp_stop_router(struct llarp_router *router)
|
|
|
|
{
|
2018-05-16 13:56:51 +00:00
|
|
|
if(router)
|
|
|
|
router->Close();
|
|
|
|
}
|
2018-01-29 14:19:00 +00:00
|
|
|
|
2018-05-22 15:54:19 +00:00
|
|
|
void
|
|
|
|
llarp_router_iterate_links(struct llarp_router *router,
|
|
|
|
struct llarp_router_link_iter i)
|
|
|
|
{
|
|
|
|
for(auto link : router->links)
|
|
|
|
if(!i.visit(&i, router, link))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
llarp_free_router(struct llarp_router **router)
|
|
|
|
{
|
|
|
|
if(*router)
|
|
|
|
{
|
|
|
|
for(auto &link : (*router)->links)
|
|
|
|
{
|
|
|
|
link->free_impl(link);
|
|
|
|
delete link;
|
|
|
|
}
|
|
|
|
delete *router;
|
2018-01-08 13:49:05 +00:00
|
|
|
}
|
2018-01-29 14:27:24 +00:00
|
|
|
*router = nullptr;
|
|
|
|
}
|
2018-01-08 13:49:05 +00:00
|
|
|
}
|
2018-01-19 16:51:27 +00:00
|
|
|
|
2018-05-17 20:00:58 +00:00
|
|
|
namespace llarp
|
|
|
|
{
|
2018-05-22 15:54:19 +00:00
|
|
|
void
|
|
|
|
router_iter_config(llarp_config_iterator *iter, const char *section,
|
|
|
|
const char *key, const char *val)
|
2018-05-20 17:45:47 +00:00
|
|
|
{
|
2018-05-22 15:54:19 +00:00
|
|
|
llarp_router *self = static_cast< llarp_router * >(iter->user);
|
|
|
|
int af;
|
|
|
|
uint16_t proto;
|
|
|
|
if(StrEq(val, "eth"))
|
|
|
|
{
|
|
|
|
af = AF_PACKET;
|
|
|
|
proto = LLARP_ETH_PROTO;
|
|
|
|
}
|
2018-05-20 17:45:47 +00:00
|
|
|
else
|
|
|
|
{
|
2018-05-23 13:49:00 +00:00
|
|
|
af = AF_INET6;
|
2018-05-22 15:54:19 +00:00
|
|
|
proto = std::atoi(val);
|
2018-05-20 17:45:47 +00:00
|
|
|
}
|
2018-05-22 15:54:19 +00:00
|
|
|
|
|
|
|
struct llarp_link *link = nullptr;
|
|
|
|
if(StrEq(section, "iwp-links"))
|
|
|
|
{
|
2018-05-22 19:19:06 +00:00
|
|
|
link = new llarp_link;
|
|
|
|
llarp::Zero(link, sizeof(llarp_link));
|
2018-05-22 15:54:19 +00:00
|
|
|
|
|
|
|
llarp_iwp_args args = {
|
|
|
|
.mem = self->mem,
|
|
|
|
.crypto = &self->crypto,
|
|
|
|
.logic = self->logic,
|
|
|
|
.cryptoworker = self->tp,
|
|
|
|
.keyfile = self->transport_keyfile.c_str(),
|
|
|
|
};
|
|
|
|
iwp_link_init(link, args, &self->muxer);
|
2018-05-22 18:41:38 +00:00
|
|
|
if(llarp_link_initialized(link))
|
2018-05-22 15:54:19 +00:00
|
|
|
{
|
2018-05-22 18:41:38 +00:00
|
|
|
if(link->configure(link, self->netloop, key, af, proto))
|
|
|
|
{
|
|
|
|
llarp_ai ai;
|
|
|
|
link->get_our_address(link, &ai);
|
|
|
|
llarp::Addr addr = ai;
|
|
|
|
printf("link %s bound to %s\n", key, addr.to_string().c_str());
|
2018-05-22 19:19:06 +00:00
|
|
|
self->AddLink(link);
|
2018-05-22 18:41:38 +00:00
|
|
|
return;
|
|
|
|
}
|
2018-05-22 15:54:19 +00:00
|
|
|
}
|
2018-05-22 18:41:38 +00:00
|
|
|
printf("link %s failed to configure\n", key);
|
2018-05-22 15:54:19 +00:00
|
|
|
}
|
2018-05-22 18:41:38 +00:00
|
|
|
else if(StrEq(section, "iwp-connect"))
|
2018-05-22 15:54:19 +00:00
|
|
|
{
|
2018-05-22 18:41:38 +00:00
|
|
|
self->connect[key] = val;
|
2018-04-05 14:43:16 +00:00
|
|
|
}
|
2018-05-23 20:37:43 +00:00
|
|
|
else if(StrEq(section, "router"))
|
|
|
|
{
|
|
|
|
if(StrEq(key, "contact-file"))
|
|
|
|
{
|
|
|
|
self->our_rc_file = val;
|
|
|
|
}
|
|
|
|
if(StrEq(key, "transport-privkey"))
|
|
|
|
{
|
|
|
|
self->transport_keyfile = val;
|
|
|
|
}
|
|
|
|
if(StrEq(key, "ident-privkey"))
|
|
|
|
{
|
|
|
|
self->ident_keyfile = val;
|
|
|
|
}
|
|
|
|
}
|
2018-01-19 16:51:27 +00:00
|
|
|
}
|
2018-05-22 15:54:19 +00:00
|
|
|
|
2018-02-01 13:21:00 +00:00
|
|
|
} // namespace llarp
|