mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 03:05:07 +03:00 
			
		
		
		
	make GetSessions use the session workers to avoid races
This commit is contained in:
		
							parent
							
								
									d39428735d
								
							
						
					
					
						commit
						40553a6a44
					
				
					 1 changed files with 24 additions and 9 deletions
				
			
		| 
						 | 
					@ -211,16 +211,31 @@ func (c *Core) GetSessions() []Session {
 | 
				
			||||||
	var sessions []Session
 | 
						var sessions []Session
 | 
				
			||||||
	getSessions := func() {
 | 
						getSessions := func() {
 | 
				
			||||||
		for _, sinfo := range c.sessions.sinfos {
 | 
							for _, sinfo := range c.sessions.sinfos {
 | 
				
			||||||
			// TODO? skipped known but timed out sessions?
 | 
								var session Session
 | 
				
			||||||
			session := Session{
 | 
								workerFunc := func() {
 | 
				
			||||||
				Coords:      append([]byte{}, sinfo.coords...),
 | 
									session := Session{
 | 
				
			||||||
				MTU:         sinfo.getMTU(),
 | 
										Coords:      append([]byte{}, sinfo.coords...),
 | 
				
			||||||
				BytesSent:   sinfo.bytesSent,
 | 
										MTU:         sinfo.getMTU(),
 | 
				
			||||||
				BytesRecvd:  sinfo.bytesRecvd,
 | 
										BytesSent:   sinfo.bytesSent,
 | 
				
			||||||
				Uptime:      time.Now().Sub(sinfo.timeOpened),
 | 
										BytesRecvd:  sinfo.bytesRecvd,
 | 
				
			||||||
				WasMTUFixed: sinfo.wasMTUFixed,
 | 
										Uptime:      time.Now().Sub(sinfo.timeOpened),
 | 
				
			||||||
 | 
										WasMTUFixed: sinfo.wasMTUFixed,
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
									copy(session.PublicKey[:], sinfo.theirPermPub[:])
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
			copy(session.PublicKey[:], sinfo.theirPermPub[:])
 | 
								var skip bool
 | 
				
			||||||
 | 
								func() {
 | 
				
			||||||
 | 
									defer func() {
 | 
				
			||||||
 | 
										if recover() != nil {
 | 
				
			||||||
 | 
											skip = true
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									}()
 | 
				
			||||||
 | 
									sinfo.doWorker(workerFunc)
 | 
				
			||||||
 | 
								}()
 | 
				
			||||||
 | 
								if skip {
 | 
				
			||||||
 | 
									continue
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
								// TODO? skipped known but timed out sessions?
 | 
				
			||||||
			sessions = append(sessions, session)
 | 
								sessions = append(sessions, session)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue