From b1340f9e35ef91a9fda5489a2453a39c62cfb1ee Mon Sep 17 00:00:00 2001 From: mykola2312 <49044616+mykola2312@users.noreply.github.com> Date: Fri, 3 Jan 2025 12:37:21 +0200 Subject: [PATCH] make changes to routing table --- net/lux_router.go | 34 ++++++++++++++++++++++++++++------ 1 file changed, 28 insertions(+), 6 deletions(-) diff --git a/net/lux_router.go b/net/lux_router.go index 04ca4bc..af5d975 100644 --- a/net/lux_router.go +++ b/net/lux_router.go @@ -14,17 +14,20 @@ type LuxRoute struct { } type LuxRouter struct { + thisKey crypto.LuxKey keyStore crypto.LuxKeyStore - routes map[proto.LuxID]LuxRoute + + routes []LuxRoute outbound []LuxChannel inbound []LuxChannel } -func NewLuxRouter(ks crypto.LuxKeyStore) LuxRouter { +func NewLuxRouter(key crypto.LuxKey, ks crypto.LuxKeyStore) LuxRouter { return LuxRouter{ + thisKey: key, keyStore: ks, - routes: make(map[proto.LuxID]LuxRoute), + routes: make([]LuxRoute, 0), outbound: make([]LuxChannel, 0), inbound: make([]LuxChannel, 0), } @@ -35,7 +38,12 @@ func (r *LuxRouter) addOutboundChannel(ch LuxChannel) *LuxChannel { return &r.outbound[len(r.outbound)-1] } -func (r *LuxRouter) AddOutboundRoute(id proto.LuxID, chType LuxChannelType, udpAddr string) error { +func (r *LuxRouter) addInboundChannel(ch LuxChannel) *LuxChannel { + r.inbound = append(r.inbound, ch) + return &r.inbound[len(r.inbound)-1] +} + +func (r *LuxRouter) CreateOutboundRoute(id proto.LuxID, chType LuxChannelType, udpAddr string) error { // we gonna look up key by id from key store key, ok := r.keyStore.Get(id) if !ok { @@ -48,10 +56,24 @@ func (r *LuxRouter) AddOutboundRoute(id proto.LuxID, chType LuxChannelType, udpA return err } - r.routes[id] = LuxRoute{ + r.routes = append(r.routes, LuxRoute{ Key: key, Destination: channel.Address, Associated: r.addOutboundChannel(channel), - } + }) + return nil +} + +func (r *LuxRouter) CreateInboundChannel(chType LuxChannelType, udpAddr string) error { + channel, err := NewLuxInboundChannel(udpAddr, chType) + if err != nil { + return err + } + + r.routes = append(r.routes, LuxRoute{ + Key: r.thisKey, + Destination: channel.Address, + Associated: r.addInboundChannel(channel), + }) return nil }