diff --git a/include/llarp/logger.hpp b/include/llarp/logger.hpp index 6a40a5a01..105ae5abd 100644 --- a/include/llarp/logger.hpp +++ b/include/llarp/logger.hpp @@ -82,14 +82,14 @@ namespace llarp struct log_timestamp { std::string format = "%c %Z"; - friend - std::ostream & operator << (std::ostream & out, const log_timestamp & ts) + friend std::ostream& + operator<<(std::ostream& out, const log_timestamp& ts) { auto now = llarp::Clock_t::to_time_t(llarp::Clock_t::now()); return out << std::put_time(std::localtime(&now), ts.format.c_str()); } }; - + /** internal */ template < typename... TArgs > void diff --git a/include/llarp/path.hpp b/include/llarp/path.hpp index cae111a1f..f8d7933a6 100644 --- a/include/llarp/path.hpp +++ b/include/llarp/path.hpp @@ -410,8 +410,8 @@ namespace llarp GetByUpstream(const RouterID& id, const PathID_t& path); IHopHandler* - GetPathForTransfer(const PathID_t & topath); - + GetPathForTransfer(const PathID_t& topath); + IHopHandler* GetByDownstream(const RouterID& id, const PathID_t& path); diff --git a/include/llarp/time.hpp b/include/llarp/time.hpp index 541220e8d..85fb0a08b 100644 --- a/include/llarp/time.hpp +++ b/include/llarp/time.hpp @@ -8,5 +8,4 @@ namespace llarp typedef std::chrono::system_clock Clock_t; } - #endif diff --git a/llarp/ip.cpp b/llarp/ip.cpp index 1ce41498f..70d5b473f 100644 --- a/llarp/ip.cpp +++ b/llarp/ip.cpp @@ -32,13 +32,13 @@ namespace llarp } static uint32_t - ipchksum_pseudoIPv4(uint32_t src_ip_n, uint32_t dst_ip_n, - uint8_t proto, uint16_t innerlen) + ipchksum_pseudoIPv4(uint32_t src_ip_n, uint32_t dst_ip_n, uint8_t proto, + uint16_t innerlen) { - #define IPCS(x) ((x & 0xFFFF) + (x >> 16)) - uint32_t sum = (uint32_t)IPCS(src_ip_n) + (uint32_t)IPCS(dst_ip_n) + - (uint32_t)proto + (uint32_t)htons(innerlen); - #undef IPCS +#define IPCS(x) ((x & 0xFFFF) + (x >> 16)) + uint32_t sum = (uint32_t)IPCS(src_ip_n) + (uint32_t)IPCS(dst_ip_n) + + (uint32_t)proto + (uint32_t)htons(innerlen); +#undef IPCS return sum; } @@ -61,15 +61,13 @@ namespace llarp } static uint16_t - deltachksum(uint16_t old_sum, - uint32_t old_src_ip_n, uint32_t old_dst_ip_n, + deltachksum(uint16_t old_sum, uint32_t old_src_ip_n, uint32_t old_dst_ip_n, uint32_t new_src_ip_n, uint32_t new_dst_ip_n) { - #define IPCS(x) ((x & 0xFFFF) + (x >> 16)) - uint32_t sum = ~old_sum - + IPCS(new_src_ip_n) + IPCS(new_dst_ip_n) - - IPCS(old_src_ip_n) - IPCS(old_dst_ip_n); - #undef IPCS +#define IPCS(x) ((x & 0xFFFF) + (x >> 16)) + uint32_t sum = ~old_sum + IPCS(new_src_ip_n) + IPCS(new_dst_ip_n) + - IPCS(old_src_ip_n) - IPCS(old_dst_ip_n); +#undef IPCS while(sum >> 16) sum = (sum & 0xffff) + (sum >> 16); return ~sum; @@ -77,11 +75,10 @@ namespace llarp static std::map< byte_t, std::function< void(const ip_header *, byte_t *, size_t) > > - protoDstCheckSummer = - { - // is this even correct??? - // {RFC3022} says that IPv4 hdr isn't included in ICMP checksum calc - // and that we don't need to modify it + protoDstCheckSummer = { + // is this even correct??? + // {RFC3022} says that IPv4 hdr isn't included in ICMP checksum calc + // and that we don't need to modify it #if 0 { // ICMP @@ -98,19 +95,16 @@ namespace llarp } }, #endif - { - // TCP - 6, - [](const ip_header *hdr, byte_t *pkt, size_t sz) - { - auto hlen = size_t(hdr->ihl * 4); - if(hlen + 16 + 2 > sz) - return; - - uint16_t *check = (uint16_t *)(pkt + hlen + 16); - *check = deltachksum(*check, 0, 0, hdr->saddr, hdr->daddr); - } - }, + {// TCP + 6, + [](const ip_header *hdr, byte_t *pkt, size_t sz) { + auto hlen = size_t(hdr->ihl * 4); + if(hlen + 16 + 2 > sz) + return; + + uint16_t *check = (uint16_t *)(pkt + hlen + 16); + *check = deltachksum(*check, 0, 0, hdr->saddr, hdr->daddr); + }}, }; void IPv4Packet::UpdateChecksumsOnDst() @@ -118,7 +112,7 @@ namespace llarp auto hdr = Header(); // IPv4 checksum - auto hlen = size_t(hdr->ihl * 4); + auto hlen = size_t(hdr->ihl * 4); hdr->check = 0; if(hlen <= sz) hdr->check = ipchksum(buf, hlen); @@ -133,22 +127,18 @@ namespace llarp } static std::map< - byte_t, std::function< void(const ip_header *, byte_t *, size_t) > > - protoSrcCheckSummer = - { - { - // TCP - 6, - [](const ip_header *hdr, byte_t *pkt, size_t sz) - { - auto hlen = size_t(hdr->ihl * 4); - if(hlen + 16 + 2 > sz) - return; - - uint16_t *check = (uint16_t *)(pkt + hlen + 16); - *check = deltachksum(*check, hdr->saddr, hdr->daddr, 0, 0); - } - }, + byte_t, std::function< void(const ip_header *, byte_t *, size_t) > > + protoSrcCheckSummer = { + {// TCP + 6, + [](const ip_header *hdr, byte_t *pkt, size_t sz) { + auto hlen = size_t(hdr->ihl * 4); + if(hlen + 16 + 2 > sz) + return; + + uint16_t *check = (uint16_t *)(pkt + hlen + 16); + *check = deltachksum(*check, hdr->saddr, hdr->daddr, 0, 0); + }}, }; void IPv4Packet::UpdateChecksumsOnSrc() diff --git a/llarp/path.cpp b/llarp/path.cpp index 776cee53c..535257ebc 100644 --- a/llarp/path.cpp +++ b/llarp/path.cpp @@ -204,8 +204,8 @@ namespace llarp return m_Router; } - IHopHandler * - PathContext::GetPathForTransfer(const PathID_t & id) + IHopHandler* + PathContext::GetPathForTransfer(const PathID_t& id) { RouterID us(OurRouterID()); auto& map = m_TransitPaths; @@ -220,7 +220,7 @@ namespace llarp } return nullptr; } - + void PathContext::PutTransitHop(TransitHop* hop) {