-
Notifications
You must be signed in to change notification settings - Fork 202
/
storageResolver.go
76 lines (61 loc) · 2.12 KB
/
storageResolver.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package storageResolvers
import (
"fmt"
"sync"
"time"
"github.com/ElrondNetwork/elrond-go-core/core"
"github.com/ElrondNetwork/elrond-go-core/data/endProcess"
"github.com/ElrondNetwork/elrond-go/common"
"github.com/ElrondNetwork/elrond-go/dataRetriever"
"github.com/ElrondNetwork/elrond-go/p2p"
)
type storageResolver struct {
messenger dataRetriever.MessageHandler
responseTopicName string
manualEpochStartNotifier dataRetriever.ManualEpochStartNotifier
chanGracefullyClose chan endProcess.ArgEndProcess
mutSignaled sync.Mutex
signaled bool
delayBeforeGracefulClose time.Duration
}
// ProcessReceivedMessage does nothing, won't be able to process network requests
func (sr *storageResolver) ProcessReceivedMessage(_ p2p.MessageP2P, _ core.PeerID) error {
return nil
}
// SetResolverDebugHandler returns nil, no debugging associated to this implementation
func (sr *storageResolver) SetResolverDebugHandler(_ dataRetriever.ResolverDebugHandler) error {
return nil
}
// SetNumPeersToQuery does nothing
func (sr *storageResolver) SetNumPeersToQuery(_ int, _ int) {
}
// NumPeersToQuery returns (0, 0) tuple as it won't request any connected peer
func (sr *storageResolver) NumPeersToQuery() (int, int) {
return 0, 0
}
func (sr *storageResolver) sendToSelf(buffToSend []byte) error {
return sr.messenger.SendToConnectedPeer(sr.responseTopicName, buffToSend, sr.messenger.ID())
}
func (sr *storageResolver) signalGracefullyClose() {
sr.mutSignaled.Lock()
defer sr.mutSignaled.Unlock()
if sr.signaled {
return
}
sr.signaled = true
go sr.asyncCallGracefullyClose()
}
func (sr *storageResolver) asyncCallGracefullyClose() {
crtEpoch := sr.manualEpochStartNotifier.CurrentEpoch()
argEndProcess := endProcess.ArgEndProcess{
Reason: common.ImportComplete,
Description: fmt.Sprintf("import ended because data from epochs %d or %d does not exist",
crtEpoch-1, crtEpoch),
}
time.Sleep(sr.delayBeforeGracefulClose)
select {
case sr.chanGracefullyClose <- argEndProcess:
default:
log.Debug("storageResolver.RequestDataFromHash: could not wrote on the end chan")
}
}