make it compile and run make format

pull/6/head^2
Jeff Becker 6 years ago
parent 9c28115555
commit a68cfefaa6
No known key found for this signature in database
GPG Key ID: F357B3B42F6F9B05

@ -177,7 +177,6 @@ set(LIB_SRC
llarp/address_info.cpp
llarp/bencode.cpp
llarp/buffer.cpp
llarp/base64.cpp
llarp/config.cpp
llarp/context.cpp
llarp/crypto_async.cpp

@ -1,19 +1,20 @@
#include <signal.h>
#include <getopt.h>
#include <signal.h>
#include <stdio.h> /* fprintf, printf */
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h> /* getaddrinfo, getnameinfo */
#include <stdlib.h> /* exit */
#include <string.h> /* memset */
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <string>
#include "net.hpp"
#include "logger.hpp"
#include "net.hpp"
bool done = false;
@ -26,7 +27,8 @@ handle_signal(int sig)
#define BUF_SIZE 512
struct query {
struct query
{
uint16_t length;
char *url;
unsigned char request[BUF_SIZE];
@ -36,12 +38,15 @@ struct query {
#define SERVER "8.8.8.8"
#define PORT 53
struct sockaddr *resolveHost(char *url) {
struct sockaddr *
resolveHost(char *url)
{
struct query dnsQuery;
dnsQuery.length = 12;
dnsQuery.url = url;
dnsQuery.reqType = 0x01;
// dnsQuery.request = { 0xDB, 0x42, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
// dnsQuery.request = { 0xDB, 0x42, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,
// 0x00, 0x00, 0x00 };
dnsQuery.request[0] = 0xDB;
dnsQuery.request[1] = 0x42;
dnsQuery.request[2] = 0x01;
@ -62,19 +67,24 @@ struct sockaddr *resolveHost(char *url) {
dnsQuery.reqType = 0x01;
word = strtok(url, ".");
while (word) {
llarp::LogDebug("parsing hostname: \"%s\" is %zu characters\n", word, strlen(word));
while(word)
{
llarp::LogDebug("parsing hostname: \"%s\" is %zu characters\n", word,
strlen(word));
dnsQuery.request[dnsQuery.length++] = strlen(word);
for (i = 0; i < strlen(word); i++) {
for(i = 0; i < strlen(word); i++)
{
dnsQuery.request[dnsQuery.length++] = word[i];
}
word = strtok(NULL, ".");
}
dnsQuery.request[dnsQuery.length++] = 0x00; // End of the host name
dnsQuery.request[dnsQuery.length++] = 0x00; // 0x0001 - Query is a Type A query (host address)
dnsQuery.request[dnsQuery.length++] =
0x00; // 0x0001 - Query is a Type A query (host address)
dnsQuery.request[dnsQuery.length++] = dnsQuery.reqType;
dnsQuery.request[dnsQuery.length++] = 0x00; // 0x0001 - Query is class IN (Internet address)
dnsQuery.request[dnsQuery.length++] =
0x00; // 0x0001 - Query is class IN (Internet address)
dnsQuery.request[dnsQuery.length++] = 0x01;
struct sockaddr_in addr;
@ -100,7 +110,8 @@ struct sockaddr *resolveHost(char *url) {
int sockfd;
sockfd = socket(AF_INET, SOCK_DGRAM, 0);
if (sockfd < 0) {
if(sockfd < 0)
{
llarp::LogWarn("Error creating socket!\n");
return nullptr;
}
@ -113,8 +124,10 @@ struct sockaddr *resolveHost(char *url) {
size = sizeof(addr);
// hexdump("sending packet", &dnsQuery.request, dnsQuery.length);
ret = sendto(sockfd, dnsQuery.request, dnsQuery.length, 0, (struct sockaddr*)&addr, size);
if (ret < 0) {
ret = sendto(sockfd, dnsQuery.request, dnsQuery.length, 0,
(struct sockaddr *)&addr, size);
if(ret < 0)
{
llarp::LogWarn("Error Sending Request");
return nullptr;
}
@ -122,7 +135,8 @@ struct sockaddr *resolveHost(char *url) {
memset(&buffer, 0, BUF_SIZE);
ret = recvfrom(sockfd, buffer, BUF_SIZE, 0, (struct sockaddr *)&addr, &size);
if (ret < 0) {
if(ret < 0)
{
llarp::LogWarn("Error Receiving Response");
return nullptr;
}
@ -150,43 +164,55 @@ struct sockaddr *resolveHost(char *url) {
llarp::LogDebug("additional records count: %u\n", ARCOUNT);
llarp::LogDebug("query type: %u\n", dnsQuery.reqType);
QCLASS = (uint16_t) dnsQuery.request[dnsQuery.length - 2] * 0x100 + dnsQuery.request[dnsQuery.length - 1];
QCLASS = (uint16_t)dnsQuery.request[dnsQuery.length - 2] * 0x100
+ dnsQuery.request[dnsQuery.length - 1];
llarp::LogDebug("query class: %u\n", QCLASS);
length = dnsQuery.length + 1; // to skip 0xc00c
ATYPE = (uint16_t)buffer[length + 1] * 0x100 + buffer[length + 2];
llarp::LogDebug("answer type: %u\n", ATYPE);
ACLASS = (uint16_t)buffer[length + 3] * 0x100 + buffer[length + 4];
llarp::LogDebug("answer class: %u\n", ACLASS);
TTL = (uint32_t) buffer[length + 5] * 0x1000000 + buffer[length + 6] * 0x10000 + buffer[length + 7] * 0x100 + buffer[length + 8];
TTL = (uint32_t)buffer[length + 5] * 0x1000000 + buffer[length + 6] * 0x10000
+ buffer[length + 7] * 0x100 + buffer[length + 8];
llarp::LogDebug("seconds to cache: %u\n", TTL);
RDLENGTH = (uint16_t)buffer[length + 9] * 0x100 + buffer[length + 10];
llarp::LogDebug("bytes in answer: %u\n", RDLENGTH);
MSGID = (uint16_t)buffer[0] * 0x100 + buffer[1];
llarp::LogDebug("answer msg id: %u\n", MSGID);
if (rcode == 2) {
if(rcode == 2)
{
llarp::LogWarn("nameserver %s returned SERVFAIL:\n", SERVER);
llarp::LogWarn(" the name server was unable to process this query due to a\n problem with the name server.\n");
llarp::LogWarn(
" the name server was unable to process this query due to a\n "
"problem with the name server.\n");
return nullptr;
} else if (rcode == 3) {
llarp::LogWarn("nameserver %s returned NXDOMAIN for %s:\n", SERVER, dnsQuery.url);
llarp::LogWarn(" the domain name referenced in the query does not exist\n");
}
else if(rcode == 3)
{
llarp::LogWarn("nameserver %s returned NXDOMAIN for %s:\n", SERVER,
dnsQuery.url);
llarp::LogWarn(
" the domain name referenced in the query does not exist\n");
return nullptr;
}
/* search for and print IPv4 addresses */
if (dnsQuery.reqType == 0x01) {
if(dnsQuery.reqType == 0x01)
{
llarp::LogDebug("DNS server's answer is: (type#=%u):", ATYPE);
// printf("IPv4 address(es) for %s:\n", dnsQuery.url);
for (i = 0 ; i < ret ; i++) {
if (buffer[i] == 0xC0 && buffer[i+3] == 0x01) {
ip++; i += 12; /* ! += buf[i+1]; */
llarp::LogDebug(" %u.%u.%u.%u\n", buffer[i], buffer[i+1], buffer[i+2], buffer[i+3]);
for(i = 0; i < ret; i++)
{
if(buffer[i] == 0xC0 && buffer[i + 3] == 0x01)
{
ip++;
i += 12; /* ! += buf[i+1]; */
llarp::LogDebug(" %u.%u.%u.%u\n", buffer[i], buffer[i + 1],
buffer[i + 2], buffer[i + 3]);
struct sockaddr *g_addr = new sockaddr;
g_addr->sa_family = AF_INET;
g_addr->sa_len = sizeof(in_addr);
// g_addr->sa_len = sizeof(in_addr);
struct in_addr *addr = &((struct sockaddr_in *)g_addr)->sin_addr;
unsigned char *ip;
@ -202,7 +228,8 @@ struct sockaddr *resolveHost(char *url) {
}
}
if (!ip) {
if(!ip)
{
llarp::LogWarn(" No IPv4 address found in the DNS response!\n");
return nullptr;
}
@ -210,7 +237,8 @@ struct sockaddr *resolveHost(char *url) {
return nullptr;
}
int get16bits(const char*& buffer) throw ()
int
get16bits(const char *&buffer) throw()
{
int value = static_cast< unsigned char >(buffer[0]);
value = value << 8;
@ -219,14 +247,16 @@ int get16bits(const char*& buffer) throw ()
return value;
}
void put16bits(char*& buffer, uint value) throw ()
void
put16bits(char *&buffer, uint value) throw()
{
buffer[0] = (value & 0xFF00) >> 8;
buffer[1] = value & 0xFF;
buffer += 2;
}
void put32bits(char*& buffer, unsigned long value) throw ()
void
put32bits(char *&buffer, unsigned long value) throw()
{
buffer[0] = (value & 0xFF000000) >> 24;
buffer[1] = (value & 0xFF0000) >> 16;
@ -252,7 +282,8 @@ struct dns_msg
uint arCount;
};
dns_msg *decode_hdr(const char *buffer)
dns_msg *
decode_hdr(const char *buffer)
{
dns_msg *hdr = new dns_msg;
hdr->id = get16bits(buffer);
@ -271,14 +302,13 @@ dns_msg *decode_hdr(const char *buffer)
return hdr;
}
void code_domain(char*& buffer, const std::string& domain) throw()
void
code_domain(char *&buffer, const std::string &domain) throw()
{
int start(0), end; // indexes
llarp::LogInfo("domain [", domain, "]");
while((end = domain.find('.', start)) != std::string::npos)
{
*buffer++ = end - start; // label length octet
for(int i = start; i < end; i++)
{
@ -323,10 +353,11 @@ main(int argc, char *argv[])
m_address.sin_family = AF_INET;
m_address.sin_addr.s_addr = INADDR_ANY;
m_address.sin_port = htons(1053);
int rbind = bind(m_sockfd, (struct sockaddr *) & m_address,
sizeof (struct sockaddr_in));
int rbind =
bind(m_sockfd, (struct sockaddr *)&m_address, sizeof(struct sockaddr_in));
if (rbind != 0) {
if(rbind != 0)
{
llarp::LogError("Could not bind: ", strerror(errno));
return 0;
}
@ -352,13 +383,16 @@ main(int argc, char *argv[])
std::string m_qName = "";
int length = *p_buffer++;
// llarp::LogInfo("qNamLen", length);
while (length != 0) {
for (int i = 0; i < length; i++) {
while(length != 0)
{
for(int i = 0; i < length; i++)
{
char c = *p_buffer++;
m_qName.append(1, c);
}
length = *p_buffer++;
if (length != 0) m_qName.append(1,'.');
if(length != 0)
m_qName.append(1, '.');
}
uint m_qType = get16bits(p_buffer);
uint m_qClass = get16bits(p_buffer);
@ -422,7 +456,8 @@ main(int argc, char *argv[])
// nbytes = m_response.code(buffer);
sendto(m_sockfd, buffer, out_bytes, 0, (struct sockaddr *) &clientAddress, addrLen);
sendto(m_sockfd, buffer, out_bytes, 0, (struct sockaddr *)&clientAddress,
addrLen);
}
/*
std::string host("www.google.com");
@ -436,5 +471,4 @@ main(int argc, char *argv[])
*/
return code;
}

@ -1,7 +1,7 @@
#include <getopt.h>
#include <llarp.h>
#include <signal.h>
#include <llarp/logger.h>
#include <getopt.h>
#include <signal.h>
#include <sys/param.h> // for MIN
struct llarp_main *ctx = 0;
@ -44,18 +44,18 @@ main(int argc, char *argv[])
{
cSetLogLevel(eLogDebug);
}
else
if (strncmp(optarg, "info", MIN(strlen(optarg), (unsigned long)4))==0)
else if(strncmp(optarg, "info", MIN(strlen(optarg), (unsigned long)4))
== 0)
{
cSetLogLevel(eLogInfo);
}
else
if (strncmp(optarg, "warn", MIN(strlen(optarg), (unsigned long)4))==0)
else if(strncmp(optarg, "warn", MIN(strlen(optarg), (unsigned long)4))
== 0)
{
cSetLogLevel(eLogWarn);
}
else
if (strncmp(optarg, "error", MIN(strlen(optarg), (unsigned long)5))==0)
else if(strncmp(optarg, "error", MIN(strlen(optarg), (unsigned long)5))
== 0)
{
cSetLogLevel(eLogError);
}

@ -48,7 +48,8 @@ aiLister(struct llarp_ai_list_iter *request, struct llarp_ai *addr)
return true;
}
void displayRC(llarp_rc *rc)
void
displayRC(llarp_rc *rc)
{
char ftmp[68] = {0};
const char *hexPubSigKey =
@ -75,7 +76,8 @@ HandleDHTLocate(llarp_router_lookup_job *job)
}
// shutdown router
// well because we're in the gotroutermessage, we can't sigint because we'll deadlock because we're session locked
// well because we're in the gotroutermessage, we can't sigint because we'll
// deadlock because we're session locked
// llarp_main_signal(ctx, SIGINT);
// llarp_timer_run(logic->timer, logic->thread);
@ -146,7 +148,8 @@ main(int argc, char *argv[])
{"read", required_argument, 0, 'r'},
{0, 0, 0, 0}};
int option_index = 0;
c = getopt_long(argc, argv, "c:o:g:lu:i:e:q:nr:", long_options, &option_index);
c = getopt_long(argc, argv, "c:o:g:lu:i:e:q:nr:", long_options,
&option_index);
if(c == -1)
break;
switch(c)
@ -157,22 +160,30 @@ main(int argc, char *argv[])
conffname = optarg;
break;
case 'o':
if (strncmp(optarg, "debug", std::min(strlen(optarg), static_cast<unsigned long>(5)))==0)
if(strncmp(optarg, "debug",
std::min(strlen(optarg), static_cast< unsigned long >(5)))
== 0)
{
llarp::SetLogLevel(llarp::eLogDebug);
}
else
if (strncmp(optarg, "info", std::min(strlen(optarg), static_cast<unsigned long>(4)))==0)
else if(strncmp(
optarg, "info",
std::min(strlen(optarg), static_cast< unsigned long >(4)))
== 0)
{
llarp::SetLogLevel(llarp::eLogInfo);
}
else
if (strncmp(optarg, "warn", std::min(strlen(optarg), static_cast<unsigned long>(4)))==0)
else if(strncmp(
optarg, "warn",
std::min(strlen(optarg), static_cast< unsigned long >(4)))
== 0)
{
llarp::SetLogLevel(llarp::eLogWarn);
}
else
if (strncmp(optarg, "error", std::min(strlen(optarg), static_cast<unsigned long>(5)))==0)
else if(strncmp(
optarg, "error",
std::min(strlen(optarg), static_cast< unsigned long >(5)))
== 0)
{
llarp::SetLogLevel(llarp::eLogError);
}

@ -45,7 +45,6 @@ llarp_rc_free(struct llarp_rc *rc);
bool
llarp_rc_new(struct llarp_rc *rc);
bool
llarp_rc_verify_sig(struct llarp_crypto *crypto, struct llarp_rc *rc);

@ -200,7 +200,8 @@ namespace llarp
}
*/
llarp::LogInfo("LookupRouterViaJob node count: ", nodes->nodes.size());
llarp::LogInfo("LookupRouterViaJob recursive: ", job->iterative?"yes":"no");
llarp::LogInfo("LookupRouterViaJob recursive: ",
job->iterative ? "yes" : "no");
if(nodes->FindClosest(job->target, peer))
LookupRouter(job->target, ourKey, 0, peer, job, job->iterative);

@ -87,10 +87,11 @@ namespace llarp
" iterating to next peer ", nextPeer,
" already asked ", pending->exclude.size(),
" other peers");
// REVIEW: is this ok to relay the pending->job as the current job (seems to make things work)
// REVIEW: is this ok to relay the pending->job as the current job
// (seems to make things work)
dht.LookupRouter(pending->target, pending->requester,
pending->requesterTX, nextPeer, pending->job,
true, pending->exclude);
pending->requesterTX, nextPeer, pending->job, true,
pending->exclude);
}
else
{

Loading…
Cancel
Save