Permalink
Browse files

Merge branch 'master' of git://github.com/RJ/playdar

  • Loading branch information...
2 parents 20d4a80 + fe88023 commit 8c0b129178cd41990efbb902743f5b0ee41cf2ac @jonocole jonocole committed Jul 13, 2009
Showing with 135 additions and 23,010 deletions.
  1. +0 −20 contrib/darknet/CMakeLists.txt
  2. +0 −15 contrib/darknet/README.txt
  3. +0 −269 contrib/darknet/connection.hpp
  4. +0 −548 contrib/darknet/darknet.cpp
  5. +0 −171 contrib/darknet/darknet.h
  6. +0 −143 contrib/darknet/msgs.h
  7. +0 −114 contrib/darknet/servent.cpp
  8. +0 −67 contrib/darknet/servent.h
  9. +0 −150 contrib/darknet/ss_darknet.cpp
  10. +0 −71 contrib/darknet/ss_darknet.h
  11. +0 −18 contrib/f2f/CMakeLists.txt
  12. +0 −2 contrib/f2f/README.txt
  13. +0 −191 contrib/f2f/f2f.cpp
  14. +0 −62 contrib/f2f/f2f.h
  15. +0 −55 contrib/f2f/f2f_ss.hpp
  16. +0 −463 contrib/f2f/jbot.cpp
  17. +0 −137 contrib/f2f/jbot.h
  18. +0 −399 contrib/lan-external-process/build/CMakeCache.txt
  19. +0 −36 contrib/lan-external-process/build/CMakeFiles/CMakeCCompiler.cmake
  20. +0 −36 contrib/lan-external-process/build/CMakeFiles/CMakeCXXCompiler.cmake
  21. BIN contrib/lan-external-process/build/CMakeFiles/CMakeDetermineCompilerABI_C.bin
  22. BIN contrib/lan-external-process/build/CMakeFiles/CMakeDetermineCompilerABI_CXX.bin
  23. +0 −25 contrib/lan-external-process/build/CMakeFiles/CMakeDirectoryInformation.cmake
  24. +0 −104 contrib/lan-external-process/build/CMakeFiles/CMakeOutput.log
  25. +0 −15 contrib/lan-external-process/build/CMakeFiles/CMakeSystem.cmake
  26. +0 −176 contrib/lan-external-process/build/CMakeFiles/CompilerIdC/CMakeCCompilerId.c
  27. BIN contrib/lan-external-process/build/CMakeFiles/CompilerIdC/a.out
  28. +0 −163 contrib/lan-external-process/build/CMakeFiles/CompilerIdCXX/CMakeCXXCompilerId.cpp
  29. BIN contrib/lan-external-process/build/CMakeFiles/CompilerIdCXX/a.out
  30. +0 −55 contrib/lan-external-process/build/CMakeFiles/Makefile.cmake
  31. +0 −102 contrib/lan-external-process/build/CMakeFiles/Makefile2
  32. +0 −1 contrib/lan-external-process/build/CMakeFiles/cmake.check_cache
  33. +0 −13,992 contrib/lan-external-process/build/CMakeFiles/lanresolver.dir/CXX.includecache
  34. +0 −21 contrib/lan-external-process/build/CMakeFiles/lanresolver.dir/DependInfo.cmake
  35. +0 −190 contrib/lan-external-process/build/CMakeFiles/lanresolver.dir/build.make
  36. +0 −13 contrib/lan-external-process/build/CMakeFiles/lanresolver.dir/cmake_clean.cmake
  37. +0 −2,425 contrib/lan-external-process/build/CMakeFiles/lanresolver.dir/depend.internal
  38. +0 −2,425 contrib/lan-external-process/build/CMakeFiles/lanresolver.dir/depend.make
  39. +0 −8 contrib/lan-external-process/build/CMakeFiles/lanresolver.dir/flags.make
  40. BIN ...s/lanresolver.dir/home/rj/src/playdar/deps/json_spirit_v3.00/json_spirit/json_spirit_reader.cpp.o
  41. BIN ...es/lanresolver.dir/home/rj/src/playdar/deps/json_spirit_v3.00/json_spirit/json_spirit_value.cpp.o
  42. BIN ...s/lanresolver.dir/home/rj/src/playdar/deps/json_spirit_v3.00/json_spirit/json_spirit_writer.cpp.o
  43. +0 −1 contrib/lan-external-process/build/CMakeFiles/lanresolver.dir/link.txt
  44. BIN contrib/lan-external-process/build/CMakeFiles/lanresolver.dir/main.cpp.o
  45. +0 −5 contrib/lan-external-process/build/CMakeFiles/lanresolver.dir/progress.make
  46. +0 −1 contrib/lan-external-process/build/CMakeFiles/progress.make
  47. +0 −247 contrib/lan-external-process/build/Makefile
  48. +0 −44 contrib/lan-external-process/build/cmake_install.cmake
  49. BIN contrib/lan-external-process/build/lanresolver
  50. +0 −5 etc/playdar.conf
  51. +32 −0 includes/playdar/config.hpp
  52. +1 −1 includes/playdar/pluginadaptor.h
  53. +5 −0 includes/playdar/pluginadaptor_impl.hpp
  54. +87 −20 resolvers/lan/lan.cpp
  55. +10 −4 resolvers/lan/lan.h
@@ -1,20 +0,0 @@
-ADD_LIBRARY( darknet SHARED
- darknet.cpp
- servent.cpp
- ss_darknet.cpp
- )
-#
-# Ensure the shared library file is called <CLASS NAME>.resolver
-# Playdar looks for a class with the same name as the file, minus suffix
-#
-SET_TARGET_PROPERTIES( darknet PROPERTIES
- PREFIX ""
- SUFFIX ".resolver"
- CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PLAYDAR_DIR}/plugins"
- )
-
-TARGET_LINK_LIBRARIES( darknet
- ${OSSPUUID_LIBRARIES} # BSD-like
- ${Boost_LIBRARIES} # Boost license
- ${PLAYDAR_PLUGIN_LDFLAGS}
- )
View
@@ -1,15 +0,0 @@
-The beginnings of a darknet implementation.
-
-You connect to all your friends, they connect to theirs.
-Queries will be flood based, fwding with a delay of ~100ms.
-Query cancellations fwded immediately so cancellations can reach search
-frontier quickly. Max query survival time of a few seconds.
-You only ever get msgs from immediate friends, all queries and fetching of
-data appear to come from immediate friends, although they might be relaying
-to one of their friends. You can't necesarily tell.
-Never know true source of a resolved item. Friends re-transmit to you.
-
-Must provide ip:port of peers atm. Plan to bootstrap the mesh network using
-xmpp accounts and rosters, possibly with gloox library and gtalk servers.
-
-will also need upnp auto-port-fwd setup code. possibly from libtorrent.
@@ -1,269 +0,0 @@
-#ifndef _PLAYDAR_DARKNET_CONNECTION_HPP_
-#define _PLAYDAR_DARKNET_CONNECTION_HPP_
-
-#include <boost/asio.hpp>
-#include <boost/bind.hpp>
-#include <boost/shared_ptr.hpp>
-#include <boost/enable_shared_from_this.hpp>
-#include <boost/tuple/tuple.hpp>
-#include <boost/thread/thread.hpp>
-#include <boost/thread/mutex.hpp>
-#include <boost/thread/condition.hpp>
-#include <string>
-#include <sstream>
-#include <vector>
-
-#include "msgs.h"
-
-using namespace std;
-
-namespace playdar {
-namespace resolvers {
-
-/// This class represents a Connection to one other playdar user.
-/// i.e. Use this instead of socket directly.
-/// it knows how to marshal objects to and from the wire protocol
-/// It keeps some state related to the Connection, eg are they authenticated.
-class Connection
-: public boost::enable_shared_from_this<Connection>
-
-{
-public:
-
- Connection(boost::asio::io_service& io_service)
- : m_socket(io_service), m_sending(false), m_authed(false)
- {
- }
-
- ~Connection()
- {
- cout << "dtor Connection shutting down" << endl;
- }
-
- void close()
- {
- if(socket().is_open()) socket().close();
- }
-
- bool alive()
- {
- // perhaps make this actually ping them in future.
- // this is typically checked before starting a stream.
- return socket().is_open();
- }
-
- /// Get the underlying socket. Used for making a Connection or for accepting
- /// an incoming Connection.
- boost::asio::ip::tcp::socket& socket()
- {
- return m_socket;
- }
-
- /// Asynchronously write a data structure to the socket.
- /// Seems like asio doesnt make any promises if you stack up multiple
- /// async_write calls - so we queue them and call it sequentially.
- void async_write(msg_ptr msg)//, FuncTemplate handler)
- {
- {
- boost::mutex::scoped_lock lk(m_mutex);
- m_writeq.push_back(msg);
- }
- msg_ptr noop(new LameMsg(GENERIC));
- boost::system::error_code e;
- do_async_write(e, noop);
- }
-
- /// Calls to do_async_write are chained - it will call itself when a write
- /// completes, to send the next msg in the queue. Bails when none left.
- void do_async_write(const boost::system::error_code& e, msg_ptr finished_msg)
- {
- boost::mutex::scoped_lock lk(m_mutex);
- // if this is a GENERIC (ie, null) msg, it's actually a dispatch call:
- if(m_sending && finished_msg->msgtype()==GENERIC)
- {
- //cout << "bailing from do_async_write - already sending (sending=true)" << endl;
- return;
- }
- if(m_writeq.empty())
- {
- //cout << "bailing from do_async_write, q empty (sending=false)" << endl;
- m_sending = false;
- return;
- }
- msg_ptr msg = m_writeq.front();
- m_writeq.pop_front();
- msg_header outbound_header;
- outbound_header.msgtype = htonl( msg->msgtype() );
- outbound_header.length = htonl( msg->payload_len() );
- size_t data_len = sizeof(msg_header) + msg->payload_len();
- char * data = (char*) malloc(data_len);
- memcpy(data, (char*)&outbound_header, sizeof(msg_header));
- memcpy(data+sizeof(msg_header), msg->serialize().data(), msg->payload_len());
- msg->set_membuf(data); // msg will free() data on destruction.
- std::vector<boost::asio::const_buffer> buffers;
- buffers.push_back(boost::asio::buffer(data, data_len));
- // add to write queue:
- m_sending = true;
- //cout << "dispatching write. write queue size is: " << m_writeq.size() << endl;
- boost::asio::async_write(m_socket, buffers,
- boost::bind(&Connection::do_async_write, this,
- boost::asio::placeholders::error,
- msg));
- }
-
-
-
- /// Setup a call to read the next msg_header
- template <typename FuncTemplate>
- void async_read(FuncTemplate handler)
- {
- msg_ptr msg(new LameMsg()); // what the data from the wire becomes
- void (Connection::*f)( const boost::system::error_code&,
- boost::tuple<FuncTemplate>,
- msg_ptr,
- char *)
- = &Connection::handle_read_header<FuncTemplate>;
- // Issue a read operation to read exactly the number of bytes in a header.
- char * header_buf = (char*) malloc(sizeof(msg_header)*sizeof(char));
- boost::asio::async_read(m_socket,
- boost::asio::buffer(header_buf,
- sizeof(msg_header)),
- boost::bind(f,
- shared_from_this(),
- boost::asio::placeholders::error,
- boost::make_tuple(handler),
- msg,
- header_buf));
- }
-
-
- /// Handle a completed read of a message header. The handler is passed using
- /// a tuple since boost::bind seems to have trouble binding a function object
- /// created using boost::bind as a parameter.
- template <typename FuncTemplate>
- void handle_read_header(const boost::system::error_code& e,
- boost::tuple<FuncTemplate> handler,
- msg_ptr msg,
- char * header_buf)
- {
- //cout << "handle_read_header" << endl;
-
- if (e)
- {
- cerr << "err" << endl;
- free(header_buf);
- msg_ptr null_msg;
- boost::get<0>(handler)(e, null_msg);
- return;
- }
- msg_header * inbound_header = (msg_header *)header_buf;
- // convert from nbo to host bo
- inbound_header->length = ntohl( inbound_header->length );
- inbound_header->msgtype = ntohl( inbound_header->msgtype );
-
- msg->m_msgtype = inbound_header->msgtype;
- msg->m_expected_len = inbound_header->length;
-
-
-
- // Start an asynchronous call to receive the data.
- void (Connection::*f)(
- const boost::system::error_code&,
- boost::tuple<FuncTemplate>,
- msg_ptr,
- char *)
- = &Connection::handle_read_data<FuncTemplate>;
-
- if(0 && msg->msgtype() != SIDDATA)
- {
- cout << "header, msgtype = " << inbound_header->msgtype
- << " length = " << inbound_header->length
- << " read.. " << inbound_header->length
- << " bytes" << endl;
- }
- // 16K is max payload size.
- assert( msg->m_expected_len <= 16384 );
-
- size_t payloadsize = inbound_header->length * sizeof(char);
- char * payload_buf = (char*) malloc(payloadsize);
-
- assert(inbound_header->length <= payloadsize);
-
- free(header_buf);
-
- boost::asio::async_read(m_socket,
- boost::asio::buffer(payload_buf, payloadsize),
- boost::bind(f,
- shared_from_this(),
- boost::asio::placeholders::error,
- handler,
- msg,
- payload_buf));
-
- }
-
- /// Handle a completed read of message data.
- template <typename FuncTemplate>
- void handle_read_data(const boost::system::error_code& e,
- boost::tuple<FuncTemplate> handler,
- msg_ptr msg,
- char * payload_buf)
- {
- //cout << "handle_read_data" << endl;
- if (e)
- {
- free(payload_buf);
- cerr << "errrrrrr" << endl;
- boost::get<0>(handler)(e,msg);
- }
- else
- {
- // build the lamemsg structure from the data just received.
- try
- {
- msg->set_payload(string((const char *)payload_buf, msg->m_expected_len), msg->m_expected_len);
- free(payload_buf);
- if(msg->msgtype()!=SIDDATA)
- {
- //cout << "handle_read_data("
- // << msg->toString() <<")" << endl;
- }
- }
- catch (std::exception& /*e*/)
- {
- // Unable to decode data.
- boost::system::error_code error(boost::asio::error::invalid_argument);
- boost::get<0>(handler)(error, msg);
- return;
- }
- // Inform caller that data has been received ok.
- boost::get<0>(handler)(e,msg);
- }
- }
-
- string username() const { return m_username; }
- void set_username(string u){ m_username = u; }
- bool authed() const { return m_authed; }
- void set_authed(bool b) { m_authed = b; }
- size_t writeq_size() const { return m_writeq.size(); }
-
-private:
- /// The underlying socket.
- boost::asio::ip::tcp::socket m_socket;
-
- boost::mutex m_mutex;
- bool m_sending; // are we currently awaiting an async_write to finish
- deque< msg_ptr > m_writeq; // queue of outgoing messages
-
- /// Stateful stuff the protocol handler/servent will set:
- string m_username; // username of user at end of Connection
- bool m_authed;
-
-};
-
-
-
-} // namespace
-} // namespace playdar
-
-#endif
Oops, something went wrong.

0 comments on commit 8c0b129

Please sign in to comment.