vkmEngine 1.0.0
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
join_cookie.h
1#pragma once
2
3#include <cstddef>
4#include <cstdint>
5
6#include "platform/net/net_address.h"
7
8namespace Vkm::Engine {
9
22uint64_t sipHash24(uint64_t k0, uint64_t k1, const uint8_t* data, size_t size);
23
33class NetJoinCookie {
34 public:
36 static constexpr double WINDOW_SECONDS = 10.0;
37
38 public:
39 NetJoinCookie() = default;
40 ~NetJoinCookie() = default;
41
42 NetJoinCookie(const NetJoinCookie& other) = default;
43 NetJoinCookie& operator=(const NetJoinCookie& other) = default;
44
45 NetJoinCookie(NetJoinCookie && other) = default;
46 NetJoinCookie& operator=(NetJoinCookie && other) = default;
47
48 public:
50 void rekey();
51
59 uint64_t issue(const NetAddress& to, double now) const;
60
69 bool accepts(const NetAddress& from, uint64_t token, double now) const;
70
71 private:
72 uint64_t forWindow(const NetAddress& address, uint64_t window) const;
73
74 private:
75 uint64_t m_k0 = 0;
76 uint64_t m_k1 = 0;
77};
78
79} // namespace Vkm::Engine
void rekey()
Draw a new key from the operating system. Every token given before is void.
bool accepts(const NetAddress &from, uint64_t token, double now) const
Whether token is one issue() gave from, this window or the last.
static constexpr double WINDOW_SECONDS
How long one window lasts, in seconds; a token is good for one to two of them.
Definition join_cookie.h:36
uint64_t issue(const NetAddress &to, double now) const
The token for to, as of now.
Where a datagram came from, or is going to: an IPv4 host and a port.
Definition net_address.h:13