0.3.2
This commit is contained in:
34
pkg/pathfinder/pathfinder.go
Normal file
34
pkg/pathfinder/pathfinder.go
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user