Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
StunClient.h
Go to the documentation of this file.
1/* Copyright (C) 2021 Wildfire Games.
2 * Copyright (C) 2013-2016 SuperTuxKart-Team.
3 * This file is part of 0 A.D.
4 *
5 * 0 A.D. is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * 0 A.D. is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19#ifndef STUNCLIENT_H
20#define STUNCLIENT_H
21
22#include "ps/CStrForward.h"
23
24#include <string>
25
26typedef struct _ENetHost ENetHost;
27
28namespace StunClient
29{
30/**
31 * Return the publicly accessible IP of the given ENet host/socket.
32 * This is done by contacting STUN server.
33 * The return IP & port should only be considered valid for the give host/socket.
34 */
35bool FindPublicIP(ENetHost& enetClient, CStr8& ip, u16& port);
36
37/**
38 * Send a message to the target server with the given ENet host/socket.
39 * This will open a port on the local gateway (if any) to receive trafic,
40 * allowing the recipient to answer (thus 'punching a hole' in the NAT).
41 * NB: this assumes consistent NAT, i.e. the outgoing port is always the same for the given client,
42 * thus allowing the IP discovered via STUN to be sent to the target server.
43 */
44void SendHolePunchingMessages(ENetHost& enetClient, const std::string& serverAddress, u16 serverPort);
45
46/**
47 * Return the local IP.
48 * Technically not a STUN method, but convenient to define here.
49 */
50bool FindLocalIP(CStr8& ip);
51}
52
53#endif // STUNCLIENT_H
struct _ENetHost ENetHost
Definition: NetClient.h:37
Definition: StunClient.cpp:35
bool FindPublicIP(ENetHost &transactionHost, CStr &ip, u16 &port)
Definition: StunClient.cpp:338
bool FindLocalIP(CStr &ip)
Definition: StunClient.cpp:375
void SendHolePunchingMessages(ENetHost &enetClient, const std::string &serverAddress, u16 serverPort)
Send a message to the target server with the given ENet host/socket.
Definition: StunClient.cpp:355
uint16_t u16
Definition: types.h:38