|  | @@ -187,20 +187,18 @@ func (this *Shadowsocks) handleConnection(conn *hub.TCPConn) {
 | 
											
												
													
														|  |  	var writeFinish sync.Mutex
 |  |  	var writeFinish sync.Mutex
 | 
											
												
													
														|  |  	writeFinish.Lock()
 |  |  	writeFinish.Lock()
 | 
											
												
													
														|  |  	go func() {
 |  |  	go func() {
 | 
											
												
													
														|  | -		firstChunk := alloc.NewBuffer().Slice(0, this.config.Cipher.IVSize())
 |  | 
 | 
											
												
													
														|  | -		defer firstChunk.Release()
 |  | 
 | 
											
												
													
														|  | 
 |  | +		if payload, ok := <-ray.InboundOutput(); ok {
 | 
											
												
													
														|  | 
 |  | +			payload.SliceBack(16)
 | 
											
												
													
														|  | 
 |  | +			rand.Read(payload.Value[:16])
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -		writer, err := this.config.Cipher.NewEncodingStream(key, firstChunk.Value, conn)
 |  | 
 | 
											
												
													
														|  | -		if err != nil {
 |  | 
 | 
											
												
													
														|  | -			log.Error("Shadowsocks: Failed to create encoding stream: ", err)
 |  | 
 | 
											
												
													
														|  | -			return
 |  | 
 | 
											
												
													
														|  | -		}
 |  | 
 | 
											
												
													
														|  | 
 |  | +			writer, err := this.config.Cipher.NewEncodingStream(key, payload.Value[:16], conn)
 | 
											
												
													
														|  | 
 |  | +			if err != nil {
 | 
											
												
													
														|  | 
 |  | +				log.Error("Shadowsocks: Failed to create encoding stream: ", err)
 | 
											
												
													
														|  | 
 |  | +				return
 | 
											
												
													
														|  | 
 |  | +			}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | -		if payload, ok := <-ray.InboundOutput(); ok {
 |  | 
 | 
											
												
													
														|  | -			firstChunk.Append(payload.Value)
 |  | 
 | 
											
												
													
														|  | 
 |  | +			writer.Write(payload.Value)
 | 
											
												
													
														|  |  			payload.Release()
 |  |  			payload.Release()
 | 
											
												
													
														|  | -
 |  | 
 | 
											
												
													
														|  | -			writer.Write(firstChunk.Value)
 |  | 
 | 
											
												
													
														|  |  			v2io.ChanToWriter(writer, ray.InboundOutput())
 |  |  			v2io.ChanToWriter(writer, ray.InboundOutput())
 | 
											
												
													
														|  |  		}
 |  |  		}
 | 
											
												
													
														|  |  		writeFinish.Unlock()
 |  |  		writeFinish.Unlock()
 |