FIX routing issue with neighbor nodes syncing

This commit is contained in:
mykola2312 2025-01-30 09:47:19 +02:00
parent 88aad95cfb
commit c88ba03b66
2 changed files with 17 additions and 11 deletions

View file

@ -135,7 +135,7 @@ 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.
func (r *LuxRouter) CreateOutboundRoute(id proto.LuxID, chType LuxChannelType, udpAddr string) error {
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)
if !ok {
@ -149,15 +149,20 @@ func (r *LuxRouter) CreateOutboundRoute(id proto.LuxID, chType LuxChannelType, u
}
var routeType LuxRouteType
switch r.GetRouterType() {
case proto.LuxTypeHost:
if key.Type == proto.LuxTypeNode {
routeType = LuxRouteFromSource
} else {
if len(params) == 1 && params[0] {
// DIRTY QUICK HACK to force neighbor-to-node packets use source key
routeType = LuxRouteFromSource
} else {
switch r.GetRouterType() {
case proto.LuxTypeHost:
if key.Type == proto.LuxTypeNode {
routeType = LuxRouteFromSource
} else {
routeType = LuxRouteToTarget
}
case proto.LuxTypeNode:
routeType = LuxRouteToTarget
}
case proto.LuxTypeNode:
routeType = LuxRouteToTarget
}
r.routes[key.Id] = &LuxRoute{
@ -444,6 +449,7 @@ func (r *LuxRouter) Multicast(packet LuxPacket, group proto.LuxType) error {
targetKey, _ := r.keyStore.Get(route.Target)
if targetKey.Type == group {
packet.Target = key.Id
packet.Nonce = GenerateLuxNonce()
dgram, err := EncryptLuxPacket(packet, key, route.Destination)
if err != nil {

View file

@ -72,15 +72,15 @@ 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)
err = node.router.CreateOutboundRoute(id, net.LuxChannelInterior, udpAddr, true)
if err != nil {
return err
}
}
// just add to neighbor list to let other nodes know
node.neighborLock.Lock()
defer node.neighborLock.Unlock()
// node.neighborLock.Lock()
// defer node.neighborLock.Unlock()
node.neighbors[id] = udpIp