1 /*
2 
3 Copyright (c) 2016, Arvid Norberg
4 All rights reserved.
5 
6 Redistribution and use in source and binary forms, with or without
7 modification, are permitted provided that the following conditions
8 are met:
9 
10     * Redistributions of source code must retain the above copyright
11       notice, this list of conditions and the following disclaimer.
12     * Redistributions in binary form must reproduce the above copyright
13       notice, this list of conditions and the following disclaimer in
14       the documentation and/or other materials provided with the distribution.
15     * Neither the name of the author nor the names of its
16       contributors may be used to endorse or promote products derived
17       from this software without specific prior written permission.
18 
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
23 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 POSSIBILITY OF SUCH DAMAGE.
30 
31 */
32 
33 #ifndef LIBTORRENT_TYPES_HPP
34 #define LIBTORRENT_TYPES_HPP
35 
36 #include <cstdint>
37 #include <algorithm>
38 #include <array>
39 
40 namespace libtorrent { namespace dht {
41 
42 	struct public_key
43 	{
44 		public_key() = default;
public_keylibtorrent::dht::public_key45 		explicit public_key(char const* b)
46 		{ std::copy(b, b + len, bytes.begin()); }
operator ==libtorrent::dht::public_key47 		bool operator==(public_key const& rhs) const
48 		{ return bytes == rhs.bytes; }
49 		static constexpr int len = 32;
50 		std::array<char, len> bytes;
51 	};
52 
53 	struct secret_key
54 	{
55 		secret_key() = default;
secret_keylibtorrent::dht::secret_key56 		explicit secret_key(char const* b)
57 		{ std::copy(b, b + len, bytes.begin()); }
operator ==libtorrent::dht::secret_key58 		bool operator==(secret_key const& rhs) const
59 		{ return bytes == rhs.bytes; }
60 		static constexpr int len = 64;
61 		std::array<char, len> bytes;
62 	};
63 
64 	struct signature
65 	{
66 		signature() = default;
signaturelibtorrent::dht::signature67 		explicit signature(char const* b)
68 		{ std::copy(b, b + len, bytes.begin()); }
operator ==libtorrent::dht::signature69 		bool operator==(signature const& rhs) const
70 		{ return bytes == rhs.bytes; }
71 		static constexpr int len = 64;
72 		std::array<char, len> bytes;
73 	};
74 
75 	struct sequence_number
76 	{
sequence_numberlibtorrent::dht::sequence_number77 		sequence_number() : value(0) {}
sequence_numberlibtorrent::dht::sequence_number78 		explicit sequence_number(std::int64_t v) : value(v) {}
79 		sequence_number(sequence_number const& sqn) = default;
operator <libtorrent::dht::sequence_number80 		bool operator<(sequence_number rhs) const
81 		{ return value < rhs.value; }
operator >libtorrent::dht::sequence_number82 		bool operator>(sequence_number rhs) const
83 		{ return value > rhs.value; }
operator =libtorrent::dht::sequence_number84 		sequence_number& operator=(sequence_number rhs)
85 		{ value = rhs.value; return *this; }
operator <=libtorrent::dht::sequence_number86 		bool operator<=(sequence_number rhs) const
87 		{ return value <= rhs.value; }
operator ==libtorrent::dht::sequence_number88 		bool operator==(sequence_number const& rhs) const
89 		{ return value == rhs.value; }
operator ++libtorrent::dht::sequence_number90 		sequence_number& operator++()
91 		{ ++value; return *this; }
92 		std::int64_t value;
93 	};
94 
95 }}
96 
97 #endif // LIBTORRENT_TYPES_HPP
98