make changes to routing table
This commit is contained in:
parent
36640c1ffa
commit
b1340f9e35
1 changed files with 28 additions and 6 deletions
|
|
@ -14,17 +14,20 @@ type LuxRoute struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type LuxRouter struct {
|
type LuxRouter struct {
|
||||||
|
thisKey crypto.LuxKey
|
||||||
keyStore crypto.LuxKeyStore
|
keyStore crypto.LuxKeyStore
|
||||||
routes map[proto.LuxID]LuxRoute
|
|
||||||
|
routes []LuxRoute
|
||||||
|
|
||||||
outbound []LuxChannel
|
outbound []LuxChannel
|
||||||
inbound []LuxChannel
|
inbound []LuxChannel
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLuxRouter(ks crypto.LuxKeyStore) LuxRouter {
|
func NewLuxRouter(key crypto.LuxKey, ks crypto.LuxKeyStore) LuxRouter {
|
||||||
return LuxRouter{
|
return LuxRouter{
|
||||||
|
thisKey: key,
|
||||||
keyStore: ks,
|
keyStore: ks,
|
||||||
routes: make(map[proto.LuxID]LuxRoute),
|
routes: make([]LuxRoute, 0),
|
||||||
outbound: make([]LuxChannel, 0),
|
outbound: make([]LuxChannel, 0),
|
||||||
inbound: 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]
|
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
|
// we gonna look up key by id from key store
|
||||||
key, ok := r.keyStore.Get(id)
|
key, ok := r.keyStore.Get(id)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
@ -48,10 +56,24 @@ func (r *LuxRouter) AddOutboundRoute(id proto.LuxID, chType LuxChannelType, udpA
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
r.routes[id] = LuxRoute{
|
r.routes = append(r.routes, LuxRoute{
|
||||||
Key: key,
|
Key: key,
|
||||||
Destination: channel.Address,
|
Destination: channel.Address,
|
||||||
Associated: r.addOutboundChannel(channel),
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue