~ubuntu-branches/ubuntu/maverick/libtorrent-rasterbar/maverick

« back to all changes in this revision

Viewing changes to src/lsd.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Christophe Sauthier
  • Date: 2010-08-10 12:59:37 UTC
  • mfrom: (1.3.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20100810125937-jbcmmf17y8yo9hgz
Tags: 0.15.0-0ubuntu1
* New upstream version.
* debian/patches/100_fix_html_docs.patch: refreshed.
* debian/control: bump up standards-version to 3.9.1 (no changes).

Show diffs side-by-side

added added

removed removed

Lines of Context:
83
83
{
84
84
        if (m_disabled) return;
85
85
 
86
 
        std::stringstream btsearch;
87
 
        btsearch << "BT-SEARCH * HTTP/1.1\r\n"
 
86
        char ih_hex[41];
 
87
        to_hex((char const*)&ih[0], 20, ih_hex);
 
88
        char msg[200];
 
89
        int msg_len = snprintf(msg, sizeof(msg),
 
90
                "BT-SEARCH * HTTP/1.1\r\n"
88
91
                "Host: 239.192.152.143:6771\r\n"
89
 
                "Port: " << to_string(listen_port).elems << "\r\n"
90
 
                "Infohash: " << ih << "\r\n"
91
 
                "\r\n\r\n";
92
 
        std::string const& msg = btsearch.str();
 
92
                "Port: %d\r\n"
 
93
                "Infohash: %s\r\n"
 
94
                "\r\n\r\n", listen_port, ih_hex);
93
95
 
94
96
        m_retry_count = 1;
95
97
        error_code ec;
96
 
        m_socket.send(msg.c_str(), int(msg.size()), ec);
 
98
        m_socket.send(msg, msg_len, ec);
97
99
        if (ec)
98
100
        {
99
101
                m_disabled = true;
101
103
        }
102
104
 
103
105
#if defined(TORRENT_LOGGING) || defined(TORRENT_VERBOSE_LOGGING)
104
 
        m_log << time_now_string()
105
 
                << " ==> announce: ih: " << ih << " port: " << to_string(listen_port).elems << std::endl;
 
106
        {
 
107
                char msg[200];
 
108
                snprintf(msg, sizeof(msg), "%s ==> announce: ih: %s port: %u"
 
109
                        , time_now_string(), ih_hex, listen_port);
 
110
                m_log << msg << std::endl;
 
111
        }
106
112
#endif
107
113
 
108
114
        m_broadcast_timer.expires_from_now(milliseconds(250 * m_retry_count), ec);
109
 
        m_broadcast_timer.async_wait(boost::bind(&lsd::resend_announce, self(), _1, msg));
 
115
        m_broadcast_timer.async_wait(boost::bind(&lsd::resend_announce, self(), _1
 
116
                , std::string(msg)));
110
117
}
111
118
 
112
119
void lsd::resend_announce(error_code const& e, std::string msg)
139
146
        {
140
147
#if defined(TORRENT_LOGGING) || defined(TORRENT_VERBOSE_LOGGING)
141
148
        m_log << time_now_string()
142
 
                << " <== announce: incomplete HTTP message\n";
 
149
                << " <== announce: incomplete HTTP message" << std::endl;
143
150
#endif
144
151
                return;
145
152
        }
174
181
        }
175
182
 
176
183
        sha1_hash ih(0);
177
 
        std::istringstream ih_sstr(ih_str);
178
 
        ih_sstr >> ih;
 
184
        from_hex(ih_str.c_str(), 40, (char*)&ih[0]);
179
185
        int port = std::atoi(port_str.c_str());
180
186
 
181
187
        if (!ih.is_all_zeros() && port != 0)
182
188
        {
183
189
#if defined(TORRENT_LOGGING) || defined(TORRENT_VERBOSE_LOGGING)
184
 
                m_log << time_now_string()
185
 
                        << " *** incoming local announce " << from.address()
186
 
                        << ":" << to_string(port).elems << " ih: " << ih << std::endl;
 
190
                char msg[200];
 
191
                snprintf(msg, 200, "%s *** incoming local announce %s:%d ih: %s\n"
 
192
                        , time_now_string(), print_address(from.address()).c_str()
 
193
                        , port, ih_str.c_str());
187
194
#endif
188
195
                // we got an announce, pass it on through the callback
189
196
#ifndef BOOST_NO_EXCEPTIONS