Exemple #1
0
        private void ReqSyncBlock(bool bCheckemptyDB = true)
        {
            LogHelper.WriteMethodLog(true);
            if (bCheckemptyDB)
            {
                if (LeveldbOperator.OpenDB(AppSettings.XXPDBFolder) != ConstHelper.BC_OK)
                {
                    DBFileInfo df  = this.commHandler.RequestHightestDBInfo();
                    string     str = string.Format("Ip:{0}, highest:{1} size:{2}", df.IP, df.LastBlockHeight, df.DBFileSize);
                    MessageBox.Show(str);
                    Task.Run(() => {
                        string SavePath = Path.Combine(AppSettings.XXPTempFolder, ConstHelper.BC_DBZipName);
                        long lRet       = this.commHandler.StartReceiveFile(df.IP, df.DBFileSize, SavePath);
                        if (lRet == -1)
                        {
                            MessageBox.Show("try later, there is a file transfering now");
                        }
                        else
                        {
                            MessageBox.Show("Received: " + lRet.ToString());
                            FileIOHelper.DeleteDir(AppSettings.XXPDBFolder);
                            Directory.CreateDirectory(AppSettings.XXPDBFolder);
                            ZipHelper.UnZip(SavePath, AppSettings.XXPDBFolder);
                            this.InitFromDB();
                        }
                        this.commHandler.DisposeTransFileHelper();
                    });

                    if (this.commHandler.RequestStartTransDB(df.IP) != ConstHelper.BC_OK)
                    {
                    }
                }
                LeveldbOperator.CloseDB();
            }


            ResponseBlock BkInfo = this.commHandler.RequestNewBlockInfo(this.bkHandler.GetLastBlock());

            if (BkInfo.BlockResult == BlockResultType.Lower)
            {
                string sRet = this.commHandler.GetNewBlocks(BkInfo.IP, this.bkHandler.GetLastBlock());
            }
            LogHelper.WriteMethodLog(false);
        }
Exemple #2
0
        private void ResearchNodes_Click(object sender, EventArgs e)
        {
            LogHelper.WriteMethodLog(true);
            string Ip = this.textBoxSeedIP.Text;
            //step1 handshake
            bool bRet = this.commHandler.RequestHandshake(Ip);

            if (!bRet)
            {
                MessageBox.Show("Invalid seed IP");
                return;
            }
            //step2 get more Nodes IP
            List <string> lstAddress = this.commHandler.RequestMoreNodes(Ip);
            List <string> lstNew     = new List <string>();

            // step3 handshake lstAddress
            foreach (var item in lstAddress)
            {
                if (item == OSHelper.GetLocalIP())
                {
                    continue;
                }
                if (this.commHandler.RequestHandshake(item))
                {
                    lstNew.Add(item);
                }
            }
            // step4 send new addresses to all I know
            this.commHandler.SendNewAddress2Others(lstNew);
            this.textBoxConnectedNodes.Text = this.commHandler.GetAddressCount().ToString();

            if (LeveldbOperator.OpenDB(AppSettings.XXPDBFolder) != ConstHelper.BC_OK)
            {
                DBFileInfo df  = this.commHandler.RequestHightestDBInfo();
                string     str = string.Format("Ip:{0}, highest:{1} size:{2}", df.IP, df.LastBlockHeight, df.DBFileSize);

                Task.Run(() => {
                    string SavePath = Path.Combine(AppSettings.XXPTempFolder, ConstHelper.BC_DBZipName);
                    long lRet       = this.commHandler.StartReceiveFile(df.IP, df.DBFileSize, SavePath);
                    if (lRet == -1)
                    {
                        MessageBox.Show("try later, there is a file transfering now");
                    }
                    else
                    {
                        MessageBox.Show("Received: " + lRet.ToString());
                        FileIOHelper.DeleteDir(AppSettings.XXPDBFolder);
                        Directory.CreateDirectory(AppSettings.XXPDBFolder);
                        ZipHelper.UnZip(SavePath, AppSettings.XXPDBFolder);
                        this.InitFromDB();
                    }
                    this.commHandler.DisposeTransFileHelper();
                });
                MessageBox.Show(str);
                if (this.commHandler.RequestStartTransDB(df.IP) != ConstHelper.BC_OK)
                {
                }
            }
            LeveldbOperator.CloseDB();

            ResponseBlock BkInfo = this.commHandler.RequestNewBlockInfo(this.bkHandler.GetLastBlock());

            if (BkInfo.BlockResult == BlockResultType.Lower)
            {
                string sRet = this.commHandler.GetNewBlocks(BkInfo.IP, this.bkHandler.GetLastBlock());
            }

            LogHelper.WriteMethodLog(false);
        }