Skip to content

Commit

Permalink
update schall and discover (#228)
Browse files Browse the repository at this point in the history
  • Loading branch information
AstaFrode authored Jan 23, 2024
1 parent 715ecdd commit 6ef0b47
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 24 deletions.
13 changes: 7 additions & 6 deletions node/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,12 +51,13 @@ const (
Cach_prefix_ParseBlock = "parseblocks"
)

func (n *Node) connectBoot() {
chainSt := n.GetChainState()
if !chainSt {
return
}

func (n *Node) connectBoot(ch chan bool) {
defer func() {
ch <- true
if err := recover(); err != nil {
n.Pnc(utils.RecoverError(err))
}
}()
minerSt := n.GetMinerState()
if minerSt != pattern.MINER_STATE_POSITIVE &&
minerSt != pattern.MINER_STATE_FROZEN {
Expand Down
23 changes: 10 additions & 13 deletions node/discover.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (n *Node) findPeers(ch chan<- bool) {
defer func() {
ch <- true
if err := recover(); err != nil {
n.Pnc(utils.RecoverError(err))
n.Pnc(utils.RecoverError(err))
}
}()

Expand All @@ -57,18 +57,15 @@ func (n *Node) recvPeers(ch chan<- bool) {

n.Discover("info", ">>>>> start recvPeers <<<<<")

for {
select {
case foundPeer := <-n.GetDiscoveredPeers():
for _, v := range foundPeer.Responses {
if v != nil {
if len(v.Addrs) > 0 {
n.SavePeer(peer.AddrInfo{
ID: v.ID,
Addrs: v.Addrs,
})
n.GetDht().RoutingTable().TryAddPeer(v.ID, true, true)
}
for foundPeer := range n.GetDiscoveredPeers() {
for _, v := range foundPeer.Responses {
if v != nil {
if len(v.Addrs) > 0 {
n.SavePeer(peer.AddrInfo{
ID: v.ID,
Addrs: v.Addrs,
})
n.GetDht().RoutingTable().TryAddPeer(v.ID, true, true)
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions node/filereport.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,22 @@ func (n *Node) reportFiles(ch chan<- bool) {
}
continue
}

if _, err = os.Stat(filepath.Join(n.GetDirs().FileDir, roothash)); err != nil {
err = os.Mkdir(filepath.Join(n.GetDirs().FileDir, roothash), os.ModeDir)
if err != nil {
n.Report("err", fmt.Sprintf("[Mkdir.FileDir(%s)] %v", roothash, err))
continue
}
}
fstat, err := os.Stat(filepath.Join(n.GetDirs().TmpDir, roothash, savedFrgment))
if err != nil {
n.Report("err", fmt.Sprintf("[os.Stat(%s)] %v", roothash, err))
continue
}
if fstat.Size() != pattern.FragmentSize {
continue
}
err = os.Rename(filepath.Join(n.GetDirs().TmpDir, roothash, savedFrgment),
filepath.Join(n.GetDirs().FileDir, roothash, savedFrgment))
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions node/filetag.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func (n *Node) serviceTag(ch chan<- bool) {
} else {
if len(buf) != pattern.FragmentSize {
recover = true
os.Remove(f)
n.Stag("err", fmt.Sprintf("[%s.%s] File fragment size [%d] is not equal to %d", fid, fragmentHash, len(buf), pattern.FragmentSize))
}
}
Expand Down
11 changes: 8 additions & 3 deletions node/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,13 @@ func (n *Node) Run() {
ch_calctag = make(chan bool, 1)
ch_replace = make(chan bool, 1)
ch_restoreMgt = make(chan bool, 1)
ch_connectBoot = make(chan bool, 1)
ch_reportLogs = make(chan bool, 1)
ch_GenIdleFile = make(chan bool, 1)
)
ch_calctag <- true
ch_ConnectChain <- true
ch_connectBoot <- true
ch_idlechallenge <- true
ch_servicechallenge <- true
ch_reportfiles <- true
Expand Down Expand Up @@ -124,7 +126,7 @@ func (n *Node) Run() {
}

go n.poisMgt(ch_spaceMgt)
go n.findPeers(ch_findPeers)
//go n.findPeers(ch_findPeers)
go n.recvPeers(ch_recvPeers)

n.Log("info", fmt.Sprintf("Use %d cpu cores", n.GetCpuCores()))
Expand All @@ -148,6 +150,10 @@ func (n *Node) Run() {

case <-task_30S.C:
n.SetTaskPeriod("30s")
if len(ch_connectBoot) > 0 {
<-ch_connectBoot
go n.connectBoot(ch_connectBoot)
}
if len(ch_reportfiles) > 0 {
<-ch_reportfiles
go n.reportFiles(ch_reportfiles)
Expand All @@ -171,7 +177,7 @@ func (n *Node) Run() {

if len(ch_findPeers) > 0 {
<-ch_findPeers
go n.findPeers(ch_findPeers)
//go n.findPeers(ch_findPeers)
}

if len(ch_recvPeers) > 0 {
Expand Down Expand Up @@ -202,7 +208,6 @@ func (n *Node) Run() {

case <-task_Hour.C:
n.SetTaskPeriod("1h")
go n.connectBoot()
// go n.UpdatePeers()
go n.reportLogsMgt(ch_reportLogs)
n.SetTaskPeriod("1h-end")
Expand Down
5 changes: 3 additions & 2 deletions node/serviceChallenge.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ func (n *Node) calcSigma(
return names, us, mus, sigma, usig, err
}
for j := 0; j < len(fragments); j++ {
isChall = true
isChall = false
fragmentHash = filepath.Base(fragments[j])
ok, err = n.Has([]byte(Cach_prefix_Tag + roothash + "." + fragmentHash))
if err != nil {
Expand All @@ -296,6 +296,7 @@ func (n *Node) calcSigma(
for _, segment := range fmeta.SegmentList {
for _, fragment := range segment.FragmentList {
if sutils.CompareSlice(fragment.Miner[:], n.GetSignatureAccPulickey()) {
isChall = true
if fragmentHash == string(fragment.Hash[:]) {
if fragment.Tag.HasValue() {
ok, block := fragment.Tag.Unwrap()
Expand All @@ -315,7 +316,7 @@ func (n *Node) calcSigma(
}
}
}
if !isChall {
if isChall {
break
}
}
Expand Down

0 comments on commit 6ef0b47

Please sign in to comment.