Skip to content

Commit

Permalink
[fix] connect() filter didn't actually open a socket before calling b…
Browse files Browse the repository at this point in the history
…ack as 'open' state
  • Loading branch information
pajama-coder committed Jul 4, 2024
1 parent c5007e8 commit ad5a517
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
1 change: 0 additions & 1 deletion src/filters/connect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,6 @@ void Connect::process(Event *evt) {
}

try {
m_outbound->open();
if (bind) {
m_outbound->bind(bind->str());
} else if (options.protocol == Outbound::Protocol::NETLINK) {
Expand Down
22 changes: 16 additions & 6 deletions src/outbound.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,6 @@ auto Outbound::address() -> pjs::Str* {
return m_address;
}

void Outbound::open() {
state(Outbound::State::open);
}

void Outbound::close(StreamEnd *eos) {
InputContext ic;
retain();
Expand Down Expand Up @@ -277,6 +273,7 @@ void OutboundTCP::bind(const std::string &address) {
auto &s = SocketTCP::socket();
tcp::endpoint ep(asio::ip::make_address(ip), port);
s.open(ep.protocol());
state(Outbound::State::open);
s.bind(ep);
const auto &local = s.local_endpoint();
m_local_addr = local.address().to_string();
Expand Down Expand Up @@ -429,7 +426,13 @@ void OutboundTCP::connect(const asio::ip::tcp::endpoint &target) {
Log::debug(Log::OUTBOUND, "%s connecting...", desc);
}

socket().async_connect(
auto &s = socket();
if (!s.is_open()) {
s.open(target.protocol());
state(Outbound::State::open);
}

s.async_connect(
target,
[=](const std::error_code &ec) {
InputContext ic;
Expand Down Expand Up @@ -530,6 +533,7 @@ void OutboundUDP::bind(const std::string &address) {
auto &s = SocketUDP::socket();
udp::endpoint ep(asio::ip::make_address(ip), port);
s.open(ep.protocol());
state(Outbound::State::open);
s.bind(ep);
const auto &local = s.local_endpoint();
m_local_addr = local.address().to_string();
Expand Down Expand Up @@ -686,7 +690,13 @@ void OutboundUDP::connect(const asio::ip::udp::endpoint &target) {
Log::debug(Log::OUTBOUND, "%s connecting...", desc);
}

socket().async_connect(
auto &s = socket();
if (!s.is_open()) {
s.open(target.protocol());
state(Outbound::State::open);
}

s.async_connect(
target,
[=](const std::error_code &ec) {
InputContext ic;
Expand Down
1 change: 0 additions & 1 deletion src/outbound.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ class Outbound :
virtual auto get_traffic_in() ->size_t = 0;
virtual auto get_traffic_out() ->size_t = 0;

void open();
void close(StreamEnd *eos);

protected:
Expand Down

0 comments on commit ad5a517

Please sign in to comment.