CUGL 2.5
Cornell University Game Library
Loading...
Searching...
No Matches
Public Member Functions | Public Attributes | List of all members
cugl::net::ICEAddress Class Reference

#include <CUICEAddress.h>

Inheritance diagram for cugl::net::ICEAddress:
cugl::net::InetAddress

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 ()
 
ICEAddressoperator= (const ICEAddress &src)=default
 
ICEAddressoperator= (ICEAddress &&src)=default
 
ICEAddressset (const ICEAddress &src)
 
ICEAddressset (const std::shared_ptr< ICEAddress > &src)
 
virtual ICEAddressset (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 ()
 
InetAddressoperator= (const InetAddress &src)=default
 
InetAddressoperator= (InetAddress &&src)=default
 
InetAddressset (const InetAddress &src)
 
InetAddressset (const std::shared_ptr< InetAddress > &src)
 
virtual InetAddressset (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 }
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ ICEAddress() [1/7]

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.

◆ ICEAddress() [2/7]

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.

Parameters
portThe address port

◆ ICEAddress() [3/7]

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.

Parameters
addressThe address of the STUN server
portThe address port

◆ ICEAddress() [4/7]

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.

Parameters
addressThe address of the TURN server
usernameThe user name for the TURN server
passwordThe password for the TURN server
portThe address port

◆ ICEAddress() [5/7]

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

Parameters
prefsThe address settings

◆ ICEAddress() [6/7]

cugl::net::ICEAddress::ICEAddress ( const ICEAddress src)
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.

Parameters
srcThe original internet address to copy

◆ ICEAddress() [7/7]

cugl::net::ICEAddress::ICEAddress ( ICEAddress &&  src)
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.

Parameters
srcThe original address contributing resources

◆ ~ICEAddress()

cugl::net::ICEAddress::~ICEAddress ( )
inline

Deletes this ICE address, disposing all resources

Member Function Documentation

◆ operator=() [1/2]

ICEAddress & cugl::net::ICEAddress::operator= ( const ICEAddress src)
default

Assigns this address to be a copy of the given ICE address.

Parameters
srcThe address to copy
Returns
a reference to this address for chaining purposes.

◆ operator=() [2/2]

ICEAddress & cugl::net::ICEAddress::operator= ( ICEAddress &&  src)
default

Assigns this address to have the resources of the given ICE address.

Parameters
srcThe address to take resources from
Returns
a reference to this address for chaining purposes.

◆ set() [1/3]

ICEAddress & cugl::net::ICEAddress::set ( const ICEAddress src)

Assigns this address to be a copy of the given ICE address.

Parameters
srcThe address to copy
Returns
a reference to this address for chaining purposes.

◆ set() [2/3]

ICEAddress & cugl::net::ICEAddress::set ( const std::shared_ptr< ICEAddress > &  src)

Assigns this address to be a copy of the given ICE address.

Parameters
srcThe address to copy
Returns
a reference to this address for chaining purposes.

◆ set() [3/3]

virtual ICEAddress & cugl::net::ICEAddress::set ( const std::shared_ptr< JsonValue > &  pref)
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".

Parameters
prefThe address settings
Returns
a reference to this address for chaining purposes.

Reimplemented from cugl::net::InetAddress.

◆ toString()

virtual const std::string cugl::net::ICEAddress::toString ( ) const
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.

Returns
a string representation of this address.

Reimplemented from cugl::net::InetAddress.

Member Data Documentation

◆ password

std::string cugl::net::ICEAddress::password

The ICE password (ignored for STUN servers)

◆ turn

bool cugl::net::ICEAddress::turn

Whether this is a TURN server (false for STUN)

◆ username

std::string cugl::net::ICEAddress::username

The ICE username (ignored for STUN servers)


The documentation for this class was generated from the following file: