mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 03:05:07 +03:00 
			
		
		
		
	admin socket getpaths
This commit is contained in:
		
							parent
							
								
									eb4a22724f
								
							
						
					
					
						commit
						8d09e68e80
					
				
					 2 changed files with 44 additions and 0 deletions
				
			
		| 
						 | 
					@ -117,6 +117,17 @@ func (a *AdminSocket) SetupAdminHandlers(na *AdminSocket) {
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		return res, nil
 | 
							return res, nil
 | 
				
			||||||
	})
 | 
						})
 | 
				
			||||||
 | 
						_ = a.AddHandler("getPaths", []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", []string{}, func(in json.RawMessage) (interface{}, error) {
 | 
						_ = a.AddHandler("getSessions", []string{}, func(in json.RawMessage) (interface{}, error) {
 | 
				
			||||||
		req := &GetSessionsRequest{}
 | 
							req := &GetSessionsRequest{}
 | 
				
			||||||
		res := &GetSessionsResponse{}
 | 
							res := &GetSessionsResponse{}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
							
								
								
									
										33
									
								
								src/admin/getpaths.go
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								src/admin/getpaths.go
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,33 @@
 | 
				
			||||||
 | 
					package admin
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import (
 | 
				
			||||||
 | 
						"encoding/hex"
 | 
				
			||||||
 | 
						"net"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						"github.com/yggdrasil-network/yggdrasil-go/src/address"
 | 
				
			||||||
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type GetPathsRequest struct {
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type GetPathsResponse struct {
 | 
				
			||||||
 | 
						Paths map[string]PathEntry `json:"paths"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type PathEntry struct {
 | 
				
			||||||
 | 
						PublicKey string   `json:"key"`
 | 
				
			||||||
 | 
						Path      []uint64 `json:"path"`
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					func (a *AdminSocket) getPathsHandler(req *GetPathsRequest, res *GetPathsResponse) error {
 | 
				
			||||||
 | 
						res.Paths = map[string]PathEntry{}
 | 
				
			||||||
 | 
						for _, p := range a.core.GetPaths() {
 | 
				
			||||||
 | 
							addr := address.AddrForKey(p.Key)
 | 
				
			||||||
 | 
							so := net.IP(addr[:]).String()
 | 
				
			||||||
 | 
							res.Paths[so] = PathEntry{
 | 
				
			||||||
 | 
								PublicKey: hex.EncodeToString(p.Key),
 | 
				
			||||||
 | 
								Path:      p.Path,
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return nil
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue