mirror of
https://github.com/tim-beatham/smegmesh.git
synced 2025-08-19 01:15:58 +02:00
36-add-route-path-into-route-object
Added the route path into the route object so that we can see what meshes packets are routed across.
This commit is contained in:
@@ -340,7 +340,7 @@ func (m *CrdtMeshManager) AddRoutes(nodeId string, routes ...mesh.Route) error {
|
||||
for _, route := range routes {
|
||||
err = routeMap.Map().Set(route.GetDestination().String(), Route{
|
||||
Destination: route.GetDestination().String(),
|
||||
HopCount: int64(route.GetHopCount()),
|
||||
Path: route.GetPath(),
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
@@ -372,6 +372,7 @@ func (m *CrdtMeshManager) getRoutes(nodeId string) ([]Route, error) {
|
||||
}
|
||||
|
||||
routes, err := automerge.As[map[string]Route](routeMap)
|
||||
|
||||
return lib.MapValues(routes), err
|
||||
}
|
||||
|
||||
@@ -398,10 +399,10 @@ func (m *CrdtMeshManager) GetRoutes(targetNode string) (map[string]mesh.Route, e
|
||||
for _, route := range nodeRoutes {
|
||||
otherRoute, ok := routes[route.GetDestination().String()]
|
||||
|
||||
if !ok || route.GetHopCount() < otherRoute.GetHopCount() {
|
||||
if !ok || route.GetHopCount()+1 < otherRoute.GetHopCount() {
|
||||
routes[route.GetDestination().String()] = &Route{
|
||||
Destination: route.GetDestination().String(),
|
||||
HopCount: int64(route.GetHopCount()) + 1,
|
||||
Path: append(route.Path, m.GetMeshId()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -524,7 +525,10 @@ func (m *MeshNodeCrdt) GetTimeStamp() int64 {
|
||||
|
||||
func (m *MeshNodeCrdt) GetRoutes() []mesh.Route {
|
||||
return lib.Map(lib.MapValues(m.Routes), func(r Route) mesh.Route {
|
||||
return &r
|
||||
return &Route{
|
||||
Destination: r.Destination,
|
||||
Path: r.Path,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -588,5 +592,9 @@ func (r *Route) GetDestination() *net.IPNet {
|
||||
}
|
||||
|
||||
func (r *Route) GetHopCount() int {
|
||||
return int(r.HopCount)
|
||||
return len(r.Path)
|
||||
}
|
||||
|
||||
func (r *Route) GetPath() []string {
|
||||
return r.Path
|
||||
}
|
||||
|
@@ -2,8 +2,8 @@ package crdt
|
||||
|
||||
// Route: Represents a CRDT of the given route
|
||||
type Route struct {
|
||||
Destination string `automerge:"destination"`
|
||||
HopCount int64 `automerge:"hopCount"`
|
||||
Destination string `automerge:"destination"`
|
||||
Path []string `automerge:"path"`
|
||||
}
|
||||
|
||||
// MeshNodeCrdt: Represents a CRDT for a mesh nodes
|
||||
|
Reference in New Issue
Block a user