replace buggy CreateOutboundRoute that refused to work without target key

This commit is contained in:
mykola2312 2025-01-30 14:49:26 +02:00
parent 5d65ad3e4b
commit 1af0aacf96
3 changed files with 26 additions and 2 deletions

View file

@ -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) {

View file

@ -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 {

View file

@ -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
}