mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2026-10-23 08:32:43 +00:00
61 lines
1.2 KiB
C++
61 lines
1.2 KiB
C++
/*
|
|
* Copyright (c) 2026, The PurpleI2P Project
|
|
*
|
|
* This file is part of Purple i2pd project and licensed under BSD3
|
|
*
|
|
* See full license text in LICENSE file at top of project tree
|
|
*/
|
|
|
|
#ifndef TORRENTS_DHT_H__
|
|
#define TORRENTS_DHT_H__
|
|
|
|
#ifndef NO_TORRENTS
|
|
|
|
#include <inttypes.h>
|
|
#include <openssl/sha.h>
|
|
#include <memory>
|
|
#include <array>
|
|
#include <utility>
|
|
#include "Identity.h"
|
|
#include "I2PService.h"
|
|
#include "util.h"
|
|
|
|
namespace i2p
|
|
{
|
|
namespace torrents
|
|
{
|
|
using NodeID = std::array<uint8_t, SHA_DIGEST_LENGTH>;
|
|
using NodeInfo = std::array<uint8_t, std::tuple_size<NodeID>::value + i2p::data::IdentHash::len + 2>;
|
|
|
|
class TorrentsTunnel;
|
|
class TorrentsDHT
|
|
{
|
|
public:
|
|
|
|
TorrentsDHT (TorrentsTunnel& tunnel, uint16_t port);
|
|
|
|
void Start ();
|
|
void Stop ();
|
|
|
|
uint16_t GetRPort () const { return m_Port + 1; };
|
|
void HandleRawDatagram (const uint8_t * buf, size_t len);
|
|
|
|
private:
|
|
|
|
void HandleDatagram (const i2p::data::IdentityEx& from, uint16_t fromPort, uint16_t toPort,
|
|
const uint8_t * buf, size_t len, const i2p::util::Mapping * options);
|
|
|
|
private:
|
|
|
|
TorrentsTunnel& m_Tunnel;
|
|
uint16_t m_Port;
|
|
NodeID m_NodeID;
|
|
NodeInfo m_NodeInfo; // 20 byte Node ID + 32 byte IdentHash + 2 byte port
|
|
};
|
|
}
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|