|
@@ -125,6 +125,7 @@ Type
|
|
|
|
|
|
TOrderedServerAddressListTS = Class
|
|
TOrderedServerAddressListTS = Class
|
|
private
|
|
private
|
|
|
|
+ FAllowDeleteOnClean: Boolean;
|
|
FNetData : TNetData;
|
|
FNetData : TNetData;
|
|
FCritical : TPCCriticalSection;
|
|
FCritical : TPCCriticalSection;
|
|
FListByIp : TList;
|
|
FListByIp : TList;
|
|
@@ -149,6 +150,7 @@ Type
|
|
Procedure UpdateNetConnection(netConnection : TNetConnection);
|
|
Procedure UpdateNetConnection(netConnection : TNetConnection);
|
|
procedure GetNodeServersToConnnect(maxNodes : Integer; useArray : Boolean; var nsa : TNodeServerAddressArray);
|
|
procedure GetNodeServersToConnnect(maxNodes : Integer; useArray : Boolean; var nsa : TNodeServerAddressArray);
|
|
Function GetValidNodeServers(OnlyWhereIConnected : Boolean; Max : Integer): TNodeServerAddressArray;
|
|
Function GetValidNodeServers(OnlyWhereIConnected : Boolean; Max : Integer): TNodeServerAddressArray;
|
|
|
|
+ property AllowDeleteOnClean : Boolean read FAllowDeleteOnClean write FAllowDeleteOnClean;
|
|
End;
|
|
End;
|
|
|
|
|
|
|
|
|
|
@@ -240,6 +242,8 @@ Type
|
|
TNetData = Class(TComponent)
|
|
TNetData = Class(TComponent)
|
|
private
|
|
private
|
|
FMaxNodeServersAddressesBuffer: Integer;
|
|
FMaxNodeServersAddressesBuffer: Integer;
|
|
|
|
+ FMaxServersConnected: Integer;
|
|
|
|
+ FMinServersConnected: Integer;
|
|
FNetDataNotifyEventsThread : TNetDataNotifyEventsThread;
|
|
FNetDataNotifyEventsThread : TNetDataNotifyEventsThread;
|
|
FNodePrivateKey : TECPrivateKey;
|
|
FNodePrivateKey : TECPrivateKey;
|
|
FNetConnections : TPCThreadList;
|
|
FNetConnections : TPCThreadList;
|
|
@@ -265,6 +269,8 @@ Type
|
|
FNetworkAdjustedTime : TNetworkAdjustedTime;
|
|
FNetworkAdjustedTime : TNetworkAdjustedTime;
|
|
Procedure IncStatistics(incActiveConnections,incClientsConnections,incServersConnections,incServersConnectionsWithResponse : Integer; incBytesReceived, incBytesSend : Int64);
|
|
Procedure IncStatistics(incActiveConnections,incClientsConnections,incServersConnections,incServersConnectionsWithResponse : Integer; incBytesReceived, incBytesSend : Int64);
|
|
procedure SetMaxNodeServersAddressesBuffer(AValue: Integer);
|
|
procedure SetMaxNodeServersAddressesBuffer(AValue: Integer);
|
|
|
|
+ procedure SetMaxServersConnected(AValue: Integer);
|
|
|
|
+ procedure SetMinServersConnected(AValue: Integer);
|
|
procedure SetNetConnectionsActive(const Value: Boolean); protected
|
|
procedure SetNetConnectionsActive(const Value: Boolean); protected
|
|
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
|
|
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
|
|
Procedure DiscoverServersTerminated(Sender : TObject);
|
|
Procedure DiscoverServersTerminated(Sender : TObject);
|
|
@@ -326,6 +332,8 @@ Type
|
|
Property NetworkAdjustedTime : TNetworkAdjustedTime read FNetworkAdjustedTime;
|
|
Property NetworkAdjustedTime : TNetworkAdjustedTime read FNetworkAdjustedTime;
|
|
Property MaxNodeServersAddressesBuffer : Integer read FMaxNodeServersAddressesBuffer write SetMaxNodeServersAddressesBuffer;
|
|
Property MaxNodeServersAddressesBuffer : Integer read FMaxNodeServersAddressesBuffer write SetMaxNodeServersAddressesBuffer;
|
|
Property OnProcessReservedAreaMessage : TProcessReservedAreaMessage read FOnProcessReservedAreaMessage write FOnProcessReservedAreaMessage;
|
|
Property OnProcessReservedAreaMessage : TProcessReservedAreaMessage read FOnProcessReservedAreaMessage write FOnProcessReservedAreaMessage;
|
|
|
|
+ Property MinServersConnected : Integer read FMinServersConnected write SetMinServersConnected;
|
|
|
|
+ Property MaxServersConnected : Integer read FMaxServersConnected write SetMaxServersConnected;
|
|
End;
|
|
End;
|
|
|
|
|
|
{ TNetConnection }
|
|
{ TNetConnection }
|
|
@@ -487,7 +495,11 @@ begin
|
|
// Is an old blacklisted IP? (More than 1 hour)
|
|
// Is an old blacklisted IP? (More than 1 hour)
|
|
If (P^.is_blacklisted) AND
|
|
If (P^.is_blacklisted) AND
|
|
((forceCleanAll) OR ((P^.last_connection+(CT_LAST_CONNECTION_MAX_MINUTES)) < (UnivDateTimeToUnix(DateTime2UnivDateTime(now))))) then begin
|
|
((forceCleanAll) OR ((P^.last_connection+(CT_LAST_CONNECTION_MAX_MINUTES)) < (UnivDateTimeToUnix(DateTime2UnivDateTime(now))))) then begin
|
|
- SecuredDeleteFromListByIp(i);
|
|
|
|
|
|
+ if (AllowDeleteOnClean) then begin
|
|
|
|
+ SecuredDeleteFromListByIp(i);
|
|
|
|
+ end else begin
|
|
|
|
+ P^.is_blacklisted:=False;
|
|
|
|
+ end;
|
|
inc(Result);
|
|
inc(Result);
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
@@ -502,6 +514,7 @@ var i : Integer;
|
|
nsa : TNodeServerAddress;
|
|
nsa : TNodeServerAddress;
|
|
currunixtimestamp : Cardinal;
|
|
currunixtimestamp : Cardinal;
|
|
begin
|
|
begin
|
|
|
|
+ If Not (FAllowDeleteOnClean) then Exit;
|
|
currunixtimestamp := UnivDateTimeToUnix(DateTime2UnivDateTime(now));
|
|
currunixtimestamp := UnivDateTimeToUnix(DateTime2UnivDateTime(now));
|
|
FCritical.Acquire;
|
|
FCritical.Acquire;
|
|
Try
|
|
Try
|
|
@@ -575,6 +588,7 @@ begin
|
|
FCritical := TPCCriticalSection.Create(Classname);
|
|
FCritical := TPCCriticalSection.Create(Classname);
|
|
FListByIp := TList.Create;
|
|
FListByIp := TList.Create;
|
|
FListByNetConnection := TList.Create;
|
|
FListByNetConnection := TList.Create;
|
|
|
|
+ FAllowDeleteOnClean := True;
|
|
end;
|
|
end;
|
|
|
|
|
|
function TOrderedServerAddressListTS.DeleteNetConnection(netConnection: TNetConnection) : Boolean;
|
|
function TOrderedServerAddressListTS.DeleteNetConnection(netConnection: TNetConnection) : Boolean;
|
|
@@ -863,7 +877,8 @@ begin
|
|
Index := L;
|
|
Index := L;
|
|
end;
|
|
end;
|
|
|
|
|
|
-procedure TOrderedServerAddressListTS.SetNodeServerAddress(Const nodeServerAddress: TNodeServerAddress);
|
|
|
|
|
|
+procedure TOrderedServerAddressListTS.SetNodeServerAddress(
|
|
|
|
+ const nodeServerAddress: TNodeServerAddress);
|
|
Var i : Integer;
|
|
Var i : Integer;
|
|
P : PNodeServerAddress;
|
|
P : PNodeServerAddress;
|
|
begin
|
|
begin
|
|
@@ -1147,6 +1162,8 @@ begin
|
|
FNetClientsDestroyThread := TNetClientsDestroyThread.Create(Self);
|
|
FNetClientsDestroyThread := TNetClientsDestroyThread.Create(Self);
|
|
FNetworkAdjustedTime := TNetworkAdjustedTime.Create;
|
|
FNetworkAdjustedTime := TNetworkAdjustedTime.Create;
|
|
FMaxNodeServersAddressesBuffer:=(CT_MAX_NODESERVERS_BUFFER DIV 2);
|
|
FMaxNodeServersAddressesBuffer:=(CT_MAX_NODESERVERS_BUFFER DIV 2);
|
|
|
|
+ FMinServersConnected:=CT_MinServersConnected;
|
|
|
|
+ FMaxServersConnected:=CT_MaxServersConnected;
|
|
If Not Assigned(_NetData) then _NetData := Self;
|
|
If Not Assigned(_NetData) then _NetData := Self;
|
|
end;
|
|
end;
|
|
|
|
|
|
@@ -1267,9 +1284,9 @@ begin
|
|
end;
|
|
end;
|
|
FNodeServersAddresses.CleanBlackList(False);
|
|
FNodeServersAddresses.CleanBlackList(False);
|
|
If NetStatistics.ClientsConnections>0 then begin
|
|
If NetStatistics.ClientsConnections>0 then begin
|
|
- j := CT_MinServersConnected - NetStatistics.ServersConnectionsWithResponse;
|
|
|
|
|
|
+ j := FMinServersConnected - NetStatistics.ServersConnectionsWithResponse;
|
|
end else begin
|
|
end else begin
|
|
- j := CT_MaxServersConnected - NetStatistics.ServersConnectionsWithResponse;
|
|
|
|
|
|
+ j := FMaxServersConnected - NetStatistics.ServersConnectionsWithResponse;
|
|
end;
|
|
end;
|
|
if j<=0 then exit;
|
|
if j<=0 then exit;
|
|
{$IFDEF HIGHLOG}TLog.NewLog(ltDebug,Classname,'Discover servers start process searching up to '+inttostr(j)+' servers');{$ENDIF}
|
|
{$IFDEF HIGHLOG}TLog.NewLog(ltDebug,Classname,'Discover servers start process searching up to '+inttostr(j)+' servers');{$ENDIF}
|
|
@@ -1578,6 +1595,10 @@ Const CT_LogSender = 'GetNewBlockChainFromClient';
|
|
end else begin
|
|
end else begin
|
|
// Restore a part from disk
|
|
// Restore a part from disk
|
|
Bank.DiskRestoreFromOperations(start_block-1);
|
|
Bank.DiskRestoreFromOperations(start_block-1);
|
|
|
|
+ if (Bank.BlocksCount<start_block) then begin
|
|
|
|
+ TLog.NewLog(lterror,CT_LogSender,Format('No blockchain found start block %d, current %d',[start_block-1,Bank.BlocksCount]));
|
|
|
|
+ start_block := Bank.BlocksCount;
|
|
|
|
+ end;
|
|
IsUsingSnapshot := False;
|
|
IsUsingSnapshot := False;
|
|
end;
|
|
end;
|
|
start := start_block;
|
|
start := start_block;
|
|
@@ -1628,7 +1649,9 @@ Const CT_LogSender = 'GetNewBlockChainFromClient';
|
|
BlocksList.Free;
|
|
BlocksList.Free;
|
|
end;
|
|
end;
|
|
start := Bank.BlocksCount;
|
|
start := Bank.BlocksCount;
|
|
- until (Bank.BlocksCount=Connection.FRemoteOperationBlock.block+1) Or (finished);
|
|
|
|
|
|
+ until (Bank.BlocksCount=Connection.FRemoteOperationBlock.block+1) Or (finished)
|
|
|
|
+ // Allow to do not download ALL new blockchain in a separate folder, only needed blocks!
|
|
|
|
+ Or (Bank.SafeBox.WorkSum > (TNode.Node.Bank.SafeBox.WorkSum + $FFFFFFFF) );
|
|
// New Build 1.5 more work vs more high
|
|
// New Build 1.5 more work vs more high
|
|
// work = SUM(target) of all previous blocks (Int64)
|
|
// work = SUM(target) of all previous blocks (Int64)
|
|
// -----------------------------
|
|
// -----------------------------
|
|
@@ -1647,11 +1670,13 @@ Const CT_LogSender = 'GetNewBlockChainFromClient';
|
|
try
|
|
try
|
|
for start:=start_c to TNode.Node.Bank.BlocksCount-1 do begin
|
|
for start:=start_c to TNode.Node.Bank.BlocksCount-1 do begin
|
|
If TNode.Node.Bank.LoadOperations(OpExecute,start) then begin
|
|
If TNode.Node.Bank.LoadOperations(OpExecute,start) then begin
|
|
- for i:=0 to OpExecute.Count-1 do begin
|
|
|
|
- // TODO: NEED TO EXCLUDE OPERATIONS ALREADY INCLUDED IN BLOCKCHAIN?
|
|
|
|
- oldBlockchainOperations.AddOperationToHashTree(OpExecute.Operation[i]);
|
|
|
|
|
|
+ if (OpExecute.Count>0) then begin
|
|
|
|
+ for i:=0 to OpExecute.Count-1 do begin
|
|
|
|
+ // TODO: NEED TO EXCLUDE OPERATIONS ALREADY INCLUDED IN BLOCKCHAIN?
|
|
|
|
+ oldBlockchainOperations.AddOperationToHashTree(OpExecute.Operation[i]);
|
|
|
|
+ end;
|
|
|
|
+ TLog.NewLog(ltInfo,CT_LogSender,'Recovered '+IntToStr(OpExecute.Count)+' operations from block '+IntToStr(start));
|
|
end;
|
|
end;
|
|
- TLog.NewLog(ltInfo,CT_LogSender,'Recovered '+IntToStr(OpExecute.Count)+' operations from block '+IntToStr(start));
|
|
|
|
end else begin
|
|
end else begin
|
|
TLog.NewLog(ltError,CT_LogSender,'Fatal error: Cannot read block '+IntToStr(start));
|
|
TLog.NewLog(ltError,CT_LogSender,'Fatal error: Cannot read block '+IntToStr(start));
|
|
end;
|
|
end;
|
|
@@ -1792,7 +1817,7 @@ Const CT_LogSender = 'GetNewBlockChainFromClient';
|
|
SetLength(chunks,0);
|
|
SetLength(chunks,0);
|
|
try
|
|
try
|
|
// Will obtain chunks of 10000 blocks each
|
|
// Will obtain chunks of 10000 blocks each
|
|
- for i:=0 to _blockcount DIV 10000 do begin
|
|
|
|
|
|
+ for i:=0 to ((_blockcount-1) DIV 10000) do begin // Bug v3.0.1 and minors
|
|
receiveChunk := TMemoryStream.Create;
|
|
receiveChunk := TMemoryStream.Create;
|
|
if (Not DownloadSafeBoxChunk(_blockcount,op.initial_safe_box_hash,(i*10000),((i+1)*10000)-1,receiveChunk,safeBoxHeader,errors)) then begin
|
|
if (Not DownloadSafeBoxChunk(_blockcount,op.initial_safe_box_hash,(i*10000),((i+1)*10000)-1,receiveChunk,safeBoxHeader,errors)) then begin
|
|
receiveChunk.Free;
|
|
receiveChunk.Free;
|
|
@@ -1842,6 +1867,7 @@ Const CT_LogSender = 'GetNewBlockChainFromClient';
|
|
If Not IsMyBlockchainValid then begin
|
|
If Not IsMyBlockchainValid then begin
|
|
TNode.Node.Bank.Storage.EraseStorage;
|
|
TNode.Node.Bank.Storage.EraseStorage;
|
|
end;
|
|
end;
|
|
|
|
+ TNode.Node.Bank.Storage.SaveBank;
|
|
Connection.Send_GetBlocks(TNode.Node.Bank.BlocksCount,100,request_id);
|
|
Connection.Send_GetBlocks(TNode.Node.Bank.BlocksCount,100,request_id);
|
|
Result := true;
|
|
Result := true;
|
|
end else begin
|
|
end else begin
|
|
@@ -1868,6 +1894,7 @@ begin
|
|
TLog.NewLog(ltdebug,CT_LogSender,'Is discovering servers...');
|
|
TLog.NewLog(ltdebug,CT_LogSender,'Is discovering servers...');
|
|
exit;
|
|
exit;
|
|
end;
|
|
end;
|
|
|
|
+ if (Not Assigned(TNode.Node.Bank.StorageClass)) then Exit;
|
|
//
|
|
//
|
|
If FIsGettingNewBlockChainFromClient then begin
|
|
If FIsGettingNewBlockChainFromClient then begin
|
|
TLog.NewLog(ltdebug,CT_LogSender,'Is getting new blockchain from client...');
|
|
TLog.NewLog(ltdebug,CT_LogSender,'Is getting new blockchain from client...');
|
|
@@ -1973,6 +2000,22 @@ begin
|
|
else FMaxNodeServersAddressesBuffer:=AValue;
|
|
else FMaxNodeServersAddressesBuffer:=AValue;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+procedure TNetData.SetMaxServersConnected(AValue: Integer);
|
|
|
|
+begin
|
|
|
|
+ if FMaxServersConnected=AValue then Exit;
|
|
|
|
+ if AValue<1 then FMaxServersConnected:=1
|
|
|
|
+ else FMaxServersConnected:=AValue;
|
|
|
|
+ if FMaxServersConnected<FMinServersConnected then FMinServersConnected:=FMaxServersConnected;
|
|
|
|
+end;
|
|
|
|
+
|
|
|
|
+procedure TNetData.SetMinServersConnected(AValue: Integer);
|
|
|
|
+begin
|
|
|
|
+ if FMinServersConnected=AValue then Exit;
|
|
|
|
+ if AValue<1 then FMinServersConnected:=1
|
|
|
|
+ else FMinServersConnected:=AValue;
|
|
|
|
+ if FMaxServersConnected<FMinServersConnected then FMaxServersConnected:=FMinServersConnected;
|
|
|
|
+end;
|
|
|
|
+
|
|
class function TNetData.NetData: TNetData;
|
|
class function TNetData.NetData: TNetData;
|
|
begin
|
|
begin
|
|
if Not Assigned(_NetData) then begin
|
|
if Not Assigned(_NetData) then begin
|
|
@@ -2966,7 +3009,7 @@ begin
|
|
if (b=1) then begin
|
|
if (b=1) then begin
|
|
DataBuffer.Read(c,SizeOf(c));
|
|
DataBuffer.Read(c,SizeOf(c));
|
|
start:=c;
|
|
start:=c;
|
|
- max:=c;
|
|
|
|
|
|
+ max:=1; // Bug 3.0.1 (was c instead of fixed 1)
|
|
end else begin
|
|
end else begin
|
|
DataBuffer.Read(c,SizeOf(c));
|
|
DataBuffer.Read(c,SizeOf(c));
|
|
start:=c;
|
|
start:=c;
|
|
@@ -4037,7 +4080,7 @@ begin
|
|
FNetData.FNetStatistics.ServersConnections := newstats.ServersConnections;
|
|
FNetData.FNetStatistics.ServersConnections := newstats.ServersConnections;
|
|
FNetData.FNetStatistics.ServersConnectionsWithResponse := newstats.ServersConnectionsWithResponse;
|
|
FNetData.FNetStatistics.ServersConnectionsWithResponse := newstats.ServersConnectionsWithResponse;
|
|
// Must stop clients?
|
|
// Must stop clients?
|
|
- if (nserverclients>CT_MaxServersConnected) And // This is to ensure there are more serverclients than clients
|
|
|
|
|
|
+ if (nserverclients>FNetData.MaxServersConnected) And // This is to ensure there are more serverclients than clients
|
|
((nserverclients + nactive + ndeleted)>=FNetData.FMaxConnections) And (Assigned(netserverclientstop)) then begin
|
|
((nserverclients + nactive + ndeleted)>=FNetData.FMaxConnections) And (Assigned(netserverclientstop)) then begin
|
|
TLog.NewLog(ltinfo,Classname,Format('Sending FinalizeConnection to NodeConnection %s created on %s (working time %s) - NetServerClients:%d Servers_active:%d Servers_deleted:%d',
|
|
TLog.NewLog(ltinfo,Classname,Format('Sending FinalizeConnection to NodeConnection %s created on %s (working time %s) - NetServerClients:%d Servers_active:%d Servers_deleted:%d',
|
|
[netserverclientstop.Client.ClientRemoteAddr,FormatDateTime('hh:nn:ss',netserverclientstop.CreatedTime),
|
|
[netserverclientstop.Client.ClientRemoteAddr,FormatDateTime('hh:nn:ss',netserverclientstop.CreatedTime),
|
|
@@ -4048,7 +4091,7 @@ begin
|
|
finally
|
|
finally
|
|
FNetData.FNetConnections.UnlockList;
|
|
FNetData.FNetConnections.UnlockList;
|
|
end;
|
|
end;
|
|
- if (nactive<=CT_MaxServersConnected) And (Not Terminated) then begin
|
|
|
|
|
|
+ if (nactive<=FNetData.MaxServersConnected) And (Not Terminated) then begin
|
|
// Discover
|
|
// Discover
|
|
FNetData.DiscoverServers;
|
|
FNetData.DiscoverServers;
|
|
end;
|
|
end;
|