From 5707c230e2dee96551a9464661dece56a6aafa48 Mon Sep 17 00:00:00 2001 From: Sudo-Ivan Date: Mon, 29 Dec 2025 23:27:16 -0600 Subject: [PATCH] fix: update request handling to support multiple data types for requested_at, path_hash, and request_payload, and improve logging for request processing --- pkg/link/link.go | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/pkg/link/link.go b/pkg/link/link.go index 8766afc..2b5f9f1 100644 --- a/pkg/link/link.go +++ b/pkg/link/link.go @@ -807,7 +807,7 @@ func (l *Link) handleResourceAdvertisement(pkt *packet.Packet) error { if l.destination != nil { handler := l.destination.GetRequestHandler(requestID) if handler != nil { - response := handler(requestID, nil, requestID, l.remoteIdentity, time.Now()) + response := handler(requestID, nil, requestID, l.linkID, l.remoteIdentity, time.Now()) if response != nil { return l.sendResourceResponse(requestID, response) } @@ -1014,19 +1014,43 @@ func (l *Link) handleRequest(plaintext []byte, pkt *packet.Packet) error { return errors.New("invalid request format") } - requestedAt := time.Unix(int64(requestData[common.ZERO].(int64)), common.ZERO) - pathHash := requestData[common.ONE].([]byte) - requestPayload := requestData[common.TWO].([]byte) + requestedAtFloat, ok := requestData[common.ZERO].(float64) + if !ok { + if requestedAtInt, ok := requestData[common.ZERO].(int64); ok { + requestedAtFloat = float64(requestedAtInt) + } else { + return fmt.Errorf("invalid requested_at type: %T", requestData[common.ZERO]) + } + } + requestedAt := time.Unix(int64(requestedAtFloat), 0) - requestID := identity.TruncatedHash(plaintext) + pathHash, ok := requestData[common.ONE].([]byte) + if !ok { + return fmt.Errorf("invalid path_hash type: %T", requestData[common.ONE]) + } + + var requestPayload []byte + if requestData[common.TWO] != nil { + if payload, ok := requestData[common.TWO].([]byte); ok { + requestPayload = payload + } else { + return fmt.Errorf("invalid request_payload type: %T", requestData[common.TWO]) + } + } + + requestID := pkt.TruncatedHash() + + debug.Log(debug.DEBUG_INFO, "Handling request", "path_hash", fmt.Sprintf("%x", pathHash), "request_id", fmt.Sprintf("%x", requestID)) if l.destination != nil { handler := l.destination.GetRequestHandler(pathHash) if handler != nil { - response := handler(pathHash, requestPayload, requestID, l.remoteIdentity, requestedAt) + response := handler(pathHash, requestPayload, requestID, l.linkID, l.remoteIdentity, requestedAt) if response != nil { return l.sendResponse(requestID, response) } + } else { + debug.Log(debug.DEBUG_VERBOSE, "No handler found for path", "path_hash", fmt.Sprintf("%x", pathHash)) } }