From 59486330ec8bf8b6c530f1aed57ecfcc45f67394 Mon Sep 17 00:00:00 2001 From: Ivan Date: Fri, 21 Nov 2025 12:43:00 -0600 Subject: [PATCH] update HandleIncomingLinkRequest to accept packet instead of linkID and add HandleRequest method for improved request handling --- pkg/destination/destination.go | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/pkg/destination/destination.go b/pkg/destination/destination.go index 591ef97..d27d3af 100644 --- a/pkg/destination/destination.go +++ b/pkg/destination/destination.go @@ -251,18 +251,12 @@ func (d *Destination) GetLinkCallback() common.LinkEstablishedCallback { return d.linkCallback } -func (d *Destination) HandleIncomingLinkRequest(linkID []byte, transport interface{}, networkIface common.NetworkInterface) error { +func (d *Destination) HandleIncomingLinkRequest(pkt interface{}, transport interface{}, networkIface common.NetworkInterface) error { debug.Log(debug.DEBUG_INFO, "Handling incoming link request for destination", "hash", fmt.Sprintf("%x", d.GetHash())) - // Import link package here to avoid circular dependency at package level - // We'll use dynamic import by having the caller create the link - // For now, just call the callback with a placeholder - if d.linkCallback != nil { - debug.Log(debug.DEBUG_INFO, "Calling link established callback") - // Pass linkID as the link object for now - // The callback will need to handle creating the actual link - d.linkCallback(linkID) + debug.Log(debug.DEBUG_INFO, "Calling link established callback with packet") + d.linkCallback(pkt) } else { debug.Log(debug.DEBUG_VERBOSE, "No link callback set") } @@ -393,6 +387,20 @@ func (d *Destination) DeregisterRequestHandler(path string) bool { return false } +func (d *Destination) HandleRequest(path string, data []byte, requestID []byte, linkID []byte, remoteIdentity *identity.Identity, requestedAt int64) []byte { + d.mutex.RLock() + handler, exists := d.requestHandlers[path] + d.mutex.RUnlock() + + if !exists { + debug.Log(debug.DEBUG_INFO, "No handler registered for path", "path", path) + return []byte(">Not Found\n\nThe requested resource was not found.") + } + + debug.Log(debug.DEBUG_VERBOSE, "Calling request handler", "path", path) + return handler.ResponseGenerator(path, data, requestID, linkID, remoteIdentity, requestedAt) +} + func (d *Destination) Encrypt(plaintext []byte) ([]byte, error) { if d.destType == PLAIN { debug.Log(debug.DEBUG_VERBOSE, "Using plaintext transmission for PLAIN destination")