summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/connection.h11
-rw-r--r--src/InspIRCd.layout26
-rw-r--r--src/connection.cpp51
-rw-r--r--src/inspircd.cpp70
4 files changed, 136 insertions, 22 deletions
diff --git a/include/connection.h b/include/connection.h
index ac76654f9..710b90a2d 100644
--- a/include/connection.h
+++ b/include/connection.h
@@ -36,7 +36,10 @@ class ircd_connector : public classbase
*/
sockaddr_in addr;
- /** File descriptor of the outbound connection
+ char host[MAXBUF];
+ int port;
+
+ /** File descriptor of the connection
*/
int fd;
@@ -70,6 +73,9 @@ class ircd_connector : public classbase
void SetDescriptor(int fd);
int GetState();
void SetState(int state);
+ char* GetServerIP();
+ int GetServerPort();
+ bool SetHostAndPort(char* host, int port);
};
@@ -113,11 +119,12 @@ class connection : public classbase
connection();
bool CreateListener(char* host, int p);
bool BeginLink(char* targethost, int port, char* password, char* servername);
+ bool MeshCookie(char* targethost, int port, long cookie, char* servername);
void TerminateLink(char* targethost);
bool SendPacket(char *message, const char* host);
bool RecvPacket(std::deque<std::string> &messages, char* host);
ircd_connector* FindHost(std::string host);
- bool AddIncoming(int fd,char* targethost);
+ bool AddIncoming(int fd,char* targethost, int sourceport);
long GenKey();
};
diff --git a/src/InspIRCd.layout b/src/InspIRCd.layout
index 686e7c83b..36c7cf28e 100644
--- a/src/InspIRCd.layout
+++ b/src/InspIRCd.layout
@@ -1,5 +1,5 @@
[Editors]
-Focused=1
+Focused=-1
Order=1,2,4,6,3,7,25,5,24,-1
[Editor_0]
@@ -12,10 +12,10 @@ LeftChar=1
[Editor_1]
Open=1
-Top=1
-CursorCol=25
-CursorRow=4522
-TopLine=4491
+Top=0
+CursorCol=9
+CursorRow=6454
+TopLine=6578
LeftChar=1
[Editor_2]
@@ -108,10 +108,10 @@ LeftChar=1
[Editor_13]
Open=1
-Top=0
-CursorCol=5
-CursorRow=48
-TopLine=16
+Top=1
+CursorCol=77
+CursorRow=122
+TopLine=68
LeftChar=1
[Editor_14]
@@ -139,7 +139,7 @@ TopLine=1
LeftChar=1
[Editor_17]
-Open=1
+Open=0
Top=0
CursorCol=34
CursorRow=122
@@ -197,9 +197,9 @@ LeftChar=1
[Editor_24]
Open=1
Top=0
-CursorCol=50
-CursorRow=238
-TopLine=207
+CursorCol=87
+CursorRow=189
+TopLine=158
LeftChar=1
[Editor_25]
Open=1
diff --git a/src/connection.cpp b/src/connection.cpp
index c2b67412a..48127086e 100644
--- a/src/connection.cpp
+++ b/src/connection.cpp
@@ -93,8 +93,27 @@ bool connection::CreateListener(char* host, int p)
return true;
}
+char* ircd_connector::GetServerIP()
+{
+ return this->host;
+}
+
+int ircd_connector::GetServerPort()
+{
+ return this->port;
+}
+
+bool ircd_connector::SetHostAndPort(char* host, int port)
+{
+ strncpy(this->host,host,160);
+ this->port = port;
+ return true;
+}
+
bool ircd_connector::SetHostAddress(char* host, int port)
{
+ strncpy(this->host,host,160);
+ this->port = port;
memset((void*)&addr, 0, sizeof(addr));
addr.sin_family = AF_INET;
inet_aton(host,&addr.sin_addr);
@@ -167,7 +186,35 @@ bool connection::BeginLink(char* targethost, int port, char* password, char* ser
return false;
}
-bool connection::AddIncoming(int fd,char* targethost)
+bool connection::MeshCookie(char* targethost, int port, long cookie, char* servername)
+{
+ char connect[MAXBUF];
+
+ ircd_connector connector;
+
+ WriteOpers("Establishing meshed link to %s:%d",targethost,port);
+
+ if (this->fd)
+ {
+ if (connector.MakeOutboundConnection(targethost,port))
+ {
+ // targethost has been turned into an ip...
+ // we dont want this as the server name.
+ connector.SetServerName(servername);
+ sprintf(connect,"- %d %s :%s",cookie,getservername().c_str(),getserverdesc().c_str());
+ connector.SetState(STATE_NOAUTH_OUTBOUND);
+ this->connectors.push_back(connector);
+ return this->SendPacket(connect, servername);
+ }
+ else
+ {
+ WriteOpers("Could not create outbound connection to %s:%d",targethost,port);
+ }
+ }
+ return false;
+}
+
+bool connection::AddIncoming(int fd,char* targethost, int sourceport)
{
char connect[MAXBUF];
@@ -175,6 +222,7 @@ bool connection::AddIncoming(int fd,char* targethost)
// targethost has been turned into an ip...
// we dont want this as the server name.
+ connector.SetHostAndPort(targethost, sourceport);
connector.SetServerName(targethost);
connector.SetDescriptor(fd);
connector.SetState(STATE_NOAUTH_INBOUND);
@@ -184,6 +232,7 @@ bool connection::AddIncoming(int fd,char* targethost)
int recvbuf = 32768;
setsockopt(fd,SOL_SOCKET,SO_SNDBUF,(const void *)&sendbuf,sizeof(sendbuf));
setsockopt(fd,SOL_SOCKET,SO_RCVBUF,(const void *)&recvbuf,sizeof(sendbuf));
+ log(DEBUG,"connection::AddIncoming() Added connection: %s:%d",host,sourceport);
this->connectors.push_back(connector);
return true;
}
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index 74785a167..4004bf08e 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -76,7 +76,7 @@ int WHOWAS_MAX = 100; // default 100 people maximum in the WHOWAS list
int DieDelay = 5;
time_t startup_time = time(NULL);
int NetBufferSize = 10240; // NetBufferSize used as the buffer size for all read() ops
-time_t nb_start = time(NULL);
+time_t nb_start = 0;
extern vector<Module*> modules;
std::vector<std::string> module_names;
@@ -182,6 +182,7 @@ char* Passwd(userrec *user);
bool IsDenied(userrec *user);
void AddWhoWas(userrec* u);
+std::vector<long> auth_cookies;
std::stringstream config_f(stringstream::in | stringstream::out);
void safedelete(userrec *p)
@@ -4183,9 +4184,10 @@ void Error(int status)
}
-int main (int argc, char *argv[])
+int main(int argc, char *argv[])
{
Start();
+ srand(time(NULL));
log(DEBUG,"*** InspIRCd starting up!");
if (!FileExists(CONFIG_FILE))
{
@@ -6364,6 +6366,16 @@ void handle_b(char token,char* params,serverrec* source,serverrec* reply, char*
strncpy(user->dhost,host,160);
}
+void handle_plus(char token,char* params,serverrec* source,serverrec* reply, char* udp_host)
+{
+ // %s %s %d %d
+ char* servername = strtok(params," ");
+ char* ipaddr = strtok(NULL," ");
+ char* ipport = strtok(NULL," ");
+ char* cookie = strtok(NULL," ");
+ me[defaultRoute]->MeshCookie(ipaddr,atoi(ipport),atoi(cookie),servername);
+}
+
void handle_J(char token,char* params,serverrec* source,serverrec* reply, char* udp_host)
{
@@ -6417,15 +6429,36 @@ void handle_J(char token,char* params,serverrec* source,serverrec* reply, char*
}
}
-void process_restricted_commands(char token,char* params,serverrec* source,serverrec* reply, char* udp_host)
+void process_restricted_commands(char token,char* params,serverrec* source,serverrec* reply, char* udp_host,char* ipaddr,int port)
{
+ long authcookie = rand()*rand();
+
switch(token)
{
// Y <TS>
// start netburst
case 'Y':
nb_start = time(NULL);
- WriteOpers("Server %s is starting netburst.",source->name);
+ WriteOpers("Server %s is starting netburst.",udp_host);
+ // now broadcast this new servers address out to all servers that are linked to us,
+ // except the newcomer. They'll all attempt to connect back to it.
+ char buffer[MAXBUF];
+ snprintf(buffer,MAXBUF,"+ %s %s %d %d",udp_host,ipaddr,port,authcookie);
+ NetSendToAllExcept(udp_host,buffer);
+ snprintf(buffer,MAXBUF,"~ %d",authcookie);
+ NetSendToAllExcept(udp_host,buffer);
+ break;
+ // ~
+ // Store authcookie
+ // once stored, this authcookie permits other servers to log in
+ // without user or password, using it.
+ case '~':
+ auth_cookies.push_back(atoi(params));
+ log(DEBUG,"Stored auth cookie, will permit servers with auth-cookie %d",atoi(params));
+ break;
+ // connect back to a server using an authcookie
+ case '+':
+ handle_plus(token,params,source,reply,udp_host);
break;
// ?
// ping
@@ -6532,7 +6565,10 @@ void process_restricted_commands(char token,char* params,serverrec* source,serve
case 'F':
WriteOpers("Server %s has completed netburst. (%d secs)",udp_host,time(NULL)-nb_start);
handle_F(token,params,source,reply,udp_host);
+ nb_start = 0;
break;
+ // X <reserved>
+ // Send netburst now
case 'X':
WriteOpers("Sending my netburst to %s",udp_host);
DoSync(source,udp_host);
@@ -6557,6 +6593,23 @@ void handle_link_packet(char* udp_msg, char* udp_host, serverrec *serv)
if (strstr(params," :")) {
strncpy(finalparam,strstr(params," :"),1024);
}
+ if (token == '-') {
+ char* cookie = strtok(params," ");
+ char* servername = strtok(NULL," ");
+ char* serverdesc = finalparam+2;
+ WriteOpers("AuthCookie CONNECT from %s (%s)",servername,udp_host);
+ for (int u = 0; u < auth_cookies.size(); u++)
+ {
+ if (auth_cookies[u] == atoi(cookie))
+ {
+ WriteOpers("Allowed cookie from %s, is now part of the mesh",servername);
+ return;
+ }
+ }
+ WriteOpers("Bad cookie from %s!",servername);
+ return;
+ }
+ else
if (token == 'S') {
// S test.chatspike.net password :ChatSpike InspIRCd test server
char* servername = strtok(params," ");
@@ -6699,7 +6752,7 @@ void handle_link_packet(char* udp_msg, char* udp_host, serverrec *serv)
// found a valid ircd_connector.
// TODO: Fix this so it only lets servers in that are in the
// STATE_CONNECTED state!!!
- process_restricted_commands(token,params,me[j],serv,udp_host);
+ process_restricted_commands(token,params,me[j],serv,udp_host,me[j]->connectors[x].GetServerIP(),me[j]->connectors[x].GetServerPort());
return;
}
}
@@ -6939,7 +6992,7 @@ int InspIRCd(void)
incomingSockfd = accept (me[x]->fd, (sockaddr *) &client, &length);
strncpy (remotehost,(char *) inet_ntoa (client.sin_addr),MAXBUF);
// add to this connections ircd_connector vector
- me[x]->AddIncoming(incomingSockfd,remotehost);
+ me[x]->AddIncoming(incomingSockfd,remotehost,ntohs(client.sin_port));
}
}
}
@@ -6959,6 +7012,11 @@ int InspIRCd(void)
log(DEBUG,"Invalid string from %s [route%d]",udp_host,x);
break;
}
+ // during a netburst, send all data to all other linked servers
+ if ((nb_start>0) && (udp_msg[0] != 'Y') && (udp_msg[0] != 'X') && (udp_msg[0] != 'F'))
+ {
+ NetSendToAllExcept(udp_msg,udp_host);
+ }
FOREACH_MOD OnPacketReceive(udp_msg);
handle_link_packet(udp_msg, udp_host, me[x]);
}