mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 11:15:07 +03:00 
			
		
		
		
	Merge develop into bugfixes
This commit is contained in:
		
						commit
						681e9afc79
					
				
					 1 changed files with 22 additions and 1 deletions
				
			
		| 
						 | 
					@ -368,14 +368,35 @@ func (c *Core) SetLogger(log *log.Logger) {
 | 
				
			||||||
// connection drops.
 | 
					// connection drops.
 | 
				
			||||||
func (c *Core) AddPeer(addr string, sintf string) error {
 | 
					func (c *Core) AddPeer(addr string, sintf string) error {
 | 
				
			||||||
	if err := c.CallPeer(addr, sintf); err != nil {
 | 
						if err := c.CallPeer(addr, sintf); err != nil {
 | 
				
			||||||
 | 
							// TODO: We maybe want this to write the peer to the persistent
 | 
				
			||||||
 | 
							// configuration even if a connection attempt fails, but first we'll need to
 | 
				
			||||||
 | 
							// move the code to check the peer URI so that we don't deliberately save a
 | 
				
			||||||
 | 
							// peer with a known bad URI. Loading peers from config should really do the
 | 
				
			||||||
 | 
							// same thing too but I don't think that happens today
 | 
				
			||||||
		return err
 | 
							return err
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	c.config.Mutex.Lock()
 | 
						c.config.Mutex.Lock()
 | 
				
			||||||
	if sintf == "" {
 | 
						if sintf == "" {
 | 
				
			||||||
 | 
							for _, peer := range c.config.Current.Peers {
 | 
				
			||||||
 | 
								if peer == addr {
 | 
				
			||||||
 | 
									return errors.New("peer already added")
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		c.config.Current.Peers = append(c.config.Current.Peers, addr)
 | 
							c.config.Current.Peers = append(c.config.Current.Peers, addr)
 | 
				
			||||||
 | 
						} else {
 | 
				
			||||||
 | 
							if _, ok := c.config.Current.InterfacePeers[sintf]; ok {
 | 
				
			||||||
 | 
								for _, peer := range c.config.Current.InterfacePeers[sintf] {
 | 
				
			||||||
 | 
									if peer == addr {
 | 
				
			||||||
 | 
										return errors.New("peer already added")
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							if _, ok := c.config.Current.InterfacePeers[sintf]; !ok {
 | 
				
			||||||
 | 
								c.config.Current.InterfacePeers[sintf] = []string{addr}
 | 
				
			||||||
		} else {
 | 
							} else {
 | 
				
			||||||
			c.config.Current.InterfacePeers[sintf] = append(c.config.Current.InterfacePeers[sintf], addr)
 | 
								c.config.Current.InterfacePeers[sintf] = append(c.config.Current.InterfacePeers[sintf], addr)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
	c.config.Mutex.Unlock()
 | 
						c.config.Mutex.Unlock()
 | 
				
			||||||
	return nil
 | 
						return nil
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue