Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add portfwding, handle servers that do resource binding and change yo…

…ur jid resource (ie, gtalk)
  • Loading branch information...
commit 3d6f23755461ceab47291cce27ac7cfb33310065 1 parent 540e99e
@RJ authored
View
11 CMakeLists.txt
@@ -1,10 +1,4 @@
# This plugin depends on libf2f:
-#SET(F2F_LIB_DIR "/home/rj/src/libf2f/lib")
-#SET(F2F_INC_DIR "/home/rj/src/libf2f/include")
-#LINK_DIRECTORIES( ${F2F_LIB_DIR} )
-#INCLUDE_DIRECTORIES( ${F2F_INC_DIR} )
-
-
ADD_LIBRARY( greynet SHARED
src/greynet.cpp
src/ss_greynet.cpp
@@ -21,8 +15,9 @@ SET_TARGET_PROPERTIES( greynet PROPERTIES
)
TARGET_LINK_LIBRARIES( greynet
- f2f
- gloox
+ /usr/local/lib/libgloox.a
+ /usr/local/lib/libf2f.a
+ /usr/local/lib/libportfwd.a
${Boost_LIBRARIES}
${PLAYDAR_PLUGIN_LDFLAGS}
)
View
17 README.txt
@@ -1,7 +1,7 @@
-greynet - a playdar plugin for friends
-======================================
+Greynet - a darknet/mesh network plugin for Playdar
+===================================================
This plugin logs into XMPP (gTalk/jabber/etc) and detects which of your friends
-are also running playdar-greynet, it then makes a direct connection to all of
+are also running playdar+greynet, it then makes a direct connection to all of
them to form a darknet/mesh network, external to XMPP.
Queries and resulting files are streamed over the mesh in a darknet fashion,
@@ -19,6 +19,11 @@ Alice, who still doesn't know Charlie exists. To Alice, it looks like Bob has
the matching file. If Alice requests to stream it, Bob requests to Charlie and
acts as a proxy, so Alice only ever knows about Bob.
+XMPP Note
+---------
+You can be logged in multiple times - just use the same account as you use for
+chat with this plugin. The plugin doesn't receive msgs, and shouldn't confuse
+anyone.
How to build it
===============
@@ -78,10 +83,12 @@ Slap something like this in your playdar.conf, in the "plugins" object:
"server" : "talk.google.com",
"port" : 5222
},
- "ip" : "127.0.0.1",
"port" : 60211,
- "nat" : true
+ "connection" : "nat"
}
+If you are directly connected to the internet, change "connection": "direct"
+and add: "ip" : "1.2.3.4" where 1.2.3.4 is your external IP address.
+You can change the port to anything you want, it is sent to peers over XMPP.
View
40 src/greynet.cpp
@@ -16,7 +16,7 @@
#include "playdar/auth.h"
// default port for f2f mesh
-#define GREYNET_PORT 60210
+#define GREYNET_PORT 60211
using namespace std;
using namespace json_spirit;
@@ -61,6 +61,25 @@ bool greynet::init(pa_ptr pap)
("plugins.greynet.peerport",GREYNET_PORT)
);
}
+
+ // port fwd setup:
+ const string conntype = m_pap->get<string>("plugins.greynet.connection", "nat");
+ if( conntype == "nat" )
+ {
+ m_pf = boost::shared_ptr<Portfwd>(new Portfwd);
+ if( m_pf->init(2500) && m_pf->add(port) )
+ {
+ cout << "Port forward setup ok!" << endl;
+ }else{
+ cout << "FAILED to detect nat router, no port fwd available."
+ << "greynet aborting, no port-fwd." << endl;
+ return false;
+ }
+ }
+ else
+ {
+ cout << "greynet connection!=nat, no port-fwd required." << endl;
+ }
jabber_start( m_pap->get<string>("plugins.greynet.jabber.jid",""),
m_pap->get<string>("plugins.greynet.jabber.password",""),
@@ -74,6 +93,11 @@ bool greynet::init(pa_ptr pap)
greynet::~greynet() throw()
{
cout << "DTOR greynet" << endl;
+ if( m_pf )
+ {
+ cout << "Removing port fwd..." << endl;
+ m_pf->remove( m_pap->get("plugins.greynet.port", GREYNET_PORT) );
+ }
if( m_jbot )
{
cout << "Stopping xmpp bot.." << endl;
@@ -163,18 +187,28 @@ void
greynet::jabber_new_peer(const string& jid)
{
cout << "New jabber peer reported: " << jid << endl;
- if( jid == m_pap->get<string>("plugins.greynet.jabber.jid","") )
+ if( jid == m_jbot->jid() )
{
cout << "self, no action." << endl;
return;
}
+ // get our external IP:
+ string extip = m_pap->get<string>("plugins.greynet.ip","");
+ if( extip == "" && m_pf ) extip = m_pf->external_ip();
+ if( extip == "" )
+ {
+ cout << "ERROR greynet doesn't know external IP address" << endl
+ << "either enable connection:nat, or add \"ip\":\"x.x.x.x\" to config"
+ << endl;
+ return;
+ }
// tell them our ip/port
string cookie = m_pap->gen_uuid();
m_peer_cookies[cookie] = jid;
using namespace json_spirit;
Object o;
o.push_back( Pair("playdar-greynet", "0.1") );
- o.push_back( Pair("peer_ip", m_pap->get<string>("plugins.greynet.ip","")) );
+ o.push_back( Pair("peer_ip", extip) );
o.push_back( Pair("peer_port", m_pap->get<int>("plugins.greynet.port", GREYNET_PORT)) );
o.push_back( Pair("cookie", cookie) );
ostringstream os;
View
4 src/greynet.h
@@ -21,6 +21,8 @@
#include "jbot.h"
+#include "portfwd/portfwd.h"
+
using namespace libf2f; // pff
namespace playdar {
@@ -151,6 +153,8 @@ class greynet
boost::shared_ptr<boost::thread> m_jbot_thread;
std::map<std::string, std::string> m_peer_cookies; // cookie->jid
+ boost::shared_ptr<Portfwd> m_pf;
+
boost::thread_group m_threads;
boost::shared_ptr<boost::asio::io_service> m_io_service;
View
3  src/jbot.cpp
@@ -97,7 +97,8 @@ jbot::onConnect()
// have changed our requested /resource
JID jid( m_jid );
jid.setResource( j->resource() );
- printf( "connected as: %s\n", jid.full().c_str() );
+ m_jid = jid.full();
+ printf( "connected as: %s\n", m_jid.c_str() );
}
void
View
2  src/jbot.h
@@ -63,7 +63,7 @@ class jbot
void set_msg_received_callback( boost::function<void(const std::string&, const std::string&)> cb);
void set_new_peer_callback( boost::function<void(const std::string& jid)> cb);
void clear_msg_received_callback();
-
+ const std::string& jid() const { return m_jid; }
/// GLOOX IMPLEMENTATION STUFF FOLLOWS
Please sign in to comment.
Something went wrong with that request. Please try again.