summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--anytun.cpp35
-rw-r--r--options.cpp36
-rw-r--r--options.h6
3 files changed, 69 insertions, 8 deletions
diff --git a/anytun.cpp b/anytun.cpp
index 081f009..f853b9c 100644
--- a/anytun.cpp
+++ b/anytun.cpp
@@ -216,7 +216,23 @@ void* sender(void* p)
pthread_exit(NULL);
}
-void* syncReceiver(void* p )
+void* syncConnector(void* p )
+{
+ Param* param = reinterpret_cast<Param*>(p);
+
+ SocketHandler h;
+ SyncSocket sock(h,param->cl);
+ // sock.EnableSSL();
+ sock.Open( param->opt.getRemoteSyncAddr(), param->opt.getRemoteSyncPort());
+ h.Add(&sock);
+ while (h.GetCount())
+ {
+ h.Select();
+ }
+ pthread_exit(NULL);
+}
+
+void* syncListener(void* p )
{
Param* param = reinterpret_cast<Param*>(p);
@@ -224,7 +240,7 @@ void* syncReceiver(void* p )
SyncListenSocket<SyncSocket,ConnectionList> l(h,param->cl);
if (l.Bind(param->opt.getLocalSyncPort()))
- return(NULL);
+ pthread_exit(NULL);
Utility::ResolveLocal(); // resolve local hostname
h.Add(&l);
h.Select(1,0);
@@ -340,20 +356,27 @@ int main(int argc, char* argv[])
pthread_create(&senderThread, NULL, sender, &p);
pthread_t receiverThread;
pthread_create(&receiverThread, NULL, receiver, &p);
- pthread_t syncReceiverThread;
+ pthread_t syncListenerThread;
+ pthread_t syncConnectorThread;
if ( opt.getLocalSyncPort())
- pthread_create(&syncReceiverThread, NULL, syncReceiver, &p);
+ pthread_create(&syncListenerThread, NULL, syncListener, &p);
+ if ( opt.getRemoteSyncPort() && opt.getRemoteSyncAddr() != "")
+ pthread_create(&syncConnectorThread, NULL, syncConnector, &p);
int ret = sig.run();
pthread_cancel(senderThread);
pthread_cancel(receiverThread);
if ( opt.getLocalSyncPort())
- pthread_cancel(syncReceiverThread);
+ pthread_cancel(syncListenerThread);
+ if ( opt.getRemoteSyncPort() && opt.getRemoteSyncAddr() != "")
+ pthread_cancel(syncConnectorThread);
pthread_join(senderThread, NULL);
pthread_join(receiverThread, NULL);
if ( opt.getLocalSyncPort())
- pthread_join(syncReceiverThread, NULL);
+ pthread_join(syncListenerThread, NULL);
+ if ( opt.getRemoteSyncPort() && opt.getRemoteSyncAddr() != "")
+ pthread_join(syncConnectorThread, NULL);
delete src;
diff --git a/options.cpp b/options.cpp
index bb19576..4bdefd0 100644
--- a/options.cpp
+++ b/options.cpp
@@ -78,6 +78,8 @@ Options::Options()
local_addr_ = "";
local_port_ = 4444;
local_sync_port_ = 0;
+ remote_sync_port_ = 0;
+ remote_sync_addr_ = "";
remote_addr_ = "";
remote_port_ = 4444;
dev_name_ = "tap";
@@ -107,6 +109,8 @@ bool Options::parse(int argc, char* argv[])
PARSE_SCALAR_PARAM("-i","--interface", local_addr_)
PARSE_SCALAR_PARAM("-p","--port", local_port_)
PARSE_SCALAR_PARAM("-S","--sync-port", local_sync_port_)
+ PARSE_SCALAR_PARAM("-R","--remote-sync-host", remote_sync_addr_)
+ PARSE_SCALAR_PARAM("-O","--remote-sync-port", remote_sync_port_)
PARSE_SCALAR_PARAM("-r","--remote-host", remote_addr_)
PARSE_SCALAR_PARAM("-o","--remote-port", remote_port_)
PARSE_SCALAR_PARAM("-d","--dev", dev_name_)
@@ -130,10 +134,12 @@ void Options::printUsage()
std::cout << " [-i|--interface] <interface> local interface to bind to" << std::endl;
std::cout << " [-p|--port] <port> local anycast port to bind to" << std::endl;
std::cout << " [-S|--sync-port] <port> local unicast/sync port to bind to" << std::endl;
- std::cout << " [-r|--remote-host] <hostname/ip> remote host" << std::endl;
+ std::cout << " [-R|--remote-sync-host] <hostname|ip> remote unicast/sync host" << std::endl;
+ std::cout << " [-O|--remote-sync-port] <port> remote unicast/sync port to bind to" << std::endl;
+ std::cout << " [-r|--remote-host] <hostname|ip> remote host" << std::endl;
std::cout << " [-o|--remote-port] <port> remote port" << std::endl;
std::cout << " [-d|--dev] <name> device name" << std::endl;
- std::cout << " [-t|--type] <tun|tap> device type" << std::endl;
+ std::cout << " [-t|--type] <tun|tap> device type" << std::endl;
std::cout << " [-n|--ifconfig] <local> the local address for the tun/tap device" << std::endl
<< " <remote|netmask> the remote address(tun) or netmask(tap)" << std::endl;
std::cout << " [-w|--window-size] <window size> seqence number window size" << std::endl;
@@ -149,6 +155,8 @@ void Options::printOptions()
std::cout << "local_addr='" << local_addr_ << "'" << std::endl;
std::cout << "local_port='" << local_port_ << "'" << std::endl;
std::cout << "local_sync_port='" << local_sync_port_ << "'" << std::endl;
+ std::cout << "remote_sync_port='" << remote_sync_port_ << "'" << std::endl;
+ std::cout << "remote_sync_addr='" << remote_sync_addr_ << "'" << std::endl;
std::cout << "remote_addr='" << remote_addr_ << "'" << std::endl;
std::cout << "remote_port='" << remote_port_ << "'" << std::endl;
std::cout << "dev_name='" << dev_name_ << "'" << std::endl;
@@ -232,6 +240,30 @@ Options& Options::setLocalSyncPort(u_int16_t l)
return *this;
}
+u_int16_t Options::getRemoteSyncPort()
+{
+ return remote_sync_port_;
+}
+
+Options& Options::setRemoteSyncPort(u_int16_t l)
+{
+ remote_sync_port_ = l;
+ return *this;
+}
+
+std::string Options::getRemoteSyncAddr()
+{
+ Lock lock(mutex);
+ return remote_sync_addr_;
+}
+
+Options& Options::setRemoteSyncAddr(std::string r)
+{
+ Lock lock(mutex);
+ remote_sync_addr_ = r;
+ return *this;
+}
+
std::string Options::getRemoteAddr()
{
Lock lock(mutex);
diff --git a/options.h b/options.h
index 08c299a..191b303 100644
--- a/options.h
+++ b/options.h
@@ -50,6 +50,10 @@ public:
Options& setLocalAddr(std::string l);
std::string getLocalSyncAddr();
Options& setLocalSyncAddr(std::string l);
+ std::string getRemoteSyncAddr();
+ Options& setRemoteSyncAddr(std::string l);
+ u_int16_t getRemoteSyncPort();
+ Options& setRemoteSyncPort(u_int16_t l);
u_int16_t getLocalPort();
Options& setLocalPort(u_int16_t l);
std::string getRemoteAddr();
@@ -83,6 +87,8 @@ private:
std::string local_sync_addr_;
u_int16_t local_port_;
u_int16_t local_sync_port_;
+ std::string remote_sync_addr_;
+ u_int16_t remote_sync_port_;
std::string remote_addr_;
u_int16_t remote_port_;
std::string dev_name_;