Browse Source

different log levels

pull/106/head
orignal 10 years ago
parent
commit
1f69d1b890
  1. 82
      SSU.cpp
  2. 24
      SSUData.cpp

82
SSU.cpp

@ -37,7 +37,7 @@ namespace transport @@ -37,7 +37,7 @@ namespace transport
uint8_t sharedKey[256];
if (!dh.Agree (sharedKey, m_DHKeysPair->privateKey, pubKey))
{
LogPrint ("Couldn't create shared key");
LogPrint (eLogError, "Couldn't create shared key");
return;
};
@ -104,14 +104,14 @@ namespace transport @@ -104,14 +104,14 @@ namespace transport
auto address = i2p::context.GetRouterInfo ().GetSSUAddress ();
if (!address)
{
LogPrint ("SSU is not supported");
LogPrint (eLogError, "SSU is not supported");
return;
}
if (Validate (buf, len, address->key))
Decrypt (buf, len, address->key);
else
{
LogPrint ("MAC verification failed ", len, " bytes from ", senderEndpoint);
LogPrint (eLogError, "MAC verification failed ", len, " bytes from ", senderEndpoint);
m_Server.DeleteSession (this);
return;
}
@ -128,7 +128,7 @@ namespace transport @@ -128,7 +128,7 @@ namespace transport
switch (header->GetPayloadType ())
{
case PAYLOAD_TYPE_DATA:
LogPrint ("SSU data received");
LogPrint (eLogDebug, "SSU data received");
ProcessData (buf + sizeof (SSUHeader), len - sizeof (SSUHeader));
break;
case PAYLOAD_TYPE_SESSION_REQUEST:
@ -141,12 +141,12 @@ namespace transport @@ -141,12 +141,12 @@ namespace transport
ProcessSessionConfirmed (buf, len);
break;
case PAYLOAD_TYPE_PEER_TEST:
LogPrint ("SSU peer test received");
LogPrint (eLogDebug, "SSU peer test received");
ProcessPeerTest (buf + sizeof (SSUHeader), len - sizeof (SSUHeader), senderEndpoint);
break;
case PAYLOAD_TYPE_SESSION_DESTROYED:
{
LogPrint ("SSU session destroy received");
LogPrint (eLogDebug, "SSU session destroy received");
m_Server.DeleteSession (this); // delete this
break;
}
@ -156,21 +156,21 @@ namespace transport @@ -156,21 +156,21 @@ namespace transport
m_Server.DeleteSession (this);
break;
case PAYLOAD_TYPE_RELAY_REQUEST:
LogPrint ("SSU relay request received");
LogPrint (eLogDebug, "SSU relay request received");
ProcessRelayRequest (buf + sizeof (SSUHeader), len - sizeof (SSUHeader), senderEndpoint);
break;
case PAYLOAD_TYPE_RELAY_INTRO:
LogPrint ("SSU relay intro received");
LogPrint (eLogDebug, "SSU relay intro received");
ProcessRelayIntro (buf + sizeof (SSUHeader), len - sizeof (SSUHeader));
break;
default:
LogPrint ("Unexpected SSU payload type ", (int)header->GetPayloadType ());
LogPrint (eLogWarning, "Unexpected SSU payload type ", (int)header->GetPayloadType ());
}
}
void SSUSession::ProcessSessionRequest (uint8_t * buf, size_t len, const boost::asio::ip::udp::endpoint& senderEndpoint)
{
LogPrint ("Session request received");
LogPrint (eLogDebug, "Session request received");
m_RemoteEndpoint = senderEndpoint;
if (!m_DHKeysPair)
m_DHKeysPair = transports.GetNextDHKeysPair ();
@ -182,11 +182,11 @@ namespace transport @@ -182,11 +182,11 @@ namespace transport
{
if (!m_RemoteRouter || !m_DHKeysPair)
{
LogPrint ("Unsolicited session created message");
LogPrint (eLogWarning, "Unsolicited session created message");
return;
}
LogPrint ("Session created received");
LogPrint (eLogDebug, "Session created received");
m_Timer.cancel (); // connect timer
SignedData s; // x,y, our IP, our port, remote IP, remote port, relayTag, signed on time
uint8_t * payload = buf + sizeof (SSUHeader);
@ -215,14 +215,14 @@ namespace transport @@ -215,14 +215,14 @@ namespace transport
m_SessionKeyDecryption.Decrypt (payload, 48, payload);
// verify
if (!s.Verify (m_RemoteIdentity, payload))
LogPrint ("SSU signature verification failed");
LogPrint (eLogError, "SSU signature verification failed");
SendSessionConfirmed (y, ourAddress);
}
void SSUSession::ProcessSessionConfirmed (uint8_t * buf, size_t len)
{
LogPrint ("Session confirmed received");
LogPrint (eLogDebug, "Session confirmed received");
uint8_t * payload = buf + sizeof (SSUHeader);
payload++; // identity fragment info
uint16_t identitySize = be16toh (*(uint16_t *)payload);
@ -245,7 +245,7 @@ namespace transport @@ -245,7 +245,7 @@ namespace transport
auto introKey = GetIntroKey ();
if (!introKey)
{
LogPrint ("SSU is not supported");
LogPrint (eLogError, "SSU is not supported");
return;
}
@ -267,7 +267,7 @@ namespace transport @@ -267,7 +267,7 @@ namespace transport
auto address = i2p::context.GetRouterInfo ().GetSSUAddress ();
if (!address)
{
LogPrint ("SSU is not supported");
LogPrint (eLogError, "SSU is not supported");
return;
}
@ -301,7 +301,7 @@ namespace transport @@ -301,7 +301,7 @@ namespace transport
auto address = i2p::context.GetRouterInfo ().GetSSUAddress ();
if (!introKey || !address)
{
LogPrint ("SSU is not supported");
LogPrint (eLogError, "SSU is not supported");
return;
}
CryptoPP::RandomNumberGenerator& rnd = i2p::context.GetRandomNumberGenerator ();
@ -444,7 +444,7 @@ namespace transport @@ -444,7 +444,7 @@ namespace transport
FillHeaderAndEncrypt (PAYLOAD_TYPE_RELAY_RESPONSE, buf, 64, introKey, iv, introKey);
m_Server.Send (buf, 64, from);
}
LogPrint ("SSU relay response sent");
LogPrint (eLogDebug, "SSU relay response sent");
}
void SSUSession::SendRelayIntro (SSUSession * session, const boost::asio::ip::udp::endpoint& from)
@ -464,12 +464,12 @@ namespace transport @@ -464,12 +464,12 @@ namespace transport
rnd.GenerateBlock (iv, 16); // random iv
FillHeaderAndEncrypt (PAYLOAD_TYPE_RELAY_INTRO, buf, 48, session->m_SessionKey, iv, session->m_MacKey);
m_Server.Send (buf, 48, session->m_RemoteEndpoint);
LogPrint ("SSU relay intro sent");
LogPrint (eLogDebug, "SSU relay intro sent");
}
void SSUSession::ProcessRelayResponse (uint8_t * buf, size_t len)
{
LogPrint ("Relay response received");
LogPrint (eLogDebug, "Relay response received");
uint8_t * payload = buf + sizeof (SSUHeader);
payload++; // remote size
//boost::asio::ip::address_v4 remoteIP (be32toh (*(uint32_t* )(payload)));
@ -498,7 +498,7 @@ namespace transport @@ -498,7 +498,7 @@ namespace transport
m_Server.Send (buf, 0, boost::asio::ip::udp::endpoint (address, port));
}
else
LogPrint ("Address size ", size, " is not supported");
LogPrint (eLogWarning, "Address size ", size, " is not supported");
}
void SSUSession::FillHeaderAndEncrypt (uint8_t payloadType, uint8_t * buf, size_t len,
@ -506,7 +506,7 @@ namespace transport @@ -506,7 +506,7 @@ namespace transport
{
if (len < sizeof (SSUHeader))
{
LogPrint ("Unexpected SSU packet length ", len);
LogPrint (eLogError, "Unexpected SSU packet length ", len);
return;
}
SSUHeader * header = (SSUHeader *)buf;
@ -529,7 +529,7 @@ namespace transport @@ -529,7 +529,7 @@ namespace transport
{
if (len < sizeof (SSUHeader))
{
LogPrint ("Unexpected SSU packet length ", len);
LogPrint (eLogError, "Unexpected SSU packet length ", len);
return;
}
SSUHeader * header = (SSUHeader *)buf;
@ -550,7 +550,7 @@ namespace transport @@ -550,7 +550,7 @@ namespace transport
{
if (len < sizeof (SSUHeader))
{
LogPrint ("Unexpected SSU packet length ", len);
LogPrint (eLogError, "Unexpected SSU packet length ", len);
return;
}
SSUHeader * header = (SSUHeader *)buf;
@ -566,7 +566,7 @@ namespace transport @@ -566,7 +566,7 @@ namespace transport
{
if (len < sizeof (SSUHeader))
{
LogPrint ("Unexpected SSU packet length ", len);
LogPrint (eLogError, "Unexpected SSU packet length ", len);
return;
}
SSUHeader * header = (SSUHeader *)buf;
@ -583,7 +583,7 @@ namespace transport @@ -583,7 +583,7 @@ namespace transport
{
if (len < sizeof (SSUHeader))
{
LogPrint ("Unexpected SSU packet length ", len);
LogPrint (eLogError, "Unexpected SSU packet length ", len);
return false;
}
SSUHeader * header = (SSUHeader *)buf;
@ -756,7 +756,7 @@ namespace transport @@ -756,7 +756,7 @@ namespace transport
uint8_t * introKey = buf;
if (port && !address)
{
LogPrint ("Address of ", size, " bytes not supported");
LogPrint (eLogWarning, "Address of ", size, " bytes not supported");
return;
}
if (m_PeerTestNonces.count (nonce) > 0)
@ -764,13 +764,13 @@ namespace transport @@ -764,13 +764,13 @@ namespace transport
// existing test
if (m_PeerTest)
{
LogPrint ("SSU peer test from Bob. We are Alice");
LogPrint (eLogDebug, "SSU peer test from Bob. We are Alice");
m_PeerTestNonces.erase (nonce);
m_PeerTest = false;
}
else if (port)
{
LogPrint ("SSU peer test from Charlie. We are Bob");
LogPrint (eLogDebug, "SSU peer test from Charlie. We are Bob");
boost::asio::ip::udp::endpoint ep (boost::asio::ip::address_v4 (be32toh (address)), be16toh (port)); // Alice's address/port
auto session = m_Server.FindSession (ep); // find session with Alice
if (session)
@ -778,7 +778,7 @@ namespace transport @@ -778,7 +778,7 @@ namespace transport
}
else
{
LogPrint ("SSU peer test from Alice. We are Charlie");
LogPrint (eLogDebug, "SSU peer test from Alice. We are Charlie");
SendPeerTest (nonce, senderEndpoint.address ().to_v4 ().to_ulong (),
senderEndpoint.port (), introKey); // to Alice
}
@ -791,13 +791,13 @@ namespace transport @@ -791,13 +791,13 @@ namespace transport
m_PeerTestNonces.insert (nonce);
if (port)
{
LogPrint ("SSU peer test from Bob. We are Charlie");
LogPrint (eLogDebug, "SSU peer test from Bob. We are Charlie");
Send (PAYLOAD_TYPE_PEER_TEST, buf1, len); // back to Bob
SendPeerTest (nonce, be32toh (address), be16toh (port), introKey); // to Alice
}
else
{
LogPrint ("SSU peer test from Alice. We are Bob");
LogPrint (eLogDebug, "SSU peer test from Alice. We are Bob");
auto session = m_Server.GetRandomEstablishedSession (this); // charlie
if (session)
session->SendPeerTest (nonce, senderEndpoint.address ().to_v4 ().to_ulong (),
@ -805,7 +805,7 @@ namespace transport @@ -805,7 +805,7 @@ namespace transport
}
}
else
LogPrint ("SSU peer test from Charlie. We are Alice");
LogPrint (eLogDebug, "SSU peer test from Charlie. We are Alice");
}
}
@ -852,11 +852,11 @@ namespace transport @@ -852,11 +852,11 @@ namespace transport
void SSUSession::SendPeerTest ()
{
LogPrint ("SSU sending peer test");
LogPrint (eLogDebug, "SSU sending peer test");
auto address = i2p::context.GetRouterInfo ().GetSSUAddress ();
if (!address)
{
LogPrint ("SSU is not supported. Can't send peer test");
LogPrint (eLogError, "SSU is not supported. Can't send peer test");
return;
}
uint32_t nonce = i2p::context.GetRandomNumberGenerator ().GenerateWord32 ();
@ -877,7 +877,7 @@ namespace transport @@ -877,7 +877,7 @@ namespace transport
// encrypt message with session key
FillHeaderAndEncrypt (PAYLOAD_TYPE_DATA, buf, 48);
Send (buf, 48);
LogPrint ("SSU keep-alive sent");
LogPrint (eLogDebug, "SSU keep-alive sent");
ScheduleTermination ();
}
}
@ -890,7 +890,7 @@ namespace transport @@ -890,7 +890,7 @@ namespace transport
// encrypt message with session key
FillHeaderAndEncrypt (PAYLOAD_TYPE_SESSION_DESTROYED, buf, 48);
Send (buf, 48);
LogPrint ("SSU session destroyed sent");
LogPrint (eLogDebug, "SSU session destroyed sent");
}
}
@ -900,7 +900,7 @@ namespace transport @@ -900,7 +900,7 @@ namespace transport
size_t msgSize = len + sizeof (SSUHeader);
if (msgSize > SSU_MTU)
{
LogPrint ("SSU payload size ", msgSize, " exceeds MTU");
LogPrint (eLogWarning, "SSU payload size ", msgSize, " exceeds MTU");
return;
}
memcpy (buf + sizeof (SSUHeader), payload, len);
@ -963,7 +963,7 @@ namespace transport @@ -963,7 +963,7 @@ namespace transport
}
catch (std::exception& ex)
{
LogPrint ("SSU server: ", ex.what ());
LogPrint (eLogError, "SSU server: ", ex.what ());
}
}
}
@ -1095,7 +1095,7 @@ namespace transport @@ -1095,7 +1095,7 @@ namespace transport
}
else
{
LogPrint ("Can't connect to unreachable router. No introducers presented");
LogPrint (eLogWarning, "Can't connect to unreachable router. No introducers presented");
m_Sessions.erase (remoteEndpoint);
delete session;
session = nullptr;
@ -1104,7 +1104,7 @@ namespace transport @@ -1104,7 +1104,7 @@ namespace transport
}
}
else
LogPrint ("Router ", router->GetIdentHashAbbreviation (), " doesn't have SSU address");
LogPrint (eLogWarning, "Router ", router->GetIdentHashAbbreviation (), " doesn't have SSU address");
}
return session;
}

24
SSUData.cpp

@ -47,7 +47,7 @@ namespace transport @@ -47,7 +47,7 @@ namespace transport
}
else
{
LogPrint ("Unexpected MTU ", ssuAddress->mtu);
LogPrint (eLogWarning, "Unexpected MTU ", ssuAddress->mtu);
m_PacketSize = SSU_MAX_PACKET_SIZE;
}
}
@ -143,7 +143,7 @@ namespace transport @@ -143,7 +143,7 @@ namespace transport
uint16_t fragmentSize = fragmentInfo & 0x1FFF; // bits 0 - 13
bool isLast = fragmentInfo & 0x010000; // bit 16
uint8_t fragmentNum = fragmentInfo >> 17; // bits 23 - 17
LogPrint ("SSU data fragment ", (int)fragmentNum, " of message ", msgID, " size=", (int)fragmentSize, isLast ? " last" : " non-last");
LogPrint (eLogDebug, "SSU data fragment ", (int)fragmentNum, " of message ", msgID, " size=", (int)fragmentSize, isLast ? " last" : " non-last");
// find message with msgID
I2NPMessage * msg = nullptr;
@ -190,22 +190,22 @@ namespace transport @@ -190,22 +190,22 @@ namespace transport
break;
}
if (isLast)
LogPrint ("Message ", msgID, " complete");
LogPrint (eLogDebug, "Message ", msgID, " complete");
}
}
else
{
if (fragmentNum < incompleteMessage->nextFragmentNum)
// duplicate fragment
LogPrint ("Duplicate fragment ", (int)fragmentNum, " of message ", msgID, ". Ignored");
LogPrint (eLogWarning, "Duplicate fragment ", (int)fragmentNum, " of message ", msgID, ". Ignored");
else
{
// missing fragment
LogPrint ("Missing fragments from ", (int)incompleteMessage->nextFragmentNum, " to ", fragmentNum - 1, " of message ", msgID);
LogPrint (eLogWarning, "Missing fragments from ", (int)incompleteMessage->nextFragmentNum, " to ", fragmentNum - 1, " of message ", msgID);
auto savedFragment = new Fragment (fragmentNum, buf, fragmentSize, isLast);
if (!incompleteMessage->savedFragments.insert (savedFragment).second)
{
LogPrint ("Fragment ", (int)fragmentNum, " of message ", msgID, " already saved");
LogPrint (eLogWarning, "Fragment ", (int)fragmentNum, " of message ", msgID, " already saved");
delete savedFragment;
}
}
@ -230,7 +230,7 @@ namespace transport @@ -230,7 +230,7 @@ namespace transport
}
else
{
LogPrint ("SSU message ", msgID, " already received");
LogPrint (eLogWarning, "SSU message ", msgID, " already received");
i2p::DeleteI2NPMessage (msg);
}
}
@ -243,7 +243,7 @@ namespace transport @@ -243,7 +243,7 @@ namespace transport
m_Session.Established ();
}
else
LogPrint ("SSU unexpected message ", (int)msg->GetHeader ()->typeID);
LogPrint (eLogError, "SSU unexpected message ", (int)msg->GetHeader ()->typeID);
DeleteI2NPMessage (msg);
}
}
@ -258,7 +258,7 @@ namespace transport @@ -258,7 +258,7 @@ namespace transport
//uint8_t * start = buf;
uint8_t flag = *buf;
buf++;
LogPrint ("Process SSU data flags=", (int)flag);
LogPrint (eLogDebug, "Process SSU data flags=", (int)flag);
// process acks if presented
if (flag & (DATA_FLAG_ACK_BITFIELDS_INCLUDED | DATA_FLAG_EXPLICIT_ACKS_INCLUDED))
ProcessAcks (buf, flag);
@ -267,7 +267,7 @@ namespace transport @@ -267,7 +267,7 @@ namespace transport
{
uint8_t extendedDataSize = *buf;
buf++; // size
LogPrint ("SSU extended data of ", extendedDataSize, " bytes presented");
LogPrint (eLogDebug, "SSU extended data of ", extendedDataSize, " bytes presented");
buf += extendedDataSize;
}
// process data
@ -279,7 +279,7 @@ namespace transport @@ -279,7 +279,7 @@ namespace transport
uint32_t msgID = msg->ToSSU ();
if (m_SentMessages.count (msgID) > 0)
{
LogPrint ("SSU message ", msgID, " already sent");
LogPrint (eLogWarning, "SSU message ", msgID, " already sent");
DeleteI2NPMessage (msg);
return;
}
@ -363,7 +363,7 @@ namespace transport @@ -363,7 +363,7 @@ namespace transport
{
if (fragmentNum > 64)
{
LogPrint ("Fragment number ", fragmentNum, " exceeds 64");
LogPrint (eLogWarning, "Fragment number ", fragmentNum, " exceeds 64");
return;
}
uint8_t buf[64 + 18];

Loading…
Cancel
Save