summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/anytun-config.cpp7
-rw-r--r--src/anytun.cpp7
-rw-r--r--src/packetSource.cpp4
-rw-r--r--src/packetSource.h3
-rw-r--r--src/resolver.cpp10
-rw-r--r--src/resolver.h8
-rw-r--r--src/syncServer.cpp4
-rw-r--r--src/syncServer.h2
8 files changed, 30 insertions, 15 deletions
diff --git a/src/anytun-config.cpp b/src/anytun-config.cpp
index f8bc4f4..4ef4112 100644
--- a/src/anytun-config.cpp
+++ b/src/anytun-config.cpp
@@ -88,6 +88,11 @@ void createConnection(const PacketSourceEndpoint & remote_end, ConnectionList &
sem.up();
}
+void createConnectionResolver(const PacketSourceResolverIt& it, ConnectionList & cl, u_int16_t seqSize, SyncQueue & queue, mux_t mux, Semaphore& sem)
+{
+ createConnection(*it, cl, seqSize, queue, mux, sem);
+}
+
void createConnectionError(const std::exception& e, Semaphore& sem, int& ret)
{
cLog.msg(Log::PRIO_ERROR) << "uncaught runtime error: " << e.what();
@@ -133,7 +138,7 @@ int main(int argc, char* argv[])
UDPPacketSource::proto::endpoint endpoint;
// allow emtpy endpoint!!!
gResolver.resolveUdp(gOpt.getRemoteAddr(), gOpt.getRemotePort(),
- boost::bind(createConnection, _1, boost::ref(cl), gOpt.getSeqWindowSize(), boost::ref(queue), gOpt.getMux(), boost::ref(sem)),
+ boost::bind(createConnectionResolver, _1, boost::ref(cl), gOpt.getSeqWindowSize(), boost::ref(queue), gOpt.getMux(), boost::ref(sem)),
boost::bind(createConnectionError, _1, boost::ref(sem), boost::ref(ret)),
gOpt.getResolvAddrType());
sem.down();
diff --git a/src/anytun.cpp b/src/anytun.cpp
index 63f250f..200b33d 100644
--- a/src/anytun.cpp
+++ b/src/anytun.cpp
@@ -97,6 +97,11 @@ void createConnection(const PacketSourceEndpoint& remote_end, window_size_t seqS
#endif
}
+void createConnectionResolver(const PacketSourceResolverIt& it, window_size_t seqSize, mux_t mux)
+{
+ createConnection(*it, seqSize, mux);
+}
+
void createConnectionError(const std::exception& e)
{
gSignalController.inject(SIGERROR, e.what());
@@ -455,7 +460,7 @@ int main(int argc, char* argv[])
PacketSource* src = new UDPPacketSource(gOpt.getLocalAddr(), gOpt.getLocalPort());
if(gOpt.getRemoteAddr() != "")
- gResolver.resolveUdp(gOpt.getRemoteAddr(), gOpt.getRemotePort(), boost::bind(createConnection, _1, gOpt.getSeqWindowSize(), gOpt.getMux()), boost::bind(createConnectionError, _1), gOpt.getResolvAddrType());
+ gResolver.resolveUdp(gOpt.getRemoteAddr(), gOpt.getRemotePort(), boost::bind(createConnectionResolver, _1, gOpt.getSeqWindowSize(), gOpt.getMux()), boost::bind(createConnectionError, _1), gOpt.getResolvAddrType());
HostList connect_to = gOpt.getRemoteSyncHosts();
#ifndef NO_ROUTING
diff --git a/src/packetSource.cpp b/src/packetSource.cpp
index 0882de5..c9a0412 100644
--- a/src/packetSource.cpp
+++ b/src/packetSource.cpp
@@ -50,8 +50,10 @@ UDPPacketSource::UDPPacketSource(std::string localaddr, std::string port) : sock
gResolver.resolveUdp(localaddr, port, boost::bind(&UDPPacketSource::onResolve, this, _1), boost::bind(&UDPPacketSource::onError, this, _1), gOpt.getResolvAddrType());
}
-void UDPPacketSource::onResolve(const boost::asio::ip::udp::endpoint& e)
+void UDPPacketSource::onResolve(const PacketSourceResolverIt& it)
{
+ PacketSourceEndpoint e = *it;
+
cLog.msg(Log::PRIO_NOTICE) << "opening socket: " << e;
sock_.open(e.protocol());
sock_.bind(e);
diff --git a/src/packetSource.h b/src/packetSource.h
index 626a259..f388517 100644
--- a/src/packetSource.h
+++ b/src/packetSource.h
@@ -40,6 +40,7 @@
// TODO: fix this when other packetSource types are introduced
typedef boost::asio::ip::udp::endpoint PacketSourceEndpoint;
+typedef boost::asio::ip::udp::resolver::iterator PacketSourceResolverIt;
class PacketSource
{
@@ -65,7 +66,7 @@ public:
u_int32_t recv(u_int8_t* buf, u_int32_t len, PacketSourceEndpoint& remote);
void send(u_int8_t* buf, u_int32_t len, PacketSourceEndpoint remote);
- void onResolve(const boost::asio::ip::udp::endpoint& e);
+ void onResolve(const PacketSourceResolverIt& it);
void onError(const std::runtime_error& e);
private:
diff --git a/src/resolver.cpp b/src/resolver.cpp
index 66f1e7e..36b2c2e 100644
--- a/src/resolver.cpp
+++ b/src/resolver.cpp
@@ -40,20 +40,20 @@ using ::boost::asio::ip::udp;
using ::boost::asio::ip::tcp;
template<class Proto>
-void waitAndEnqueue(u_int32_t s, const std::string& addr, const std::string& port, boost::function<void(boost::asio::ip::basic_endpoint<Proto>)> const& onResolve, ErrorCallback const& onError, ResolvAddrType r)
+void waitAndEnqueue(u_int32_t s, const std::string& addr, const std::string& port, boost::function<void(const boost::asio::ip::basic_resolver_iterator<Proto>)> const& onResolve, ErrorCallback const& onError, ResolvAddrType r)
{
cLog.msg(Log::PRIO_ERROR) << "the resolver only supports udp and tcp";
}
template<>
-void waitAndEnqueue(u_int32_t s, const std::string& addr, const std::string& port, boost::function<void(boost::asio::ip::basic_endpoint<udp>)> const& onResolve, ErrorCallback const& onError, ResolvAddrType r)
+void waitAndEnqueue(u_int32_t s, const std::string& addr, const std::string& port, boost::function<void(const boost::asio::ip::basic_resolver_iterator<udp>)> const& onResolve, ErrorCallback const& onError, ResolvAddrType r)
{
boost::this_thread::sleep(boost::posix_time::milliseconds(s * 1000));
gResolver.resolveUdp(addr, port, onResolve, onError, r);
}
template<>
-void waitAndEnqueue(u_int32_t s, const std::string& addr, const std::string& port, boost::function<void(boost::asio::ip::basic_endpoint<tcp>)> const& onResolve, ErrorCallback const& onError, ResolvAddrType r)
+void waitAndEnqueue(u_int32_t s, const std::string& addr, const std::string& port, boost::function<void(const boost::asio::ip::basic_resolver_iterator<tcp>)> const& onResolve, ErrorCallback const& onError, ResolvAddrType r)
{
boost::this_thread::sleep(boost::posix_time::milliseconds(s * 1000));
gResolver.resolveTcp(addr, port, onResolve, onError, r);
@@ -61,7 +61,7 @@ void waitAndEnqueue(u_int32_t s, const std::string& addr, const std::string& por
template<class Proto>
-ResolveHandler<Proto>::ResolveHandler(const std::string& addr, const std::string& port, boost::function<void(boost::asio::ip::basic_endpoint<Proto>)> const& onResolve, ErrorCallback const& onError, ResolvAddrType r) : addr_(addr), port_(port), onResolve_(onResolve), onError_(onError), resolv_addr_type_(r)
+ResolveHandler<Proto>::ResolveHandler(const std::string& addr, const std::string& port, boost::function<void(const boost::asio::ip::basic_resolver_iterator<Proto>)> const& onResolve, ErrorCallback const& onError, ResolvAddrType r) : addr_(addr), port_(port), onResolve_(onResolve), onError_(onError), resolv_addr_type_(r)
{
}
@@ -70,7 +70,7 @@ void ResolveHandler<Proto>::operator()(const boost::system::error_code& e, const
{
if(boost::system::posix_error::success == e) {
try {
- onResolve_(*endpointIt);
+ onResolve_(endpointIt);
}
catch(const std::runtime_error& e)
{
diff --git a/src/resolver.h b/src/resolver.h
index dfec8cc..ea4a57b 100644
--- a/src/resolver.h
+++ b/src/resolver.h
@@ -40,21 +40,21 @@
#include "datatypes.h"
#include "threadUtils.hpp"
-typedef boost::function<void (boost::asio::ip::udp::endpoint)> UdpResolveCallback;
-typedef boost::function<void (boost::asio::ip::tcp::endpoint)> TcpResolveCallback;
+typedef boost::function<void (const boost::asio::ip::udp::resolver::iterator)> UdpResolveCallback;
+typedef boost::function<void (const boost::asio::ip::tcp::resolver::iterator)> TcpResolveCallback;
typedef boost::function<void (std::runtime_error const&)> ErrorCallback;
template<class Proto>
class ResolveHandler
{
public:
- ResolveHandler(const std::string& addr, const std::string& port, boost::function<void (boost::asio::ip::basic_endpoint<Proto>)> const& onResolve, ErrorCallback const& onError, ResolvAddrType r = ANY);
+ ResolveHandler(const std::string& addr, const std::string& port, boost::function<void (const boost::asio::ip::basic_resolver_iterator<Proto>)> const& onResolve, ErrorCallback const& onError, ResolvAddrType r = ANY);
void operator()(const boost::system::error_code& e, const boost::asio::ip::basic_resolver_iterator<Proto>);
private:
std::string addr_;
std::string port_;
- boost::function<void (boost::asio::ip::basic_endpoint<Proto>)> onResolve_;
+ boost::function<void (const boost::asio::ip::basic_resolver_iterator<Proto>)> onResolve_;
ErrorCallback onError_;
ResolvAddrType resolv_addr_type_;
};
diff --git a/src/syncServer.cpp b/src/syncServer.cpp
index b61872c..ecf9fb4 100644
--- a/src/syncServer.cpp
+++ b/src/syncServer.cpp
@@ -42,8 +42,10 @@ SyncServer::SyncServer(std::string localaddr, std::string port, ConnectCallback
gResolver.resolveTcp(localaddr, port, boost::bind(&SyncServer::onResolve, this, _1), boost::bind(&SyncServer::onResolvError, this, _1));
}
-void SyncServer::onResolve(const SyncTcpConnection::proto::endpoint& e)
+void SyncServer::onResolve(const SyncTcpConnection::proto::resolver::iterator& it)
{
+ SyncTcpConnection::proto::endpoint e = *it;
+
acceptor_.open(e.protocol());
acceptor_.set_option(boost::asio::socket_base::reuse_address(true));
acceptor_.bind(e);
diff --git a/src/syncServer.h b/src/syncServer.h
index b73247f..dc007d6 100644
--- a/src/syncServer.h
+++ b/src/syncServer.h
@@ -50,7 +50,7 @@ class SyncServer
{
public:
SyncServer(std::string localaddr, std::string port, ConnectCallback onConnect);
- void onResolve(const SyncTcpConnection::proto::endpoint& e);
+ void onResolve(const SyncTcpConnection::proto::resolver::iterator& it);
void onResolvError(const std::runtime_error& e);
void run();