mirror of
https://github.com/transmission/transmission
synced 2025-01-03 05:25:52 +00:00
fix: invalid socket address in tr_peerIo::reconnect()
(#6750)
* fix: don't discard socket if reconnect failed * fix: don't try to reconnect more than once
This commit is contained in:
parent
d935d364ed
commit
6384abeb2b
2 changed files with 20 additions and 9 deletions
|
@ -626,6 +626,17 @@ void tr_handshake::on_error(tr_peerIo* io, tr_error const& error, void* vhandsha
|
||||||
{
|
{
|
||||||
auto* handshake = static_cast<tr_handshake*>(vhandshake);
|
auto* handshake = static_cast<tr_handshake*>(vhandshake);
|
||||||
|
|
||||||
|
auto const retry = [&]()
|
||||||
|
{
|
||||||
|
handshake->send_handshake(io);
|
||||||
|
handshake->set_state(State::AwaitingHandshake);
|
||||||
|
};
|
||||||
|
auto const fail = [&]()
|
||||||
|
{
|
||||||
|
tr_logAddTraceHand(handshake, fmt::format("handshake socket err: {:s} ({:d})", error.message(), error.code()));
|
||||||
|
handshake->done(false);
|
||||||
|
};
|
||||||
|
|
||||||
if (io->is_utp() && !io->is_incoming() && handshake->is_state(State::AwaitingYb))
|
if (io->is_utp() && !io->is_incoming() && handshake->is_state(State::AwaitingYb))
|
||||||
{
|
{
|
||||||
// the peer probably doesn't speak µTP.
|
// the peer probably doesn't speak µTP.
|
||||||
|
@ -641,10 +652,12 @@ void tr_handshake::on_error(tr_peerIo* io, tr_error const& error, void* vhandsha
|
||||||
|
|
||||||
if (handshake->mediator_->allows_tcp() && io->reconnect())
|
if (handshake->mediator_->allows_tcp() && io->reconnect())
|
||||||
{
|
{
|
||||||
handshake->send_handshake(io);
|
retry();
|
||||||
handshake->set_state(State::AwaitingHandshake);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fail();
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if the error happened while we were sending a public key, we might
|
/* if the error happened while we were sending a public key, we might
|
||||||
|
@ -654,13 +667,11 @@ void tr_handshake::on_error(tr_peerIo* io, tr_error const& error, void* vhandsha
|
||||||
handshake->encryption_mode_ != TR_ENCRYPTION_REQUIRED && handshake->mediator_->allows_tcp() && io->reconnect())
|
handshake->encryption_mode_ != TR_ENCRYPTION_REQUIRED && handshake->mediator_->allows_tcp() && io->reconnect())
|
||||||
{
|
{
|
||||||
tr_logAddTraceHand(handshake, "handshake failed, trying plaintext...");
|
tr_logAddTraceHand(handshake, "handshake failed, trying plaintext...");
|
||||||
handshake->send_handshake(io);
|
retry();
|
||||||
handshake->set_state(State::AwaitingHandshake);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
tr_logAddTraceHand(handshake, fmt::format("handshake socket err: {:s} ({:d})", error.message(), error.code()));
|
fail();
|
||||||
handshake->done(false);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---
|
// ---
|
||||||
|
|
|
@ -245,12 +245,12 @@ bool tr_peerIo::reconnect()
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
socket_ = tr_netOpenPeerSocket(session_, socket_address(), is_seed());
|
auto sock = tr_netOpenPeerSocket(session_, socket_address(), is_seed());
|
||||||
|
if (!sock.is_tcp())
|
||||||
if (!socket_.is_tcp())
|
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
socket_ = std::move(sock);
|
||||||
|
|
||||||
this->event_read_.reset(event_new(session_->event_base(), socket_.handle.tcp, EV_READ, event_read_cb, this));
|
this->event_read_.reset(event_new(session_->event_base(), socket_.handle.tcp, EV_READ, event_read_cb, this));
|
||||||
this->event_write_.reset(event_new(session_->event_base(), socket_.handle.tcp, EV_WRITE, event_write_cb, this));
|
this->event_write_.reset(event_new(session_->event_base(), socket_.handle.tcp, EV_WRITE, event_write_cb, this));
|
||||||
|
|
Loading…
Reference in a new issue