mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-10 08:00:38 +03:00
eliminate unnecessary const_cast
This commit is contained in:
parent
ec5eafafeb
commit
c266575528
@ -43,7 +43,7 @@ namespace i2p
|
|||||||
void RouterContext::OverrideNTCPAddress (const char * host, int port)
|
void RouterContext::OverrideNTCPAddress (const char * host, int port)
|
||||||
{
|
{
|
||||||
m_RouterInfo.CreateBuffer ();
|
m_RouterInfo.CreateBuffer ();
|
||||||
auto address = m_RouterInfo.GetNTCPAddress ();
|
auto address = const_cast<i2p::data::RouterInfo::Address *>(m_RouterInfo.GetNTCPAddress ());
|
||||||
if (address)
|
if (address)
|
||||||
{
|
{
|
||||||
address->host = boost::asio::ip::address::from_string (host);
|
address->host = boost::asio::ip::address::from_string (host);
|
||||||
|
@ -303,17 +303,17 @@ namespace data
|
|||||||
return m_SupportedTransports & (eSSUV4 | eSSUV6);
|
return m_SupportedTransports & (eSSUV4 | eSSUV6);
|
||||||
}
|
}
|
||||||
|
|
||||||
RouterInfo::Address * RouterInfo::GetNTCPAddress (bool v4only)
|
const RouterInfo::Address * RouterInfo::GetNTCPAddress (bool v4only) const
|
||||||
{
|
{
|
||||||
return GetAddress (eTransportNTCP, v4only);
|
return GetAddress (eTransportNTCP, v4only);
|
||||||
}
|
}
|
||||||
|
|
||||||
RouterInfo::Address * RouterInfo::GetSSUAddress (bool v4only)
|
const RouterInfo::Address * RouterInfo::GetSSUAddress (bool v4only) const
|
||||||
{
|
{
|
||||||
return GetAddress (eTransportSSU, v4only);
|
return GetAddress (eTransportSSU, v4only);
|
||||||
}
|
}
|
||||||
|
|
||||||
RouterInfo::Address * RouterInfo::GetAddress (TransportStyle s, bool v4only)
|
const RouterInfo::Address * RouterInfo::GetAddress (TransportStyle s, bool v4only) const
|
||||||
{
|
{
|
||||||
for (auto& address : m_Addresses)
|
for (auto& address : m_Addresses)
|
||||||
{
|
{
|
||||||
|
@ -54,8 +54,8 @@ namespace data
|
|||||||
const char * GetIdentHashAbbreviation () const { return m_IdentHashAbbreviation; };
|
const char * GetIdentHashAbbreviation () const { return m_IdentHashAbbreviation; };
|
||||||
uint64_t GetTimestamp () const { return m_Timestamp; };
|
uint64_t GetTimestamp () const { return m_Timestamp; };
|
||||||
std::vector<Address>& GetAddresses () { return m_Addresses; };
|
std::vector<Address>& GetAddresses () { return m_Addresses; };
|
||||||
Address * GetNTCPAddress (bool v4only = true);
|
const Address * GetNTCPAddress (bool v4only = true) const;
|
||||||
Address * GetSSUAddress (bool v4only = true);
|
const Address * GetSSUAddress (bool v4only = true) const;
|
||||||
const RoutingKey& GetRoutingKey () const { return m_RoutingKey; };
|
const RoutingKey& GetRoutingKey () const { return m_RoutingKey; };
|
||||||
|
|
||||||
void AddNTCPAddress (const char * host, int port);
|
void AddNTCPAddress (const char * host, int port);
|
||||||
@ -91,7 +91,7 @@ namespace data
|
|||||||
size_t ReadString (char * str, std::istream& s);
|
size_t ReadString (char * str, std::istream& s);
|
||||||
void WriteString (const std::string& str, std::ostream& s);
|
void WriteString (const std::string& str, std::ostream& s);
|
||||||
void UpdateIdentHashBase64 ();
|
void UpdateIdentHashBase64 ();
|
||||||
Address * GetAddress (TransportStyle s, bool v4only);
|
const Address * GetAddress (TransportStyle s, bool v4only) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
15
SSU.cpp
15
SSU.cpp
@ -14,8 +14,8 @@ namespace i2p
|
|||||||
namespace ssu
|
namespace ssu
|
||||||
{
|
{
|
||||||
|
|
||||||
SSUSession::SSUSession (SSUServer * server, const boost::asio::ip::udp::endpoint& remoteEndpoint,
|
SSUSession::SSUSession (SSUServer * server, boost::asio::ip::udp::endpoint& remoteEndpoint,
|
||||||
i2p::data::RouterInfo * router): m_Server (server), m_RemoteEndpoint (remoteEndpoint),
|
const i2p::data::RouterInfo * router): m_Server (server), m_RemoteEndpoint (remoteEndpoint),
|
||||||
m_RemoteRouter (router), m_State (eSessionStateUnknown)
|
m_RemoteRouter (router), m_State (eSessionStateUnknown)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
@ -273,7 +273,7 @@ namespace ssu
|
|||||||
m_Server->Send (buf, 480, m_RemoteEndpoint);
|
m_Server->Send (buf, 480, m_RemoteEndpoint);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SSUSession::ProcessIntroKeyEncryptedMessage (uint8_t expectedPayloadType, i2p::data::RouterInfo& r, uint8_t * buf, size_t len)
|
bool SSUSession::ProcessIntroKeyEncryptedMessage (uint8_t expectedPayloadType, const i2p::data::RouterInfo& r, uint8_t * buf, size_t len)
|
||||||
{
|
{
|
||||||
auto address = r.GetSSUAddress ();
|
auto address = r.GetSSUAddress ();
|
||||||
if (address)
|
if (address)
|
||||||
@ -299,7 +299,8 @@ namespace ssu
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SSUSession::FillHeaderAndEncrypt (uint8_t payloadType, uint8_t * buf, size_t len, uint8_t * aesKey, uint8_t * iv, uint8_t * macKey)
|
void SSUSession::FillHeaderAndEncrypt (uint8_t payloadType, uint8_t * buf, size_t len,
|
||||||
|
const uint8_t * aesKey, const uint8_t * iv, const uint8_t * macKey)
|
||||||
{
|
{
|
||||||
if (len < sizeof (SSUHeader))
|
if (len < sizeof (SSUHeader))
|
||||||
{
|
{
|
||||||
@ -320,7 +321,7 @@ namespace ssu
|
|||||||
i2p::crypto::HMACMD5Digest (encrypted, encryptedLen + 18, macKey, header->mac);
|
i2p::crypto::HMACMD5Digest (encrypted, encryptedLen + 18, macKey, header->mac);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SSUSession::Decrypt (uint8_t * buf, size_t len, uint8_t * aesKey)
|
void SSUSession::Decrypt (uint8_t * buf, size_t len, const uint8_t * aesKey)
|
||||||
{
|
{
|
||||||
if (len < sizeof (SSUHeader))
|
if (len < sizeof (SSUHeader))
|
||||||
{
|
{
|
||||||
@ -335,7 +336,7 @@ namespace ssu
|
|||||||
m_Decryption.ProcessData (encrypted, encrypted, encryptedLen);
|
m_Decryption.ProcessData (encrypted, encrypted, encryptedLen);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SSUSession::Validate (uint8_t * buf, size_t len, uint8_t * macKey)
|
bool SSUSession::Validate (uint8_t * buf, size_t len, const uint8_t * macKey)
|
||||||
{
|
{
|
||||||
if (len < sizeof (SSUHeader))
|
if (len < sizeof (SSUHeader))
|
||||||
{
|
{
|
||||||
@ -535,7 +536,7 @@ namespace ssu
|
|||||||
LogPrint ("SSU receive error: ", ecode.message ());
|
LogPrint ("SSU receive error: ", ecode.message ());
|
||||||
}
|
}
|
||||||
|
|
||||||
SSUSession * SSUServer::GetSession (i2p::data::RouterInfo * router)
|
SSUSession * SSUServer::GetSession (const i2p::data::RouterInfo * router)
|
||||||
{
|
{
|
||||||
SSUSession * session = nullptr;
|
SSUSession * session = nullptr;
|
||||||
if (router)
|
if (router)
|
||||||
|
16
SSU.h
16
SSU.h
@ -62,8 +62,8 @@ namespace ssu
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
SSUSession (SSUServer * server, const boost::asio::ip::udp::endpoint& remoteEndpoint,
|
SSUSession (SSUServer * server, boost::asio::ip::udp::endpoint& remoteEndpoint,
|
||||||
i2p::data::RouterInfo * router = nullptr);
|
const i2p::data::RouterInfo * router = nullptr);
|
||||||
void ProcessNextMessage (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& senderEndpoint);
|
void ProcessNextMessage (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& senderEndpoint);
|
||||||
|
|
||||||
void Connect ();
|
void Connect ();
|
||||||
@ -86,16 +86,16 @@ namespace ssu
|
|||||||
void SendMsgAck (uint32_t msgID);
|
void SendMsgAck (uint32_t msgID);
|
||||||
void SendSesionDestroyed ();
|
void SendSesionDestroyed ();
|
||||||
|
|
||||||
bool ProcessIntroKeyEncryptedMessage (uint8_t expectedPayloadType, i2p::data::RouterInfo& r, uint8_t * buf, size_t len);
|
bool ProcessIntroKeyEncryptedMessage (uint8_t expectedPayloadType, const i2p::data::RouterInfo& r, uint8_t * buf, size_t len);
|
||||||
void FillHeaderAndEncrypt (uint8_t payloadType, uint8_t * buf, size_t len, uint8_t * aesKey, uint8_t * iv, uint8_t * macKey);
|
void FillHeaderAndEncrypt (uint8_t payloadType, uint8_t * buf, size_t len, const uint8_t * aesKey, const uint8_t * iv, const uint8_t * macKey);
|
||||||
void Decrypt (uint8_t * buf, size_t len, uint8_t * aesKey);
|
void Decrypt (uint8_t * buf, size_t len, const uint8_t * aesKey);
|
||||||
bool Validate (uint8_t * buf, size_t len, uint8_t * macKey);
|
bool Validate (uint8_t * buf, size_t len, const uint8_t * macKey);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
SSUServer * m_Server;
|
SSUServer * m_Server;
|
||||||
boost::asio::ip::udp::endpoint m_RemoteEndpoint;
|
boost::asio::ip::udp::endpoint m_RemoteEndpoint;
|
||||||
i2p::data::RouterInfo * m_RemoteRouter;
|
const i2p::data::RouterInfo * m_RemoteRouter;
|
||||||
SessionState m_State;
|
SessionState m_State;
|
||||||
CryptoPP::CBC_Mode<CryptoPP::AES>::Encryption m_Encryption;
|
CryptoPP::CBC_Mode<CryptoPP::AES>::Encryption m_Encryption;
|
||||||
CryptoPP::CBC_Mode<CryptoPP::AES>::Decryption m_Decryption;
|
CryptoPP::CBC_Mode<CryptoPP::AES>::Decryption m_Decryption;
|
||||||
@ -111,7 +111,7 @@ namespace ssu
|
|||||||
~SSUServer ();
|
~SSUServer ();
|
||||||
void Start ();
|
void Start ();
|
||||||
void Stop ();
|
void Stop ();
|
||||||
SSUSession * GetSession (i2p::data::RouterInfo * router);
|
SSUSession * GetSession (const i2p::data::RouterInfo * router);
|
||||||
void DeleteSession (SSUSession * session);
|
void DeleteSession (SSUSession * session);
|
||||||
void DeleteAllSessions ();
|
void DeleteAllSessions ();
|
||||||
|
|
||||||
|
@ -55,8 +55,7 @@ namespace i2p
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: do it for SSU only
|
//DetectExternalIP ();
|
||||||
DetectExternalIP ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Transports::Stop ()
|
void Transports::Stop ()
|
||||||
@ -189,7 +188,7 @@ namespace i2p
|
|||||||
{
|
{
|
||||||
auto router = i2p::data::netdb.GetRandomRouter ();
|
auto router = i2p::data::netdb.GetRandomRouter ();
|
||||||
if (router && router->IsSSU () && m_SSUServer)
|
if (router && router->IsSSU () && m_SSUServer)
|
||||||
m_SSUServer->GetSession (const_cast<i2p::data::RouterInfo *>(router)); //TODO
|
m_SSUServer->GetSession (router);
|
||||||
}
|
}
|
||||||
if (m_Timer)
|
if (m_Timer)
|
||||||
{
|
{
|
||||||
|
2
hmac.h
2
hmac.h
@ -13,7 +13,7 @@ namespace crypto
|
|||||||
const uint64_t IPAD = 0x3636363636363636;
|
const uint64_t IPAD = 0x3636363636363636;
|
||||||
const uint64_t OPAD = 0x5C5C5C5C5C5C5C5C;
|
const uint64_t OPAD = 0x5C5C5C5C5C5C5C5C;
|
||||||
|
|
||||||
inline void HMACMD5Digest (uint8_t * msg, size_t len, uint8_t * key, uint8_t * digest)
|
inline void HMACMD5Digest (uint8_t * msg, size_t len, const uint8_t * key, uint8_t * digest)
|
||||||
// key is 32 bytes
|
// key is 32 bytes
|
||||||
// digest is 16 bytes
|
// digest is 16 bytes
|
||||||
// block size is 64 bytes
|
// block size is 64 bytes
|
||||||
|
Loading…
Reference in New Issue
Block a user