upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/net.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/net.h')
-rw-r--r--src/net.h28
1 files changed, 23 insertions, 5 deletions
diff --git a/src/net.h b/src/net.h
index 9f3c7e4..600922a 100644
--- a/src/net.h
+++ b/src/net.h
@@ -802,6 +802,18 @@ public:
802 802
803 803
804 804
805 // "sending: tx (N bytes)" alone was ~71% of a 13-hour production
806 // debug.log (issue #35), so tx sends are demoted to the /debugrelay-gated
807 // "relay" category; every other command's send trace stays on "net".
808 // The line is emitted in pieces across BeginMessage/EndMessage/
809 // AbortMessage, so all three must agree on the category or orphaned
810 // "(N bytes)" fragments would leak into a plain -debug log.
811 // Valid only mid-message (nPushPos != -1).
812 const char* SendLogCategory() const
813 {
814 return strcmp(GetMessageCommand(), "tx") == 0 ? "relay" : "net";
815 }
816
805 void BeginMessage(const char* pszCommand) 817 void BeginMessage(const char* pszCommand)
806 { 818 {
807 EnterCriticalSection(&cs_vSend); 819 EnterCriticalSection(&cs_vSend);
@@ -809,17 +821,19 @@ public:
809 AbortMessage(); 821 AbortMessage();
810 nPushPos = vSend.size(); 822 nPushPos = vSend.size();
811 vSend << CMessageHeader(pszCommand, 0); 823 vSend << CMessageHeader(pszCommand, 0);
812 if (LogAcceptsCategory("net")) printf("sending: %-12s ", pszCommand); 824 if (LogAcceptsCategory(SendLogCategory())) printf("sending: %-12s ", pszCommand);
813 } 825 }
814 826
815 void AbortMessage() 827 void AbortMessage()
816 { 828 {
817 if (nPushPos == -1) 829 if (nPushPos == -1)
818 return; 830 return;
831 // Capture before nPushPos is cleared; GetMessageCommand() needs it.
832 const char* pszCategory = SendLogCategory();
819 vSend.resize(nPushPos); 833 vSend.resize(nPushPos);
820 nPushPos = -1; 834 nPushPos = -1;
821 LeaveCriticalSection(&cs_vSend); 835 LeaveCriticalSection(&cs_vSend);
822 if (LogAcceptsCategory("net")) printf("(aborted)\n"); 836 if (LogAcceptsCategory(pszCategory)) printf("(aborted)\n");
823 } 837 }
824 838
825 void EndMessage() 839 void EndMessage()
@@ -827,7 +841,11 @@ public:
827 extern int nDropMessagesTest; 841 extern int nDropMessagesTest;
828 if (nDropMessagesTest > 0 && GetRand(nDropMessagesTest) == 0) 842 if (nDropMessagesTest > 0 && GetRand(nDropMessagesTest) == 0)
829 { 843 {
830 if (LogAcceptsCategory("net")) printf("dropmessages DROPPING SEND MESSAGE\n"); 844 // Same category as the "sending: " this line interrupts, so a tx
845 // does not announce its own drop under "net" having been gated
846 // off under "relay". nPushPos can be -1 here, and then
847 // GetMessageCommand() returns "" and this is "net" as before.
848 if (LogAcceptsCategory(SendLogCategory())) printf("dropmessages DROPPING SEND MESSAGE\n");
831 AbortMessage(); 849 AbortMessage();
832 return; 850 return;
833 } 851 }
@@ -839,10 +857,10 @@ public:
839 unsigned int nSize = vSend.size() - nPushPos - sizeof(CMessageHeader); 857 unsigned int nSize = vSend.size() - nPushPos - sizeof(CMessageHeader);
840 memcpy((char*)&vSend[nPushPos] + offsetof(CMessageHeader, nMessageSize), &nSize, sizeof(nSize)); 858 memcpy((char*)&vSend[nPushPos] + offsetof(CMessageHeader, nMessageSize), &nSize, sizeof(nSize));
841 859
842 if (LogAcceptsCategory("net")) printf("(%d bytes) ", nSize); 860 if (LogAcceptsCategory(SendLogCategory())) printf("(%d bytes) ", nSize);
843 //for (int i = nPushPos+sizeof(CMessageHeader); i < min(vSend.size(), nPushPos+sizeof(CMessageHeader)+20U); i++) 861 //for (int i = nPushPos+sizeof(CMessageHeader); i < min(vSend.size(), nPushPos+sizeof(CMessageHeader)+20U); i++)
844 // printf("%02x ", vSend[i] & 0xff); 862 // printf("%02x ", vSend[i] & 0xff);
845 if (LogAcceptsCategory("net")) printf("\n"); 863 if (LogAcceptsCategory(SendLogCategory())) printf("\n");
846 864
847 nPushPos = -1; 865 nPushPos = -1;
848 LeaveCriticalSection(&cs_vSend); 866 LeaveCriticalSection(&cs_vSend);