Commit d6454dd1 authored by 神楽坂玲奈's avatar 神楽坂玲奈

new

parent 6636c1ee
Pipeline #16664 failed with stages
in 48 seconds
......@@ -14,7 +14,6 @@ class Router : private boost::noncopyable {
public:
static const int secret_length = 32;
static std::map<std::pair<unsigned char, unsigned char>, int> raws; // (family,proto) => fd
static std::map<int, Router *> tuns; // fd => router
static std::map<int, Router *> all; // id => router
static unsigned char local_secret[secret_length];
......@@ -32,7 +31,6 @@ public:
system(config.up.c_str());
all[config.remote_id] = this;
tuns[tun] = this;
};
static void create_secret(const std::string &secret, unsigned char *target) {
......
......@@ -59,8 +59,7 @@ void inbound(int raw) {
}
// tun -> internet
void outbound(int tun) {
auto router = Router::tuns[tun];
void outbound(Router* router) {
unsigned char buffer[ETH_DATA_LEN];
auto meta = (Meta *) buffer;
meta->src_id = config.local_id;
......@@ -68,7 +67,7 @@ void outbound(int tun) {
meta->reserved = 0;
auto inner = buffer + sizeof(Meta);
size_t packet_length;
while ((packet_length = read(tun, inner, sizeof(buffer) - sizeof(Meta))) >= 0) {
while ((packet_length = read(router->tun, inner, sizeof(buffer) - sizeof(Meta))) >= 0) {
if (!router->remote_addr.ss_family) continue;
router->encrypt(inner, packet_length);
if (setsockopt(router->raw, SOL_SOCKET, SO_MARK, &router->config.mark, sizeof(router->config.mark)) < 0) {
......@@ -89,7 +88,7 @@ int main(int argc, char *argv[]) {
for (const auto &item: config.routers) new Router(item);
std::vector<std::thread> threads;
for (auto &[_, router]: Router::all)threads.emplace_back(outbound, router->tun);
for (auto &[_, router]: Router::all)threads.emplace_back(outbound, router);
for (auto &[_, raw]: Router::raws)threads.emplace_back(inbound, raw);
for (auto &thread: threads) thread.join();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment