Skip to content
Permalink
Browse files

network: header cleanup

  • Loading branch information...
aberaud committed Apr 14, 2019
1 parent 4f03a5c commit ef82652a1e9417cd20df3bf55f569aee26b6e6a8
@@ -22,8 +22,6 @@
#include "sockaddr.h"
#include "infohash.h"

#include <unistd.h>

#include <thread>
#include <mutex>
#include <condition_variable>
@@ -27,6 +27,12 @@
#include "dht_proxy_client.h"
#endif

#ifdef _WIN32
#include <cstring>
#define close(x) closesocket(x)
#define write(s, b, f) send(s, b, (int)strlen(b), 0)
#endif

namespace dht {

constexpr std::chrono::seconds DhtRunner::BOOTSTRAP_PERIOD;
@@ -46,7 +52,6 @@ DhtRunner::DhtRunner() : dht_()
#ifdef OPENDHT_PROXY_CLIENT
, dht_via_proxy_()
#endif //OPENDHT_PROXY_CLIENT
, peerDiscovery4_(), peerDiscovery6_()
{
#ifdef _WIN32
WSADATA wsd;
@@ -482,6 +487,7 @@ int bindSocket(const SockAddr& addr, SockAddr& bound)
#endif
if (is_ipv6)
setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&set, sizeof(set));
net::set_nonblocking(sock);
int rc = bind(sock, addr.get(), addr.getLength());
if(rc < 0) {
rc = errno;
@@ -17,27 +17,14 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/


#include "network_engine.h"
#include "request.h"
#include "default_types.h"
#include "log_enable.h"
#include "parsed_message.h"
#include "network_utils.h"

#include <msgpack.hpp>

#ifndef _WIN32
#include <arpa/inet.h>
#include <unistd.h>
#else
#include <ws2tcpip.h>
#include <io.h>
#endif
#include <fcntl.h>

#include <cstring>

namespace dht {
namespace net {

@@ -56,7 +43,7 @@ constexpr std::chrono::seconds NetworkEngine::RX_TIMEOUT;
const std::string NetworkEngine::my_v {"RNG1"};
constexpr size_t NetworkEngine::MAX_REQUESTS_PER_SEC;

static const uint8_t v4prefix[16] = {
static constexpr uint8_t v4prefix[16] = {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xFF, 0xFF, 0, 0, 0, 0
};

@@ -138,16 +125,7 @@ NetworkEngine::NetworkEngine(InfoHash& myid, NetId net, const int& s, const int&
onAnnounce(std::move(onAnnounce)),
onRefresh(std::move(onRefresh)),
myid(myid), network(net), dht_socket(s), dht_socket6(s6), DHT_LOG(log), scheduler(scheduler)
{
if (dht_socket >= 0) {
if (!set_nonblocking(dht_socket))
throw DhtException("Can't set socket to non-blocking mode");
}
if (dht_socket6 >= 0) {
if (!set_nonblocking(dht_socket6))
throw DhtException("Can't set socket to non-blocking mode");
}
}
{}

NetworkEngine::~NetworkEngine() {
clear();
@@ -18,23 +18,17 @@

#include "network_utils.h"

#ifndef _WIN32
#ifdef _WIN32
#include "utils.h"
#include "sockaddr.h"

#include <arpa/inet.h>
#include <unistd.h>
#include <sys/socket.h>
#else
#include <winsock2.h>
#include <ws2tcpip.h>
#include <io.h>
#include <string>
#include <cstring>
#define close(x) closesocket(x)
#define write(s, b, f) send(s, b, (int)strlen(b), 0)
#endif
#else
#include <fcntl.h>

#include <string>
#endif

namespace dht {
namespace net {
@@ -18,9 +18,12 @@
#pragma once

#ifdef _WIN32
#include <ws2tcpip.h>
#include <winsock2.h>
#define close(x) closesocket(x)
#define write(s, b, f) send(s, b, (int)strlen(b), 0)
#else
#include <sys/socket.h>
#include <netinet/in.h>
#include <unistd.h>
#endif

#ifndef IPV6_JOIN_GROUP
@@ -34,7 +37,6 @@ bool set_nonblocking(int fd, bool nonblocking = true);

#ifdef _WIN32
void udpPipe(int fds[2]);
// extern const char *inet_ntop(int, const void *, char *, socklen_t);
#endif

}
@@ -22,8 +22,12 @@
#ifdef _WIN32
#include <Ws2tcpip.h> // needed for ip_mreq definition for multicast
#include <Windows.h>
#include <cstring>
#define close(x) closesocket(x)
#define write(s, b, f) send(s, b, (int)strlen(b), 0)
#else
#include <sys/types.h>
#include <unistd.h>
#endif
#include <fcntl.h>

@@ -42,7 +42,7 @@ void PeerDiscoveryTester::testTransmission_ipv4(){

test_n.startPublish(data_n,port_n);

sleep(5);
std::this_thread::sleep_for(std::chrono::seconds(5));
test_n.stop();
test_s.stop();
test_n.join();
@@ -63,8 +63,8 @@ void PeerDiscoveryTester::testTransmission_ipv6(){
int port = 3333;
in_port_t port_n = 50001;
try{
dht::PeerDiscovery test_n(AF_INET6,port);
dht::PeerDiscovery test_s(AF_INET6,port);
dht::PeerDiscovery test_n(AF_INET6, port);
dht::PeerDiscovery test_s(AF_INET6, port);

try{
test_s.startDiscovery([&](const dht::InfoHash& node, const dht::SockAddr& addr){
@@ -74,19 +74,16 @@ void PeerDiscoveryTester::testTransmission_ipv6(){

test_n.startPublish(data_n,port_n);

sleep(5);
std::this_thread::sleep_for(std::chrono::seconds(5));
test_n.stop();
test_s.stop();
test_n.join();
test_s.join();
} catch(std::exception &exception){
perror(exception.what());
CPPUNIT_ASSERT(false);
}
} catch(std::exception &exception){
perror(exception.what());
} catch(std::exception &exception) {
}

}

void PeerDiscoveryTester::tearDown(){}

0 comments on commit ef82652

Please sign in to comment.
You can’t perform that action at this time.