github.com/yggdrasil-network/yggdrasil-go@v0.5.6/src/admin/getpaths.go (about) 1 package admin 2 3 import ( 4 "encoding/hex" 5 "net" 6 "sort" 7 "strings" 8 9 "github.com/yggdrasil-network/yggdrasil-go/src/address" 10 ) 11 12 type GetPathsRequest struct { 13 } 14 15 type GetPathsResponse struct { 16 Paths []PathEntry `json:"paths"` 17 } 18 19 type PathEntry struct { 20 IPAddress string `json:"address"` 21 PublicKey string `json:"key"` 22 Path []uint64 `json:"path"` 23 Sequence uint64 `json:"sequence"` 24 } 25 26 func (a *AdminSocket) getPathsHandler(req *GetPathsRequest, res *GetPathsResponse) error { 27 paths := a.core.GetPaths() 28 res.Paths = make([]PathEntry, 0, len(paths)) 29 for _, p := range paths { 30 addr := address.AddrForKey(p.Key) 31 res.Paths = append(res.Paths, PathEntry{ 32 IPAddress: net.IP(addr[:]).String(), 33 PublicKey: hex.EncodeToString(p.Key), 34 Path: p.Path, 35 Sequence: p.Sequence, 36 }) 37 } 38 sort.SliceStable(res.Paths, func(i, j int) bool { 39 return strings.Compare(res.Paths[i].PublicKey, res.Paths[j].PublicKey) < 0 40 }) 41 return nil 42 }