Advertisement
cooperlees

libtorrent 0.16.16 IPv6 LSD

Aug 21st, 2014
536
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 5.53 KB | None | 0 0
  1. diff --git c/0.16.16/src/libtorrent-rasterbar-0.16.16/include/libtorrent/lsd.hpp w/0.16.16/src/libtorrent-rasterbar-0.16.16/include/libtorrent/lsd.hpp
  2. index 2e10a35..57f010b 100644
  3. --- c/0.16.16/src/libtorrent-rasterbar-0.16.16/include/libtorrent/lsd.hpp
  4. +++ w/0.16.16/src/libtorrent-rasterbar-0.16.16/include/libtorrent/lsd.hpp
  5. @@ -76,6 +76,9 @@ private:
  6.     // the udp socket used to send and receive
  7.     // multicast messages on
  8.     broadcast_socket m_socket;
  9. +#if TORRENT_USE_IPV6
  10. +   broadcast_socket m_socket6;
  11. +#endif
  12.  
  13.     // used to resend udp packets in case
  14.     // they time out
  15. @@ -92,6 +95,9 @@ private:
  16.     int m_cookie;
  17.  
  18.     bool m_disabled;
  19. +#if TORRENT_USE_IPV6
  20. +   bool m_disabled6;
  21. +#endif
  22.  #if defined(TORRENT_LOGGING) || defined(TORRENT_VERBOSE_LOGGING)
  23.     FILE* m_log;
  24.  #endif
  25. diff --git c/0.16.16/src/libtorrent-rasterbar-0.16.16/src/broadcast_socket.cpp w/0.16.16/src/libtorrent-rasterbar-0.16.16/src/broadcast_socket.cpp
  26. index 7902ebd..9710f1e 100644
  27. --- c/0.16.16/src/libtorrent-rasterbar-0.16.16/src/broadcast_socket.cpp
  28. +++ w/0.16.16/src/libtorrent-rasterbar-0.16.16/src/broadcast_socket.cpp
  29. @@ -204,7 +204,7 @@ namespace libtorrent
  30.                 - common_bits(b1.data(), b2.data(), b1.size());
  31.  #if TORRENT_USE_IPV6
  32.         }
  33. -  
  34. +
  35.         address_v6::bytes_type b1;
  36.         address_v6::bytes_type b2;
  37.         if (a1.is_v4()) b1 = address_v6::v4_mapped(a1.to_v4()).to_bytes();
  38. @@ -239,7 +239,7 @@ namespace libtorrent
  39.         else
  40.  #endif
  41.             open_multicast_socket(ios, address_v4::any(), loopback, ec);
  42. -      
  43. +
  44.         for (std::vector<ip_interface>::const_iterator i = interfaces.begin()
  45.             , end(interfaces.end()); i != end; ++i)
  46.         {
  47. @@ -249,6 +249,19 @@ namespace libtorrent
  48.             if (!loopback && is_loopback(i->interface_address)) continue;
  49.  
  50.             ec = error_code();
  51. +#if TORRENT_USE_IPV6
  52. +           if (i->interface_address.is_v6() &&
  53. +               i->interface_address.to_v6().is_link_local()) {
  54. +               address_v6 addr6 = i->interface_address.to_v6();
  55. +               addr6.scope_id(if_nametoindex(i->name));
  56. +               open_multicast_socket(ios, addr6, loopback, ec);
  57. +
  58. +               address_v4 const& mask = i->netmask.is_v4() ?
  59. +                   i->netmask.to_v4() : address_v4();
  60. +               open_unicast_socket(ios, addr6, mask);
  61. +               continue;
  62. +           }
  63. +#endif
  64.             open_multicast_socket(ios, i->interface_address, loopback, ec);
  65.  #ifdef TORRENT_DEBUG
  66.  //         fprintf(stderr, "broadcast socket [ if: %s group: %s mask: %s ] %s\n"
  67. diff --git c/0.16.16/src/libtorrent-rasterbar-0.16.16/src/lsd.cpp w/0.16.16/src/libtorrent-rasterbar-0.16.16/src/lsd.cpp
  68. index d78dd2e..547f21c 100644
  69. --- c/0.16.16/src/libtorrent-rasterbar-0.16.16/src/lsd.cpp
  70. +++ w/0.16.16/src/libtorrent-rasterbar-0.16.16/src/lsd.cpp
  71. @@ -72,10 +72,15 @@ lsd::lsd(io_service& ios, address const& listen_interface
  72.     : m_callback(cb)
  73.     , m_socket(udp::endpoint(address_v4::from_string("239.192.152.143", ec), 6771)
  74.         , boost::bind(&lsd::on_announce, self(), _1, _2, _3))
  75. +#if TORRENT_USE_IPV6
  76. +   , m_socket6(udp::endpoint(address_v6::from_string("ff15::efc0:988f", ec), 6771)
  77. +       , boost::bind(&lsd::on_announce, self(), _1, _2, _3))
  78. +#endif
  79.     , m_broadcast_timer(ios)
  80.     , m_retry_count(1)
  81.     , m_cookie(random())
  82.     , m_disabled(false)
  83. +   , m_disabled6(false)
  84.  {
  85.  #if defined(TORRENT_LOGGING) || defined(TORRENT_VERBOSE_LOGGING)
  86.     m_log = fopen("lsd.log", "w+");
  87. @@ -96,6 +101,19 @@ lsd::lsd(io_service& ios, address const& listen_interface
  88.             , ec.value(), ec.message().c_str());
  89.     }
  90.  #endif
  91. +
  92. +#if TORRENT_USE_IPV6
  93. +   m_socket6.open(ios, ec);
  94. +#if defined(TORRENT_LOGGING) || defined(TORRENT_VERBOSE_LOGGING)
  95. +   if (ec)
  96. +   {
  97. +       if (m_log) fprintf(m_log, "FAILED TO OPEN SOCKET6: (%d) %s\n"
  98. +           , ec.value(), ec.message().c_str());
  99. +   }
  100. +#endif
  101. +#endif
  102. +
  103. +
  104.  }
  105.  
  106.  lsd::~lsd()
  107. @@ -107,14 +125,19 @@ lsd::~lsd()
  108.  
  109.  void lsd::announce(sha1_hash const& ih, int listen_port, bool broadcast)
  110.  {
  111. -   if (m_disabled) return;
  112. +#if TORRENT_USE_IPV6
  113. +   if (m_disabled && m_disabled6)
  114. +#else
  115. +   if (m_disabled)
  116. +#endif
  117. +       return;
  118.  
  119.     char ih_hex[41];
  120.     to_hex((char const*)&ih[0], 20, ih_hex);
  121.     char msg[200];
  122.     int msg_len = snprintf(msg, sizeof(msg),
  123.         "BT-SEARCH * HTTP/1.1\r\n"
  124. -       "Host: 239.192.152.143:6771\r\n"
  125. +       "Host: [ff15::efc0:988f]:6771\r\n"
  126.         "Port: %d\r\n"
  127.         "Infohash: %s\r\n"
  128.         "cookie: %x\r\n"
  129. @@ -140,9 +163,31 @@ void lsd::announce(sha1_hash const& ih, int listen_port, bool broadcast)
  130.         }
  131.  #endif
  132.  
  133. -       return;
  134.     }
  135.  
  136. +#if TORRENT_USE_IPV6
  137. +   m_socket6.send(msg, msg_len, ec, broadcast ? broadcast_socket::broadcast : 0);
  138. +   if (ec)
  139. +   {
  140. +       m_disabled6 = true;
  141. +#if defined(TORRENT_LOGGING) || defined(TORRENT_VERBOSE_LOGGING)
  142. +       {
  143. +           if (m_log) fprintf(m_log, "%s failed to send message6: (%d) %s"
  144. +               , time_now_string(), ec.value(), ec.message().c_str());
  145. +       }
  146. +#endif
  147. +
  148. +   }
  149. +#endif
  150. +
  151. +
  152. +#if TORRENT_USE_IPV6
  153. +   if (m_disabled && m_disabled6)
  154. +#else
  155. +   if (m_disabled)
  156. +#endif
  157. +       return;
  158. +
  159.  #if defined TORRENT_ASIO_DEBUGGING
  160.     add_outstanding_async("lsd::resend_announce");
  161.  #endif
  162. @@ -160,6 +205,9 @@ void lsd::resend_announce(error_code const& e, std::string msg)
  163.  
  164.     error_code ec;
  165.     m_socket.send(msg.c_str(), int(msg.size()), ec);
  166. +#if TORRENT_USE_IPV6
  167. +   m_socket6.send(msg.c_str(), int(msg.size()), ec);
  168. +#endif
  169.  
  170.     ++m_retry_count;
  171.     if (m_retry_count >= 3) return;
  172. @@ -266,9 +314,15 @@ void lsd::on_announce(udp::endpoint const& from, char* buffer
  173.  void lsd::close()
  174.  {
  175.     m_socket.close();
  176. +#if TORRENT_USE_IPV6
  177. +   m_socket6.close();
  178. +#endif
  179.     error_code ec;
  180.     m_broadcast_timer.cancel(ec);
  181.     m_disabled = true;
  182. +#if TORRENT_USE_IPV6
  183. +   m_disabled6 = true;
  184. +#endif
  185.     m_callback.clear();
  186.  }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement