|  | @@ -2,6 +2,7 @@ package kcp
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  import (
 |  |  import (
 | 
											
												
													
														|  |  	"net"
 |  |  	"net"
 | 
											
												
													
														|  | 
 |  | +	"sync/atomic"
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  	"github.com/v2ray/v2ray-core/common/dice"
 |  |  	"github.com/v2ray/v2ray-core/common/dice"
 | 
											
												
													
														|  |  	"github.com/v2ray/v2ray-core/common/log"
 |  |  	"github.com/v2ray/v2ray-core/common/log"
 | 
											
										
											
												
													
														|  | @@ -9,6 +10,10 @@ import (
 | 
											
												
													
														|  |  	"github.com/v2ray/v2ray-core/transport/internet"
 |  |  	"github.com/v2ray/v2ray-core/transport/internet"
 | 
											
												
													
														|  |  )
 |  |  )
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  | 
 |  | +var (
 | 
											
												
													
														|  | 
 |  | +	globalConv = uint32(dice.Roll(65536))
 | 
											
												
													
														|  | 
 |  | +)
 | 
											
												
													
														|  | 
 |  | +
 | 
											
												
													
														|  |  func DialKCP(src v2net.Address, dest v2net.Destination) (internet.Connection, error) {
 |  |  func DialKCP(src v2net.Address, dest v2net.Destination) (internet.Connection, error) {
 | 
											
												
													
														|  |  	udpDest := v2net.UDPDestination(dest.Address(), dest.Port())
 |  |  	udpDest := v2net.UDPDestination(dest.Address(), dest.Port())
 | 
											
												
													
														|  |  	log.Info("Dialling KCP to ", udpDest)
 |  |  	log.Info("Dialling KCP to ", udpDest)
 | 
											
										
											
												
													
														|  | @@ -18,7 +23,8 @@ func DialKCP(src v2net.Address, dest v2net.Destination) (internet.Connection, er
 | 
											
												
													
														|  |  	}
 |  |  	}
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  	cpip := NewSimpleAuthenticator()
 |  |  	cpip := NewSimpleAuthenticator()
 | 
											
												
													
														|  | -	session := NewConnection(uint16(dice.Roll(65536)), conn, conn.LocalAddr().(*net.UDPAddr), conn.RemoteAddr().(*net.UDPAddr), cpip)
 |  | 
 | 
											
												
													
														|  | 
 |  | +	conv := uint16(atomic.AddUint32(&globalConv, 1))
 | 
											
												
													
														|  | 
 |  | +	session := NewConnection(conv, conn, conn.LocalAddr().(*net.UDPAddr), conn.RemoteAddr().(*net.UDPAddr), cpip)
 | 
											
												
													
														|  |  	session.FetchInputFrom(conn)
 |  |  	session.FetchInputFrom(conn)
 | 
											
												
													
														|  |  
 |  |  
 | 
											
												
													
														|  |  	return session, nil
 |  |  	return session, nil
 |