Skip to content

Commit

Permalink
Merge pull request #63 from MortezaBashsiz/dev
Browse files Browse the repository at this point in the history
close socket and early return in server and agent handler
  • Loading branch information
MortezaBashsiz authored Aug 27, 2024
2 parents 1fbd4ab + dca0cb5 commit b9977a1
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ DEPS := $(OBJS:.o=.d)
build: all

# Main task
all: format $(TARGET) deb
all: format $(TARGET)

# Build package
deb: deb

format:
clang-format --style=Google -i src/*
Expand Down
Binary file modified files/deb/nipovpn.deb
Binary file not shown.
Binary file modified nipovpn/usr/bin/nipovpn
Binary file not shown.
6 changes: 6 additions & 0 deletions src/agenthandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,16 @@ void AgentHandler::handle() {
} else {
// Close the socket if no data is available
client_->socket().close();
return;
}
} else {
// Log if the request is not a valid HTTP request
log_->write("[AgentHandler handle] [NOT HTTP Request] [Request] : " +
streambufToString(readBuffer_),
Log::Level::DEBUG);
// Close the socket if no data is available
client_->socket().close();
return;
}
} else {
// Log encryption failure and close the socket
Expand All @@ -163,6 +167,8 @@ void AgentHandler::handle() {
client_->socket().remote_endpoint().address().to_string() + ":" +
std::to_string(client_->socket().remote_endpoint().port()) + "] ",
Log::Level::INFO);
// Close the socket if no data is available
client_->socket().close();
return;
}
}
9 changes: 9 additions & 0 deletions src/serverhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ void ServerHandler::handle() {
} else {
// Close the connection if no data was read.
client_->socket().close();
return;
}
} break;
}
Expand All @@ -151,6 +152,9 @@ void ServerHandler::handle() {
log_->write("[ServerHandler handle] [NOT HTTP Request] [Request] : " +
streambufToString(readBuffer_),
Log::Level::DEBUG);
// Close the socket if no data is available
client_->socket().close();
return;
}
} else {
// Log decryption failure and close the connection.
Expand All @@ -160,13 +164,18 @@ void ServerHandler::handle() {
log_->write("[ServerHandler handle] [Decryption Failed] : " +
request_->toString(),
Log::Level::INFO);
// Close the socket if no data is available
client_->socket().close();
return;
}
} else {
// Log if the request is not from an agent.
log_->write(
"[ServerHandler handle] [NOT HTTP Request From Agent] [Request] : " +
streambufToString(readBuffer_),
Log::Level::DEBUG);
// Close the socket if no data is available
client_->socket().close();
return;
}
}

0 comments on commit b9977a1

Please sign in to comment.