-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
439 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#pragma once | ||
|
||
#include "../common/packet.hpp" | ||
#include "sessionmanager.hpp" | ||
|
||
namespace tunmode | ||
{ | ||
class UDPSession; | ||
|
||
class UDPManager : public SessionManager | ||
{ | ||
public: | ||
UDPManager(); | ||
|
||
void handle_packet(const Packet& packet) override; | ||
|
||
private: | ||
Session* add(uintptr_t id) override; | ||
|
||
friend class UDPSession; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#pragma once | ||
|
||
#include "session.hpp" | ||
#include "../common/packet.hpp" | ||
#include "../common/buffer.hpp" | ||
|
||
#include <cstdint> | ||
|
||
namespace tunmode | ||
{ | ||
class UDPManager; | ||
|
||
class UDPSession : public Session | ||
{ | ||
public: | ||
UDPSession(UDPManager* manager, uint64_t id); | ||
|
||
private: | ||
UDPManager* manager; | ||
uint32_t poll_timeout; | ||
|
||
int poll(struct pollfd fds[2]) override; | ||
void loop() override; | ||
void _loop(); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#pragma once | ||
|
||
#include "socket.hpp" | ||
#include "sessionsocket.hpp" | ||
#include "../common/packet.hpp" | ||
#include "../common/buffer.hpp" | ||
|
||
#include <netinet/in.h> | ||
#include <cstdint> | ||
|
||
namespace tunmode | ||
{ | ||
class UDPSocket : public SessionSocket | ||
{ | ||
public: | ||
UDPSocket(); | ||
~UDPSocket() override; | ||
|
||
void init(Socket* skt); | ||
|
||
size_t send_tun(Packet& packet) override; | ||
size_t send(const Buffer& buffer) override; | ||
size_t recv(Buffer& buffer) override; | ||
|
||
void operator<<(const Buffer& buffer) override; | ||
void operator>>(Buffer& buffer) override; | ||
|
||
void close(); | ||
|
||
private: | ||
in_addr client_addr; | ||
u_short client_port; | ||
in_addr server_addr; | ||
u_short server_port; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include <tunmode/manager/udpmanager.hpp> | ||
#include <tunmode/session/udpsession.hpp> | ||
#include <tunmode/common/utils.hpp> | ||
|
||
namespace tunmode | ||
{ | ||
UDPManager::UDPManager() : SessionManager() {} | ||
|
||
void UDPManager::handle_packet(const Packet& packet) | ||
{ | ||
UDPSession* session = reinterpret_cast<UDPSession*>(this->get_or_add(packet.get_id())); | ||
*(session->get_client_socket()) < packet; | ||
} | ||
|
||
Session* UDPManager::add(uint64_t id) | ||
{ | ||
UDPSession* session = new UDPSession(this, id); | ||
utils::protect_socket(session->get_server_socket()->get_socket()); | ||
this->sessions.insert({id, session}); | ||
|
||
return session; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.