Agent Mesh
Go a2aa2a-protocolagent-meshagentic-aiinferencemcpmeshmesh-networknetwork-securitynetworking-aip2p-network
address reviews
Antonio Ojeaa23936b06921
diff --git a/internal/node/middleware.go b/internal/node/middleware.goindex 0cfa72e4..3533b8ca 100644--- a/internal/node/middleware.go+++ b/internal/node/middleware.go@@ -40,19 +40,18 @@ type RequestContext struct {// trackingStream wraps a network.Stream to count bytes read and written.type trackingStream struct {network.Stream- bytesRead int64- bytesWritten int64+ bytesRead atomic.Int64+ bytesWritten atomic.Int64}func (t *trackingStream) Read(p []byte) (n int, err error) {n, err = t.Stream.Read(p)- atomic.AddInt64(&t.bytesRead, int64(n))+ t.bytesRead.Add(int64(n))return n, err}-func (t *trackingStream) Write(p []byte) (n int, err error) {n, err = t.Stream.Write(p)- atomic.AddInt64(&t.bytesWritten, int64(n))+ t.bytesWritten.Add(int64(n))return n, err}@@ -72,8 +71,8 @@ func (n *SamNode) WithBiscuitAuth(next func(network.Stream, RequestContext)) net"peer_id", remotePeer.String(),"target", target,"protocol", reqCtx.Protocol,- "bytes_read", atomic.LoadInt64(&ts.bytesRead),- "bytes_written", atomic.LoadInt64(&ts.bytesWritten),+ "bytes_read", ts.bytesRead.Load(),+ "bytes_written", ts.bytesWritten.Load(),)if err := ts.Close(); err != nil {logger.Debugf("[Auth] Failed to close stream: %v", err)diff --git a/internal/node/middleware_test.go b/internal/node/middleware_test.goindex d91017c8..7b0882f8 100644--- a/internal/node/middleware_test.go+++ b/internal/node/middleware_test.go@@ -709,8 +709,8 @@ func TestTrackingStream(t *testing.T) {if err != nil || n != len(writeData) {t.Fatalf("Write failed: %v", err)}- if ts.bytesWritten != int64(len(writeData)) {- t.Errorf("Expected bytesWritten to be %d, got %d", len(writeData), ts.bytesWritten)+ if ts.bytesWritten.Load() != int64(len(writeData)) {+ t.Errorf("Expected bytesWritten to be %d, got %d", len(writeData), ts.bytesWritten.Load())}// Read data@@ -720,7 +720,7 @@ func TestTrackingStream(t *testing.T) {if err != nil {t.Fatalf("Read failed: %v", err)}- if ts.bytesRead != int64(n) {- t.Errorf("Expected bytesRead to be %d, got %d", n, ts.bytesRead)+ if ts.bytesRead.Load() != int64(n) {+ t.Errorf("Expected bytesRead to be %d, got %d", n, ts.bytesRead.Load())}}diff --git a/internal/node/node.go b/internal/node/node.goindex 2e531857..104300a2 100644--- a/internal/node/node.go+++ b/internal/node/node.go@@ -1714,24 +1714,24 @@ func (n *SamNode) ListLocalServices(typeFilter api.ServiceType) []*api.ServiceIntype readCloserWithCount struct {io.ReadCloser- bytesRead int64+ bytesRead atomic.Int64}func (rc *readCloserWithCount) Read(p []byte) (int, error) {n, err := rc.ReadCloser.Read(p)- atomic.AddInt64(&rc.bytesRead, int64(n))+ rc.bytesRead.Add(int64(n))return n, err}type responseWriterWithCount struct {http.ResponseWriter- bytesWritten int64+ bytesWritten atomic.Int64statusCode int}func (w *responseWriterWithCount) Write(p []byte) (int, error) {n, err := w.ResponseWriter.Write(p)- atomic.AddInt64(&w.bytesWritten, int64(n))+ w.bytesWritten.Add(int64(n))return n, err}@@ -1775,8 +1775,8 @@ func (n *SamNode) StartIngressServer(ctx context.Context) error {"peer_id", peerIDStr,"target", finalTarget,"protocol", "/libp2p-http",- "bytes_read", atomic.LoadInt64(&rc.bytesRead),- "bytes_written", atomic.LoadInt64(&wc.bytesWritten),+ "bytes_read", rc.bytesRead.Load(),+ "bytes_written", wc.bytesWritten.Load(),)}()@@ -1860,8 +1860,6 @@ func (n *SamNode) StartIngressServer(ctx context.Context) error {}r.URL.RawPath = ""- r.URL.RawPath = ""-svc.Handler().ServeHTTP(w, r)}),}