diff --git a/host/lux_host.go b/host/lux_host.go index e1ef602..37021a5 100644 --- a/host/lux_host.go +++ b/host/lux_host.go @@ -64,5 +64,5 @@ func (host *LuxHost) Heartbeat() error { } state.Write(&packet.Buffer) - return host.router.Multicast(packet) + return host.router.Multicast(packet, proto.LuxTypeNode) } diff --git a/net/lux_router.go b/net/lux_router.go index 5719f7e..8752941 100644 --- a/net/lux_router.go +++ b/net/lux_router.go @@ -17,6 +17,8 @@ type LuxRoute struct { Nonces LuxNonceList } +// !!!!! +// TODO: map key can be destination ID, while Key (+ ID) in route struct would be SOURCE type LuxRouter struct { thisKey crypto.LuxKey keyStore crypto.LuxKeyStore @@ -301,9 +303,9 @@ func (r *LuxRouter) Send(packet LuxPacket) error { return route.Associated.Send(dgram) } -func (r *LuxRouter) Multicast(packet LuxPacket) error { +func (r *LuxRouter) Multicast(packet LuxPacket, group proto.LuxType) error { for _, route := range r.routes { - if bytes.Equal(route.Key.Id.UUID[:], packet.Target.UUID[:]) { + if route.Key.Type == group { packet.Nonce = GenerateLuxNonce() dgram, err := EncryptLuxPacket(packet, route.Key, route.Destination) if err != nil { diff --git a/tests/lux_host_test.go b/tests/lux_host_test.go index deccfca..8ae5dde 100644 --- a/tests/lux_host_test.go +++ b/tests/lux_host_test.go @@ -20,17 +20,19 @@ func (*DummyWANProvider) Provide() (host.LuxOption, error) { func TestHeartbeatMulticast(t *testing.T) { ks := crypto.NewLuxKeyStore("/tmp/keystore.dat") - keyNode, _ := crypto.NewLuxKey(proto.LuxTypeNode) - ks.Put(keyNode) + keyNodeA, _ := crypto.NewLuxKey(proto.LuxTypeNode) + ks.Put(keyNodeA) + keyNodeB, _ := crypto.NewLuxKey(proto.LuxTypeNode) + ks.Put(keyNodeB) keyHost, _ := crypto.NewLuxKey(proto.LuxTypeHost) ks.Put(keyHost) - nodeA := net.NewLuxRouter(keyNode, ks) + nodeA := net.NewLuxRouter(keyNodeA, ks) nodeA.CreateInboundChannel(net.LuxChannelInterior, "127.0.0.1:9979") nodeA.Start() defer nodeA.Stop() - nodeB := net.NewLuxRouter(keyNode, ks) + nodeB := net.NewLuxRouter(keyNodeB, ks) nodeB.CreateInboundChannel(net.LuxChannelInterior, "127.0.0.2:9979") nodeB.Start() defer nodeB.Stop()