CUGL 2.5
Cornell University Game Library
|
#include <CUICEAddress.h>
Public Member Functions | |
ICEAddress () | |
ICEAddress (uint16_t port) | |
ICEAddress (const std::string address, uint16_t port=3478) | |
ICEAddress (const std::string address, const std::string username, const std::string password, uint16_t port=3478) | |
ICEAddress (const std::shared_ptr< JsonValue > &prefs) | |
ICEAddress (const ICEAddress &src)=default | |
ICEAddress (ICEAddress &&src)=default | |
~ICEAddress () | |
ICEAddress & | operator= (const ICEAddress &src)=default |
ICEAddress & | operator= (ICEAddress &&src)=default |
ICEAddress & | set (const ICEAddress &src) |
ICEAddress & | set (const std::shared_ptr< ICEAddress > &src) |
virtual ICEAddress & | set (const std::shared_ptr< JsonValue > &pref) override |
virtual const std::string | toString () const override |
Public Member Functions inherited from cugl::net::InetAddress | |
InetAddress () | |
InetAddress (uint16_t port) | |
InetAddress (const std::string address, uint16_t port=0) | |
InetAddress (const std::shared_ptr< JsonValue > &prefs) | |
InetAddress (const InetAddress &src)=default | |
InetAddress (InetAddress &&src)=default | |
~InetAddress () | |
InetAddress & | operator= (const InetAddress &src)=default |
InetAddress & | operator= (InetAddress &&src)=default |
InetAddress & | set (const InetAddress &src) |
InetAddress & | set (const std::shared_ptr< InetAddress > &src) |
virtual InetAddress & | set (const std::shared_ptr< JsonValue > &pref) |
virtual const std::string | toString () const |
Type | getType () const |
bool | isValid () const |
Public Attributes | |
bool | turn |
std::string | username |
std::string | password |
Public Attributes inherited from cugl::net::InetAddress | |
std::string | address |
uint16_t | port |
Additional Inherited Members | |
Public Types inherited from cugl::net::InetAddress | |
enum class | Type : int { INVALID = 0 , IPV4 = 1 , IPV6 = 2 , HOSTNAME = 3 } |
This class represents an ICE internet address (with a username and password).
An ICE (Interactive Connectivity Establishment) server is used to provide NAT punchthrough services. This allows players to connect across different networks, or even in the same network when the game lobby is located in another network.
ICE servers are categorized as STUN (Session Traversal Utilities for NAT) or TURN (Traversal Using Relays around NAT) servers. STUN servers use simple UDP rerouting to help players find each other. While they are successful on most networks, they can be blocked by aggressive firewalls. TURN servers act as a communication middleman for getting around firewalls.
Because STUN servers perform simple rerouting, they are freely available and do not require log-in credentials. Google has several available, such as "stun.l.google.com:19302" or "stun4.l.google.com:19302".
TURN servers must actively communicate in a session, and therefore are unlikely to be free. Most require user accounts and passwords. But the issue is entirely the compute cost. CUGL is compatible with open source TURN servers such as Violet:
https://github.com/paullouisageneau/violet
For this reason, this class will always associate a username and password with a TURN server.
Like its parent class, this class is effectively a simple struct. All attributes are publicly available and we do not use the standard CUGL shared pointer architecture. Internet addresses are designed to be use on the stack, though you can combine them with share pointers if you wish.
cugl::net::ICEAddress::ICEAddress | ( | ) |
Creates an ICE address to refer to the localhost
The address will be the hostname "localhost". It will be categorized as a STUN server with default port 3478. The constructor does not perform any validation that the combined address port are reachable.
cugl::net::ICEAddress::ICEAddress | ( | uint16_t | port | ) |
Creates an ICE address to refer to the localhost
The address will be the hostname "localhost". It will be categorized as a STUN server. The constructor does not perform any validation that the combined address port are reachable.
port | The address port |
cugl::net::ICEAddress::ICEAddress | ( | const std::string | address, |
uint16_t | port = 3478 |
||
) |
Creates an ICE address for the given address.
The address will be categorized as a STUN server. The constructor does not perform any validation that the combined address and port are reachable.
address | The address of the STUN server |
port | The address port |
cugl::net::ICEAddress::ICEAddress | ( | const std::string | address, |
const std::string | username, | ||
const std::string | password, | ||
uint16_t | port = 3478 |
||
) |
Creates an ICE address for the given address, username and password
The address will be categorized as a TURN server. The constructor does not perform any validation that the combined address and port are reachable.
address | The address of the TURN server |
username | The user name for the TURN server |
password | The password for the TURN server |
port | The address port |
cugl::net::ICEAddress::ICEAddress | ( | const std::shared_ptr< JsonValue > & | prefs | ) |
Creates this ICE address using a JSON entry.
The JSON value should be an object with at least three keys: "address", "port", and "turn". The "port" should be an integer, while "turn" is a boolean. If "turn" is true, this constructor will search for additional keys "username" and "password".
prefs | The address settings |
|
default |
Creates a copy of the given ICE address.
This copy constructor is provided so that internet addresses may be used safely on the stack, without the use of pointers.
src | The original internet address to copy |
|
default |
Creates a new ICE address with the resources of the given one.
This move constructor is provided so that internet addresses may be used efficiently on the stack, without the use of pointers.
src | The original address contributing resources |
|
inline |
Deletes this ICE address, disposing all resources
|
default |
Assigns this address to be a copy of the given ICE address.
src | The address to copy |
|
default |
Assigns this address to have the resources of the given ICE address.
src | The address to take resources from |
ICEAddress & cugl::net::ICEAddress::set | ( | const ICEAddress & | src | ) |
Assigns this address to be a copy of the given ICE address.
src | The address to copy |
ICEAddress & cugl::net::ICEAddress::set | ( | const std::shared_ptr< ICEAddress > & | src | ) |
Assigns this address to be a copy of the given ICE address.
src | The address to copy |
|
overridevirtual |
Assigns this address according to the given JSON object
The JSON value should be an object with at least three keys: "address", "port", and "turn". The "port" should be an integer, while "turn" is a boolean. If "turn" is true, this constructor will search for additional keys "username" and "password".
pref | The address settings |
Reimplemented from cugl::net::InetAddress.
|
overridevirtual |
Returns a string representation of this address.
The string with present the address in a form usable by Web RTC communication. The format is
[("stun"|"turn") "://"][username ":" password "@"]hostname[":" port]
The username and password will only be visible for a TURN server. If these values are blank, even though the address is for a TURN server, the strings "username" and "password" will be used literally.
Reimplemented from cugl::net::InetAddress.
std::string cugl::net::ICEAddress::password |
The ICE password (ignored for STUN servers)
bool cugl::net::ICEAddress::turn |
Whether this is a TURN server (false for STUN)
std::string cugl::net::ICEAddress::username |
The ICE username (ignored for STUN servers)