danicoin/src/P2p/ConnectionContext.h

71 lines
2 KiB
C
Raw Normal View History

// Copyright (c) 2011-2016 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 <list>
#include <ostream>
#include <unordered_set>
#include <boost/uuid/uuid.hpp>
#include "Common/StringTools.h"
#include "crypto/hash.h"
namespace CryptoNote {
2015-07-30 15:22:07 +00:00
struct CryptoNoteConnectionContext {
2015-07-15 12:23:00 +00:00
uint8_t version;
2015-05-27 12:08:46 +00:00
boost::uuids::uuid m_connection_id;
uint32_t m_remote_ip = 0;
uint32_t m_remote_port = 0;
bool m_is_income = false;
time_t m_started = 0;
enum state {
state_befor_handshake = 0, //default state
state_synchronizing,
state_idle,
state_normal,
state_sync_required,
2015-07-15 12:23:00 +00:00
state_pool_sync_required,
2015-05-27 12:08:46 +00:00
state_shutdown
};
state m_state = state_befor_handshake;
2015-07-30 15:22:07 +00:00
std::list<Crypto::Hash> m_needed_objects;
std::unordered_set<Crypto::Hash> m_requested_objects;
uint32_t m_remote_blockchain_height = 0;
uint32_t m_last_response_height = 0;
2015-05-27 12:08:46 +00:00
};
2015-07-30 15:22:07 +00:00
inline std::string get_protocol_state_string(CryptoNoteConnectionContext::state s) {
2015-05-27 12:08:46 +00:00
switch (s) {
2015-07-30 15:22:07 +00:00
case CryptoNoteConnectionContext::state_befor_handshake:
2015-05-27 12:08:46 +00:00
return "state_befor_handshake";
2015-07-30 15:22:07 +00:00
case CryptoNoteConnectionContext::state_synchronizing:
2015-05-27 12:08:46 +00:00
return "state_synchronizing";
2015-07-30 15:22:07 +00:00
case CryptoNoteConnectionContext::state_idle:
2015-05-27 12:08:46 +00:00
return "state_idle";
2015-07-30 15:22:07 +00:00
case CryptoNoteConnectionContext::state_normal:
2015-05-27 12:08:46 +00:00
return "state_normal";
2015-07-30 15:22:07 +00:00
case CryptoNoteConnectionContext::state_sync_required:
2015-05-27 12:08:46 +00:00
return "state_sync_required";
case CryptoNoteConnectionContext::state_pool_sync_required:
return "state_pool_sync_required";
2015-07-30 15:22:07 +00:00
case CryptoNoteConnectionContext::state_shutdown:
2015-05-27 12:08:46 +00:00
return "state_shutdown";
default:
return "unknown";
}
}
}
namespace std {
2015-07-30 15:22:07 +00:00
inline std::ostream& operator << (std::ostream& s, const CryptoNote::CryptoNoteConnectionContext& context) {
2015-05-27 12:08:46 +00:00
return s << "[" << Common::ipAddressToString(context.m_remote_ip) << ":" <<
context.m_remote_port << (context.m_is_income ? " INC" : " OUT") << "] ";
}
}