mirror of
https://github.com/PurpleI2P/i2pd.git
synced 2025-07-01 10:14:36 +02:00
send Datagram3
Some checks are pending
Build Debian packages / bookworm (push) Waiting to run
Build Debian packages / bullseye (push) Waiting to run
Build Debian packages / buster (push) Waiting to run
Build on FreeBSD / with UPnP (push) Waiting to run
Build on OSX / With USE_UPNP=no (push) Waiting to run
Build on OSX / With USE_UPNP=yes (push) Waiting to run
Build on Windows / CMake x86_64 (push) Waiting to run
Build on Windows / clang-x86_64 (push) Waiting to run
Build on Windows / i686 (push) Waiting to run
Build on Windows / ucrt-x86_64 (push) Waiting to run
Build on Windows / x86_64 (push) Waiting to run
Build on Windows / CMake clang-x86_64 (push) Waiting to run
Build on Windows / CMake i686 (push) Waiting to run
Build on Windows / CMake ucrt-x86_64 (push) Waiting to run
Build on Windows / XP (push) Waiting to run
Build on Ubuntu / Make with USE_UPNP=no (push) Waiting to run
Build on Ubuntu / Make with USE_UPNP=yes (push) Waiting to run
Build on Ubuntu / CMake with -DWITH_UPNP=OFF (push) Waiting to run
Build on Ubuntu / CMake with -DWITH_UPNP=ON (push) Waiting to run
Build containers / Building container for linux/amd64 (push) Waiting to run
Build containers / Building container for linux/arm64 (push) Waiting to run
Build containers / Building container for linux/arm/v7 (push) Waiting to run
Build containers / Building container for linux/386 (push) Waiting to run
Build containers / Pushing merged manifest (push) Blocked by required conditions
Some checks are pending
Build Debian packages / bookworm (push) Waiting to run
Build Debian packages / bullseye (push) Waiting to run
Build Debian packages / buster (push) Waiting to run
Build on FreeBSD / with UPnP (push) Waiting to run
Build on OSX / With USE_UPNP=no (push) Waiting to run
Build on OSX / With USE_UPNP=yes (push) Waiting to run
Build on Windows / CMake x86_64 (push) Waiting to run
Build on Windows / clang-x86_64 (push) Waiting to run
Build on Windows / i686 (push) Waiting to run
Build on Windows / ucrt-x86_64 (push) Waiting to run
Build on Windows / x86_64 (push) Waiting to run
Build on Windows / CMake clang-x86_64 (push) Waiting to run
Build on Windows / CMake i686 (push) Waiting to run
Build on Windows / CMake ucrt-x86_64 (push) Waiting to run
Build on Windows / XP (push) Waiting to run
Build on Ubuntu / Make with USE_UPNP=no (push) Waiting to run
Build on Ubuntu / Make with USE_UPNP=yes (push) Waiting to run
Build on Ubuntu / CMake with -DWITH_UPNP=OFF (push) Waiting to run
Build on Ubuntu / CMake with -DWITH_UPNP=ON (push) Waiting to run
Build containers / Building container for linux/amd64 (push) Waiting to run
Build containers / Building container for linux/arm64 (push) Waiting to run
Build containers / Building container for linux/arm/v7 (push) Waiting to run
Build containers / Building container for linux/386 (push) Waiting to run
Build containers / Pushing merged manifest (push) Blocked by required conditions
This commit is contained in:
parent
f230c110aa
commit
a5631bd1b5
2 changed files with 36 additions and 15 deletions
|
@ -58,25 +58,35 @@ namespace datagram
|
||||||
{
|
{
|
||||||
if (session)
|
if (session)
|
||||||
{
|
{
|
||||||
if (m_Owner->GetIdentity ()->GetSigningKeyType () == i2p::data::SIGNING_KEY_TYPE_DSA_SHA1)
|
if (session->GetVersion () == eDatagramV3)
|
||||||
{
|
{
|
||||||
uint8_t hash[32];
|
constexpr uint8_t flags[] = { 0x00, 0x03 }; // datagram3, no options
|
||||||
SHA256(payload, len, hash);
|
auto msg = CreateDataMessage ({{m_Owner->GetIdentity ()->GetIdentHash (), 32},
|
||||||
m_Owner->Sign (hash, 32, m_Signature.data ());
|
{flags, 2}, {payload, len}}, fromPort, toPort, i2p::client::PROTOCOL_TYPE_DATAGRAM3, false); // datagram3
|
||||||
|
session->SendMsg(msg);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
m_Owner->Sign (payload, len, m_Signature.data ());
|
{
|
||||||
|
if (m_Owner->GetIdentity ()->GetSigningKeyType () == i2p::data::SIGNING_KEY_TYPE_DSA_SHA1)
|
||||||
|
{
|
||||||
|
uint8_t hash[32];
|
||||||
|
SHA256(payload, len, hash);
|
||||||
|
m_Owner->Sign (hash, 32, m_Signature.data ());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
m_Owner->Sign (payload, len, m_Signature.data ());
|
||||||
|
|
||||||
auto msg = CreateDataMessage ({{m_From.data (), m_From.size ()}, {m_Signature.data (), m_Signature.size ()}, {payload, len}},
|
auto msg = CreateDataMessage ({{m_From.data (), m_From.size ()}, {m_Signature.data (), m_Signature.size ()}, {payload, len}},
|
||||||
fromPort, toPort, false, !session->IsRatchets ()); // datagram
|
fromPort, toPort, i2p::client::PROTOCOL_TYPE_DATAGRAM, !session->IsRatchets ()); // datagram1
|
||||||
session->SendMsg(msg);
|
session->SendMsg(msg);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatagramDestination::SendRawDatagram (std::shared_ptr<DatagramSession> session, const uint8_t * payload, size_t len, uint16_t fromPort, uint16_t toPort)
|
void DatagramDestination::SendRawDatagram (std::shared_ptr<DatagramSession> session, const uint8_t * payload, size_t len, uint16_t fromPort, uint16_t toPort)
|
||||||
{
|
{
|
||||||
if (session)
|
if (session)
|
||||||
session->SendMsg(CreateDataMessage ({{payload, len}}, fromPort, toPort, true, !session->IsRatchets ())); // raw
|
session->SendMsg(CreateDataMessage ({{payload, len}}, fromPort, toPort, i2p::client::PROTOCOL_TYPE_RAW, !session->IsRatchets ())); // raw
|
||||||
}
|
}
|
||||||
|
|
||||||
void DatagramDestination::FlushSendQueue (std::shared_ptr<DatagramSession> session)
|
void DatagramDestination::FlushSendQueue (std::shared_ptr<DatagramSession> session)
|
||||||
|
@ -145,6 +155,7 @@ namespace datagram
|
||||||
if (!memcmp (from->GetRemoteStaticKey (), staticKey, 32))
|
if (!memcmp (from->GetRemoteStaticKey (), staticKey, 32))
|
||||||
{
|
{
|
||||||
auto session = ObtainSession (ident);
|
auto session = ObtainSession (ident);
|
||||||
|
session->SetVersion (eDatagramV3);
|
||||||
session->SetRemoteLeaseSet (ls);
|
session->SetRemoteLeaseSet (ls);
|
||||||
session->Ack ();
|
session->Ack ();
|
||||||
auto r = FindReceiver(toPort);
|
auto r = FindReceiver(toPort);
|
||||||
|
@ -274,7 +285,7 @@ namespace datagram
|
||||||
|
|
||||||
std::shared_ptr<I2NPMessage> DatagramDestination::CreateDataMessage (
|
std::shared_ptr<I2NPMessage> DatagramDestination::CreateDataMessage (
|
||||||
const std::vector<std::pair<const uint8_t *, size_t> >& payloads,
|
const std::vector<std::pair<const uint8_t *, size_t> >& payloads,
|
||||||
uint16_t fromPort, uint16_t toPort, bool isRaw, bool checksum)
|
uint16_t fromPort, uint16_t toPort, uint8_t protocolType, bool checksum)
|
||||||
{
|
{
|
||||||
size_t size;
|
size_t size;
|
||||||
auto msg = m_I2NPMsgsPool.AcquireShared ();
|
auto msg = m_I2NPMsgsPool.AcquireShared ();
|
||||||
|
@ -290,8 +301,8 @@ namespace datagram
|
||||||
{
|
{
|
||||||
htobe32buf (msg->GetPayload (), size); // length
|
htobe32buf (msg->GetPayload (), size); // length
|
||||||
htobe16buf (buf + 4, fromPort); // source port
|
htobe16buf (buf + 4, fromPort); // source port
|
||||||
htobe16buf (buf + 6, toPort); // destination port
|
htobe16buf (buf + 6, toPort); // destination port
|
||||||
buf[9] = isRaw ? i2p::client::PROTOCOL_TYPE_RAW : i2p::client::PROTOCOL_TYPE_DATAGRAM; // raw or datagram protocol
|
buf[9] = protocolType; // raw or datagram protocol
|
||||||
msg->len += size + 4;
|
msg->len += size + 4;
|
||||||
msg->FillI2NPMessageHeader (eI2NPData, 0, checksum);
|
msg->FillI2NPMessageHeader (eI2NPData, 0, checksum);
|
||||||
}
|
}
|
||||||
|
@ -350,8 +361,7 @@ namespace datagram
|
||||||
DatagramSession::DatagramSession(std::shared_ptr<i2p::client::ClientDestination> localDestination,
|
DatagramSession::DatagramSession(std::shared_ptr<i2p::client::ClientDestination> localDestination,
|
||||||
const i2p::data::IdentHash & remoteIdent) :
|
const i2p::data::IdentHash & remoteIdent) :
|
||||||
m_LocalDestination(localDestination), m_RemoteIdent(remoteIdent),
|
m_LocalDestination(localDestination), m_RemoteIdent(remoteIdent),
|
||||||
m_LastUse (0), m_LastFlush (0),
|
m_LastUse (0), m_LastFlush (0), m_RequestingLS (false), m_Version (eDatagramV1)
|
||||||
m_RequestingLS(false)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,13 @@ namespace datagram
|
||||||
const uint64_t DATAGRAM_MAX_FLUSH_INTERVAL = 5; // in milliseconds
|
const uint64_t DATAGRAM_MAX_FLUSH_INTERVAL = 5; // in milliseconds
|
||||||
const int DATAGRAM_SESSION_ACK_REQUEST_INTERVAL = 5500; // in milliseconds
|
const int DATAGRAM_SESSION_ACK_REQUEST_INTERVAL = 5500; // in milliseconds
|
||||||
|
|
||||||
|
enum DatagramVersion
|
||||||
|
{
|
||||||
|
eDatagramV1 = 1,
|
||||||
|
eDatagramV2 = 2,
|
||||||
|
eDatagramV3 = 3,
|
||||||
|
};
|
||||||
|
|
||||||
constexpr uint16_t DATAGRAM3_FLAG_OPTIONS = 0x10;
|
constexpr uint16_t DATAGRAM3_FLAG_OPTIONS = 0x10;
|
||||||
|
|
||||||
class DatagramSession : public std::enable_shared_from_this<DatagramSession>
|
class DatagramSession : public std::enable_shared_from_this<DatagramSession>
|
||||||
|
@ -69,6 +76,9 @@ namespace datagram
|
||||||
|
|
||||||
bool IsRatchets () const { return m_RoutingSession && m_RoutingSession->IsRatchets (); }
|
bool IsRatchets () const { return m_RoutingSession && m_RoutingSession->IsRatchets (); }
|
||||||
void SetRemoteLeaseSet (std::shared_ptr<const i2p::data::LeaseSet> ls) { m_RemoteLeaseSet = ls; }
|
void SetRemoteLeaseSet (std::shared_ptr<const i2p::data::LeaseSet> ls) { m_RemoteLeaseSet = ls; }
|
||||||
|
|
||||||
|
DatagramVersion GetVersion () const { return m_Version; }
|
||||||
|
void SetVersion (DatagramVersion version) { m_Version = version; }
|
||||||
|
|
||||||
struct Info
|
struct Info
|
||||||
{
|
{
|
||||||
|
@ -104,6 +114,7 @@ namespace datagram
|
||||||
std::vector<std::shared_ptr<I2NPMessage> > m_SendQueue;
|
std::vector<std::shared_ptr<I2NPMessage> > m_SendQueue;
|
||||||
uint64_t m_LastUse, m_LastFlush; // milliseconds
|
uint64_t m_LastUse, m_LastFlush; // milliseconds
|
||||||
bool m_RequestingLS;
|
bool m_RequestingLS;
|
||||||
|
DatagramVersion m_Version;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef std::shared_ptr<DatagramSession> DatagramSession_ptr;
|
typedef std::shared_ptr<DatagramSession> DatagramSession_ptr;
|
||||||
|
@ -147,7 +158,7 @@ namespace datagram
|
||||||
std::shared_ptr<DatagramSession> ObtainSession(const i2p::data::IdentHash & ident);
|
std::shared_ptr<DatagramSession> ObtainSession(const i2p::data::IdentHash & ident);
|
||||||
|
|
||||||
std::shared_ptr<I2NPMessage> CreateDataMessage (const std::vector<std::pair<const uint8_t *, size_t> >& payloads,
|
std::shared_ptr<I2NPMessage> CreateDataMessage (const std::vector<std::pair<const uint8_t *, size_t> >& payloads,
|
||||||
uint16_t fromPort, uint16_t toPort, bool isRaw = false, bool checksum = true);
|
uint16_t fromPort, uint16_t toPort, uint8_t protocolType, bool checksum = true);
|
||||||
|
|
||||||
void HandleDatagram (uint16_t fromPort, uint16_t toPort, uint8_t *const& buf, size_t len);
|
void HandleDatagram (uint16_t fromPort, uint16_t toPort, uint8_t *const& buf, size_t len);
|
||||||
void HandleRawDatagram (uint16_t fromPort, uint16_t toPort, const uint8_t * buf, size_t len);
|
void HandleRawDatagram (uint16_t fromPort, uint16_t toPort, const uint8_t * buf, size_t len);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue