Merge pull request #16 from joonicks/dev

network outage fix
This commit is contained in:
joonicks 2020-05-25 14:56:12 +02:00 committed by GitHub
commit 8fb7ecc692
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 53 additions and 36 deletions

View File

@ -1,5 +1,7 @@
3.1 -- WORK IN PROGRESS (~May, 2018)
* Fixed: If the network interface goes down, the mech will mark all servers as unconnectable,
permanently, so even when the network comes back up... Fixed!
* Fixed: Bug with bigsay characters defined with blank lines.
* Changed: Session config is saved to "filename.sessiontemp" and once the save is complete
its moved to "filename.session", just in case something happens that might create a corrupt

View File

@ -216,7 +216,7 @@ int write_session(void)
#ifdef DYNCMD
/*
* because of "chaccess XXX disable" its best to save chaccess last
* because of "chaccess ___ disable" its best to save chaccess last
*/
for(j=0;mcmd[j].name;j++)
{
@ -689,7 +689,7 @@ void connect_to_server(void)
{
if ((!sptry) || (sp->usenum < sptry->usenum))
{
if (sp->err == 0)
if (sp->err == 0 || sp->err == SP_ERRCONN)
sptry = sp;
else
if (
@ -1130,12 +1130,7 @@ void process_server_input(void)
sp = find_server(current->server);
if (!sp)
{
#ifdef IDWRAP
unlink_identfile();
#endif /* IDWRAP */
close(current->sock);
current->sock = -1;
return;
goto breaksock2;
}
#ifdef DEBUG
debug("[PSI] Connecting via WinGate proxy...\n");
@ -1152,6 +1147,7 @@ void process_server_input(void)
}
current->connect = CN_WINGATEWAIT;
current->conntry = now;
current->heartbeat = 0;
return;
}
#endif /* WINGATE */
@ -1184,16 +1180,12 @@ get_line:
}
else
{
#ifdef IDWRAP
unlink_identfile();
#endif /* IDWRAP */
close(current->sock);
current->sock = -1;
return;
goto breaksock2;
}
}
#endif /* WINGATE */
current->conntry = now;
current->heartbeat = 0;
parse_server_input(linebuf);
goto get_line;
}
@ -1203,19 +1195,47 @@ get_line:
case EAGAIN:
break;
default:
#ifdef DEBUG
debug("[PSI] {%i} errno = %i; closing server socket\n",current->sock,errno);
#endif /* DEBUG */
*current->sockdata = 0;
#ifdef IDWRAP
unlink_identfile();
#endif /* IDWRAP */
close(current->sock);
current->sock = -1;
current->connect = CN_NOSOCK;
break;
goto breaksock;
}
}
/* server has been quiet for too long */
if (current->conntry + SERVERSILENCETIMEOUT <= now && current->heartbeat == 0)
{
#ifdef DEBUG
debug("[PSI] {%i} server has been quiet for too long (%is)...\n",current->sock,SERVERSILENCETIMEOUT);
#endif /* DEBUG */
/* push something to the server to test the socket, this should break a zombie socket */
to_server("PING :LT%lu\n",current->conntry);
current->heartbeat = 1;
}
/* server has been quiet for WAY too long */
if (current->conntry + (SERVERSILENCETIMEOUT*2) <= now)
{
#ifdef DEBUG
debug("[PSI] {%i} server has been quiet for WAY too long (%is), forcing reconnect...\n",current->sock,SERVERSILENCETIMEOUT*2);
#endif /* DEBUG */
errno = 110; /* connection timed out */
goto breaksock;
}
/* situation normal */
return;
breaksock:
#ifdef DEBUG
debug("[PSI] {%i} errno = %i; closing server socket\n",current->sock,errno);
#endif /* DEBUG */
breaksock2:
*current->sockdata = 0;
#ifdef IDWRAP
unlink_identfile();
#endif /* IDWRAP */
close(current->sock);
current->sock = -1;
current->connect = CN_NOSOCK;
return;
}
/*

View File

@ -260,6 +260,8 @@ LS const DEFstruct CNdefs[] =
{ CN_DISCONNECT, "CN_DISCONNECT" },
{ CN_BOTDIE, "CN_BOTDIE" },
{ CN_NEXTSERV, "CN_NEXTSERV" },
{ CN_WINGATEWAIT, "CN_WINGATEWAIT" },
{ CN_SPINNING, "CN_SPINNING" },
{ 0, }};
LS const DEFstruct SPdefs[] =

View File

@ -665,6 +665,7 @@ doit_jumptonext:
}
#endif /* RAWDNS */
}
/* not an else block since previous block might set sock to != -1 */
if (current->sock != -1)
{
if (current->ip.s_addr == 0)
@ -785,15 +786,6 @@ restart_dcc:
if (current->connect == CN_ONLINE)
{
/*
* Its possible to get stuck waiting forever if a FIN packet is lost
* unless you do this...
*/
if ((current->conntry - now) > SERVERSILENCETIMEOUT)
{
to_server("PING :%lu\n",now);
current->conntry += 10; /* send more unless an answer is received in <10 seconds */
}
/*
* Keep server idle-timer low to seem like you are chatting
*/

View File

@ -884,9 +884,9 @@ void do_seen(COMMAND_ARGS)
}
if (h || d)
{
sprintf(ago,"%s%i hour%s and ",ago,h,EXTRA_CHAR(h));
sprintf(ago+strlen(ago),"%i hour%s and ",h,EXTRA_CHAR(h));
}
sprintf(ago,"%s%i minute%s",ago,m,EXTRA_CHAR(m));
sprintf(ago+strlen(ago),"%i minute%s",m,EXTRA_CHAR(m));
n = seen->nick;
u = seen->userhost;

View File

@ -579,6 +579,7 @@ typedef struct Mech
time_t conntry; /* when connect try started */
/* re-used for server activity once connected */
int heartbeat; /* handle server timeout stuff */
time_t activity; /* Away timer (AAWAY) */
time_t ontime; /* how long the bot has been connected */