diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0cbb6eb6..03d21b71 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -107,6 +107,7 @@ list (APPEND opendht_SOURCES
src/storage.h
src/listener.h
src/search.h
+ src/net.h
src/parsed_message.h
src/request.h
src/callbacks.cpp
@@ -134,7 +135,6 @@ list (APPEND opendht_HEADERS
include/opendht/routing_table.h
include/opendht/node_cache.h
include/opendht/network_engine.h
- include/opendht/net.h
include/opendht/scheduler.h
include/opendht/rate_limiter.h
include/opendht/securedht.h
diff --git a/MSVC/opendht.vcxproj b/MSVC/opendht.vcxproj
index cfa9fcc9..4c494bf5 100644
--- a/MSVC/opendht.vcxproj
+++ b/MSVC/opendht.vcxproj
@@ -47,7 +47,6 @@
-
@@ -60,6 +59,7 @@
+
diff --git a/include/opendht/net.h b/include/opendht/net.h
deleted file mode 100644
index fd680e51..00000000
--- a/include/opendht/net.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (C) 2014-2017 Savoir-faire Linux Inc.
- * Author(s) : Adrien Béraud
- * Simon Désaulniers
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program. If not, see .
- */
-
-#pragma once
-
-#include
-#include
-
-namespace dht {
-namespace net {
-
-struct TransPrefix : public std::array {
- TransPrefix(const std::string& str) : std::array({{(uint8_t)str[0], (uint8_t)str[1]}}) {}
- static const TransPrefix PING;
- static const TransPrefix FIND_NODE;
- static const TransPrefix GET_VALUES;
- static const TransPrefix ANNOUNCE_VALUES;
- static const TransPrefix REFRESH;
- static const TransPrefix LISTEN;
-};
-
-/* Transaction-ids are 4-bytes long, with the first two bytes identifying
- * the kind of request, and the remaining two a sequence number in
- * host order.
- */
-struct TransId final : public std::array {
- static const constexpr uint16_t INVALID {0};
-
- TransId() { std::fill(begin(), end(), 0); }
- TransId(const std::array& o) { std::copy(o.begin(), o.end(), begin()); }
- TransId(const TransPrefix prefix, uint16_t seqno = 0) {
- std::copy_n(prefix.begin(), prefix.size(), begin());
- *reinterpret_cast(data()+prefix.size()) = seqno;
- }
- TransId(uint32_t id) {
- *reinterpret_cast(data()) = htonl(id);
- }
-
- uint32_t toInt() const {
- return ntohl(*reinterpret_cast(&(*this)[0]));
- }
-
- bool matches(const TransPrefix prefix) const {
- return std::equal(begin(), begin()+2, prefix.begin());
- }
-};
-
-TransId unpackTid(msgpack::object& o);
-
-} /* namespace net */
-} /* dht */
diff --git a/include/opendht/network_engine.h b/include/opendht/network_engine.h
index 1fc5f020..ba9a06ef 100644
--- a/include/opendht/network_engine.h
+++ b/include/opendht/network_engine.h
@@ -27,7 +27,6 @@
#include "utils.h"
#include "rng.h"
#include "rate_limiter.h"
-#include "net.h"
#include
#include
@@ -41,6 +40,7 @@ namespace net {
struct Request;
struct Socket;
+struct TransId;
#ifndef MSG_CONFIRM
#define MSG_CONFIRM 0
@@ -169,7 +169,7 @@ private:
std::function,
const InfoHash&,
const Blob&,
- uint32_t,
+ Tid,
const Query&)> onListen {};
/**
* Called on announce request.
@@ -231,7 +231,7 @@ public:
* @param nodes6 The ipv6 closest nodes.
* @param values The values to send.
*/
- void tellListener(Sp n, uint32_t socket_id, const InfoHash& hash, want_t want, const Blob& ntoken,
+ void tellListener(Sp n, Tid socket_id, const InfoHash& hash, want_t want, const Blob& ntoken,
std::vector>&& nodes, std::vector>&& nodes6,
std::vector>&& values, const Query& q);
@@ -465,18 +465,18 @@ private:
// basic wrapper for socket sendto function
int send(const char *buf, size_t len, int flags, const SockAddr& addr);
- void sendValueParts(TransId tid, const std::vector& svals, const SockAddr& addr);
+ void sendValueParts(const TransId& tid, const std::vector& svals, const SockAddr& addr);
std::vector packValueHeader(msgpack::sbuffer&, const std::vector>&);
- void maintainRxBuffer(const TransId& tid);
+ void maintainRxBuffer(Tid tid);
/*************
* Answers *
*************/
/* answer to a ping request */
- void sendPong(const SockAddr& addr, TransId tid);
+ void sendPong(const SockAddr& addr, Tid tid);
/* answer to findnodes/getvalues request */
void sendNodesValues(const SockAddr& addr,
- TransId tid,
+ Tid tid,
const Blob& nodes,
const Blob& nodes6,
const std::vector>& st,
@@ -490,12 +490,12 @@ private:
std::vector>& nodes,
std::vector>& nodes6);
/* answer to a listen request */
- void sendListenConfirmation(const SockAddr& addr, TransId tid);
+ void sendListenConfirmation(const SockAddr& addr, Tid tid);
/* answer to put request */
- void sendValueAnnounced(const SockAddr& addr, TransId, Value::Id);
+ void sendValueAnnounced(const SockAddr& addr, Tid, Value::Id);
/* answer in case of error */
void sendError(const SockAddr& addr,
- TransId tid,
+ Tid tid,
uint16_t code,
const std::string& message,
bool include_id=false);
@@ -519,8 +519,8 @@ private:
size_t limiter_maintenance {0};
// requests handling
- std::map> requests {};
- std::map partial_messages;
+ std::map> requests {};
+ std::map partial_messages;
MessageStats in_stats {}, out_stats {};
std::set blacklist {};
diff --git a/include/opendht/node.h b/include/opendht/node.h
index 1f6efda9..394b1156 100644
--- a/include/opendht/node.h
+++ b/include/opendht/node.h
@@ -22,7 +22,6 @@
#include "infohash.h" // includes socket structures
#include "utils.h"
#include "sockaddr.h"
-#include "net.h"
#include
#include