mirror of
				https://github.com/yggdrasil-network/yggdrasil-go.git
				synced 2025-11-04 03:05:07 +03:00 
			
		
		
		
	reduce part of sendWorker that needs to keep a mutex
This commit is contained in:
		
							parent
							
								
									72ed541bf3
								
							
						
					
					
						commit
						099bd3ae1e
					
				
					 1 changed files with 16 additions and 12 deletions
				
			
		| 
						 | 
					@ -492,23 +492,27 @@ func (sinfo *sessionInfo) sendWorker() {
 | 
				
			||||||
		case <-sinfo.cancel.Finished():
 | 
							case <-sinfo.cancel.Finished():
 | 
				
			||||||
			return
 | 
								return
 | 
				
			||||||
		case bs := <-sinfo.send:
 | 
							case bs := <-sinfo.send:
 | 
				
			||||||
			// TODO
 | 
								var p wire_trafficPacket
 | 
				
			||||||
			var packet []byte
 | 
								var k crypto.BoxSharedKey
 | 
				
			||||||
			sessionFunc := func() {
 | 
								sessionFunc := func() {
 | 
				
			||||||
				defer util.PutBytes(bs)
 | 
					 | 
				
			||||||
				sinfo.bytesSent += uint64(len(bs))
 | 
									sinfo.bytesSent += uint64(len(bs))
 | 
				
			||||||
				payload, nonce := crypto.BoxSeal(&sinfo.sharedSesKey, bs, &sinfo.myNonce)
 | 
									p = wire_trafficPacket{
 | 
				
			||||||
				defer util.PutBytes(payload)
 | 
										Coords: append([]byte(nil), sinfo.coords...),
 | 
				
			||||||
				// Construct the wire packet to send to the router
 | 
					 | 
				
			||||||
				p := wire_trafficPacket{
 | 
					 | 
				
			||||||
					Coords:  sinfo.coords,
 | 
					 | 
				
			||||||
					Handle: sinfo.theirHandle,
 | 
										Handle: sinfo.theirHandle,
 | 
				
			||||||
					Nonce:   *nonce,
 | 
										Nonce:  sinfo.myNonce,
 | 
				
			||||||
					Payload: payload,
 | 
					 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
				packet = p.encode()
 | 
									sinfo.myNonce.Increment()
 | 
				
			||||||
 | 
									k = sinfo.sharedSesKey
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
								// Get the mutex-protected info needed to encrypt the packet
 | 
				
			||||||
			sinfo.doFunc(sessionFunc)
 | 
								sinfo.doFunc(sessionFunc)
 | 
				
			||||||
 | 
								// Encrypt the packet
 | 
				
			||||||
 | 
								p.Payload, _ = crypto.BoxSeal(&k, bs, &p.Nonce)
 | 
				
			||||||
 | 
								packet := p.encode()
 | 
				
			||||||
 | 
								// Cleanup
 | 
				
			||||||
 | 
								util.PutBytes(bs)
 | 
				
			||||||
 | 
								util.PutBytes(p.Payload)
 | 
				
			||||||
 | 
								// Send the packet
 | 
				
			||||||
			sinfo.core.router.out(packet)
 | 
								sinfo.core.router.out(packet)
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue