This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Status of uTorrent dht?

Tags: None
(comma "," separated)
jdong
Registered Member
Posts
358
Karma
0

Sun Nov 05, 2006 12:35 am
Here's yet another version of my DHT ping hack, this time I am triggering a portReceived() in socket.cpp on incoming connections, so we can catch a DHT ping for remotely initiated connect, too.

It's a nice feeling connecting to a large torrent and watching those DHT ping messages fly by :D

I also reverted DHT tick marks to their original behavior, and prevented portReceived triggers for port == 0 from peers.cpp (it's already handled correctly in socket.cpp)


It's a bit ugly, but it does work.
Code: Select all
=== modified file 'libktorrent/mse/streamsocket.cpp'
--- libktorrent/mse/streamsocket.cpp   2006-11-03 23:52:12 +0000
+++ libktorrent/mse/streamsocket.cpp   2006-11-03 23:51:54 +0000
@@ -51,6 +51,7 @@
       reinserted_data = 0;
       reinserted_data_size = 0;
       reinserted_data_read = 0;
+      port=0;
       
    }
 
@@ -62,6 +63,7 @@
       reinserted_data_size = 0;
       reinserted_data_read = 0;
       sock->setTOS(tos);
+      port=0;
    }
 
    StreamSocket::~StreamSocket()
@@ -181,6 +183,7 @@
       if (ip.isNull() || ip.length() == 0)
          return false;
       
+      this->port=port;
       // we don't wanna block the current thread so set non blocking
       sock->setNonBlocking();
       if (sock->connectTo(Address(ip,port)))
@@ -214,7 +217,10 @@
    {
       return sock->getPeerName().toString();
    }
-   
+   Uint16 StreamSocket::getPort() const
+   {
+      return port;
+   }   
    void StreamSocket::setRC4Encryptor(RC4Encryptor* e)
    {
       if (enc)

=== modified file 'libktorrent/mse/streamsocket.h'
--- libktorrent/mse/streamsocket.h   2006-11-03 23:52:12 +0000
+++ libktorrent/mse/streamsocket.h   2006-11-03 23:51:54 +0000
@@ -103,7 +103,7 @@
       
       /// Get the IP address of the remote peer
       QString getIPAddress() const;
-      
+      Uint16 getPort() const;
       /**
        * Reinsert data, this is needed when we read to much during the crypto handshake.
        * This data will be the first to read out. The data will be copied to a temporary buffer
@@ -151,7 +151,7 @@
       bool monitored;
       net::SocketReader* rdr;
       net::SocketWriter* wrt;
-      
+      Uint16 port;   
       static Uint8 tos;
    };
 

=== modified file 'libktorrent/net/socket.cpp'
--- libktorrent/net/socket.cpp   2006-11-03 23:52:12 +0000
+++ libktorrent/net/socket.cpp   2006-11-05 00:14:57 +0000
@@ -29,6 +29,7 @@
 #include <netinet/in.h>
 #include <netinet/tcp.h>
 #include <arpa/inet.h>
+#include <kademlia/dhtbase.h>
 
 #ifdef Q_OS_LINUX
 #include <asm/ioctls.h>
@@ -253,6 +254,11 @@
       a.setIP(ntohl(addr.sin_addr.s_addr));
 
       Out(SYS_CON|LOG_DEBUG) << "Accepted connection from " << QString(inet_ntoa(addr.sin_addr)) << endl;
+                          if(Globals::instance().getDHT().isRunning())
+                    {
+                Globals::instance().getDHT().portRecieved(QString(inet_ntoa(addr.sin_addr)),a.port());
+        }
+
       return sfd;
    }
    

=== modified file 'libktorrent/torrent/peer.cpp'
--- libktorrent/torrent/peer.cpp   2006-11-03 23:52:12 +0000
+++ libktorrent/torrent/peer.cpp   2006-11-05 00:21:55 +0000
@@ -31,6 +31,8 @@
 #include "packetwriter.h"
 #include "peerdownloader.h"
 #include "peeruploader.h"
+#include <kademlia/dhtbase.h>
+
 
 using namespace net;
 
@@ -62,7 +64,7 @@
       
       connect_time = QTime::currentTime();
       //sock->attachPeer(this);
-      stats.client = peer_id.identifyClient();
+      stats.client = peer_id.identifyClient();   
       stats.ip_addresss = getIPAddresss();
       stats.choked = true;
       stats.download_rate = 0;
@@ -86,6 +88,16 @@
       {
          sock->startMonitoring(preader,pwriter);
       }
+          if(Globals::instance().getDHT().isRunning())
+          {
+         if(sock->getPort())
+         {
+                  gotPortPacket(getIPAddresss(),sock->getPort());
+                       Globals::instance().getDHT().portRecieved(getIPAddresss(),sock->getPort());
+         }
+        }
+        else
+          Out() << "DHT not running!" << endl;
    }
 
 
@@ -122,6 +134,7 @@
       const Uint8* tmp_buf = packet;
       //Out() << "Got packet : " << len << " type = " << type <<  endl;
       Uint8 type = tmp_buf[0];
+
       switch (type)
       {
          case CHOKE:

Moshroum
Registered Member
Posts
63
Karma
0

Sun Nov 05, 2006 11:00 am
Ok, I see a lot of "sending ping request" but no response from the other clients -> nothing happens to my nodes count
George
Moderator
Posts
5421
Karma
1

Sun Nov 05, 2006 12:16 pm
Moshroum wrote:Ok, I see a lot of "sending ping request" but no response from the other clients -> nothing happens to my nodes count


Even if peers reply to your ping, that doesn't mean your node count goes up, depending on what bucket the peers ends up it can replace an existing node or none at all if all nodes in that bucket are still active.
jdong
Registered Member
Posts
358
Karma
0

Sun Nov 05, 2006 3:20 pm
I've tested this patch in an isolated uTorrent swarm, and it on average picks up 50 or so nodes from 2 uTorrent pings.
George
Moderator
Posts
5421
Karma
1

Mon Nov 06, 2006 6:24 pm
I allready added the automatic pinging in SVN.
jdong
Registered Member
Posts
358
Karma
0

Mon Nov 06, 2006 6:46 pm
Yep, I noticed that. I've tested it out and it indeed works. Well, that just leaves the holy grail of uTorrent Peer Exchange left :D
djseverin
Registered Member
Posts
10
Karma
0

Awesome

Wed Nov 08, 2006 12:27 am
jdong - great work there, I don't have the coding skill to sit down and hack up additions to kTorrent, but can appreciate what you've done there. Have got the latest SVN compiled and running. Very nice.

Ivan - was that you who contacted the uTorrent devs on their forum? If so, you are a very very patient fellow :-)

I really hope that this little DHT issue can be sorted out, the uTorrent group, and especially their users, have a great deal to gain by conforming to the standard as well.

Just wanted to let all the dev's know that your time and the work you put into kTorrent is very much appreciated!


"We are the music makers, we are the dreamers of dreams"
imported4-Ivan
Registered Member
Posts
819
Karma
0

Wed Nov 08, 2006 4:14 am
Ivan - was that you who contacted the uTorrent devs on their forum? If so, you are a very very patient fellow Smile

Yeah :)
Well, honestly I was **** having to repeat one damn thing lots of times but in hope everything will work out, I kept my patience somehow...

Any volunteers to help with that matter - feel free to jump in discussion :)
jdong
Registered Member
Posts
358
Karma
0

Wed Nov 08, 2006 5:21 am
Ivan wrote:
Ivan - was that you who contacted the uTorrent devs on their forum? If so, you are a very very patient fellow Smile

Yeah :)
Well, honestly I was **** having to repeat one damn thing lots of times but in hope everything will work out, I kept my patience somehow...

Any volunteers to help with that matter - feel free to jump in discussion :)


Well, it seems like one of us needs to find this 'ludde' guy that they speak of to advance this discussion any more.... and he's surprisingly missing in action :D


Bookmarks



Who is online

Registered users: bartoloni, Bing [Bot], Evergrowing, Google [Bot], q.ignora, watchstar