Advertise more routes
This commit is contained in:
parent
1105c1d49a
commit
e20eb9be2d
3 changed files with 42 additions and 10 deletions
8
peer.go
8
peer.go
|
@ -277,7 +277,13 @@ func (p *peer) handle(ctx context.Context) error {
|
|||
log.Printf("Learned about these networks: %v", pkt.Networks)
|
||||
|
||||
for _, nt := range pkt.Networks {
|
||||
upsertRoutes(ddp.Network(nt.RangeStart), ddp.Network(nt.RangeEnd), p, nt.Distance)
|
||||
upsertRoutes(
|
||||
nt.Extended,
|
||||
ddp.Network(nt.RangeStart),
|
||||
ddp.Network(nt.RangeEnd),
|
||||
p,
|
||||
nt.Distance,
|
||||
)
|
||||
}
|
||||
|
||||
// TODO: track which networks we don't have zone info for, and
|
||||
|
|
27
route.go
27
route.go
|
@ -11,14 +11,20 @@ import (
|
|||
)
|
||||
|
||||
type route struct {
|
||||
peer *peer
|
||||
metric uint8
|
||||
last time.Time
|
||||
extended bool
|
||||
netStart ddp.Network
|
||||
netEnd ddp.Network
|
||||
peer *peer
|
||||
metric uint8
|
||||
last time.Time
|
||||
}
|
||||
|
||||
var (
|
||||
routingTableMu sync.Mutex
|
||||
routingTable = make(map[ddp.Network][]*route)
|
||||
|
||||
allRoutesMu sync.Mutex
|
||||
allRoutes = make(map[*route]struct{})
|
||||
)
|
||||
|
||||
func lookupRoute(network ddp.Network) *route {
|
||||
|
@ -32,16 +38,23 @@ func lookupRoute(network ddp.Network) *route {
|
|||
return rs[0]
|
||||
}
|
||||
|
||||
func upsertRoutes(netStart, netEnd ddp.Network, peer *peer, metric uint8) error {
|
||||
func upsertRoutes(extended bool, netStart, netEnd ddp.Network, peer *peer, metric uint8) error {
|
||||
if netStart > netEnd {
|
||||
return fmt.Errorf("invalid network range [%d, %d]", netStart, netEnd)
|
||||
}
|
||||
r := &route{
|
||||
peer: peer,
|
||||
metric: metric,
|
||||
last: time.Now(),
|
||||
extended: extended,
|
||||
netStart: netStart,
|
||||
netEnd: netEnd,
|
||||
peer: peer,
|
||||
metric: metric,
|
||||
last: time.Now(),
|
||||
}
|
||||
|
||||
allRoutesMu.Lock()
|
||||
allRoutes[r] = struct{}{}
|
||||
allRoutesMu.Unlock()
|
||||
|
||||
routingTableMu.Lock()
|
||||
defer routingTableMu.Unlock()
|
||||
for n := netStart; n <= netEnd; n++ {
|
||||
|
|
17
rtmp.go
17
rtmp.go
|
@ -198,7 +198,7 @@ func (m *RTMPMachine) broadcastData(myAddr aarp.AddrPair) error {
|
|||
}
|
||||
|
||||
func (m *RTMPMachine) dataPacket(myAddr ddp.Addr) *rtmp.DataPacket {
|
||||
return &rtmp.DataPacket{
|
||||
p := &rtmp.DataPacket{
|
||||
RouterAddr: myAddr,
|
||||
Extended: true,
|
||||
NetworkTuples: []rtmp.NetworkTuple{
|
||||
|
@ -213,5 +213,18 @@ func (m *RTMPMachine) dataPacket(myAddr ddp.Addr) *rtmp.DataPacket {
|
|||
},
|
||||
},
|
||||
}
|
||||
// TODO: append more networks! implement a route table!
|
||||
allRoutesMu.Lock()
|
||||
defer allRoutesMu.Unlock()
|
||||
for rt := range allRoutes {
|
||||
if rt.peer == nil {
|
||||
continue
|
||||
}
|
||||
p.NetworkTuples = append(p.NetworkTuples, rtmp.NetworkTuple{
|
||||
Extended: rt.extended,
|
||||
RangeStart: rt.netStart,
|
||||
RangeEnd: rt.netEnd,
|
||||
Distance: rt.metric,
|
||||
})
|
||||
}
|
||||
return p
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue