76 lines
1.9 KiB
C
76 lines
1.9 KiB
C
|
// Copyright (c) 2012-2015, The CryptoNote developers, The Bytecoin developers
|
||
|
//
|
||
|
// This file is part of Bytecoin.
|
||
|
//
|
||
|
// Bytecoin is free software: you can redistribute it and/or modify
|
||
|
// it under the terms of the GNU Lesser General Public License as published by
|
||
|
// the Free Software Foundation, either version 3 of the License, or
|
||
|
// (at your option) any later version.
|
||
|
//
|
||
|
// Bytecoin is distributed in the hope that it will be useful,
|
||
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
// GNU Lesser General Public License for more details.
|
||
|
//
|
||
|
// You should have received a copy of the GNU Lesser General Public License
|
||
|
// along with Bytecoin. If not, see <http://www.gnu.org/licenses/>.
|
||
|
|
||
|
#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;
|
||
|
typedef uint64_t peerid_type;
|
||
|
|
||
|
#pragma pack (push, 1)
|
||
|
|
||
|
struct net_address
|
||
|
{
|
||
|
uint32_t ip;
|
||
|
uint32_t port;
|
||
|
};
|
||
|
|
||
|
struct peerlist_entry
|
||
|
{
|
||
|
net_address adr;
|
||
|
peerid_type id;
|
||
|
time_t last_seen;
|
||
|
};
|
||
|
|
||
|
struct connection_entry
|
||
|
{
|
||
|
net_address adr;
|
||
|
peerid_type id;
|
||
|
bool is_income;
|
||
|
};
|
||
|
|
||
|
#pragma pack(pop)
|
||
|
|
||
|
inline bool operator < (const net_address& a, const net_address& b) {
|
||
|
return std::tie(a.ip, a.port) < std::tie(b.ip, b.port);
|
||
|
}
|
||
|
|
||
|
inline bool operator == (const net_address& a, const net_address& b) {
|
||
|
return memcmp(&a, &b, sizeof(a)) == 0;
|
||
|
}
|
||
|
|
||
|
inline std::ostream& operator << (std::ostream& s, const net_address& na) {
|
||
|
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
|
||
|
}
|
||
|
|
||
|
}
|