mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 03:05:07 +03:00 
			
		
		
		
	update admin functions and fix core tests
This commit is contained in:
		
							parent
							
								
									abbe94fa80
								
							
						
					
					
						commit
						e99c870d51
					
				
					 9 changed files with 66 additions and 45 deletions
				
			
		| 
						 | 
				
			
			@ -145,20 +145,22 @@ func (a *AdminSocket) SetupAdminHandlers() {
 | 
			
		|||
			return res, nil
 | 
			
		||||
		},
 | 
			
		||||
	)
 | 
			
		||||
	_ = a.AddHandler(
 | 
			
		||||
		"getPaths", "Show established paths through this node", []string{},
 | 
			
		||||
		func(in json.RawMessage) (interface{}, error) {
 | 
			
		||||
			req := &GetPathsRequest{}
 | 
			
		||||
			res := &GetPathsResponse{}
 | 
			
		||||
			if err := json.Unmarshal(in, &req); err != nil {
 | 
			
		||||
				return nil, err
 | 
			
		||||
			}
 | 
			
		||||
			if err := a.getPathsHandler(req, res); err != nil {
 | 
			
		||||
				return nil, err
 | 
			
		||||
			}
 | 
			
		||||
			return res, nil
 | 
			
		||||
		},
 | 
			
		||||
	)
 | 
			
		||||
	/*
 | 
			
		||||
		_ = a.AddHandler(
 | 
			
		||||
			"getPaths", "Show established paths through this node", []string{},
 | 
			
		||||
			func(in json.RawMessage) (interface{}, error) {
 | 
			
		||||
				req := &GetPathsRequest{}
 | 
			
		||||
				res := &GetPathsResponse{}
 | 
			
		||||
				if err := json.Unmarshal(in, &req); err != nil {
 | 
			
		||||
					return nil, err
 | 
			
		||||
				}
 | 
			
		||||
				if err := a.getPathsHandler(req, res); err != nil {
 | 
			
		||||
					return nil, err
 | 
			
		||||
				}
 | 
			
		||||
				return res, nil
 | 
			
		||||
			},
 | 
			
		||||
		)
 | 
			
		||||
	*/
 | 
			
		||||
	_ = a.AddHandler(
 | 
			
		||||
		"getSessions", "Show established traffic sessions with remote nodes", []string{},
 | 
			
		||||
		func(in json.RawMessage) (interface{}, error) {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -18,8 +18,10 @@ type GetDHTResponse struct {
 | 
			
		|||
type DHTEntry struct {
 | 
			
		||||
	IPAddress string `json:"address"`
 | 
			
		||||
	PublicKey string `json:"key"`
 | 
			
		||||
	Port      uint64 `json:"port"`
 | 
			
		||||
	Rest      uint64 `json:"rest"`
 | 
			
		||||
	Parent    string `json:"parent"`
 | 
			
		||||
	Sequence  uint64 `json:"sequence"`
 | 
			
		||||
	//Port      uint64 `json:"port"`
 | 
			
		||||
	//Rest      uint64 `json:"rest"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (a *AdminSocket) getDHTHandler(req *GetDHTRequest, res *GetDHTResponse) error {
 | 
			
		||||
| 
						 | 
				
			
			@ -30,8 +32,10 @@ func (a *AdminSocket) getDHTHandler(req *GetDHTRequest, res *GetDHTResponse) err
 | 
			
		|||
		res.DHT = append(res.DHT, DHTEntry{
 | 
			
		||||
			IPAddress: net.IP(addr[:]).String(),
 | 
			
		||||
			PublicKey: hex.EncodeToString(d.Key[:]),
 | 
			
		||||
			Port:      d.Port,
 | 
			
		||||
			Rest:      d.Rest,
 | 
			
		||||
			Parent:    hex.EncodeToString(d.Parent[:]),
 | 
			
		||||
			Sequence:  d.Sequence,
 | 
			
		||||
			//Port:      d.Port,
 | 
			
		||||
			//Rest:      d.Rest,
 | 
			
		||||
		})
 | 
			
		||||
	}
 | 
			
		||||
	sort.SliceStable(res.DHT, func(i, j int) bool {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,5 +1,7 @@
 | 
			
		|||
package admin
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 | 
			
		||||
import (
 | 
			
		||||
	"encoding/hex"
 | 
			
		||||
	"net"
 | 
			
		||||
| 
						 | 
				
			
			@ -38,3 +40,5 @@ func (a *AdminSocket) getPathsHandler(req *GetPathsRequest, res *GetPathsRespons
 | 
			
		|||
	})
 | 
			
		||||
	return nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
*/
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue