summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/InspIRCd.layout18
-rw-r--r--src/connection.cpp90
-rw-r--r--src/inspircd.cpp13
3 files changed, 99 insertions, 22 deletions
diff --git a/src/InspIRCd.layout b/src/InspIRCd.layout
index 36d142425..5c357b73a 100644
--- a/src/InspIRCd.layout
+++ b/src/InspIRCd.layout
@@ -1,5 +1,5 @@
[Editors]
-Focused=24
+Focused=1
Order=1,2,-1,4,6,3,7,25,5,24
[Editor_0]
@@ -12,10 +12,10 @@ LeftChar=1
[Editor_1]
Open=1
-Top=0
-CursorCol=24
-CursorRow=6946
-TopLine=6898
+Top=1
+CursorCol=30
+CursorRow=6600
+TopLine=6564
LeftChar=1
[Editor_2]
@@ -196,10 +196,10 @@ LeftChar=1
[Editor_24]
Open=1
-Top=1
-CursorCol=1
-CursorRow=194
-TopLine=1
+Top=0
+CursorCol=19
+CursorRow=158
+TopLine=312
LeftChar=1
[Editor_25]
Open=1
diff --git a/src/connection.cpp b/src/connection.cpp
index 3a756be3b..156a5fcea 100644
--- a/src/connection.cpp
+++ b/src/connection.cpp
@@ -136,9 +136,64 @@ bool connection::SendPacket(char *message, char* host, int port, long ourkey)
log(DEBUG,"sendto() failed for Connection::SendPacket() with a packet of size %d: %s",sizeof(p),strerror(errno));
return false;
}
+ this->state = STATE_WAIT_FOR_ACK;
+
+ // host_address remains unchanged. we only want to receive from where we just sent the packet to.
+
+ // retry the packet up to 5 times
+ for (int retries = 0; retries < 5; retries++)
+ {
+ socklen_t host_address_size;
+ host_address.sin_family=AF_INET;
+ host_address_size=sizeof(host_address);
+
+ if (recvfrom(fd,&p2,sizeof(p2),0,(sockaddr*)&host_address,&host_address_size)<0)
+ {
+ return false;
+ }
+
+ if (cycles >= 10)
+ {
+ log(DEFAULT,"ERROR! connection::SendPacket() waited >10000 nanosecs for an ACK. Will resend up to 5 times");
+ }
+ else
+ {
+ if (p2.type != PT_ACK_ONLY)
+ {
+ packet_buf pb;
+ pb.p.id = p.id;
+ pb.p.key = p.key;
+ pb.p.type = p.type;
+ strcpy(pb.p.data,p.data);
+ strcpy(pb.host,inet_ntoa(host_address.sin_addr));
+ pb.port = ntohs(host_address.sin_port);
+ this->buffer.push_back(pb);
+
+ log(DEFAULT,"ERROR! connection::SendPacket() received a data response and was expecting an ACK!!!");
+ this->state = STATE_CLEAR;
+ return true;
+ }
+
+ if (p2.id != p.id)
+ {
+ log(DEFAULT,"ERROR! connection::SendPacket() received an ack for a packet it didnt send!");
+ this->state = STATE_CLEAR;
+ return false;
+ }
+ else
+ {
+ log(DEFAULT,"Successfully received ACK");
+ this->state = STATE_CLEAR;
+ return true;
+ break;
+ }
+ }
+ }
+ log(DEFAULT,"We never received an ack. Something fishy going on, host is dead.");
this->state = STATE_CLEAR;
- return true;
+ return false;
+
}
bool connection::SendSYN(char* host, int port)
@@ -239,6 +294,18 @@ bool connection::RecvPacket(char *message, char* host, int &prt, long &theirkey)
//int recvfrom(int s, void *buf, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen);
if (recvfrom(fd,&p,sizeof(p),0,(sockaddr*)&host_address,&host_address_size)<0)
{
+ if (buffer.size()>0)
+ {
+ log(DEBUG,"Fetching a buffered packet size %d",buffer.size());
+ strcpy(message,buffer[0].p.data);
+ theirkey = buffer[0].p.key;
+ strcpy(host,buffer[0].host);
+ prt = buffer[0].port;
+
+ buffer.erase(buffer.begin());
+
+ return true;
+ }
return false;
}
@@ -269,6 +336,27 @@ bool connection::RecvPacket(char *message, char* host, int &prt, long &theirkey)
theirkey = p.key;
prt = ntohs(host_address.sin_port); // the port we received it on
SendACK(host,prt,p.id);
+
+ if (buffer.size()>0)
+ {
+ log(DEBUG,"Fetching a buffered packet size %d",buffer.size());
+ packet_buf pb;
+ pb.p.id = p.id;
+ pb.p.key = p.key;
+ pb.p.type = p.type;
+ strcpy(pb.p.data,p.data);
+ strcpy(pb.host,inet_ntoa(host_address.sin_addr));
+ pb.port = ntohs(host_address.sin_port);
+ this->buffer.push_back(pb);
+
+ strcpy(message,buffer[0].p.data);
+ theirkey = buffer[0].p.key;
+ strcpy(host,buffer[0].host);
+ prt = buffer[0].port;
+
+ buffer.erase(buffer.begin());
+ }
+
return true;
}
diff --git a/src/inspircd.cpp b/src/inspircd.cpp
index 79f2d58c4..f247e0c90 100644
--- a/src/inspircd.cpp
+++ b/src/inspircd.cpp
@@ -6597,7 +6597,7 @@ void handle_link_packet(long theirkey, char* udp_msg, char* udp_host, int udp_po
if (!strcasecmp(servers[i]->internal_addr,udp_host)) {
servers[i]->key = atoi(params);
log(DEBUG,"Key for this server is now %d",servers[i]->key);
- servers[i]->sync_soon = true;
+ DoSync(serv,udp_host,udp_port,MyKey);
return;
}
}
@@ -6915,17 +6915,6 @@ int InspIRCd(void)
}
fd_reap.clear();
reap_counter=0;
- for (int j = 0; j < 255; j++)
- {
- if (servers[j])
- {
- if (servers[j]->sync_soon)
- {
- servers[j]->sync_soon = false;
- DoSync(servers[j],servers[j]->internal_addr,servers[j]->internal_port,MyKey);
- }
- }
- }
}