Fix for GitHub issue #20 (untested)

This commit is contained in:
Adam Ierymenko 2013-12-24 10:39:29 -08:00
parent 026442f28f
commit 92969b4426
6 changed files with 218 additions and 155 deletions

View file

@ -219,7 +219,11 @@ bool Switch::sendHELLO(const SharedPtr<Peer> &dest,Demarc::Port localPort,const
outp.append(now);
_r->identity.serialize(outp,false);
outp.armor(dest->key(),false);
return _r->demarc->send(localPort,remoteAddr,outp.data(),outp.size(),-1);
if (_r->demarc->send(localPort,remoteAddr,outp.data(),outp.size(),-1)) {
dest->expectResponseTo(outp.packetId(),Packet::VERB_HELLO,localPort,now);
return true;
} else return false;
}
bool Switch::unite(const Address &p1,const Address &p2,bool force)
@ -696,7 +700,8 @@ bool Switch::_trySend(const Packet &packet,bool encrypt)
tmp.armor(peer->key(),encrypt);
if (via->send(_r,tmp.data(),chunkSize,now)) {
Demarc::Port localPort;
if ((localPort = via->send(_r,tmp.data(),chunkSize,now))) {
if (chunkSize < tmp.size()) {
// Too big for one bite, fragment the rest
unsigned int fragStart = chunkSize;
@ -716,6 +721,15 @@ bool Switch::_trySend(const Packet &packet,bool encrypt)
remaining -= chunkSize;
}
}
switch(packet.verb()) {
case Packet::VERB_HELLO:
peer->expectResponseTo(packet.packetId(),Packet::VERB_HELLO,localPort,now);
break;
default:
break;
}
return true;
}
return false;