make changes to routing table

This commit is contained in:
mykola2312 2025-01-03 12:37:21 +02:00
parent 36640c1ffa
commit b1340f9e35

View file

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