mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 03:05:07 +03:00 
			
		
		
		
	Slightly nicer way to throttle peer announcements
This commit is contained in:
		
							parent
							
								
									0fc7401635
								
							
						
					
					
						commit
						a66a29779a
					
				
					 1 changed files with 3 additions and 2 deletions
				
			
		| 
						 | 
					@ -127,7 +127,7 @@ func (ps *peers) newPeer(box *boxPubKey,
 | 
				
			||||||
func (p *peer) linkLoop(in <-chan []byte) {
 | 
					func (p *peer) linkLoop(in <-chan []byte) {
 | 
				
			||||||
	ticker := time.NewTicker(time.Second)
 | 
						ticker := time.NewTicker(time.Second)
 | 
				
			||||||
	defer ticker.Stop()
 | 
						defer ticker.Stop()
 | 
				
			||||||
	p.lastSend = time.Now()
 | 
						var counter uint8
 | 
				
			||||||
	var lastRSeq uint64
 | 
						var lastRSeq uint64
 | 
				
			||||||
	for {
 | 
						for {
 | 
				
			||||||
		select {
 | 
							select {
 | 
				
			||||||
| 
						 | 
					@ -151,7 +151,7 @@ func (p *peer) linkLoop(in <-chan []byte) {
 | 
				
			||||||
					update = true
 | 
										update = true
 | 
				
			||||||
				case p.msgAnc.rseq != p.myMsg.seq:
 | 
									case p.msgAnc.rseq != p.myMsg.seq:
 | 
				
			||||||
					update = true
 | 
										update = true
 | 
				
			||||||
				case time.Since(p.lastSend) > 3*time.Second:
 | 
									case counter%4 == 0:
 | 
				
			||||||
					update = true
 | 
										update = true
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				if update {
 | 
									if update {
 | 
				
			||||||
| 
						 | 
					@ -161,6 +161,7 @@ func (p *peer) linkLoop(in <-chan []byte) {
 | 
				
			||||||
					p.lastSend = time.Now()
 | 
										p.lastSend = time.Now()
 | 
				
			||||||
					p.sendSwitchAnnounce()
 | 
										p.sendSwitchAnnounce()
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
									counter = (counter + 1) % 4
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue