MCPcopy Create free account
hub / github.com/PurpleI2P/i2pd / ReadFromBuffer

Method ReadFromBuffer

libi2pd/LeaseSet.cpp:51–131  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

49 }
50
51 void LeaseSet::ReadFromBuffer (bool readIdentity, bool verifySignature)
52 {
53 if (readIdentity || !m_Identity)
54 m_Identity = netdb.NewIdentity (m_Buffer, m_BufferLen);
55 size_t size = m_Identity->GetFullLen ();
56 if (size + 256 > m_BufferLen)
57 {
58 LogPrint (eLogError, "LeaseSet: Identity length ", int(size), " exceeds buffer size ", int(m_BufferLen));
59 m_IsValid = false;
60 return;
61 }
62 if (m_StoreLeases)
63 {
64 if (!m_EncryptionKey) m_EncryptionKey = new uint8_t[256];
65 memcpy (m_EncryptionKey, m_Buffer + size, 256);
66 }
67 size += 256; // encryption key
68 size += m_Identity->GetSigningPublicKeyLen (); // unused signing key
69 if (size + 1 > m_BufferLen)
70 {
71 LogPrint (eLogError, "LeaseSet: ", int(size), " exceeds buffer size ", int(m_BufferLen));
72 m_IsValid = false;
73 return;
74 }
75 uint8_t num = m_Buffer[size];
76 size++; // num
77 LogPrint (eLogDebug, "LeaseSet: Read num=", (int)num);
78 if (!num || num > MAX_NUM_LEASES)
79 {
80 LogPrint (eLogError, "LeaseSet: Incorrect number of leases", (int)num);
81 m_IsValid = false;
82 return;
83 }
84 if (size + num*LEASE_SIZE > m_BufferLen)
85 {
86 LogPrint (eLogError, "LeaseSet: ", int(size), " exceeds buffer size ", int(m_BufferLen));
87 m_IsValid = false;
88 return;
89 }
90
91 UpdateLeasesBegin ();
92 // process leases
93 m_ExpirationTime = 0;
94 auto ts = i2p::util::GetMillisecondsSinceEpoch ();
95 const uint8_t * leases = m_Buffer + size;
96 for (int i = 0; i < num; i++)
97 {
98 Lease lease;
99 lease.tunnelGateway = leases;
100 leases += 32; // gateway
101 lease.tunnelID = bufbe32toh (leases);
102 leases += 4; // tunnel ID
103 lease.endDate = bufbe64toh (leases);
104 leases += 8; // end date
105 UpdateLease (lease, ts);
106 }
107 if (!m_ExpirationTime)
108 {

Callers

nothing calls this directly

Calls 11

LogPrintFunction · 0.85
bufbe32tohFunction · 0.85
bufbe64tohFunction · 0.85
bufbe16tohFunction · 0.85
ProcessOfflineSignatureFunction · 0.85
NewIdentityMethod · 0.45
GetFullLenMethod · 0.45
GetSignatureLenMethod · 0.45
VerifyMethod · 0.45

Tested by

no test coverage detected