|
|
@ -197,26 +197,22 @@ func (node *Node) SendNewBlockToUnsync() { |
|
|
|
continue |
|
|
|
continue |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
node.stateMutex.Lock() |
|
|
|
for peerID, config := range node.peerRegistrationRecord { |
|
|
|
for peerID, config := range node.peerRegistrationRecord { |
|
|
|
elapseTime := time.Now().UnixNano() - config.timestamp |
|
|
|
elapseTime := time.Now().UnixNano() - config.timestamp |
|
|
|
if elapseTime > broadcastTimeout { |
|
|
|
if elapseTime > broadcastTimeout { |
|
|
|
utils.GetLogInstance().Warn("[SYNC] SendNewBlockToUnsync to peer timeout", "peerID", peerID) |
|
|
|
utils.GetLogInstance().Warn("[SYNC] SendNewBlockToUnsync to peer timeout", "peerID", peerID) |
|
|
|
// send last time and delete
|
|
|
|
|
|
|
|
config.client.PushNewBlock(node.GetSyncID(), blockHash, true) |
|
|
|
|
|
|
|
node.stateMutex.Lock() |
|
|
|
|
|
|
|
node.peerRegistrationRecord[peerID].client.Close() |
|
|
|
node.peerRegistrationRecord[peerID].client.Close() |
|
|
|
delete(node.peerRegistrationRecord, peerID) |
|
|
|
delete(node.peerRegistrationRecord, peerID) |
|
|
|
node.stateMutex.Unlock() |
|
|
|
|
|
|
|
continue |
|
|
|
continue |
|
|
|
} |
|
|
|
} |
|
|
|
response := config.client.PushNewBlock(node.GetSyncID(), blockHash, false) |
|
|
|
response := config.client.PushNewBlock(node.GetSyncID(), blockHash, false) |
|
|
|
if response != nil && response.Type == downloader_pb.DownloaderResponse_INSYNC { |
|
|
|
if response != nil && response.Type == downloader_pb.DownloaderResponse_INSYNC { |
|
|
|
node.stateMutex.Lock() |
|
|
|
|
|
|
|
node.peerRegistrationRecord[peerID].client.Close() |
|
|
|
node.peerRegistrationRecord[peerID].client.Close() |
|
|
|
delete(node.peerRegistrationRecord, peerID) |
|
|
|
delete(node.peerRegistrationRecord, peerID) |
|
|
|
node.stateMutex.Unlock() |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
node.stateMutex.Unlock() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -290,6 +286,8 @@ func (node *Node) CalculateResponse(request *downloader_pb.DownloaderRequest) (* |
|
|
|
peerID := string(request.PeerHash[:]) |
|
|
|
peerID := string(request.PeerHash[:]) |
|
|
|
ip := request.Ip |
|
|
|
ip := request.Ip |
|
|
|
port := request.Port |
|
|
|
port := request.Port |
|
|
|
|
|
|
|
node.stateMutex.Lock() |
|
|
|
|
|
|
|
defer node.stateMutex.Unlock() |
|
|
|
if _, ok := node.peerRegistrationRecord[peerID]; ok { |
|
|
|
if _, ok := node.peerRegistrationRecord[peerID]; ok { |
|
|
|
response.Type = downloader_pb.DownloaderResponse_FAIL |
|
|
|
response.Type = downloader_pb.DownloaderResponse_FAIL |
|
|
|
utils.GetLogInstance().Warn("[SYNC] peerRegistration record already exists", "ip", ip, "port", port) |
|
|
|
utils.GetLogInstance().Warn("[SYNC] peerRegistration record already exists", "ip", ip, "port", port) |
|
|
@ -307,9 +305,7 @@ func (node *Node) CalculateResponse(request *downloader_pb.DownloaderRequest) (* |
|
|
|
return response, nil |
|
|
|
return response, nil |
|
|
|
} |
|
|
|
} |
|
|
|
config := &syncConfig{timestamp: time.Now().UnixNano(), client: client} |
|
|
|
config := &syncConfig{timestamp: time.Now().UnixNano(), client: client} |
|
|
|
node.stateMutex.Lock() |
|
|
|
|
|
|
|
node.peerRegistrationRecord[peerID] = config |
|
|
|
node.peerRegistrationRecord[peerID] = config |
|
|
|
node.stateMutex.Unlock() |
|
|
|
|
|
|
|
utils.GetLogInstance().Debug("[SYNC] register peerID success", "ip", ip, "port", port) |
|
|
|
utils.GetLogInstance().Debug("[SYNC] register peerID success", "ip", ip, "port", port) |
|
|
|
response.Type = downloader_pb.DownloaderResponse_SUCCESS |
|
|
|
response.Type = downloader_pb.DownloaderResponse_SUCCESS |
|
|
|
} |
|
|
|
} |
|
|
|