|
@@ -46,6 +46,7 @@ Const
|
|
CT_INI_IDENT_LOWMEMORY = 'LOWMEMORY';
|
|
CT_INI_IDENT_LOWMEMORY = 'LOWMEMORY';
|
|
CT_INI_IDENT_MINPENDINGBLOCKSTODOWNLOADCHECKPOINT = 'MINPENDINGBLOCKSTODOWNLOADCHECKPOINT';
|
|
CT_INI_IDENT_MINPENDINGBLOCKSTODOWNLOADCHECKPOINT = 'MINPENDINGBLOCKSTODOWNLOADCHECKPOINT';
|
|
CT_INI_IDENT_PEERCACHE = 'PEERCACHE';
|
|
CT_INI_IDENT_PEERCACHE = 'PEERCACHE';
|
|
|
|
+ CT_INI_IDENT_DATA_FOLDER = 'DATAFOLDER';
|
|
|
|
|
|
Type
|
|
Type
|
|
{ TPCDaemonThread }
|
|
{ TPCDaemonThread }
|
|
@@ -55,6 +56,7 @@ Type
|
|
FIniFile : TIniFile;
|
|
FIniFile : TIniFile;
|
|
FMaxBlockToRead: Int64;
|
|
FMaxBlockToRead: Int64;
|
|
FLastNodesCacheUpdatedTS : TTickCount;
|
|
FLastNodesCacheUpdatedTS : TTickCount;
|
|
|
|
+ function GetDataFolder : String;
|
|
procedure OnNetDataReceivedHelloMessage(Sender : TObject);
|
|
procedure OnNetDataReceivedHelloMessage(Sender : TObject);
|
|
procedure OnInitSafeboxProgressNotify(sender : TObject; const message : String; curPos, totalCount : Int64);
|
|
procedure OnInitSafeboxProgressNotify(sender : TObject; const message : String; curPos, totalCount : Int64);
|
|
protected
|
|
protected
|
|
@@ -70,7 +72,6 @@ Type
|
|
TPCDaemon = Class(TCustomDaemon)
|
|
TPCDaemon = Class(TCustomDaemon)
|
|
Private
|
|
Private
|
|
FThread : TPCDaemonThread;
|
|
FThread : TPCDaemonThread;
|
|
- Procedure ThreadStopped (Sender : TObject);
|
|
|
|
public
|
|
public
|
|
Function Start : Boolean; override;
|
|
Function Start : Boolean; override;
|
|
Function Stop : Boolean; override;
|
|
Function Stop : Boolean; override;
|
|
@@ -87,7 +88,6 @@ Type
|
|
TPCDaemonMapper = Class(TCustomDaemonMapper)
|
|
TPCDaemonMapper = Class(TCustomDaemonMapper)
|
|
private
|
|
private
|
|
FLog : TLog;
|
|
FLog : TLog;
|
|
- procedure OnPascalCoinInThreadLog(logtype : TLogType; Time : TDateTime; AThreadID : TThreadID; Const sender, logtext : String);
|
|
|
|
protected
|
|
protected
|
|
Procedure DoOnCreate; override;
|
|
Procedure DoOnCreate; override;
|
|
Procedure DoOnDestroy; override;
|
|
Procedure DoOnDestroy; override;
|
|
@@ -105,6 +105,19 @@ Var _FLog : TLog;
|
|
|
|
|
|
{ TPCDaemonThread }
|
|
{ TPCDaemonThread }
|
|
|
|
|
|
|
|
+function TPCDaemonThread.GetDataFolder: String;
|
|
|
|
+Var LIniDataFolder : String;
|
|
|
|
+begin
|
|
|
|
+ LIniDataFolder := FIniFile.ReadString(CT_INI_SECTION_GLOBAL,CT_INI_IDENT_DATA_FOLDER,'').Trim;
|
|
|
|
+ if (LIniDataFolder.Length=0) then begin
|
|
|
|
+ LIniDataFolder:=TNode.GetPascalCoinDataFolder;
|
|
|
|
+ end else begin
|
|
|
|
+ TNode.SetPascalCoinDataFolder(LIniDataFolder);
|
|
|
|
+ end;
|
|
|
|
+ ForceDirectories(LIniDataFolder);
|
|
|
|
+ Result := LIniDataFolder;
|
|
|
|
+end;
|
|
|
|
+
|
|
procedure TPCDaemonThread.OnNetDataReceivedHelloMessage(Sender: TObject);
|
|
procedure TPCDaemonThread.OnNetDataReceivedHelloMessage(Sender: TObject);
|
|
Var LNsarr : TNodeServerAddressArray;
|
|
Var LNsarr : TNodeServerAddressArray;
|
|
i : Integer;
|
|
i : Integer;
|
|
@@ -154,7 +167,7 @@ var
|
|
TLog.NewLog(ltInfo,ClassName,'RPC server is active on port '+IntToStr(port));
|
|
TLog.NewLog(ltInfo,ClassName,'RPC server is active on port '+IntToStr(port));
|
|
If FIniFile.ReadBool(CT_INI_SECTION_GLOBAL,CT_INI_IDENT_RPC_SAVELOGS,true) then begin
|
|
If FIniFile.ReadBool(CT_INI_SECTION_GLOBAL,CT_INI_IDENT_RPC_SAVELOGS,true) then begin
|
|
FIniFile.WriteBool(CT_INI_SECTION_GLOBAL,CT_INI_IDENT_RPC_SAVELOGS,true);
|
|
FIniFile.WriteBool(CT_INI_SECTION_GLOBAL,CT_INI_IDENT_RPC_SAVELOGS,true);
|
|
- FRPC.LogFileName:= TNode.GetPascalCoinDataFolder+PathDelim+'pascalcoin_rpc.log';
|
|
|
|
|
|
+ FRPC.LogFileName:= GetDataFolder+PathDelim+'pascalcoin_rpc.log';
|
|
TLog.NewLog(ltInfo,ClassName,'Activating RPC logs on file '+FRPC.LogFileName);
|
|
TLog.NewLog(ltInfo,ClassName,'Activating RPC logs on file '+FRPC.LogFileName);
|
|
end else begin
|
|
end else begin
|
|
FIniFile.WriteBool(CT_INI_SECTION_GLOBAL,CT_INI_IDENT_RPC_SAVELOGS,false);
|
|
FIniFile.WriteBool(CT_INI_SECTION_GLOBAL,CT_INI_IDENT_RPC_SAVELOGS,false);
|
|
@@ -233,12 +246,10 @@ begin
|
|
// Load Node
|
|
// Load Node
|
|
// Check OpenSSL dll
|
|
// Check OpenSSL dll
|
|
if Not LoadSSLCrypt then begin
|
|
if Not LoadSSLCrypt then begin
|
|
- WriteLn('Cannot load '+SSL_C_LIB);
|
|
|
|
- WriteLn('To use this software make sure this file is available on you system or reinstall the application');
|
|
|
|
raise Exception.Create('Cannot load '+SSL_C_LIB+#10+'To use this software make sure this file is available on you system or reinstall the application');
|
|
raise Exception.Create('Cannot load '+SSL_C_LIB+#10+'To use this software make sure this file is available on you system or reinstall the application');
|
|
end;
|
|
end;
|
|
TCrypto.InitCrypto;
|
|
TCrypto.InitCrypto;
|
|
- FWalletKeys.WalletFileName := TNode.GetPascalCoinDataFolder+PathDelim+'WalletKeys.dat';
|
|
|
|
|
|
+ FWalletKeys.WalletFileName := GetDataFolder+PathDelim+'WalletKeys.dat';
|
|
// Creating Node:
|
|
// Creating Node:
|
|
FNode := TNode.Node;
|
|
FNode := TNode.Node;
|
|
{$IFDEF TESTNET}
|
|
{$IFDEF TESTNET}
|
|
@@ -249,7 +260,7 @@ begin
|
|
Try
|
|
Try
|
|
// Check Database
|
|
// Check Database
|
|
FNode.Bank.StorageClass := TFileStorage;
|
|
FNode.Bank.StorageClass := TFileStorage;
|
|
- TFileStorage(FNode.Bank.Storage).DatabaseFolder := TNode.GetPascalCoinDataFolder+PathDelim+'Data';
|
|
|
|
|
|
+ TFileStorage(FNode.Bank.Storage).DatabaseFolder := GetDataFolder+PathDelim+'Data';
|
|
TFileStorage(FNode.Bank.Storage).LowMemoryUsage := FIniFile.ReadBool(CT_INI_SECTION_GLOBAL,CT_INI_IDENT_LOWMEMORY,False);
|
|
TFileStorage(FNode.Bank.Storage).LowMemoryUsage := FIniFile.ReadBool(CT_INI_SECTION_GLOBAL,CT_INI_IDENT_LOWMEMORY,False);
|
|
// By default daemon will not download checkpoint except if specified on INI file
|
|
// By default daemon will not download checkpoint except if specified on INI file
|
|
TNetData.NetData.MinFutureBlocksToDownloadNewSafebox := FIniFile.ReadInteger(CT_INI_SECTION_GLOBAL,CT_INI_IDENT_MINPENDINGBLOCKSTODOWNLOADCHECKPOINT,0);
|
|
TNetData.NetData.MinFutureBlocksToDownloadNewSafebox := FIniFile.ReadInteger(CT_INI_SECTION_GLOBAL,CT_INI_IDENT_MINPENDINGBLOCKSTODOWNLOADCHECKPOINT,0);
|
|
@@ -268,7 +279,7 @@ begin
|
|
Try
|
|
Try
|
|
Repeat
|
|
Repeat
|
|
Sleep(100);
|
|
Sleep(100);
|
|
- Until Terminated;
|
|
|
|
|
|
+ Until (Terminated) or (Application.Terminated);
|
|
finally
|
|
finally
|
|
FreeAndNil(FMinerServer);
|
|
FreeAndNil(FMinerServer);
|
|
end;
|
|
end;
|
|
@@ -313,30 +324,26 @@ end;
|
|
|
|
|
|
{ TPCDaemon }
|
|
{ TPCDaemon }
|
|
|
|
|
|
-procedure TPCDaemon.ThreadStopped(Sender: TObject);
|
|
|
|
-begin
|
|
|
|
- FreeAndNil(FThread);
|
|
|
|
-end;
|
|
|
|
-
|
|
|
|
function TPCDaemon.Start: Boolean;
|
|
function TPCDaemon.Start: Boolean;
|
|
begin
|
|
begin
|
|
Result:=inherited Start;
|
|
Result:=inherited Start;
|
|
TLog.NewLog(ltinfo,ClassName,'Daemon Start '+BoolToStr(Result));
|
|
TLog.NewLog(ltinfo,ClassName,'Daemon Start '+BoolToStr(Result));
|
|
FThread:=TPCDaemonThread.Create;
|
|
FThread:=TPCDaemonThread.Create;
|
|
- FThread.OnTerminate:=@ThreadStopped;
|
|
|
|
- FThread.FreeOnTerminate:=False;
|
|
|
|
|
|
+ FThread.FreeOnTerminate:=True;
|
|
if (Application.HasOption('b','block')) then begin
|
|
if (Application.HasOption('b','block')) then begin
|
|
FThread.MaxBlockToRead:=StrToInt64Def(Application.GetOptionValue('b','block'),$FFFFFFFF);
|
|
FThread.MaxBlockToRead:=StrToInt64Def(Application.GetOptionValue('b','block'),$FFFFFFFF);
|
|
TLog.NewLog(ltinfo,ClassName,'Max block to read: '+IntToStr(FThread.MaxBlockToRead));
|
|
TLog.NewLog(ltinfo,ClassName,'Max block to read: '+IntToStr(FThread.MaxBlockToRead));
|
|
end;
|
|
end;
|
|
- FThread.Resume;
|
|
|
|
|
|
+ FThread.Start;
|
|
end;
|
|
end;
|
|
|
|
|
|
function TPCDaemon.Stop: Boolean;
|
|
function TPCDaemon.Stop: Boolean;
|
|
begin
|
|
begin
|
|
Result:=inherited Stop;
|
|
Result:=inherited Stop;
|
|
- TLog.NewLog(ltinfo,ClassName,'Daemon Stop: '+BoolToStr(Result));
|
|
|
|
|
|
+ TLog.NewLog(ltinfo,ClassName,'Daemon Stop Start');
|
|
FThread.Terminate;
|
|
FThread.Terminate;
|
|
|
|
+ FThread.WaitFor;
|
|
|
|
+ TLog.NewLog(ltinfo,ClassName,'Daemon Stop Finished');
|
|
end;
|
|
end;
|
|
|
|
|
|
function TPCDaemon.Pause: Boolean;
|
|
function TPCDaemon.Pause: Boolean;
|
|
@@ -362,8 +369,10 @@ end;
|
|
function TPCDaemon.ShutDown: Boolean;
|
|
function TPCDaemon.ShutDown: Boolean;
|
|
begin
|
|
begin
|
|
Result:=inherited ShutDown;
|
|
Result:=inherited ShutDown;
|
|
- TLog.NewLog(ltinfo,ClassName,'Daemon Shutdown: '+BoolToStr(Result));
|
|
|
|
|
|
+ TLog.NewLog(ltinfo,ClassName,'Daemon Shutdown Start');
|
|
FThread.Terminate;
|
|
FThread.Terminate;
|
|
|
|
+ FThread.WaitFor;
|
|
|
|
+ TLog.NewLog(ltinfo,ClassName,'Daemon Shutdown Finished');
|
|
end;
|
|
end;
|
|
|
|
|
|
function TPCDaemon.Install: Boolean;
|
|
function TPCDaemon.Install: Boolean;
|
|
@@ -380,40 +389,27 @@ end;
|
|
|
|
|
|
{ TPCDaemonMapper }
|
|
{ TPCDaemonMapper }
|
|
|
|
|
|
-procedure TPCDaemonMapper.OnPascalCoinInThreadLog(logtype: TLogType;
|
|
|
|
- Time: TDateTime; AThreadID: TThreadID; const sender, logtext: String);
|
|
|
|
-Var s : AnsiString;
|
|
|
|
-begin
|
|
|
|
-// If Not SameText(sender,TPCDaemonThread.ClassName) then exit;
|
|
|
|
- If logtype in [lterror,ltinfo] then begin
|
|
|
|
- if AThreadID=MainThreadID then s := ' MAIN:' else s:=' TID:';
|
|
|
|
- WriteLn(formatDateTime('dd/mm/yyyy hh:nn:ss.zzz',Time)+s+IntToHex(PtrInt(AThreadID),8)+' ['+CT_LogType[Logtype]+'] <'+sender+'> '+logtext);
|
|
|
|
- end;
|
|
|
|
-end;
|
|
|
|
-
|
|
|
|
procedure TPCDaemonMapper.DoOnCreate;
|
|
procedure TPCDaemonMapper.DoOnCreate;
|
|
Var D : TDaemonDef;
|
|
Var D : TDaemonDef;
|
|
begin
|
|
begin
|
|
inherited DoOnCreate;
|
|
inherited DoOnCreate;
|
|
- WriteLn('');
|
|
|
|
- WriteLn(formatDateTime('dd/mm/yyyy hh:nn:ss.zzz',now)+' Starting PascalCoin server');
|
|
|
|
FLog := TLog.Create(Nil);
|
|
FLog := TLog.Create(Nil);
|
|
- FLog.OnInThreadNewLog:=@OnPascalCoinInThreadLog;
|
|
|
|
_FLog := FLog;
|
|
_FLog := FLog;
|
|
D:=DaemonDefs.Add as TDaemonDef;
|
|
D:=DaemonDefs.Add as TDaemonDef;
|
|
- D.DisplayName:='Pascal Coin Daemon';
|
|
|
|
|
|
+ D.DisplayName:='PascalCoin Daemon';
|
|
D.Name:='PascalCoinDaemon';
|
|
D.Name:='PascalCoinDaemon';
|
|
D.DaemonClassName:='TPCDaemon';
|
|
D.DaemonClassName:='TPCDaemon';
|
|
|
|
+ D.Options:=[doAllowStop];
|
|
D.WinBindings.ServiceType:=stWin32;
|
|
D.WinBindings.ServiceType:=stWin32;
|
|
end;
|
|
end;
|
|
|
|
|
|
procedure TPCDaemonMapper.DoOnDestroy;
|
|
procedure TPCDaemonMapper.DoOnDestroy;
|
|
begin
|
|
begin
|
|
|
|
+ inherited DoOnDestroy;
|
|
If Assigned(FLog) then begin
|
|
If Assigned(FLog) then begin
|
|
FLog.OnInThreadNewLog:=Nil;
|
|
FLog.OnInThreadNewLog:=Nil;
|
|
FreeAndNil(FLog);
|
|
FreeAndNil(FLog);
|
|
end;
|
|
end;
|
|
- inherited DoOnDestroy;
|
|
|
|
end;
|
|
end;
|
|
|
|
|
|
end.
|
|
end.
|