Backported campaignd send size statistics to 1.4

This commit is contained in:
Pauli Nieminen 2008-08-06 15:28:35 +00:00
parent bf3757bf4d
commit 49526da064
5 changed files with 22 additions and 21 deletions

View file

@ -318,7 +318,7 @@ namespace {
config data;
while((sock = network::receive_data(data, 0, &gzipped)) != network::null_connection) {
if(const config* req = data.child("request_campaign_list")) {
LOG_CS << "sending campaign list to " << network::ip_address(sock) << (gzipped?" using gzip":"") << "\n";
LOG_CS << "sending campaign list to " << network::ip_address(sock) << (gzipped?" using gzip":"");
time_t epoch = time(NULL);
config campaign_list;
(campaign_list)["timestamp"] = lexical_cast<std::string>(epoch);
@ -373,28 +373,26 @@ namespace {
config response;
response.add_child("campaigns",campaign_list);
network::send_data(response, sock, gzipped);
std::cerr << " size: " << (network::send_data(response, sock, gzipped)/1024) << "kb\n";
} else if(const config* req = data.child("request_campaign")) {
LOG_CS << "sending campaign '" << (*req)["name"] << "' to " << network::ip_address(sock) << (gzipped?" using gzip":"") << "\n";
LOG_CS << "sending campaign '" << (*req)["name"] << "' to " << network::ip_address(sock) << (gzipped?" using gzip":"");
config* const campaign = campaigns().find_child("campaign","name",(*req)["name"]);
if(campaign == NULL) {
network::send_data(construct_error("Add-on '" + (*req)["name"] + "'not found."), sock, gzipped);
std::cerr << "\n";
} else {
if (gzipped)
{
std::cerr << " size: " << (file_size((*campaign)["filename"])/1024) << "\n";
network::send_file((*campaign)["filename"], sock);
#if 0
util::scoped_resource<char*,util::delete_array> buf(new char[size+1]);
stream->read(buf,size);
network::send_raw_data(buf, size, sock);
#endif
} else {
scoped_istream stream = istream_file((*campaign)["filename"]);
config cfg;
read_gz(cfg, *stream);
network::send_data(cfg, sock, false);
std::cerr << " size: " <<
network::send_data(cfg, sock, false)
<< "\n";
}
const int downloads = lexical_cast_default<int>((*campaign)["downloads"],0)+1;

View file

@ -1016,43 +1016,44 @@ void send_file(const std::string& filename, connection connection_num, const std
//! @todo Note the gzipped parameter should be removed later, we want to send
//! all data gzipped. This can be done once the campaign server is also updated
//! to work with gzipped data.
void send_data(const config& cfg, connection connection_num, const bool gzipped, const std::string packet_type
size_t send_data(const config& cfg, connection connection_num, const bool gzipped, const std::string packet_type
)
{
DBG_NW << "in send_data()...\n";
if(cfg.empty()) {
return;
return 0;
}
if(bad_sockets.count(connection_num) || bad_sockets.count(0)) {
return;
return 0;
}
// log_scope2(network, "sending data");
if(!connection_num) {
DBG_NW << "sockets: " << sockets.size() << "\n";
size_t size;
for(sockets_list::const_iterator i = sockets.begin();
i != sockets.end(); ++i) {
DBG_NW << "server socket: " << server_socket << "\ncurrent socket: " << *i << "\n";
send_data(cfg,*i, gzipped
size = send_data(cfg,*i, gzipped
#ifdef BANDWIDTH_MONITOR
, packet_type
#endif
);
}
return;
return size;
}
const connection_map::iterator info = connections.find(connection_num);
if (info == connections.end()) {
ERR_NW << "Error: socket: " << connection_num
<< "\tnot found in connection_map. Not sending...\n";
return;
return 0;
}
LOG_NW << "SENDING to: " << connection_num << ": " << cfg;
network_worker_pool::queue_data(info->second.sock, cfg, gzipped
return network_worker_pool::queue_data(info->second.sock, cfg, gzipped
#ifdef BANDWIDTH_MONITOR
, packet_type
#endif

View file

@ -181,7 +181,7 @@ void send_file(const std::string&, connection, const std::string packet_type = "
//! Function to send data down a given connection,
//! or broadcast to all peers if connection_num is 0.
//! Throws error.
void send_data(const config& cfg, connection connection_num /*= 0*/, const bool gzipped, const std::string packet_type = "unknown");
size_t send_data(const config& cfg, connection connection_num /*= 0*/, const bool gzipped, const std::string packet_type = "unknown");
void send_raw_data(const char* buf, int len, connection connection_num, const std::string packet_type = "unknown");

View file

@ -897,7 +897,7 @@ void queue_raw_data(TCPsocket sock, const char* buf, int len)
queue_buffer(sock, queued_buf);
}
void queue_data(TCPsocket sock,const config& buf, const bool gzipped
size_t queue_data(TCPsocket sock,const config& buf, const bool gzipped
#ifdef BANDWIDTH_MONITOR
, const std::string& packet_type
#endif
@ -908,10 +908,12 @@ void queue_data(TCPsocket sock,const config& buf, const bool gzipped
buffer* queued_buf = new buffer(sock);
output_to_buffer(sock, buf, queued_buf->stream, gzipped);
queued_buf->gzipped = gzipped;
size_t size = queued_buf->stream.str().size();
#ifdef BANDWIDTH_MONITOR
network::add_bandwidth_out(packet_type, queued_buf->stream.str().size());
network::add_bandwidth_out(packet_type, size);
#endif
queue_buffer(sock, queued_buf);
return size;
}
namespace

View file

@ -61,7 +61,7 @@ TCPsocket get_received_data(std::vector<char>& buf);
void queue_file(TCPsocket sock, const std::string&);
void queue_raw_data(TCPsocket sock, const char* buf, int len);
void queue_data(TCPsocket sock, const config& buf, const bool gzipped
size_t queue_data(TCPsocket sock, const config& buf, const bool gzipped
#ifdef BANDWIDTH_MONITOR
, const std::string& packet_type
#endif