This commit is contained in:
Sudo-Ivan
2025-01-01 00:40:25 -06:00
parent 785bc7d782
commit 30ea1dd0c7
15 changed files with 1016 additions and 847 deletions

View File

@@ -0,0 +1,34 @@
package pathfinder
import "time"
type PathFinder struct {
paths map[string]Path
}
type Path struct {
NextHop []byte
Interface string
HopCount byte
LastUpdated int64
}
func NewPathFinder() *PathFinder {
return &PathFinder{
paths: make(map[string]Path),
}
}
func (p *PathFinder) AddPath(destHash string, nextHop []byte, iface string, hops byte) {
p.paths[destHash] = Path{
NextHop: nextHop,
Interface: iface,
HopCount: hops,
LastUpdated: time.Now().Unix(),
}
}
func (p *PathFinder) GetPath(destHash string) (Path, bool) {
path, exists := p.paths[destHash]
return path, exists
}