The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Classes | Namespaces | Macros | Typedefs | Functions | Variables
network.cpp File Reference

Networking. More...

#include "global.hpp"
#include "gettext.hpp"
#include "log.hpp"
#include "network_worker.hpp"
#include "serialization/string_utils.hpp"
#include "thread.hpp"
#include "util.hpp"
#include "config.hpp"
#include "filesystem.hpp"
#include <cerrno>
#include <queue>
#include <iomanip>
#include <set>
#include <cstring>
#include <stdexcept>
#include <sstream>
#include <boost/exception/get_error_info.hpp>
#include <boost/exception/info.hpp>
#include <signal.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <fcntl.h>
Include dependency graph for network.cpp:

Go to the source code of this file.

Classes

struct  network::bandwidth_stats
 
struct  network::bandwidth_stats_output
 

Namespaces

 network
 High level network layer for config object transport.
 

Macros

#define SOCKET   int
 
#define DBG_NW   LOG_STREAM(debug, log_network)
 
#define LOG_NW   LOG_STREAM(info, log_network)
 
#define WRN_NW   LOG_STREAM(warn, log_network)
 
#define ERR_NW   LOG_STREAM(err, log_network)
 

Typedefs

typedef std::map< const
std::string, bandwidth_stats > 
network::bandwidth_map
 
typedef std::vector
< bandwidth_map > 
network::hour_stats_vector
 
typedef boost::shared_ptr
< bandwidth_stats > 
network::bandwidth_stats_ptr
 

Functions

static int create_connection (TCPsocket sock, const std::string &host, int port)
 
static connection_details & get_connection_details (network::connection handle)
 
static TCPsocket get_socket (network::connection handle)
 
static void remove_connection (network::connection handle)
 
static bool is_pending_remote_handle (network::connection handle)
 
static void set_remote_handle (network::connection handle, int remote_handle)
 
static void check_error ()
 
static void check_timeout ()
 Check whether too much time since the last server ping has passed and we timed out. More...
 
connection_stats network::get_connection_stats (connection connection_num)
 
pending_statistics network::get_pending_stats ()
 
void network::set_raw_data_only ()
 
size_t network::nconnections ()
 The number of peers we are connected to. More...
 
bool network::is_server ()
 If we are currently accepting connections. More...
 
connection network::connect (const std::string &host, int port=15000)
 Function to attempt to connect to a remote host. More...
 
connection network::connect (const std::string &host, int port, threading::waiter &waiter)
 
connection network::accept_connection ()
 Function to accept a connection from a remote host. More...
 
bool network::disconnect (connection connection_num=0)
 Function to disconnect from a certain host, or close all connections if connection_num is 0. More...
 
void network::queue_disconnect (connection connection_num)
 Function to queue a disconnection. More...
 
connection network::receive_data (config &cfg, connection connection_num, unsigned int timeout, bandwidth_in_ptr *bandwidth_in)
 
connection network::receive_data (config &cfg, connection connection_num=0, bandwidth_in_ptr *b=0)
 Function to receive data from either a certain connection, or all connections if connection_num is 0. More...
 
connection network::receive_data (std::vector< char > &buf, bandwidth_in_ptr *bandwidth_in)
 
static hour_stats_vector network::hour_stats (24)
 
static bandwidth_map::iterator network::add_bandwidth_entry (const std::string &packet_type)
 
std::string network::get_bandwidth_stats_all ()
 
std::string network::get_bandwidth_stats ()
 
std::string network::get_bandwidth_stats (int hour)
 
void network::add_bandwidth_out (const std::string &packet_type, size_t len)
 
void network::add_bandwidth_in (const std::string &packet_type, size_t len)
 
void network::send_file (const std::string &filename, connection connection_num, const std::string &packet_type)
 
size_t network::send_data (const config &cfg, connection connection_num=0, const std::string &packet_type="unknown")
 Function to send data down a given connection, or broadcast to all peers if connection_num is 0. More...
 
void network::send_raw_data (const char *buf, int len, connection connection_num, const std::string &packet_type)
 
void network::process_send_queue (connection connection_num=0, size_t max_size=0)
 Function to send any data that is in a connection's send_queue, up to a maximum of 'max_size' bytes – or the entire send queue if 'max_size' bytes is 0. More...
 
void network::send_data_all_except (const config &cfg, connection connection_num, const std::string &packet_type="unknown")
 Function to send data to all peers except 'connection_num'. More...
 
std::string network::ip_address (connection connection_num)
 Function to get the remote ip address of a socket. More...
 
statistics network::get_send_stats (connection handle)
 Function to see the number of bytes being processed on the current socket. More...
 
statistics network::get_receive_stats (connection handle)
 
Proxy Settings Methods

Methods to configure the connection of a client through a proxy server.

void network::enable_connection_through_proxy ()
 Attempt to connect through a proxy (as opposed to directly.) More...
 
void network::set_proxy_address (const std::string &address)
 Set the address of the proxy. More...
 
void network::set_proxy_port (const std::string &port)
 Set the port of the proxy. More...
 
void network::set_proxy_user (const std::string &user)
 Set the user to authenticate with the proxy. More...
 
void network::set_proxy_password (const std::string &password)
 Set the password to authenticate with the proxy. More...
 

Variables

static lg::log_domain log_network ("network")
 
unsigned int network::ping_timeout = 0
 Amount of seconds after the last server ping when we assume to have timed out. More...
 

Detailed Description

Networking.

Definition in file network.cpp.

Macro Definition Documentation

#define DBG_NW   LOG_STREAM(debug, log_network)
#define ERR_NW   LOG_STREAM(err, log_network)
#define LOG_NW   LOG_STREAM(info, log_network)

Definition at line 63 of file network.cpp.

Referenced by check_timeout(), network::receive_data(), and network::send_data().

#define SOCKET   int

Definition at line 56 of file network.cpp.

#define WRN_NW   LOG_STREAM(warn, log_network)

Definition at line 64 of file network.cpp.

Referenced by network::accept_connection().

Function Documentation

static void check_error ( )
static
static void check_timeout ( )
static

Check whether too much time since the last server ping has passed and we timed out.

If the last check is too long ago reset the last_ping to 'now'. This happens when we "freeze" the client one way or another or we just didn't try to receive data.

Definition at line 155 of file network.cpp.

References DBG_NW, ERR_NW, error(), LOG_NW, network::nconnections(), network::ping_interval, and network::ping_timeout.

Referenced by network::receive_data().

static int create_connection ( TCPsocket  sock,
const std::string host,
int  port 
)
static

Definition at line 100 of file network.cpp.

static connection_details& get_connection_details ( network::connection  handle)
static
static TCPsocket get_socket ( network::connection  handle)
static
static bool is_pending_remote_handle ( network::connection  handle)
static

Definition at line 126 of file network.cpp.

References get_connection_details().

Referenced by network::receive_data().

static void remove_connection ( network::connection  handle)
static

Definition at line 121 of file network.cpp.

Referenced by network::disconnect(), and network::server_manager::stop().

static void set_remote_handle ( network::connection  handle,
int  remote_handle 
)
static

Definition at line 132 of file network.cpp.

References get_connection_details().

Referenced by network::receive_data().

Variable Documentation

Definition at line 390 of file network.cpp.

Definition at line 377 of file network.cpp.

std::string error_

Definition at line 376 of file network.cpp.

std::string host_

Definition at line 374 of file network.cpp.

IPaddress localAddress

Definition at line 392 of file network.cpp.

lg::log_domain log_network("network")
static
int port_

Definition at line 375 of file network.cpp.

int ready

Definition at line 389 of file network.cpp.

IPaddress remoteAddress

Definition at line 391 of file network.cpp.

int sflag

Definition at line 393 of file network.cpp.