mirror of
https://github.com/duanhf2012/origin.git
synced 2026-03-03 04:07:39 +08:00
优化tcpservice
This commit is contained in:
@@ -53,18 +53,9 @@ type Client struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (tcpService *TcpService) genId() uint64 {
|
func (tcpService *TcpService) genId() uint64 {
|
||||||
if node.GetNodeId()>MaxNodeId{
|
|
||||||
panic("nodeId exceeds the maximum!")
|
|
||||||
}
|
|
||||||
|
|
||||||
newSeed := atomic.AddUint32(&seed,1) % MaxSeed
|
newSeed := atomic.AddUint32(&seed,1) % MaxSeed
|
||||||
nowTime := uint64(time.Now().Unix())%MaxTime
|
nowTime := uint64(time.Now().Unix())%MaxTime
|
||||||
return (uint64(node.GetNodeId())<<50)|(nowTime<<19)|uint64(newSeed)
|
return (uint64(node.GetNodeId()%MaxNodeId)<<50)|(nowTime<<19)|uint64(newSeed)
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
func GetNodeId(agentId uint64) int {
|
|
||||||
return int(agentId>>50)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tcpService *TcpService) OnInit() error{
|
func (tcpService *TcpService) OnInit() error{
|
||||||
|
|||||||
Reference in New Issue
Block a user