From 1af0aacf963244fab3ee9d298798bb466496839c Mon Sep 17 00:00:00 2001 From: mykola2312 <49044616+mykola2312@users.noreply.github.com> Date: Thu, 30 Jan 2025 14:49:26 +0200 Subject: [PATCH] replace buggy CreateOutboundRoute that refused to work without target key --- host/lux_host.go | 2 +- net/lux_router.go | 24 ++++++++++++++++++++++++ node/lux_node.go | 2 +- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/host/lux_host.go b/host/lux_host.go index 8cd45c5..56858ba 100644 --- a/host/lux_host.go +++ b/host/lux_host.go @@ -26,7 +26,7 @@ func NewLuxHost(hostname string, hostKey crypto.LuxKey, ks crypto.LuxKeyStore) L } func (host *LuxHost) AddNode(node proto.LuxID, udpAddr string) error { - return host.router.CreateOutboundRoute(node, net.LuxChannelExterior, udpAddr) + return host.router.AddOutboundRoute(node, net.LuxRouteFromSource, net.LuxChannelExterior, udpAddr) } func (host *LuxHost) AddOptionProvider(provider LuxOptionProvider) { diff --git a/net/lux_router.go b/net/lux_router.go index 81c5815..a4812ed 100644 --- a/net/lux_router.go +++ b/net/lux_router.go @@ -135,6 +135,9 @@ func (r *LuxRouter) addInboundChannel(ch LuxChannel) *LuxChannel { // the ID is not destination, but rather peer associated for this route, like source ID. // Destination router always know who is he, therefore we dont need target ID. + +// Deprecated: this function is source of many bugs and culprits. The major issue is route type determination, +// since not all hosts or nodes have destination key, as they may use LuxRouteTypeFromSource func (r *LuxRouter) CreateOutboundRoute(id proto.LuxID, chType LuxChannelType, udpAddr string, params ...bool) error { // we gonna look up key by id from key store key, ok := r.keyStore.Get(id) @@ -178,6 +181,27 @@ func (r *LuxRouter) CreateOutboundRoute(id proto.LuxID, chType LuxChannelType, u return nil } +// However, you still may need both keys for target and source ID +func (r *LuxRouter) AddOutboundRoute(target proto.LuxID, routeType LuxRouteType, chType LuxChannelType, udpAddr string) error { + channel, err := NewLuxOutboundChannel(udpAddr, chType) + if err != nil { + return err + } + + route := &LuxRoute{ + Type: routeType, + Target: target, + Source: r.thisKey.Id, + Destination: channel.Address, + Associated: r.addOutboundChannel(channel), + Nonces: NewLuxNonceList(), + } + r.routes[target] = route + + log.Debugf("outbound route: %s", route.String()) + return nil +} + func (r *LuxRouter) CreateInboundChannel(chType LuxChannelType, udpAddr string) error { channel, err := NewLuxInboundChannel(udpAddr, chType) if err != nil { diff --git a/node/lux_node.go b/node/lux_node.go index 39ffe1a..91c286e 100644 --- a/node/lux_node.go +++ b/node/lux_node.go @@ -72,7 +72,7 @@ func (node *LuxNode) AddNeighbor(id proto.LuxID, udpAddr string) error { if node.router.HasKeyFor(id) { // we have key for this node, so we can route - err = node.router.CreateOutboundRoute(id, net.LuxChannelInterior, udpAddr, true) + err = node.router.AddOutboundRoute(id, net.LuxRouteFromSource, net.LuxChannelInterior, udpAddr) if err != nil { return err }