Commit 3c853091 by James R.

ass

parent 8838c63b
......@@ -1907,6 +1907,11 @@ static void SendAskInfo(INT32 node)
netbuffer->u.askinfo.version = VERSION;
netbuffer->u.askinfo.time = (tic_t)LONG(asktime);
if (node != 0)
{
I_NetRelay(node);
}
// Even if this never arrives due to the host being firewalled, we've
// now allowed traffic from the host to us in, so once the MS relays
// our address to the host, it'll be able to speak to us.
......
......@@ -75,6 +75,7 @@ int snprintf(char *str, size_t n, const char *fmt, ...);
#include "fastcmp.h"
#include "keys.h"
#include "filesrch.h" // refreshdirmenu
#include "i_net.h"
#ifdef CMAKECONFIG
#include "config.h"
......@@ -663,6 +664,7 @@ tic_t rendergametic;
void D_SRB2Loop(void)
{
tic_t oldentertics = 0, entertic = 0, realtics = 0, rendertimeout = INFTICS;
tic_t relaytic = 0;
if (dedicated)
server = true;
......@@ -768,6 +770,16 @@ void D_SRB2Loop(void)
if (realtics > 8)
realtics = 1;
if (entertic > relaytic && serverrunning)
{
doomcom->remotenode = I_NetMakeNodewPort("skyhook.jameds.org", "7777");
doomcom->datalength = 0;
CONS_Printf("ping relay %s\n", I_GetNodeAddress(doomcom->remotenode));
I_NetSend();
Net_CloseConnection(doomcom->remotenode);
relaytic = entertic + 30*NEWTICRATE;
}
// process tics (but maybe not if realtic == 0)
TryRunTics(realtics);
......
......@@ -67,6 +67,7 @@ INT16 hardware_MAXPACKETLENGTH;
boolean (*I_NetGet)(void) = NULL;
void (*I_NetSend)(void) = NULL;
void (*I_NetRelay)(int node) = NULL;
boolean (*I_NetCanSend)(void) = NULL;
boolean (*I_NetCanGet)(void) = NULL;
void (*I_NetCloseSocket)(void) = NULL;
......
......@@ -95,6 +95,10 @@ extern boolean (*I_NetCanGet)(void);
*/
extern void (*I_NetSend)(void);
/** \brief forward hole punching request
*/
extern void (*I_NetRelay)(int node);
/** \brief ask to driver if all is ok to send data now
*/
extern boolean (*I_NetCanSend)(void);
......
......@@ -597,6 +597,29 @@ void Command_Numnodes(void)
#endif
#ifndef NONET
static boolean SOCK_GotRelay(ssize_t c)
{
if (c == 10)
{
struct sockaddr_in sin;
sin.sin_family = AF_INET;
memcpy(&sin.sin_port, &doomcom->data[4], 2U);
memcpy(&sin.sin_addr.s_addr, &doomcom->data[6], 4U);
CONS_Printf("got relay for %s\n", SOCK_AddrToStr((mysockaddr_t *)&sin));
sendto(mysockets[0], NULL, 0, 0, (struct sockaddr *)&sin, sizeof sin);
return true;
}
else
{
return false;
}
}
// Returns true if a packet was received from a new node, false in all other cases
static boolean SOCK_Get(void)
{
......@@ -613,6 +636,11 @@ static boolean SOCK_Get(void)
(void *)&fromaddress, &fromlen);
if (c != ERRSOCKET)
{
if (SOCK_GotRelay(c))
{
return false;
}
#ifdef USE_STUN
if (STUN_got_response(doomcom->data, c))
{
......@@ -801,6 +829,25 @@ static void SOCK_FreeNodenum(INT32 numnode)
// put invalid address
memset(&clientaddress[numnode], 0, sizeof (clientaddress[numnode]));
}
static void SOCK_Relay(int node)
{
const struct sockaddr_in * sin = &clientaddress[node].ip4;
const UINT32 addr = sin->sin_addr.s_addr;
const UINT16 port = sin->sin_port;
memcpy(&doomcom->data[0], &port, 2U);
memcpy(&doomcom->data[2], &addr, 4U);
CONS_Printf("request relay for %s (node %d)\n", SOCK_GetNodeAddress(node), node);
doomcom->remotenode = I_NetMakeNodewPort("skyhook.jameds.org", "7777");
doomcom->datalength = 6;
SOCK_Send();
SOCK_FreeNodenum(doomcom->remotenode);
}
#endif
//
......@@ -1380,6 +1427,7 @@ static boolean SOCK_OpenSocket(void)
I_NetCloseSocket = SOCK_CloseSocket;
I_NetFreeNodenum = SOCK_FreeNodenum;
I_NetMakeNodewPort = SOCK_NetMakeNodewPort;
I_NetRelay = SOCK_Relay;
#ifdef SELECTTEST
// seem like not work with libsocket : (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment