Browse Source

Send HELLO based on last HELLO instead of last received data

PascalCoin 6 years ago
parent
commit
6aaa91af51
2 changed files with 7 additions and 4 deletions
  1. 5 2
      src/core/UNetProtocol.pas
  2. 2 2
      src/core/UNode.pas

+ 5 - 2
src/core/UNetProtocol.pas

@@ -366,6 +366,7 @@ Type
     FTcpIpClient : TNetTcpIpClient;
     FTcpIpClient : TNetTcpIpClient;
     FRemoteOperationBlock : TOperationBlock;
     FRemoteOperationBlock : TOperationBlock;
     FRemoteAccumulatedWork : UInt64;
     FRemoteAccumulatedWork : UInt64;
+    FLastHelloReceivedTS : TTickCount;
     FLastDataReceivedTS : TTickCount;
     FLastDataReceivedTS : TTickCount;
     FLastDataSendedTS : TTickCount;
     FLastDataSendedTS : TTickCount;
     FClientBufferRead : TStream;
     FClientBufferRead : TStream;
@@ -2545,6 +2546,7 @@ begin
   FIsWaitingForResponse := false;
   FIsWaitingForResponse := false;
   FClientBufferRead := TMemoryStream.Create;
   FClientBufferRead := TMemoryStream.Create;
   FNetLock := TPCCriticalSection.Create('TNetConnection_NetLock');
   FNetLock := TPCCriticalSection.Create('TNetConnection_NetLock');
+  FLastHelloReceivedTS := 0;
   FLastDataReceivedTS := 0;
   FLastDataReceivedTS := 0;
   FLastDataSendedTS := 0;
   FLastDataSendedTS := 0;
   FRandomWaitSecondsSendHello := (CT_NewLineSecondsAvg DIV 3) + Random(CT_NewLineSecondsAvg DIV 5);
   FRandomWaitSecondsSendHello := (CT_NewLineSecondsAvg DIV 3) + Random(CT_NewLineSecondsAvg DIV 5);
@@ -2639,8 +2641,7 @@ begin
     ms.Free;
     ms.Free;
   end;
   end;
   If ((FLastDataReceivedTS>0) Or ( NOT (Self is TNetServerClient)))
   If ((FLastDataReceivedTS>0) Or ( NOT (Self is TNetServerClient)))
-     AND ((FLastDataReceivedTS+(1000*FRandomWaitSecondsSendHello)<TPlatform.GetTickCount) AND (FLastDataSendedTS+(1000*FRandomWaitSecondsSendHello)<TPlatform.GetTickCount)) then begin
-     // Build 1.4 -> Changing wait time from 120 secs to a random seconds value
+    and (TPlatform.GetElapsedMilliseconds(FLastHelloReceivedTS)>(1000*FRandomWaitSecondsSendHello)) then begin
     iPending := TNetData.NetData.PendingRequest(Self,ops);
     iPending := TNetData.NetData.PendingRequest(Self,ops);
     If iPending>=2 then begin
     If iPending>=2 then begin
       TLog.NewLog(ltDebug,Classname,'Pending requests without response... closing connection to '+ClientRemoteAddr+' > '+ops);
       TLog.NewLog(ltDebug,Classname,'Pending requests without response... closing connection to '+ClientRemoteAddr+' > '+ops);
@@ -3550,6 +3551,8 @@ Begin
         end;
         end;
       end;
       end;
 
 
+      FLastHelloReceivedTS:=TPlatform.GetTickCount;
+
       {$IFDEF HIGHLOG}TLog.NewLog(ltdebug,Classname,'Hello received: '+TPCOperationsComp.OperationBlockToText(FRemoteOperationBlock));{$ENDIF}
       {$IFDEF HIGHLOG}TLog.NewLog(ltdebug,Classname,'Hello received: '+TPCOperationsComp.OperationBlockToText(FRemoteOperationBlock));{$ENDIF}
       if (HeaderData.header_type in [ntp_request,ntp_response]) then begin
       if (HeaderData.header_type in [ntp_request,ntp_response]) then begin
         // Response:
         // Response:

+ 2 - 2
src/core/UNode.pas

@@ -396,14 +396,13 @@ Var
   ActOp : TPCOperation;
   ActOp : TPCOperation;
   {$IFDEF BufferOfFutureOperations}sAcc : TAccount;{$ENDIF}
   {$IFDEF BufferOfFutureOperations}sAcc : TAccount;{$ENDIF}
 begin
 begin
-  Result := -1;
+  Result := -1; // -1 Means Node is blocked or disabled
   if Assigned(OperationsResult) then OperationsResult.Clear;
   if Assigned(OperationsResult) then OperationsResult.Clear;
   if FDisabledsNewBlocksCount>0 then begin
   if FDisabledsNewBlocksCount>0 then begin
     errors := Format('Cannot Add Operations due is adding disabled - OpCount:%d',[OperationsHashTree.OperationsCount]);
     errors := Format('Cannot Add Operations due is adding disabled - OpCount:%d',[OperationsHashTree.OperationsCount]);
     TLog.NewLog(ltinfo,Classname,errors);
     TLog.NewLog(ltinfo,Classname,errors);
     exit;
     exit;
   end;
   end;
-  Result := 0;
   nSpam := 0;
   nSpam := 0;
   nRepeated := 0;
   nRepeated := 0;
   nError := 0;
   nError := 0;
@@ -418,6 +417,7 @@ begin
       if TThread.CurrentThread.ThreadID=MainThreadID then raise Exception.Create(s) else exit;
       if TThread.CurrentThread.ThreadID=MainThreadID then raise Exception.Create(s) else exit;
     end;
     end;
     try
     try
+      Result := 0;
       {$IFDEF BufferOfFutureOperations}
       {$IFDEF BufferOfFutureOperations}
       Process_BufferOfFutureOperations(valids_operations);
       Process_BufferOfFutureOperations(valids_operations);
       {$ENDIF}
       {$ENDIF}