Add HandleIncomingLinkRequest and GetLinkID methods for improved link handling and status retrieval; enhance logging for link proof generation and sending process.
Some checks failed
Go Build Multi-Platform / build (arm, freebsd) (push) Failing after 26s
Go Build Multi-Platform / build (arm, windows) (push) Failing after 34s
Go Build Multi-Platform / build (arm64, darwin) (push) Failing after 32s
Go Build Multi-Platform / build (arm64, freebsd) (push) Failing after 46s
Go Build Multi-Platform / build (arm64, windows) (push) Failing after 35s
Go Test Multi-Platform / Test (macos-latest, amd64) (push) Has been cancelled
Go Test Multi-Platform / Test (ubuntu-latest, amd64) (push) Has been cancelled
Run Gosec / tests (push) Has been cancelled
Go Test Multi-Platform / Test (ubuntu-latest, arm64) (push) Has been cancelled
Go Build Multi-Platform / build (amd64, windows) (push) Failing after 38s
Go Build Multi-Platform / build (amd64, darwin) (push) Failing after 44s
Go Build Multi-Platform / build (amd64, freebsd) (push) Failing after 42s
Go Build Multi-Platform / build (amd64, linux) (push) Failing after 41s
Go Build Multi-Platform / build (arm, linux) (push) Failing after 27s
Go Build Multi-Platform / build (arm64, linux) (push) Failing after 43s
Go Build Multi-Platform / Create Release (push) Has been cancelled
Go Test Multi-Platform / Test (windows-latest, amd64) (push) Has been cancelled
Go Test Multi-Platform / Test (macos-latest, arm64) (push) Has been cancelled
Go Revive Lint / lint (push) Has been cancelled

This commit is contained in:
2025-11-21 12:43:22 -06:00
parent d14692b19b
commit cfcdb62168

View File

@@ -145,6 +145,29 @@ func NewLink(dest *destination.Destination, transport *transport.Transport, netw
}
}
func HandleIncomingLinkRequest(pkt *packet.Packet, dest *destination.Destination, transport *transport.Transport, networkIface common.NetworkInterface) (*Link, error) {
debug.Log(debug.DEBUG_INFO, "Creating link for incoming request", "dest_hash", fmt.Sprintf("%x", dest.GetHash()))
l := NewLink(dest, transport, networkIface, nil, nil)
l.status = STATUS_PENDING
l.initiator = false // This is a responder link
ownerIdentity := dest.GetIdentity()
if ownerIdentity == nil {
return nil, errors.New("destination has no identity")
}
if err := l.HandleLinkRequest(pkt, ownerIdentity); err != nil {
debug.Log(debug.DEBUG_ERROR, "Failed to handle link request", "error", err)
return nil, err
}
go l.startWatchdog()
debug.Log(debug.DEBUG_INFO, "Link established for incoming request", "link_id", fmt.Sprintf("%x", l.linkID))
return l, nil
}
func (l *Link) Establish() error {
l.mutex.Lock()
defer l.mutex.Unlock()
@@ -676,6 +699,12 @@ func (l *Link) GetStatus() byte {
return l.status
}
func (l *Link) GetLinkID() []byte {
l.mutex.RLock()
defer l.mutex.RUnlock()
return l.linkID
}
func (l *Link) IsActive() bool {
return l.GetStatus() == STATUS_ACTIVE
}
@@ -1087,11 +1116,31 @@ func (l *Link) performHandshake() error {
}
func (l *Link) sendLinkProof(ownerIdentity *identity.Identity) error {
debug.Log(debug.DEBUG_ERROR, "Generating link proof", "link_id", fmt.Sprintf("%x", l.linkID), "initiator", l.initiator, "has_interface", l.networkInterface != nil)
proofPkt, err := l.GenerateLinkProof(ownerIdentity)
if err != nil {
return err
}
debug.Log(debug.DEBUG_ERROR, "Link proof packet created", "dest_hash", fmt.Sprintf("%x", proofPkt.DestinationHash), "packet_type", fmt.Sprintf("0x%02x", proofPkt.PacketType))
// For responder links (not initiator), send proof directly through the receiving interface
if !l.initiator && l.networkInterface != nil {
if err := proofPkt.Pack(); err != nil {
return fmt.Errorf("failed to pack proof packet: %w", err)
}
debug.Log(debug.DEBUG_ERROR, "Sending proof through interface", "raw_len", len(proofPkt.Raw), "interface", l.networkInterface.GetName())
if err := l.networkInterface.Send(proofPkt.Raw, ""); err != nil {
return fmt.Errorf("failed to send link proof through interface: %w", err)
}
debug.Log(debug.DEBUG_ERROR, "Link proof sent through interface", "link_id", fmt.Sprintf("%x", l.linkID), "interface", l.networkInterface.GetName())
return nil
}
// For initiator links, use transport (path lookup)
if l.transport != nil {
if err := l.transport.SendPacket(proofPkt); err != nil {
return fmt.Errorf("failed to send link proof: %w", err)