fix route id matching, now node-to-host replies works

This commit is contained in:
mykola2312 2025-01-17 09:23:11 +02:00
parent 88190c1a2d
commit bc8c4e7a0f
3 changed files with 48 additions and 1 deletions

View file

@ -33,6 +33,10 @@ func (host *LuxHost) AddOptionProvider(provider LuxOptionProvider) {
host.providers = append(host.providers, provider)
}
func (host *LuxHost) GetRouter() *net.LuxRouter {
return &host.router
}
func (host *LuxHost) CaptureState() (LuxState, error) {
state := LuxState{
Hostname: host.hostname,

View file

@ -221,6 +221,10 @@ func (r *LuxRouter) Start() {
for _, inbound := range r.inbound {
go channelReceiver(r, &inbound)
}
for _, outbound := range r.outbound {
go channelReceiver(r, &outbound)
}
r.channelLock.RUnlock()
}
@ -299,7 +303,21 @@ func (r *LuxRouter) Recv() (LuxPacket, error) {
}
// check if LuxID matches
if !bytes.Equal(packet.Target.UUID[:], route.Target.UUID[:]) {
// Node replies to host shall be matched by source ID on the host
var routeId *proto.LuxID
targetKey, _ := r.keyStore.Get(route.Target)
if r.GetRouterType() == proto.LuxTypeHost {
if targetKey.Type == proto.LuxTypeNode {
routeId = &route.Source
} else {
routeId = &route.Target
}
} else {
// on the node, we always operate by target ID
routeId = &route.Target
}
if !bytes.Equal(packet.Target.UUID[:], routeId.UUID[:]) {
// not matches.. we discard route and throw away packet
log.Infof("packet from %s received at route %v has targetID %s that mismatches associated target UUID %s",
dgram.Target.String(), route, packet.Target.String(), route.Target.String())

View file

@ -81,4 +81,29 @@ func TestHeartbeatMulticast(t *testing.T) {
t.Fatal("WAN IPs aren't equal")
}
}
// node to host reply
reply := net.LuxPacket{
Target: keyHost.Id,
Type: 0x0203,
Buffer: proto.FromSlice([]byte{1, 2, 3, 4}),
}
if err := nodeA.Send(reply); err != nil {
t.Fatal(err)
}
hostA.GetRouter().Start()
defer hostA.GetRouter().Stop()
reply2, err := hostA.GetRouter().Recv()
if err != nil {
t.Fatal(err)
}
if reply2.Type != reply.Type {
t.Fatal(".Type != reply.Type")
}
if !bytes.Equal(reply2.Buffer.AllBytes()[:4], reply.Buffer.AllBytes()) {
t.Fatal("reply payloads not equal!")
}
}