mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 11:15:07 +03:00 
			
		
		
		
	add remote URI to GetPeers (fallback to net.Conn.RemoteAddr().String() if the uri is unknown)
This commit is contained in:
		
							parent
							
								
									6c63b02385
								
							
						
					
					
						commit
						c6a7a077a3
					
				
					 4 changed files with 16 additions and 3 deletions
				
			
		| 
						 | 
				
			
			@ -18,6 +18,7 @@ type PeerEntry struct {
 | 
			
		|||
	PublicKey string   `json:"key"`
 | 
			
		||||
	Port      uint64   `json:"port"`
 | 
			
		||||
	Coords    []uint64 `json:"coords"`
 | 
			
		||||
	Remote    string   `json:"remote"`
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (a *AdminSocket) getPeersHandler(req *GetPeersRequest, res *GetPeersResponse) error {
 | 
			
		||||
| 
						 | 
				
			
			@ -29,6 +30,7 @@ func (a *AdminSocket) getPeersHandler(req *GetPeersRequest, res *GetPeersRespons
 | 
			
		|||
			PublicKey: hex.EncodeToString(p.Key),
 | 
			
		||||
			Port:      p.Port,
 | 
			
		||||
			Coords:    p.Coords,
 | 
			
		||||
			Remote:    p.Remote,
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return nil
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -28,6 +28,7 @@ type Peer struct {
 | 
			
		|||
	Root   ed25519.PublicKey
 | 
			
		||||
	Coords []uint64
 | 
			
		||||
	Port   uint64
 | 
			
		||||
	Remote string
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type DHTEntry struct {
 | 
			
		||||
| 
						 | 
				
			
			@ -56,6 +57,12 @@ func (c *Core) GetSelf() Self {
 | 
			
		|||
 | 
			
		||||
func (c *Core) GetPeers() []Peer {
 | 
			
		||||
	var peers []Peer
 | 
			
		||||
	names := make(map[net.Conn]string)
 | 
			
		||||
	c.links.mutex.Lock()
 | 
			
		||||
	for _, info := range c.links.links {
 | 
			
		||||
		names[info.conn] = info.lname
 | 
			
		||||
	}
 | 
			
		||||
	c.links.mutex.Unlock()
 | 
			
		||||
	ps := c.pc.PacketConn.Debug.GetPeers()
 | 
			
		||||
	for _, p := range ps {
 | 
			
		||||
		var info Peer
 | 
			
		||||
| 
						 | 
				
			
			@ -63,6 +70,10 @@ func (c *Core) GetPeers() []Peer {
 | 
			
		|||
		info.Root = p.Root
 | 
			
		||||
		info.Coords = p.Coords
 | 
			
		||||
		info.Port = p.Port
 | 
			
		||||
		info.Remote = p.Conn.RemoteAddr().String()
 | 
			
		||||
		if name := names[p.Conn]; name != "" {
 | 
			
		||||
			info.Remote = name
 | 
			
		||||
		}
 | 
			
		||||
		peers = append(peers, info)
 | 
			
		||||
	}
 | 
			
		||||
	return peers
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue