Browse Source

🎨 Fix line endings in Source/dvlnet/zerotier*

pull/1729/head
Gleb Mazovetskiy 5 years ago committed by Anders Jenbo
parent
commit
7a1d3100ec
  1. 80
      Source/dvlnet/zerotier_lwip.cpp
  2. 16
      Source/dvlnet/zerotier_lwip.h
  3. 140
      Source/dvlnet/zerotier_native.cpp
  4. 36
      Source/dvlnet/zerotier_native.h

80
Source/dvlnet/zerotier_lwip.cpp

@ -1,40 +1,40 @@
#include "dvlnet/zerotier_lwip.h"
#include <lwip/igmp.h>
#include <lwip/mld6.h>
#include <lwip/sockets.h>
#include <lwip/tcpip.h>
#include <SDL.h>
#ifdef USE_SDL1
#include "utils/sdl2_to_1_2_backports.h"
#else
#include "utils/sdl2_backports.h"
#endif
#include "utils/log.hpp"
#include "dvlnet/zerotier_native.h"
namespace devilution::net {
void print_ip6_addr(void *x)
{
char ipstr[INET6_ADDRSTRLEN];
auto *in = static_cast<sockaddr_in6 *>(x);
lwip_inet_ntop(AF_INET6, &(in->sin6_addr), ipstr, INET6_ADDRSTRLEN);
Log("ZeroTier: ZTS_EVENT_ADDR_NEW_IP6, addr={}", ipstr);
}
void zt_ip6setup()
{
ip6_addr_t mcaddr;
memcpy(mcaddr.addr, dvl_multicast_addr, 16);
mcaddr.zone = 0;
LOCK_TCPIP_CORE();
mld6_joingroup(IP6_ADDR_ANY6, &mcaddr);
UNLOCK_TCPIP_CORE();
}
} // namespace devilution::net
#include "dvlnet/zerotier_lwip.h"
#include <lwip/igmp.h>
#include <lwip/mld6.h>
#include <lwip/sockets.h>
#include <lwip/tcpip.h>
#include <SDL.h>
#ifdef USE_SDL1
#include "utils/sdl2_to_1_2_backports.h"
#else
#include "utils/sdl2_backports.h"
#endif
#include "utils/log.hpp"
#include "dvlnet/zerotier_native.h"
namespace devilution::net {
void print_ip6_addr(void *x)
{
char ipstr[INET6_ADDRSTRLEN];
auto *in = static_cast<sockaddr_in6 *>(x);
lwip_inet_ntop(AF_INET6, &(in->sin6_addr), ipstr, INET6_ADDRSTRLEN);
Log("ZeroTier: ZTS_EVENT_ADDR_NEW_IP6, addr={}", ipstr);
}
void zt_ip6setup()
{
ip6_addr_t mcaddr;
memcpy(mcaddr.addr, dvl_multicast_addr, 16);
mcaddr.zone = 0;
LOCK_TCPIP_CORE();
mld6_joingroup(IP6_ADDR_ANY6, &mcaddr);
UNLOCK_TCPIP_CORE();
}
} // namespace devilution::net

16
Source/dvlnet/zerotier_lwip.h

@ -1,8 +1,8 @@
namespace devilution {
namespace net {
void print_ip6_addr(void *x);
void zt_ip6setup();
} // namespace net
} // namespace devilution
namespace devilution {
namespace net {
void print_ip6_addr(void *x);
void zt_ip6setup();
} // namespace net
} // namespace devilution

140
Source/dvlnet/zerotier_native.cpp

@ -1,70 +1,70 @@
#include "dvlnet/zerotier_native.h"
#include <SDL.h>
#include <atomic>
#ifdef USE_SDL1
#include "utils/sdl2_to_1_2_backports.h"
#else
#include "utils/sdl2_backports.h"
#endif
#include <ZeroTierSockets.h>
#include <cstdlib>
#include "utils/paths.h"
#include "utils/log.hpp"
#include "dvlnet/zerotier_lwip.h"
namespace devilution::net {
//static constexpr uint64_t zt_earth = 0x8056c2e21c000001;
static constexpr uint64_t ZtNetwork = 0xaf78bf943649eb12;
static std::atomic_bool zt_network_ready(false);
static std::atomic_bool zt_node_online(false);
static std::atomic_bool zt_started(false);
static std::atomic_bool zt_joined(false);
static void Callback(struct zts_callback_msg *msg)
{
//printf("callback %i\n", msg->eventCode);
if (msg->eventCode == ZTS_EVENT_NODE_ONLINE) {
Log("ZeroTier: ZTS_EVENT_NODE_ONLINE, nodeId={:x}", (unsigned long long)msg->node->address);
zt_node_online = true;
if (!zt_joined) {
zts_join(ZtNetwork);
zt_joined = true;
}
} else if (msg->eventCode == ZTS_EVENT_NODE_OFFLINE) {
Log("ZeroTier: ZTS_EVENT_NODE_OFFLINE");
zt_node_online = false;
} else if (msg->eventCode == ZTS_EVENT_NETWORK_READY_IP6) {
Log("ZeroTier: ZTS_EVENT_NETWORK_READY_IP6, networkId={:x}", (unsigned long long)msg->network->nwid);
zt_ip6setup();
zt_network_ready = true;
} else if (msg->eventCode == ZTS_EVENT_ADDR_ADDED_IP6) {
print_ip6_addr(&(msg->addr->addr));
}
}
bool zerotier_network_ready()
{
return zt_network_ready && zt_node_online;
}
void zerotier_network_stop()
{
zts_stop();
}
void zerotier_network_start()
{
if (zt_started)
return;
zts_start(paths::PrefPath().c_str(), (void (*)(void *))Callback, 0);
std::atexit(zerotier_network_stop);
}
} // namespace devilution::net
#include "dvlnet/zerotier_native.h"
#include <SDL.h>
#include <atomic>
#ifdef USE_SDL1
#include "utils/sdl2_to_1_2_backports.h"
#else
#include "utils/sdl2_backports.h"
#endif
#include <ZeroTierSockets.h>
#include <cstdlib>
#include "utils/paths.h"
#include "utils/log.hpp"
#include "dvlnet/zerotier_lwip.h"
namespace devilution::net {
//static constexpr uint64_t zt_earth = 0x8056c2e21c000001;
static constexpr uint64_t ZtNetwork = 0xaf78bf943649eb12;
static std::atomic_bool zt_network_ready(false);
static std::atomic_bool zt_node_online(false);
static std::atomic_bool zt_started(false);
static std::atomic_bool zt_joined(false);
static void Callback(struct zts_callback_msg *msg)
{
//printf("callback %i\n", msg->eventCode);
if (msg->eventCode == ZTS_EVENT_NODE_ONLINE) {
Log("ZeroTier: ZTS_EVENT_NODE_ONLINE, nodeId={:x}", (unsigned long long)msg->node->address);
zt_node_online = true;
if (!zt_joined) {
zts_join(ZtNetwork);
zt_joined = true;
}
} else if (msg->eventCode == ZTS_EVENT_NODE_OFFLINE) {
Log("ZeroTier: ZTS_EVENT_NODE_OFFLINE");
zt_node_online = false;
} else if (msg->eventCode == ZTS_EVENT_NETWORK_READY_IP6) {
Log("ZeroTier: ZTS_EVENT_NETWORK_READY_IP6, networkId={:x}", (unsigned long long)msg->network->nwid);
zt_ip6setup();
zt_network_ready = true;
} else if (msg->eventCode == ZTS_EVENT_ADDR_ADDED_IP6) {
print_ip6_addr(&(msg->addr->addr));
}
}
bool zerotier_network_ready()
{
return zt_network_ready && zt_node_online;
}
void zerotier_network_stop()
{
zts_stop();
}
void zerotier_network_start()
{
if (zt_started)
return;
zts_start(paths::PrefPath().c_str(), (void (*)(void *))Callback, 0);
std::atexit(zerotier_network_stop);
}
} // namespace devilution::net

36
Source/dvlnet/zerotier_native.h

@ -1,18 +1,18 @@
#pragma once
namespace devilution {
namespace net {
bool zerotier_network_ready();
void zerotier_network_start();
void zerotier_network_stop();
// NOTE: We have patched our libzt to have the corresponding multicast
// MAC hardcoded, since libzt is still missing the proper handling.
const unsigned char dvl_multicast_addr[16] = {
0xff, 0x0e, 0xa8, 0xa9, 0xb6, 0x11, 0x58, 0xce,
0x04, 0x12, 0xfd, 0x73, 0x37, 0x86, 0x6f, 0xb7
};
} // namespace net
} // namespace devilution
#pragma once
namespace devilution {
namespace net {
bool zerotier_network_ready();
void zerotier_network_start();
void zerotier_network_stop();
// NOTE: We have patched our libzt to have the corresponding multicast
// MAC hardcoded, since libzt is still missing the proper handling.
const unsigned char dvl_multicast_addr[16] = {
0xff, 0x0e, 0xa8, 0xa9, 0xb6, 0x11, 0x58, 0xce,
0x04, 0x12, 0xfd, 0x73, 0x37, 0x86, 0x6f, 0xb7
};
} // namespace net
} // namespace devilution

Loading…
Cancel
Save