Skip to content

Agent Mesh

fix lint and reviews

Antonio Ojea370f9404233f
diff --git a/cmd/sam-node/mcp.go b/cmd/sam-node/mcp.go
index 32855e88..9f62d77b 100644
--- a/cmd/sam-node/mcp.go
+++ b/cmd/sam-node/mcp.go
@@ -152,10 +152,12 @@ func (n *SamNode) CallMCPTool(ctx context.Context, targetPeer peer.ID, toolName
return res, nil
}
logger.Warnf("[MCP] Tool call failed, retrying in %v: %v", backoff, err)
+ timer := time.NewTimer(backoff)
select {
case <-ctx.Done():
+ timer.Stop()
return nil, fmt.Errorf("context canceled during retry: %w", ctx.Err())
- case <-time.After(backoff):
+ case <-timer.C:
}
backoff *= 2
}
@@ -191,7 +193,7 @@ func (n *SamNode) callMCPToolOnce(ctx context.Context, targetPeer peer.ID, toolN
authBytes, _ := proto.Marshal(&authFrame)
// Handshake should be fast; set a hard deadline to prevent hanging
- s.SetDeadline(time.Now().Add(10 * time.Second))
+ _ = s.SetDeadline(time.Now().Add(10 * time.Second))
// Write AuthFrame
logger.Debugf("Writing auth frame to %s...\n", targetPeer)
@@ -210,7 +212,7 @@ func (n *SamNode) callMCPToolOnce(ctx context.Context, targetPeer peer.ID, toolN
defer reader.ReleaseMsg(msg)
// Clear deadline so the MCP SDK can use the stream normally without timing out
- s.SetDeadline(time.Time{})
+ _ = s.SetDeadline(time.Time{})
var resp api.AuthResponse
if err := proto.Unmarshal(msg, &resp); err != nil {
@@ -271,6 +273,9 @@ func (n *SamNode) fetchRemoteServiceCatalog(ctx context.Context, peerID peer.ID,
// looks up the relay's direct IPs via the DHT, and adds them to the target's peerstore.
// This prevents dial backoff errors when the relay is behind a load-balanced DNS address.
func (n *SamNode) resolveRelayAddresses(ctx context.Context, targetPeer peer.ID) {
+ if n.Host == nil || n.DHT == nil {
+ return
+ }
addrs := n.Host.Peerstore().Addrs(targetPeer)
for _, ma := range addrs {
parts := multiaddr.Split(ma)
@@ -300,7 +305,11 @@ func (n *SamNode) resolveRelayAddresses(ctx context.Context, targetPeer peer.ID)
for _, relayAddr := range pi.Addrs {
// Check if it's a direct IP (not dns)
- code := relayAddr.Protocols()[0].Code
+ protocols := relayAddr.Protocols()
+ if len(protocols) == 0 {
+ continue
+ }
+ code := protocols[0].Code
if code == multiaddr.P_IP4 || code == multiaddr.P_IP6 {
circuitPart, _ := multiaddr.NewMultiaddr(fmt.Sprintf("/p2p/%s/p2p-circuit", relayID.String()))
newMa := relayAddr.Encapsulate(circuitPart)
diff --git a/cmd/sam-node/mcp_test.go b/cmd/sam-node/mcp_test.go
index 3afd8434..6d9f474e 100644
--- a/cmd/sam-node/mcp_test.go
+++ b/cmd/sam-node/mcp_test.go
@@ -85,6 +85,7 @@ func TestResolveRelayAddresses(t *testing.T) {
if err != nil {
t.Fatal(err)
}
+ defer kdht.Close()
node := &SamNode{
Host: localHost,
@@ -108,13 +109,14 @@ func TestResolveRelayAddresses(t *testing.T) {
if err != nil {
t.Fatal(err)
}
+ defer relayDHT.Close()
- mn.LinkAll()
- mn.ConnectAllButSelf()
+ _ = mn.LinkAll()
+ _ = mn.ConnectAllButSelf()
// Wait for DHT
- kdht.RoutingTable().TryAddPeer(relayID, true, true)
- relayDHT.RoutingTable().TryAddPeer(localHost.ID(), true, true)
+ _, _ = kdht.RoutingTable().TryAddPeer(relayID, true, true)
+ _, _ = relayDHT.RoutingTable().TryAddPeer(localHost.ID(), true, true)
// Create a target node behind the relay
targetHost, err := mn.GenPeer()