summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/anytun.cpp16
-rw-r--r--src/anytun.vcproj13
-rw-r--r--src/resolver.cpp27
-rw-r--r--src/resolver.h10
4 files changed, 42 insertions, 24 deletions
diff --git a/src/anytun.cpp b/src/anytun.cpp
index bd21eb3..1b71f15 100644
--- a/src/anytun.cpp
+++ b/src/anytun.cpp
@@ -213,7 +213,7 @@ void sender(void* p)
try {
param->src.send(encrypted_packet.getBuf(), encrypted_packet.getLength(), conn.remote_end_);
- } catch (std::exception& e) {
+ } catch (std::exception&) {
//TODO: do something here
//cLog.msg(Log::PRIO_ERROR) << "could not send data: " << e.what();
}
@@ -448,13 +448,17 @@ int main(int argc, char* argv[])
HostList connect_to = gOpt.getRemoteSyncHosts();
+
+
if(gOpt.getRemoteAddr() != "")
{
- boost::asio::io_service io_service;
- UDPPacketSource::proto::resolver resolver(io_service);
- UDPPacketSource::proto::resolver::query query(gOpt.getRemoteAddr(), gOpt.getRemotePort());
- UDPPacketSource::proto::endpoint endpoint = *resolver.resolve(query);
- createConnection(endpoint,gOpt.getSeqWindowSize(), gOpt.getMux());
+ gResolver.resolveUdp(gOpt.getRemoteAddr(), gOpt.getRemotePort(),
+ boost::bind(createConnection, _1, gOpt.getSeqWindowSize(), gOpt.getMux()));
+ ///*boost::asio::io_service io_service;
+ //UDPPacketSource::proto::resolver resolver(io_service);
+ //UDPPacketSource::proto::resolver::query query(gOpt.getRemoteAddr(), gOpt.getRemotePort());
+ //UDPPacketSource::proto::endpoint endpoint = *resolver.resolve(query);
+ //createConnection(endpoint,gOpt.getSeqWindowSize(), gOpt.getMux());*/
}
#ifndef NO_ROUTING
diff --git a/src/anytun.vcproj b/src/anytun.vcproj
index 7d4759a..df660cd 100644
--- a/src/anytun.vcproj
+++ b/src/anytun.vcproj
@@ -42,13 +42,12 @@
Name="VCCLCompilerTool"
AdditionalOptions="/I &quot;C:\Program Files\boost\boost_1_35_0\&quot;"
Optimization="0"
- PreprocessorDefinitions="LOG_FILE;LOG_STDOUT;LOG_WINEVENTLOG;USE_SSL_CRYPTO;NO_DAEMON;NO_EXEC;WIN32_LEAN_AND_MEAN"
+ PreprocessorDefinitions="LOG_FILE;LOG_STDOUT;LOG_WINEVENTLOG;USE_SSL_CRYPTO;NO_DAEMON;NO_EXEC;WIN32_LEAN_AND_MEAN;BOOST_ALL_DYN_LINK"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
- Detect64BitPortabilityProblems="false"
DebugInformationFormat="4"
ForcedIncludeFiles=""
/>
@@ -116,7 +115,7 @@
/>
<Tool
Name="VCCLCompilerTool"
- PreprocessorDefinitions="LOG_FILE;LOG_STDOUT;LOG_WINEVENTLOG;USE_SSL_CRYPTO;NO_DAEMON;NO_EXEC;WIN32_LEAN_AND_MEAN"
+ PreprocessorDefinitions="LOG_FILE;LOG_STDOUT;LOG_WINEVENTLOG;USE_SSL_CRYPTO;NO_DAEMON;NO_EXEC;WIN32_LEAN_AND_MEAN;BOOST_ALL_DYN_LINK"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="3"
@@ -421,6 +420,10 @@
>
</File>
<File
+ RelativePath=".\resolver.h"
+ >
+ </File>
+ <File
RelativePath=".\routingTable.h"
>
</File>
@@ -617,6 +620,10 @@
>
</File>
<File
+ RelativePath=".\resolver.cpp"
+ >
+ </File>
+ <File
RelativePath=".\routingTable.cpp"
>
</File>
diff --git a/src/resolver.cpp b/src/resolver.cpp
index 52d0c0b..c4df658 100644
--- a/src/resolver.cpp
+++ b/src/resolver.cpp
@@ -34,13 +34,18 @@
#include "resolver.h"
#include "log.h"
-template<class Proto> ResolveHandler<Proto>::ResolveHandler(const std::string& addr, const std::string& port) : addr_(addr), port_(port)
+template<class Proto> ResolveHandler<Proto>::ResolveHandler(const std::string& addr, const std::string& port, boost::function<void(boost::asio::ip::udp::endpoint)> const& onResolve) : addr_(addr), port_(port), callback_(onResolve)
{
}
-template<class Proto> void ResolveHandler<Proto>::operator()(const boost::system::error_code& e, const boost::asio::ip::basic_resolver_iterator<Proto>)
+template<class Proto> void ResolveHandler<Proto>::operator()(const boost::system::error_code& e, const boost::asio::ip::basic_resolver_iterator<Proto> endpointIt)
{
cLog.msg(Log::PRIO_DEBUG) << "ResolveHandler<" << typeid(Proto).name() << ">() called, addr='" << addr_ << "', port='" << port_ << "'";
+ if(boost::system::errc:success == e) {
+ callback_(*endpointIt);
+ } else {
+ cLog.msg(Log::PRIO_ERROR) << << "ResolveHandler<" << typeid(Proto).name() << ">(): " << e;
+ }
}
Resolver* Resolver::inst = NULL;
@@ -70,36 +75,36 @@ Resolver::~Resolver()
void Resolver::init()
{
if(!thread_)
- thread_ = new boost::thread(boost::bind(run, this));
+ thread_ = new boost::thread(boost::bind(&Resolver::run, this));
}
-void Resolver::run(void* s)
+void Resolver::run(/*void* s*/)
{
- Resolver* self = reinterpret_cast<Resolver*>(s);
+ //Resolver* self = reinterpret_cast<Resolver*>(s);
cLog.msg(Log::PRIO_DEBUG) << "Resolver Thread started";
while(1) {
- self->io_service_.run();
- self->io_service_.reset();
+ /*self->*/io_service_.run();
+ /*self->*/io_service_.reset();
boost::this_thread::sleep(boost::posix_time::milliseconds(250));
}
}
-void Resolver::resolveUdp(const std::string& addr, const std::string& port)
+void Resolver::resolveUdp(const std::string& addr, const std::string& port, boost::function<void (boost::asio::ip::udp::endpoint)> const& onResolve)
{
cLog.msg(Log::PRIO_DEBUG) << "trying to resolv UDP: " << addr << " " << port;
boost::asio::ip::udp::resolver::query query(addr, port);
- UdpResolveHandler handler(addr, port);
+ UdpResolveHandler handler(addr, port, onResolve);
udp_resolver_.async_resolve(query, handler);
}
-void Resolver::resolveTcp(const std::string& addr, const std::string& port)
+void Resolver::resolveTcp(const std::string& addr, const std::string& port, boost::function<void (boost::asio::ip::udp::endpoint)> const& onResolve)
{
cLog.msg(Log::PRIO_DEBUG) << "trying to resolv TCP: " << addr << " " << port;
boost::asio::ip::tcp::resolver::query query(addr, port);
- TcpResolveHandler handler(addr, port);
+ TcpResolveHandler handler(addr, port, onResolve);
tcp_resolver_.async_resolve(query, handler);
}
diff --git a/src/resolver.h b/src/resolver.h
index 7f1336f..9fe51b2 100644
--- a/src/resolver.h
+++ b/src/resolver.h
@@ -34,6 +34,7 @@
#include <queue>
#include <boost/asio.hpp>
+#include <boost/function.hpp>
#include "threadUtils.hpp"
@@ -41,12 +42,13 @@ template<class Proto>
class ResolveHandler
{
public:
- ResolveHandler(const std::string& addr, const std::string& port);
+ ResolveHandler(const std::string& addr, const std::string& port, boost::function<void (boost::asio::ip::udp::endpoint)> const& onResolve);
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::udp::endpoint)> callback_;
};
typedef ResolveHandler<boost::asio::ip::udp> UdpResolveHandler;
@@ -58,10 +60,10 @@ public:
static Resolver& instance();
void init();
- static void run(void* s);
+ /*static */void run(/*void* s*/);
- void resolveUdp(const std::string& addr, const std::string& port);
- void resolveTcp(const std::string& addr, const std::string& port);
+ void resolveUdp(const std::string& addr, const std::string& port, boost::function<void (boost::asio::ip::udp::endpoint)> const& onResolve);
+ void resolveTcp(const std::string& addr, const std::string& port, boost::function<void (boost::asio::ip::udp::endpoint)> const& onResolve);
private:
Resolver();