2015-09-18 11:55:31 +00:00
|
|
|
// Copyright (c) 2011-2015 The Cryptonote developers
|
|
|
|
// Distributed under the MIT/X11 software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
2015-05-27 12:08:46 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <tuple>
|
|
|
|
#include <boost/uuid/uuid.hpp>
|
|
|
|
#include "Common/StringTools.h"
|
|
|
|
|
|
|
|
namespace CryptoNote
|
|
|
|
{
|
|
|
|
typedef boost::uuids::uuid uuid;
|
|
|
|
typedef boost::uuids::uuid net_connection_id;
|
2015-07-30 15:22:07 +00:00
|
|
|
typedef uint64_t PeerIdType;
|
2015-05-27 12:08:46 +00:00
|
|
|
|
|
|
|
#pragma pack (push, 1)
|
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
struct NetworkAddress
|
2015-05-27 12:08:46 +00:00
|
|
|
{
|
|
|
|
uint32_t ip;
|
|
|
|
uint32_t port;
|
|
|
|
};
|
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
struct PeerlistEntry
|
2015-05-27 12:08:46 +00:00
|
|
|
{
|
2015-07-30 15:22:07 +00:00
|
|
|
NetworkAddress adr;
|
|
|
|
PeerIdType id;
|
|
|
|
uint64_t last_seen;
|
2015-05-27 12:08:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct connection_entry
|
|
|
|
{
|
2015-07-30 15:22:07 +00:00
|
|
|
NetworkAddress adr;
|
|
|
|
PeerIdType id;
|
2015-05-27 12:08:46 +00:00
|
|
|
bool is_income;
|
|
|
|
};
|
|
|
|
|
|
|
|
#pragma pack(pop)
|
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
inline bool operator < (const NetworkAddress& a, const NetworkAddress& b) {
|
2015-05-27 12:08:46 +00:00
|
|
|
return std::tie(a.ip, a.port) < std::tie(b.ip, b.port);
|
|
|
|
}
|
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
inline bool operator == (const NetworkAddress& a, const NetworkAddress& b) {
|
2015-05-27 12:08:46 +00:00
|
|
|
return memcmp(&a, &b, sizeof(a)) == 0;
|
|
|
|
}
|
|
|
|
|
2015-07-30 15:22:07 +00:00
|
|
|
inline std::ostream& operator << (std::ostream& s, const NetworkAddress& na) {
|
2015-05-27 12:08:46 +00:00
|
|
|
return s << Common::ipAddressToString(na.ip) << ":" << std::to_string(na.port);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline uint32_t hostToNetwork(uint32_t n) {
|
|
|
|
return (n << 24) | (n & 0xff00) << 8 | (n & 0xff0000) >> 8 | (n >> 24);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline uint32_t networkToHost(uint32_t n) {
|
|
|
|
return hostToNetwork(n); // the same
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|