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.h22
1 files changed, 18 insertions, 4 deletions
diff --git a/src/net.h b/src/net.h
index 9f3c7e4..1aee973 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()
@@ -839,10 +853,10 @@ public:
839 unsigned int nSize = vSend.size() - nPushPos - sizeof(CMessageHeader); 853 unsigned int nSize = vSend.size() - nPushPos - sizeof(CMessageHeader);
840 memcpy((char*)&vSend[nPushPos] + offsetof(CMessageHeader, nMessageSize), &nSize, sizeof(nSize)); 854 memcpy((char*)&vSend[nPushPos] + offsetof(CMessageHeader, nMessageSize), &nSize, sizeof(nSize));
841 855
842 if (LogAcceptsCategory("net")) printf("(%d bytes) ", nSize); 856 if (LogAcceptsCategory(SendLogCategory())) printf("(%d bytes) ", nSize);
843 //for (int i = nPushPos+sizeof(CMessageHeader); i < min(vSend.size(), nPushPos+sizeof(CMessageHeader)+20U); i++) 857 //for (int i = nPushPos+sizeof(CMessageHeader); i < min(vSend.size(), nPushPos+sizeof(CMessageHeader)+20U); i++)
844 // printf("%02x ", vSend[i] & 0xff); 858 // printf("%02x ", vSend[i] & 0xff);
845 if (LogAcceptsCategory("net")) printf("\n"); 859 if (LogAcceptsCategory(SendLogCategory())) printf("\n");
846 860
847 nPushPos = -1; 861 nPushPos = -1;
848 LeaveCriticalSection(&cs_vSend); 862 LeaveCriticalSection(&cs_vSend);