Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

…ur jid resource (ie, gtalk)
  • Loading branch information...
commit 3d6f23755461ceab47291cce27ac7cfb33310065 1 parent 540e99e
Richard Jones authored
11 CMakeLists.txt
... ... @@ -1,10 +1,4 @@
1 1 # This plugin depends on libf2f:
2   -#SET(F2F_LIB_DIR "/home/rj/src/libf2f/lib")
3   -#SET(F2F_INC_DIR "/home/rj/src/libf2f/include")
4   -#LINK_DIRECTORIES( ${F2F_LIB_DIR} )
5   -#INCLUDE_DIRECTORIES( ${F2F_INC_DIR} )
6   -
7   -
8 2 ADD_LIBRARY( greynet SHARED
9 3 src/greynet.cpp
10 4 src/ss_greynet.cpp
@@ -21,8 +15,9 @@ SET_TARGET_PROPERTIES( greynet PROPERTIES
21 15 )
22 16
23 17 TARGET_LINK_LIBRARIES( greynet
24   - f2f
25   - gloox
  18 + /usr/local/lib/libgloox.a
  19 + /usr/local/lib/libf2f.a
  20 + /usr/local/lib/libportfwd.a
26 21 ${Boost_LIBRARIES}
27 22 ${PLAYDAR_PLUGIN_LDFLAGS}
28 23 )
17 README.txt
... ... @@ -1,7 +1,7 @@
1   -greynet - a playdar plugin for friends
2   -======================================
  1 +Greynet - a darknet/mesh network plugin for Playdar
  2 +===================================================
3 3 This plugin logs into XMPP (gTalk/jabber/etc) and detects which of your friends
4   -are also running playdar-greynet, it then makes a direct connection to all of
  4 +are also running playdar+greynet, it then makes a direct connection to all of
5 5 them to form a darknet/mesh network, external to XMPP.
6 6
7 7 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
19 19 the matching file. If Alice requests to stream it, Bob requests to Charlie and
20 20 acts as a proxy, so Alice only ever knows about Bob.
21 21
  22 +XMPP Note
  23 +---------
  24 +You can be logged in multiple times - just use the same account as you use for
  25 +chat with this plugin. The plugin doesn't receive msgs, and shouldn't confuse
  26 +anyone.
22 27
23 28 How to build it
24 29 ===============
@@ -78,10 +83,12 @@ Slap something like this in your playdar.conf, in the "plugins" object:
78 83 "server" : "talk.google.com",
79 84 "port" : 5222
80 85 },
81   - "ip" : "127.0.0.1",
82 86 "port" : 60211,
83   - "nat" : true
  87 + "connection" : "nat"
84 88 }
85 89
  90 +If you are directly connected to the internet, change "connection": "direct"
  91 +and add: "ip" : "1.2.3.4" where 1.2.3.4 is your external IP address.
86 92
  93 +You can change the port to anything you want, it is sent to peers over XMPP.
87 94
40 src/greynet.cpp
@@ -16,7 +16,7 @@
16 16 #include "playdar/auth.h"
17 17
18 18 // default port for f2f mesh
19   -#define GREYNET_PORT 60210
  19 +#define GREYNET_PORT 60211
20 20
21 21 using namespace std;
22 22 using namespace json_spirit;
@@ -61,6 +61,25 @@ bool greynet::init(pa_ptr pap)
61 61 ("plugins.greynet.peerport",GREYNET_PORT)
62 62 );
63 63 }
  64 +
  65 + // port fwd setup:
  66 + const string conntype = m_pap->get<string>("plugins.greynet.connection", "nat");
  67 + if( conntype == "nat" )
  68 + {
  69 + m_pf = boost::shared_ptr<Portfwd>(new Portfwd);
  70 + if( m_pf->init(2500) && m_pf->add(port) )
  71 + {
  72 + cout << "Port forward setup ok!" << endl;
  73 + }else{
  74 + cout << "FAILED to detect nat router, no port fwd available."
  75 + << "greynet aborting, no port-fwd." << endl;
  76 + return false;
  77 + }
  78 + }
  79 + else
  80 + {
  81 + cout << "greynet connection!=nat, no port-fwd required." << endl;
  82 + }
64 83
65 84 jabber_start( m_pap->get<string>("plugins.greynet.jabber.jid",""),
66 85 m_pap->get<string>("plugins.greynet.jabber.password",""),
@@ -74,6 +93,11 @@ bool greynet::init(pa_ptr pap)
74 93 greynet::~greynet() throw()
75 94 {
76 95 cout << "DTOR greynet" << endl;
  96 + if( m_pf )
  97 + {
  98 + cout << "Removing port fwd..." << endl;
  99 + m_pf->remove( m_pap->get("plugins.greynet.port", GREYNET_PORT) );
  100 + }
77 101 if( m_jbot )
78 102 {
79 103 cout << "Stopping xmpp bot.." << endl;
@@ -163,18 +187,28 @@ void
163 187 greynet::jabber_new_peer(const string& jid)
164 188 {
165 189 cout << "New jabber peer reported: " << jid << endl;
166   - if( jid == m_pap->get<string>("plugins.greynet.jabber.jid","") )
  190 + if( jid == m_jbot->jid() )
167 191 {
168 192 cout << "self, no action." << endl;
169 193 return;
170 194 }
  195 + // get our external IP:
  196 + string extip = m_pap->get<string>("plugins.greynet.ip","");
  197 + if( extip == "" && m_pf ) extip = m_pf->external_ip();
  198 + if( extip == "" )
  199 + {
  200 + cout << "ERROR greynet doesn't know external IP address" << endl
  201 + << "either enable connection:nat, or add \"ip\":\"x.x.x.x\" to config"
  202 + << endl;
  203 + return;
  204 + }
171 205 // tell them our ip/port
172 206 string cookie = m_pap->gen_uuid();
173 207 m_peer_cookies[cookie] = jid;
174 208 using namespace json_spirit;
175 209 Object o;
176 210 o.push_back( Pair("playdar-greynet", "0.1") );
177   - o.push_back( Pair("peer_ip", m_pap->get<string>("plugins.greynet.ip","")) );
  211 + o.push_back( Pair("peer_ip", extip) );
178 212 o.push_back( Pair("peer_port", m_pap->get<int>("plugins.greynet.port", GREYNET_PORT)) );
179 213 o.push_back( Pair("cookie", cookie) );
180 214 ostringstream os;
4 src/greynet.h
@@ -21,6 +21,8 @@
21 21
22 22 #include "jbot.h"
23 23
  24 +#include "portfwd/portfwd.h"
  25 +
24 26 using namespace libf2f; // pff
25 27
26 28 namespace playdar {
@@ -151,6 +153,8 @@ class greynet
151 153 boost::shared_ptr<boost::thread> m_jbot_thread;
152 154 std::map<std::string, std::string> m_peer_cookies; // cookie->jid
153 155
  156 + boost::shared_ptr<Portfwd> m_pf;
  157 +
154 158 boost::thread_group m_threads;
155 159 boost::shared_ptr<boost::asio::io_service> m_io_service;
156 160
3  src/jbot.cpp
@@ -97,7 +97,8 @@ jbot::onConnect()
97 97 // have changed our requested /resource
98 98 JID jid( m_jid );
99 99 jid.setResource( j->resource() );
100   - printf( "connected as: %s\n", jid.full().c_str() );
  100 + m_jid = jid.full();
  101 + printf( "connected as: %s\n", m_jid.c_str() );
101 102 }
102 103
103 104 void
2  src/jbot.h
@@ -63,7 +63,7 @@ class jbot
63 63 void set_msg_received_callback( boost::function<void(const std::string&, const std::string&)> cb);
64 64 void set_new_peer_callback( boost::function<void(const std::string& jid)> cb);
65 65 void clear_msg_received_callback();
66   -
  66 + const std::string& jid() const { return m_jid; }
67 67
68 68 /// GLOOX IMPLEMENTATION STUFF FOLLOWS
69 69

0 comments on commit 3d6f237

Please sign in to comment.
Something went wrong with that request. Please try again.