mirror of https://github.com/oxen-io/lokinet
commit
39e11c2b7a
@ -0,0 +1,15 @@
|
||||
#include <llarp/api.hpp>
|
||||
|
||||
int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
std::string url = llarp::api::DefaultURL;
|
||||
if(argc > 1)
|
||||
{
|
||||
url = argv[1];
|
||||
}
|
||||
llarp::api::Client cl;
|
||||
if(!cl.Start(url))
|
||||
return 1;
|
||||
return cl.Mainloop();
|
||||
}
|
@ -0,0 +1,14 @@
|
||||
#ifndef LLARP_API_HPP
|
||||
#define LLARP_API_HPP
|
||||
|
||||
#include <llarp/api/client.hpp>
|
||||
#include <llarp/api/server.hpp>
|
||||
namespace llarp
|
||||
{
|
||||
namespace api
|
||||
{
|
||||
const char DefaultURL[] = "127.0.0.1:34567";
|
||||
}
|
||||
} // namespace llarp
|
||||
|
||||
#endif
|
@ -0,0 +1,29 @@
|
||||
#ifndef LLARP_API_CLIENT_HPP
|
||||
#define LLARP_API_CLIENT_HPP
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
namespace api
|
||||
{
|
||||
struct ClientPImpl;
|
||||
|
||||
struct Client
|
||||
{
|
||||
Client();
|
||||
~Client();
|
||||
|
||||
bool
|
||||
Start(const std::string& apiURL);
|
||||
|
||||
int
|
||||
Mainloop();
|
||||
|
||||
private:
|
||||
ClientPImpl* m_Impl;
|
||||
};
|
||||
|
||||
} // namespace api
|
||||
} // namespace llarp
|
||||
#endif
|
@ -0,0 +1,125 @@
|
||||
#ifndef LLARP_API_MESSAGES_HPP
|
||||
#define LLARP_API_MESSAGES_HPP
|
||||
|
||||
#include <list>
|
||||
#include <llarp/aligned.hpp>
|
||||
#include <llarp/bencode.hpp>
|
||||
#include <llarp/crypto.hpp>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
namespace api
|
||||
{
|
||||
// forward declare
|
||||
struct Client;
|
||||
struct Server;
|
||||
|
||||
/// base message
|
||||
struct IMessage : public IBEncodeMessage
|
||||
{
|
||||
uint64_t sessionID = 0;
|
||||
uint64_t msgID = 0;
|
||||
uint64_t version = 0;
|
||||
llarp::ShortHash hash;
|
||||
|
||||
// the function name this message belongs to
|
||||
virtual std::string
|
||||
FunctionName() const = 0;
|
||||
|
||||
bool
|
||||
BEncode(llarp_buffer_t* buf) const;
|
||||
|
||||
bool
|
||||
DecodeKey(llarp_buffer_t key, llarp_buffer_t* buf);
|
||||
|
||||
virtual std::list< IBEncodeMessage* >
|
||||
GetParams() const = 0;
|
||||
|
||||
virtual bool
|
||||
DecodeParams(llarp_buffer_t* buf) = 0;
|
||||
|
||||
bool
|
||||
IsWellFormed(llarp_crypto* c, const std::string& password);
|
||||
|
||||
void
|
||||
CalculateHash(llarp_crypto* c, const std::string& password);
|
||||
};
|
||||
|
||||
/// a "yes we got your command" type message
|
||||
struct AcknoledgeMessage : public IMessage
|
||||
{
|
||||
};
|
||||
|
||||
/// start a session with the router
|
||||
struct CreateSessionMessage : public IMessage
|
||||
{
|
||||
std::list< IBEncodeMessage* >
|
||||
GetParams() const
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
bool
|
||||
DecodeParams(llarp_buffer_t* buf);
|
||||
|
||||
std::string
|
||||
FunctionName() const
|
||||
{
|
||||
return "CreateSession";
|
||||
}
|
||||
};
|
||||
|
||||
/// a keepalive ping
|
||||
struct SessionPingMessage : public IMessage
|
||||
{
|
||||
};
|
||||
|
||||
/// end a session with the router
|
||||
struct DestroySessionMessage : public IMessage
|
||||
{
|
||||
};
|
||||
|
||||
/// base messgae type for hidden service control and transmission
|
||||
struct HSMessage : public IMessage
|
||||
{
|
||||
llarp::PubKey pubkey;
|
||||
llarp::Signature sig;
|
||||
|
||||
/// validate signature on message (server side)
|
||||
bool
|
||||
SignatureIsValid(llarp_crypto* crypto) const;
|
||||
|
||||
/// sign message using secret key (client side)
|
||||
bool
|
||||
SignMessge(llarp_crypto* crypto, byte_t* seckey);
|
||||
};
|
||||
|
||||
/// create a new hidden service
|
||||
struct CreateServiceMessgae : public HSMessage
|
||||
{
|
||||
};
|
||||
|
||||
/// end an already created hidden service we created
|
||||
struct DestroyServiceMessage : public HSMessage
|
||||
{
|
||||
};
|
||||
|
||||
/// start lookup of another service's descriptor
|
||||
struct LookupServiceMessage : public IMessage
|
||||
{
|
||||
};
|
||||
|
||||
/// publish our hidden service's descriptor
|
||||
struct PublishServiceMessage : public IMessage
|
||||
{
|
||||
};
|
||||
|
||||
/// send pre encrypted data down a path we own
|
||||
struct SendPathDataMessage : public IMessage
|
||||
{
|
||||
};
|
||||
|
||||
} // namespace api
|
||||
} // namespace llarp
|
||||
|
||||
#endif
|
@ -0,0 +1,26 @@
|
||||
#ifndef LLARP_API_PARSER_HPP
|
||||
#define LLARP_API_PARSER_HPP
|
||||
#include <llarp/bencode.h>
|
||||
#include <llarp/api/messages.hpp>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
namespace api
|
||||
{
|
||||
struct MessageParser
|
||||
{
|
||||
MessageParser();
|
||||
|
||||
IMessage *
|
||||
ParseMessage(llarp_buffer_t buf);
|
||||
|
||||
private:
|
||||
static bool
|
||||
OnKey(dict_reader *r, llarp_buffer_t *key);
|
||||
IMessage *msg = nullptr;
|
||||
dict_reader r;
|
||||
};
|
||||
} // namespace api
|
||||
} // namespace llarp
|
||||
|
||||
#endif
|
@ -0,0 +1,29 @@
|
||||
#ifndef LLARP_API_SERVER_HPP
|
||||
#define LLARP_API_SERVER_HPP
|
||||
|
||||
#include <llarp/ev.h>
|
||||
#include <llarp/router.h>
|
||||
#include <string>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
namespace api
|
||||
{
|
||||
struct ServerPImpl;
|
||||
|
||||
struct Server
|
||||
{
|
||||
Server(llarp_router* r);
|
||||
~Server();
|
||||
|
||||
bool
|
||||
Bind(const std::string& url, llarp_ev_loop* loop);
|
||||
|
||||
private:
|
||||
ServerPImpl* m_Impl;
|
||||
};
|
||||
|
||||
} // namespace api
|
||||
} // namespace llarp
|
||||
|
||||
#endif
|
@ -0,0 +1,28 @@
|
||||
#ifndef LLARP_MESSAGES_PATH_LATENCY_HPP
|
||||
#define LLARP_MESSAGES_PATH_LATENCY_HPP
|
||||
|
||||
#include <llarp/routing/message.hpp>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
namespace routing
|
||||
{
|
||||
struct PathLatencyMessage : public IMessage
|
||||
{
|
||||
uint64_t T = 0;
|
||||
uint64_t L = 0;
|
||||
PathLatencyMessage();
|
||||
|
||||
bool
|
||||
BEncode(llarp_buffer_t* buf) const;
|
||||
|
||||
bool
|
||||
DecodeKey(llarp_buffer_t key, llarp_buffer_t* val);
|
||||
|
||||
bool
|
||||
HandleMessage(IMessageHandler* r) const;
|
||||
};
|
||||
} // namespace routing
|
||||
} // namespace llarp
|
||||
|
||||
#endif
|
@ -0,0 +1,57 @@
|
||||
#ifndef LLARP_SERVICE_HPP
|
||||
#define LLARP_SERVICE_HPP
|
||||
#include <llarp/aligned.hpp>
|
||||
#include <llarp/bencode.hpp>
|
||||
#include <llarp/crypto.hpp>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
namespace service
|
||||
{
|
||||
/// hidden service address
|
||||
typedef llarp::AlignedBuffer< 32 > Address;
|
||||
|
||||
typedef llarp::AlignedBuffer< 16 > VanityNonce;
|
||||
|
||||
struct Info : public llarp::IBEncodeMessage
|
||||
{
|
||||
llarp::PubKey enckey;
|
||||
llarp::PubKey signkey;
|
||||
uint64_t version = 0;
|
||||
VanityNonce vanity;
|
||||
|
||||
/// calculate our address
|
||||
void
|
||||
CalculateAddress(llarp_crypto* c, Address& addr) const;
|
||||
|
||||
bool
|
||||
BEncode(llarp_buffer_t* buf) const;
|
||||
|
||||
bool
|
||||
DecodeKey(llarp_buffer_t key, llarp_buffer_t* buf);
|
||||
};
|
||||
|
||||
// private keys
|
||||
struct Identity : public llarp::IBEncodeMessage
|
||||
{
|
||||
llarp::SecretKey enckey;
|
||||
llarp::SecretKey signkey;
|
||||
uint64_t version = 0;
|
||||
VanityNonce vanity;
|
||||
|
||||
// public service info
|
||||
Info pub;
|
||||
|
||||
// regenerate secret keys
|
||||
void
|
||||
RegenerateKeys(llarp_crypto* c);
|
||||
|
||||
// load from file
|
||||
bool
|
||||
LoadFromFile(const std::string& fpath);
|
||||
};
|
||||
|
||||
}; // namespace service
|
||||
} // namespace llarp
|
||||
|
||||
#endif
|
@ -1,28 +0,0 @@
|
||||
#ifndef LLARP_SI_H
|
||||
#define LLARP_SI_H
|
||||
#include <llarp/crypto.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct llarp_service_info
|
||||
{
|
||||
llarp_buffer_t name;
|
||||
llarp_pubkey_t signingkey;
|
||||
llarp_buffer_t vanity;
|
||||
};
|
||||
|
||||
void
|
||||
llarp_service_info_hash(struct llarp_service_info *si, llarp_hash_t *h);
|
||||
bool
|
||||
llarp_service_info_bencode(struct llarp_serivce_info *si, llarp_buffer_t *buff);
|
||||
bool
|
||||
llarp_service_info_bdecode(struct llarp_serivce_info *si, llarp_buffer_t buff);
|
||||
void
|
||||
llarp_service_info_free(struct llarp_service_info **si);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif
|
@ -0,0 +1,145 @@
|
||||
#include <arpa/inet.h>
|
||||
#include <llarp/ev.h>
|
||||
#include <llarp/logic.h>
|
||||
#include <netdb.h>
|
||||
#include <sys/socket.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include <cstring>
|
||||
#include <llarp/api/client.hpp>
|
||||
#include <llarp/api/messages.hpp>
|
||||
#include <llarp/api/parser.hpp>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
namespace api
|
||||
{
|
||||
struct ClientPImpl
|
||||
{
|
||||
ClientPImpl()
|
||||
{
|
||||
llarp_ev_loop_alloc(&loop);
|
||||
worker = llarp_init_same_process_threadpool();
|
||||
logic = llarp_init_single_process_logic(worker);
|
||||
}
|
||||
|
||||
~ClientPImpl()
|
||||
{
|
||||
llarp_ev_loop_free(&loop);
|
||||
}
|
||||
|
||||
static void
|
||||
HandleRecv(llarp_udp_io* u, const sockaddr* from, const void* buf,
|
||||
ssize_t sz)
|
||||
{
|
||||
static_cast< ClientPImpl* >(u->user)->RecvFrom(from, buf, sz);
|
||||
}
|
||||
|
||||
void
|
||||
RecvFrom(const sockaddr* from, const void* b, ssize_t sz)
|
||||
{
|
||||
if(from->sa_family != AF_INET
|
||||
|| ((sockaddr_in*)from)->sin_addr.s_addr != apiAddr.sin_addr.s_addr
|
||||
|| ((sockaddr_in*)from)->sin_port != apiAddr.sin_port)
|
||||
{
|
||||
// address missmatch
|
||||
llarp::Warn("got packet from bad address");
|
||||
return;
|
||||
}
|
||||
llarp_buffer_t buf;
|
||||
buf.base = (byte_t*)b;
|
||||
buf.cur = buf.base;
|
||||
buf.sz = sz;
|
||||
IMessage* msg = m_MessageParser.ParseMessage(buf);
|
||||
if(msg)
|
||||
{
|
||||
delete msg;
|
||||
}
|
||||
else
|
||||
llarp::Warn("Got Invalid Message");
|
||||
}
|
||||
|
||||
bool
|
||||
BindDefault()
|
||||
{
|
||||
ouraddr.sin_family = AF_INET;
|
||||
ouraddr.sin_addr.s_addr = INADDR_LOOPBACK;
|
||||
ouraddr.sin_port = 0;
|
||||
udp.user = this;
|
||||
udp.recvfrom = &HandleRecv;
|
||||
return llarp_ev_add_udp(loop, &udp, (const sockaddr*)&ouraddr) != -1;
|
||||
}
|
||||
|
||||
bool
|
||||
StartSession(const std::string& addr, uint16_t port)
|
||||
{
|
||||
apiAddr.sin_family = AF_INET;
|
||||
if(inet_pton(AF_INET, addr.c_str(), &apiAddr.sin_addr.s_addr) == -1)
|
||||
return false;
|
||||
apiAddr.sin_port = htons(port);
|
||||
CreateSessionMessage msg;
|
||||
return SendMessage(&msg);
|
||||
}
|
||||
|
||||
bool
|
||||
SendMessage(const IMessage* msg)
|
||||
{
|
||||
llarp_buffer_t buf;
|
||||
byte_t tmp[1500];
|
||||
buf.base = tmp;
|
||||
buf.cur = buf.base;
|
||||
buf.sz = sizeof(tmp);
|
||||
if(msg->BEncode(&buf))
|
||||
return llarp_ev_udp_sendto(&udp, (const sockaddr*)&apiAddr, buf.base,
|
||||
buf.sz)
|
||||
!= -1;
|
||||
return false;
|
||||
}
|
||||
|
||||
int
|
||||
Mainloop()
|
||||
{
|
||||
llarp_ev_loop_run_single_process(loop, worker, logic);
|
||||
return 0;
|
||||
}
|
||||
llarp_threadpool* worker;
|
||||
llarp_logic* logic;
|
||||
llarp_ev_loop* loop;
|
||||
sockaddr_in ouraddr;
|
||||
sockaddr_in apiAddr;
|
||||
llarp_udp_io udp;
|
||||
MessageParser m_MessageParser;
|
||||
};
|
||||
|
||||
Client::Client() : m_Impl(new ClientPImpl)
|
||||
{
|
||||
}
|
||||
|
||||
Client::~Client()
|
||||
{
|
||||
delete m_Impl;
|
||||
}
|
||||
|
||||
bool
|
||||
Client::Start(const std::string& url)
|
||||
{
|
||||
if(url.find(":") == std::string::npos)
|
||||
return false;
|
||||
if(!m_Impl->BindDefault())
|
||||
return false;
|
||||
std::string addr = url.substr(0, url.find(":"));
|
||||
std::string strport = url.substr(url.find(":") + 1);
|
||||
int port = std::stoi(strport);
|
||||
if(port == -1)
|
||||
return false;
|
||||
return m_Impl->StartSession(addr, port);
|
||||
}
|
||||
|
||||
int
|
||||
Client::Mainloop()
|
||||
{
|
||||
return m_Impl->Mainloop();
|
||||
}
|
||||
|
||||
} // namespace api
|
||||
} // namespace llarp
|
@ -0,0 +1,18 @@
|
||||
#include <list>
|
||||
#include <llarp/api/messages.hpp>
|
||||
#include <llarp/encrypted.hpp>
|
||||
#include <string>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
namespace api
|
||||
{
|
||||
|
||||
bool
|
||||
CreateSessionMessage::DecodeParams(llarp_buffer_t *buf)
|
||||
{
|
||||
std::list< llarp::Encrypted > params;
|
||||
return BEncodeReadList(params, buf);
|
||||
}
|
||||
} // namespace api
|
||||
} // namespace llarp
|
@ -0,0 +1,109 @@
|
||||
#include <llarp/api/messages.hpp>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
namespace api
|
||||
{
|
||||
bool
|
||||
IMessage::BEncode(llarp_buffer_t* buf) const
|
||||
{
|
||||
if(!bencode_start_dict(buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictString("F", FunctionName(), buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt(buf, "I", sessionID))
|
||||
return false;
|
||||
if(!BEncodeWriteDictInt(buf, "M", msgID))
|
||||
return false;
|
||||
if(!BEncodeWriteDictBEncodeList("P", GetParams(), buf))
|
||||
return false;
|
||||
if(!BEncodeWriteDictEntry("Z", hash, buf))
|
||||
return false;
|
||||
return bencode_end(buf);
|
||||
}
|
||||
|
||||
bool
|
||||
IMessage::DecodeKey(llarp_buffer_t key, llarp_buffer_t* val)
|
||||
{
|
||||
if(llarp_buffer_eq(key, "P"))
|
||||
{
|
||||
return DecodeParams(val);
|
||||
}
|
||||
bool read = false;
|
||||
if(!BEncodeMaybeReadDictInt("I", sessionID, read, key, val))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictInt("M", msgID, read, key, val))
|
||||
return false;
|
||||
if(!BEncodeMaybeReadDictEntry("Z", hash, read, key, val))
|
||||
return false;
|
||||
return read;
|
||||
}
|
||||
|
||||
bool
|
||||
IMessage::IsWellFormed(llarp_crypto* crypto, const std::string& password)
|
||||
{
|
||||
// hash password
|
||||
llarp::ShortHash secret;
|
||||
llarp_buffer_t passbuf;
|
||||
passbuf.base = (byte_t*)password.c_str();
|
||||
passbuf.cur = passbuf.base;
|
||||
passbuf.sz = password.size();
|
||||
crypto->shorthash(secret, passbuf);
|
||||
|
||||
llarp::ShortHash digest, tmpHash;
|
||||
// save hash
|
||||
tmpHash = hash;
|
||||
// zero hash
|
||||
hash.Zero();
|
||||
|
||||
// bencode
|
||||
byte_t tmp[1500];
|
||||
llarp_buffer_t buf;
|
||||
buf.base = tmp;
|
||||
buf.cur = buf.base;
|
||||
buf.sz = sizeof(tmp);
|
||||
if(!BEncode(&buf))
|
||||
return false;
|
||||
|
||||
// rewind buffer
|
||||
buf.sz = buf.cur - buf.base;
|
||||
buf.cur = buf.base;
|
||||
// calculate message auth
|
||||
crypto->hmac(digest, buf, secret);
|
||||
// restore hash
|
||||
hash = tmpHash;
|
||||
return tmpHash == digest;
|
||||
}
|
||||
|
||||
void
|
||||
IMessage::CalculateHash(llarp_crypto* crypto, const std::string& password)
|
||||
{
|
||||
// hash password
|
||||
llarp::ShortHash secret;
|
||||
llarp_buffer_t passbuf;
|
||||
passbuf.base = (byte_t*)password.c_str();
|
||||
passbuf.cur = passbuf.base;
|
||||
passbuf.sz = password.size();
|
||||
crypto->shorthash(secret, passbuf);
|
||||
|
||||
llarp::ShortHash digest;
|
||||
// zero hash
|
||||
hash.Zero();
|
||||
|
||||
// bencode
|
||||
byte_t tmp[1500];
|
||||
llarp_buffer_t buf;
|
||||
buf.base = tmp;
|
||||
buf.cur = buf.base;
|
||||
buf.sz = sizeof(tmp);
|
||||
if(BEncode(&buf))
|
||||
{
|
||||
// rewind buffer
|
||||
buf.sz = buf.cur - buf.base;
|
||||
buf.cur = buf.base;
|
||||
// calculate message auth
|
||||
crypto->hmac(hash, buf, secret);
|
||||
}
|
||||
}
|
||||
} // namespace api
|
||||
} // namespace llarp
|
@ -0,0 +1,60 @@
|
||||
#include <functional>
|
||||
#include <llarp/api/parser.hpp>
|
||||
#include <map>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
namespace api
|
||||
{
|
||||
std::map< std::string, std::function< IMessage*() > > funcmap = {
|
||||
{"CreateSession", []() { return new CreateSessionMessage; }},
|
||||
};
|
||||
|
||||
MessageParser::MessageParser()
|
||||
{
|
||||
r.user = this;
|
||||
r.on_key = &OnKey;
|
||||
}
|
||||
|
||||
bool
|
||||
MessageParser::OnKey(dict_reader* r, llarp_buffer_t* key)
|
||||
{
|
||||
MessageParser* self = static_cast< MessageParser* >(r->user);
|
||||
if(self->msg == nullptr && key == nullptr) // empty message
|
||||
return false;
|
||||
if(self->msg == nullptr && key)
|
||||
{
|
||||
// first message, function name
|
||||
if(!llarp_buffer_eq(*key, "f"))
|
||||
return false;
|
||||
llarp_buffer_t strbuf;
|
||||
if(!bencode_read_string(r->buffer, &strbuf))
|
||||
return false;
|
||||
std::string funcname((char*)strbuf.cur, strbuf.sz);
|
||||
auto itr = funcmap.find(funcname);
|
||||
if(itr == funcmap.end())
|
||||
return false;
|
||||
self->msg = itr->second();
|
||||
return true;
|
||||
}
|
||||
else if(self->msg && key)
|
||||
{
|
||||
return self->msg->DecodeKey(*key, r->buffer);
|
||||
}
|
||||
else if(self->msg && key == nullptr)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
IMessage*
|
||||
MessageParser::ParseMessage(llarp_buffer_t buf)
|
||||
{
|
||||
if(bencode_read_dict(&buf, &r))
|
||||
return msg;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace api
|
||||
} // namespace llarp
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
#include <llarp/messages/path_latency.hpp>
|
||||
|
||||
namespace llarp
|
||||
{
|
||||
namespace routing
|
||||
{
|
||||
PathLatencyMessage::PathLatencyMessage()
|
||||
{
|
||||
}
|
||||
} // namespace routing
|
||||
} // namespace llarp
|
@ -0,0 +1 @@
|
||||
#include <llarp/service.hpp>
|
@ -0,0 +1,27 @@
|
||||
#include <gtest/gtest.h>
|
||||
#include <llarp/api/messages.hpp>
|
||||
|
||||
class APITest : public ::testing::Test
|
||||
{
|
||||
public:
|
||||
llarp_crypto crypto;
|
||||
std::string apiPassword = "password";
|
||||
APITest()
|
||||
{
|
||||
llarp_crypto_libsodium_init(&crypto);
|
||||
}
|
||||
|
||||
~APITest()
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(APITest, TestMessageWellFormed)
|
||||
{
|
||||
llarp::api::CreateSessionMessage msg;
|
||||
msg.msgID = 0;
|
||||
msg.sessionID = 12345;
|
||||
msg.CalculateHash(&crypto, apiPassword);
|
||||
llarp::Info("msghash=", msg.hash);
|
||||
ASSERT_TRUE(msg.IsWellFormed(&crypto, apiPassword));
|
||||
};
|
Loading…
Reference in New Issue