mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 03:05:07 +03:00 
			
		
		
		
	update to ironwood v0.0.0-20230513191034-495699d87ae4 with API changes
This commit is contained in:
		
							parent
							
								
									1345960d5f
								
							
						
					
					
						commit
						5e95246c26
					
				
					 11 changed files with 235 additions and 198 deletions
				
			
		| 
						 | 
				
			
			@ -132,14 +132,14 @@ func (a *AdminSocket) SetupAdminHandlers() {
 | 
			
		|||
		},
 | 
			
		||||
	)
 | 
			
		||||
	_ = a.AddHandler(
 | 
			
		||||
		"getDHT", "Show known DHT entries", []string{},
 | 
			
		||||
		"getTree", "Show known Tree entries", []string{},
 | 
			
		||||
		func(in json.RawMessage) (interface{}, error) {
 | 
			
		||||
			req := &GetDHTRequest{}
 | 
			
		||||
			res := &GetDHTResponse{}
 | 
			
		||||
			req := &GetTreeRequest{}
 | 
			
		||||
			res := &GetTreeResponse{}
 | 
			
		||||
			if err := json.Unmarshal(in, &req); err != nil {
 | 
			
		||||
				return nil, err
 | 
			
		||||
			}
 | 
			
		||||
			if err := a.getDHTHandler(req, res); err != nil {
 | 
			
		||||
			if err := a.getTreeHandler(req, res); err != nil {
 | 
			
		||||
				return nil, err
 | 
			
		||||
			}
 | 
			
		||||
			return res, nil
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,7 +1,5 @@
 | 
			
		|||
package admin
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"encoding/hex"
 | 
			
		||||
	"net"
 | 
			
		||||
| 
						 | 
				
			
			@ -19,9 +17,10 @@ type GetPathsResponse struct {
 | 
			
		|||
}
 | 
			
		||||
 | 
			
		||||
type PathEntry struct {
 | 
			
		||||
	IPAddress string `json:"address"`
 | 
			
		||||
	PublicKey string `json:"key"`
 | 
			
		||||
	Sequence  uint64 `json:"sequence"`
 | 
			
		||||
	IPAddress string   `json:"address"`
 | 
			
		||||
	PublicKey string   `json:"key"`
 | 
			
		||||
	Path      []uint64 `json:"path"`
 | 
			
		||||
	Sequence  uint64   `json:"sequence"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (a *AdminSocket) getPathsHandler(req *GetPathsRequest, res *GetPathsResponse) error {
 | 
			
		||||
| 
						 | 
				
			
			@ -32,6 +31,7 @@ func (a *AdminSocket) getPathsHandler(req *GetPathsRequest, res *GetPathsRespons
 | 
			
		|||
		res.Paths = append(res.Paths, PathEntry{
 | 
			
		||||
			IPAddress: net.IP(addr[:]).String(),
 | 
			
		||||
			PublicKey: hex.EncodeToString(p.Key),
 | 
			
		||||
			Path:      p.Path,
 | 
			
		||||
			Sequence:  p.Sequence,
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
| 
						 | 
				
			
			@ -40,5 +40,3 @@ func (a *AdminSocket) getPathsHandler(req *GetPathsRequest, res *GetPathsRespons
 | 
			
		|||
	})
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
*/
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,13 +9,13 @@ import (
 | 
			
		|||
	"github.com/yggdrasil-network/yggdrasil-go/src/address"
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type GetDHTRequest struct{}
 | 
			
		||||
type GetTreeRequest struct{}
 | 
			
		||||
 | 
			
		||||
type GetDHTResponse struct {
 | 
			
		||||
	DHT []DHTEntry `json:"dht"`
 | 
			
		||||
type GetTreeResponse struct {
 | 
			
		||||
	Tree []TreeEntry `json:"tree"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type DHTEntry struct {
 | 
			
		||||
type TreeEntry struct {
 | 
			
		||||
	IPAddress string `json:"address"`
 | 
			
		||||
	PublicKey string `json:"key"`
 | 
			
		||||
	Parent    string `json:"parent"`
 | 
			
		||||
| 
						 | 
				
			
			@ -24,12 +24,12 @@ type DHTEntry struct {
 | 
			
		|||
	//Rest      uint64 `json:"rest"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (a *AdminSocket) getDHTHandler(req *GetDHTRequest, res *GetDHTResponse) error {
 | 
			
		||||
	dht := a.core.GetDHT()
 | 
			
		||||
	res.DHT = make([]DHTEntry, 0, len(dht))
 | 
			
		||||
	for _, d := range dht {
 | 
			
		||||
func (a *AdminSocket) getTreeHandler(req *GetTreeRequest, res *GetTreeResponse) error {
 | 
			
		||||
	tree := a.core.GetTree()
 | 
			
		||||
	res.Tree = make([]TreeEntry, 0, len(tree))
 | 
			
		||||
	for _, d := range tree {
 | 
			
		||||
		addr := address.AddrForKey(d.Key)
 | 
			
		||||
		res.DHT = append(res.DHT, DHTEntry{
 | 
			
		||||
		res.Tree = append(res.Tree, TreeEntry{
 | 
			
		||||
			IPAddress: net.IP(addr[:]).String(),
 | 
			
		||||
			PublicKey: hex.EncodeToString(d.Key[:]),
 | 
			
		||||
			Parent:    hex.EncodeToString(d.Parent[:]),
 | 
			
		||||
| 
						 | 
				
			
			@ -38,8 +38,8 @@ func (a *AdminSocket) getDHTHandler(req *GetDHTRequest, res *GetDHTResponse) err
 | 
			
		|||
			//Rest:      d.Rest,
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
	sort.SliceStable(res.DHT, func(i, j int) bool {
 | 
			
		||||
		return strings.Compare(res.DHT[i].PublicKey, res.DHT[j].PublicKey) < 0
 | 
			
		||||
	sort.SliceStable(res.Tree, func(i, j int) bool {
 | 
			
		||||
		return strings.Compare(res.Tree[i].PublicKey, res.Tree[j].PublicKey) < 0
 | 
			
		||||
	})
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue