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

High level network layer for config object transport. More...

Classes

struct  bandwidth_in
 
struct  bandwidth_stats
 
struct  bandwidth_stats_output
 
struct  connection_stats
 
struct  error
 
struct  manager
 
struct  pending_statistics
 
struct  server_manager
 A server manager causes listening on a given port to occur for the duration of its lifetime. More...
 
struct  statistics
 

Typedefs

typedef std::map< const
std::string, bandwidth_stats
bandwidth_map
 
typedef std::vector
< bandwidth_map
hour_stats_vector
 
typedef boost::shared_ptr
< bandwidth_stats
bandwidth_stats_ptr
 
typedef int connection
 
typedef boost::shared_ptr
< bandwidth_in
bandwidth_in_ptr
 
typedef boost::error_info
< struct tag_tcpsocket,
TCPsocket > 
tcpsocket_info
 
typedef boost::error_info
< struct tag_connum,
connection
connection_info
 

Functions

connection_stats get_connection_stats (connection connection_num)
 
pending_statistics get_pending_stats ()
 
void set_raw_data_only ()
 
size_t nconnections ()
 The number of peers we are connected to. More...
 
bool is_server ()
 If we are currently accepting connections. More...
 
connection connect (const std::string &host, int port=15000)
 Function to attempt to connect to a remote host. More...
 
connection connect (const std::string &host, int port, threading::waiter &waiter)
 
connection accept_connection ()
 Function to accept a connection from a remote host. More...
 
bool disconnect (connection connection_num=0)
 Function to disconnect from a certain host, or close all connections if connection_num is 0. More...
 
void queue_disconnect (connection connection_num)
 Function to queue a disconnection. More...
 
connection receive_data (config &cfg, connection connection_num, unsigned int timeout, bandwidth_in_ptr *bandwidth_in)
 
connection 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 receive_data (std::vector< char > &buf, bandwidth_in_ptr *bandwidth_in)
 
static hour_stats_vector hour_stats (24)
 
static bandwidth_map::iterator add_bandwidth_entry (const std::string &packet_type)
 
std::string get_bandwidth_stats_all ()
 
std::string get_bandwidth_stats ()
 
std::string get_bandwidth_stats (int hour)
 
void add_bandwidth_out (const std::string &packet_type, size_t len)
 
void add_bandwidth_in (const std::string &packet_type, size_t len)
 
void send_file (const std::string &filename, connection connection_num, const std::string &packet_type)
 
size_t 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 send_raw_data (const char *buf, int len, connection connection_num, const std::string &packet_type)
 
void 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 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 ip_address (connection connection_num)
 Function to get the remote ip address of a socket. More...
 
statistics get_send_stats (connection handle)
 Function to see the number of bytes being processed on the current socket. More...
 
statistics get_receive_stats (connection handle)
 
Proxy Settings Methods

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

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

Variables

unsigned int ping_timeout = 0
 Amount of seconds after the last server ping when we assume to have timed out. More...
 
connection const null_connection = 0
 
const int ping_interval = 30
 Minimum interval between pings. More...
 

Detailed Description

High level network layer for config object transport.

This module provides high level network access using an API similar to sockets, but primarily for the transport of config objects. This is how the games protocols work - data is sent via config objects.

A client would create a manager object to initialize the network layer, connect(), and then send_data(). A server would create a server_manager object, then accept_connection(), and finally receive_data().

Typedef Documentation

Definition at line 206 of file network.hpp.

Definition at line 961 of file network.cpp.

Definition at line 989 of file network.cpp.

Definition at line 74 of file network.hpp.

typedef boost::error_info<struct tag_connum,connection> network::connection_info

Definition at line 271 of file network.hpp.

Definition at line 962 of file network.cpp.

typedef boost::error_info<struct tag_tcpsocket,TCPsocket> network::tcpsocket_info

Definition at line 270 of file network.hpp.

Function Documentation

connection network::accept_connection ( )

Function to accept a connection from a remote host.

If no host is attempting to connect, it will return 0 immediately. Otherwise returns the new connection.

Exceptions
error

A list of all the sockets which have connected, but haven't had their initial handshake received.

Definition at line 582 of file network.cpp.

References DBG_NW, ERR_NW, and WRN_NW.

Referenced by BOOST_AUTO_TEST_CASE(), campaignd::server::run(), and WESNOTH_PARAMETERIZED_TEST_CASE().

static bandwidth_map::iterator network::add_bandwidth_entry ( const std::string packet_type)
static

Definition at line 967 of file network.cpp.

References hour_stats().

Referenced by add_bandwidth_in(), and add_bandwidth_out().

void network::add_bandwidth_in ( const std::string packet_type,
size_t  len 
)

Definition at line 1059 of file network.cpp.

References add_bandwidth_entry(), and itor.

Referenced by network::bandwidth_in::~bandwidth_in().

void network::add_bandwidth_out ( const std::string packet_type,
size_t  len 
)

Definition at line 1052 of file network.cpp.

References add_bandwidth_entry(), and itor.

Referenced by network_worker_pool::queue_data(), send_file(), and send_raw_data().

connection network::connect ( const std::string host,
int  port = 15000 
)

Function to attempt to connect to a remote host.

Returns
The new connection on success, or 0 on failure.
Exceptions
error

Definition at line 498 of file network.cpp.

Referenced by BOOST_AUTO_TEST_CASE(), ng::create_engine::create_engine(), network::server_manager::server_manager(), and WESNOTH_PARAMETERIZED_TEST_CASE().

connection network::connect ( const std::string host,
int  port,
threading::waiter waiter 
)

Definition at line 506 of file network.cpp.

References check_error().

bool network::disconnect ( connection  connection_num = 0)

Function to disconnect from a certain host, or close all connections if connection_num is 0.

Returns true if the connection was disconnected. Returns false on failure to disconnect, since the socket is in the middle of sending/receiving data. The socket will be closed when it has finished its send/receive.

Definition at line 646 of file network.cpp.

References network_worker_pool::close_socket(), DBG_NW, gui2::event::find(), get_socket(), lg::info(), is_server(), and remove_connection().

Referenced by network::error::disconnect(), campaignd::server::run(), WESNOTH_PARAMETERIZED_TEST_CASE(), and network::manager::~manager().

void network::enable_connection_through_proxy ( )

Attempt to connect through a proxy (as opposed to directly.)

Use the set_proxy_* methods to configure the connection options.

Definition at line 286 of file network.cpp.

std::string network::get_bandwidth_stats ( )

Definition at line 1024 of file network.cpp.

Referenced by get_bandwidth_stats_all().

std::string network::get_bandwidth_stats ( int  hour)
std::string network::get_bandwidth_stats_all ( )

Definition at line 1014 of file network.cpp.

References get_bandwidth_stats().

connection_stats network::get_connection_stats ( connection  connection_num)

Definition at line 225 of file network.cpp.

References get_connection_details(), get_receive_stats(), and get_send_stats().

pending_statistics network::get_pending_stats ( )

Definition at line 243 of file network.cpp.

References network_worker_pool::get_pending_stats().

statistics network::get_receive_stats ( connection  handle)

Definition at line 1201 of file network.cpp.

References network_worker_pool::get_current_transfer_stats(), and get_socket().

Referenced by get_connection_stats().

statistics network::get_send_stats ( connection  handle)

Function to see the number of bytes being processed on the current socket.

Definition at line 1197 of file network.cpp.

References network_worker_pool::get_current_transfer_stats(), and get_socket().

Referenced by get_connection_stats().

static hour_stats_vector network::hour_stats ( 24  )
static
std::string network::ip_address ( connection  connection_num)

Function to get the remote ip address of a socket.

Definition at line 1179 of file network.cpp.

References get_socket(), i, and int().

Referenced by wesnothd::room_manager::process_message(), campaignd::server::run(), and campaignd::server::send_error().

bool network::is_server ( )

If we are currently accepting connections.

Definition at line 355 of file network.cpp.

Referenced by disconnect(), and receive_data().

size_t network::nconnections ( )

The number of peers we are connected to.

Definition at line 350 of file network.cpp.

Referenced by BOOST_AUTO_TEST_CASE(), and check_timeout().

void network::process_send_queue ( connection  ,
size_t   
)

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.

Definition at line 1163 of file network.cpp.

References check_error().

Referenced by campaignd::server::run().

void network::queue_disconnect ( connection  connection_num)

Function to queue a disconnection.

Next time receive_data is called, it will generate an error on the given connection (and presumably then the handling of the error will include closing the connection).

Definition at line 697 of file network.cpp.

connection network::receive_data ( config cfg,
connection  connection_num,
unsigned int  timeout,
bandwidth_in_ptr *  bandwidth_in 
)

Definition at line 702 of file network.cpp.

Referenced by receive(), and campaignd::server::run().

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.

Will store the data received in cfg. Times out after timeout milliseconds.

Returns
The connection that data was received from, or 0 if timeout occurred.
Exceptions
errorIf an error occurred.

Definition at line 725 of file network.cpp.

References ALIGN_4, check_error(), check_timeout(), DBG_NW, e, config::empty(), ERR_NW, error(), get_connection_details(), network_worker_pool::get_received_data(), get_socket(), config::has_attribute(), i, network_worker_pool::is_locked(), is_pending_remote_handle(), is_server(), lexical_cast(), LOG_NW, network_worker_pool::receive_data(), and set_remote_handle().

connection network::receive_data ( std::vector< char > &  buf,
bandwidth_in_ptr *  bandwidth_in 
)
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.

Exceptions
error

Definition at line 1098 of file network.cpp.

References DBG_NW, config::empty(), ERR_NW, i, lg::info(), LOG_NW, and network_worker_pool::queue_data().

Referenced by BOOST_AUTO_TEST_CASE(), campaignd::server::handle_request_campaign_list(), send_data_all_except(), campaignd::server::send_error(), campaignd::server::send_message(), and try_send_random_seed().

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'.

Definition at line 1168 of file network.cpp.

References i, and send_data().

void network::send_file ( const std::string filename,
connection  connection_num,
const std::string packet_type 
)
void network::send_raw_data ( const char *  buf,
int  len,
connection  connection_num,
const std::string packet_type 
)
void network::set_proxy_address ( const std::string address)

Set the address of the proxy.

Default: "localhost".

Parameters
addressNetwork address where the proxy server should be running.

Definition at line 290 of file network.cpp.

void network::set_proxy_password ( const std::string password)

Set the password to authenticate with the proxy.

Default: "".

Parameters
passwordPassword to use for authentication purposes.

Definition at line 305 of file network.cpp.

void network::set_proxy_port ( const std::string port)

Set the port of the proxy.

Default: "3128".

Parameters
portNetwork port where the proxy server should be listening.

Definition at line 295 of file network.cpp.

void network::set_proxy_user ( const std::string user)

Set the user to authenticate with the proxy.

Default: "".

Parameters
userUser name to use for authentication purposes.

Definition at line 300 of file network.cpp.

void network::set_raw_data_only ( )

Definition at line 280 of file network.cpp.

References network_worker_pool::set_raw_data_only().

Referenced by WESNOTH_PARAMETERIZED_TEST_CASE().

Variable Documentation

connection const network::null_connection = 0

Definition at line 75 of file network.hpp.

Referenced by receive(), and campaignd::server::run().

const int network::ping_interval = 30

Minimum interval between pings.

Definition at line 306 of file network.hpp.

Referenced by check_timeout().

unsigned int network::ping_timeout = 0

Amount of seconds after the last server ping when we assume to have timed out.

When set to '0' ping timeout isn't checked. Gets set in preferences::manager according to the preferences file.

Definition at line 219 of file network.cpp.

Referenced by check_timeout().