99#include " ui_interface.h"
1010#include " util.h"
1111
12- #include < boost/filesystem.hpp>
13- #include < boost/filesystem/fstream.hpp>
1412#include < stdint.h>
1513
1614#ifndef WIN32
1715#include " sys/stat.h"
1816#endif
1917
2018using namespace std ;
21- using namespace boost ;
22-
2319
2420unsigned int nWalletDBUpdated;
2521
26-
27-
2822//
2923// CDB
3024//
@@ -60,7 +54,7 @@ void CDBEnv::Close()
6054 EnvShutdown ();
6155}
6256
63- bool CDBEnv::Open (boost::filesystem ::path pathEnv_)
57+ bool CDBEnv::Open (fs ::path pathEnv_)
6458{
6559 if (fDbEnvInit )
6660 return true ;
@@ -69,11 +63,11 @@ bool CDBEnv::Open(boost::filesystem::path pathEnv_)
6963 return false ;
7064
7165 pathEnv = pathEnv_;
72- filesystem ::path pathDataDir = pathEnv;
66+ fs ::path pathDataDir = pathEnv;
7367 strPath = pathDataDir.string ();
74- filesystem ::path pathLogDir = pathDataDir / " database" ;
75- filesystem ::create_directory (pathLogDir);
76- filesystem ::path pathErrorFile = pathDataDir / " db.log" ;
68+ fs ::path pathLogDir = pathDataDir / " database" ;
69+ fs ::create_directory (pathLogDir);
70+ fs ::path pathErrorFile = pathDataDir / " db.log" ;
7771 LogPrintf (" dbenv.open LogDir=%s ErrorFile=%s" , pathLogDir.string (), pathErrorFile.string ());
7872
7973 unsigned int nEnvFlags = 0 ;
@@ -485,107 +479,3 @@ void CDBEnv::Flush(bool fShutdown)
485479 }
486480 }
487481}
488-
489-
490- //
491- // CAddrDB
492- //
493-
494- /*
495- CAddrDB::CAddrDB()
496- {
497- pathAddr = GetDataDir() / "peers.dat";
498- }
499-
500- bool CAddrDB::Write(const CAddrMan& addr)
501- {
502- // Generate random temporary filename
503- unsigned short randv = 0;
504- RAND_bytes((unsigned char *)&randv, sizeof(randv));
505- std::string tmpfn = strprintf("peers.dat.%04x", randv);
506-
507- // serialize addresses, checksum data up to that point, then append csum
508- CDataStream ssPeers(SER_DISK, CLIENT_VERSION);
509- ssPeers << pchMessageStart;
510- ssPeers << addr;
511- uint256 hash = Hash(ssPeers.begin(), ssPeers.end());
512- ssPeers << hash;
513-
514- // open temp output file, and associate with CAutoFile
515- boost::filesystem::path pathTmp = GetDataDir() / tmpfn;
516- FILE *file = fsbridge::fopen(pathTmp.string().c_str(), "wb");
517- CAutoFile fileout(file, SER_DISK, CLIENT_VERSION);
518- if (fileout.IsNull())
519- return error("CAddrman::Write() : open failed");
520-
521- // Write and commit header, data
522- try {
523- fileout << ssPeers;
524- }
525- catch (std::exception &e) {
526- return error("CAddrman::Write() : I/O error");
527- }
528- FileCommit(fileout.Get());
529- fileout.fclose();
530-
531- // replace existing peers.dat, if any, with new peers.dat.XXXX
532- if (!RenameOver(pathTmp, pathAddr))
533- return error("CAddrman::Write() : Rename-into-place failed");
534-
535- return true;
536- }
537-
538- bool CAddrDB::Read(CAddrMan& addr)
539- {
540- // open input file, and associate with CAutoFile
541- FILE *file = fsbridge::fopen(pathAddr.string().c_str(), "rb");
542- CAutoFile filein(file, SER_DISK, CLIENT_VERSION);
543- if (filein.IsNull())
544- return error("CAddrman::Read() : open failed");
545-
546- // use file size to size memory buffer
547- int fileSize = boost::filesystem::file_size(pathAddr);
548- int dataSize = fileSize - sizeof(uint256);
549- // Don't try to resize to a negative number if file is small
550- if ( dataSize < 0 ) dataSize = 0;
551- vector<unsigned char> vchData;
552- vchData.resize(dataSize);
553- uint256 hashIn;
554-
555- // read data and checksum from file
556- try
557- {
558- filein.read((char *)&vchData[0], dataSize);
559- filein >> hashIn;
560- }
561- catch (std::exception &e) {
562- return error("CAddrman::Read() 2 : I/O error or stream data corrupted");
563- }
564- filein.fclose();
565-
566- CDataStream ssPeers(vchData, SER_DISK, CLIENT_VERSION);
567-
568- // verify stored checksum matches input data
569- uint256 hashTmp = Hash(ssPeers.begin(), ssPeers.end());
570- if (hashIn != hashTmp)
571- return error("CAddrman::Read() : checksum mismatch; data corrupted");
572-
573- unsigned char pchMsgTmp[4];
574- try {
575- // de-serialize file header (pchMessageStart magic number) and
576- ssPeers >> pchMsgTmp;
577-
578- // verify the network matches ours
579- if (memcmp(pchMsgTmp, pchMessageStart, sizeof(pchMsgTmp)))
580- return error("CAddrman::Read() : invalid network magic number");
581-
582- // de-serialize address data into one CAddrMan object
583- ssPeers >> addr;
584- }
585- catch (std::exception &e) {
586- return error("CAddrman::Read() : I/O error or stream data corrupted");
587- }
588-
589- return true;
590- }
591- */
0 commit comments