/
synchronizer_api.go
105 lines (95 loc) · 3.24 KB
/
synchronizer_api.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Copyright 2018 The go-fractal Authors
// This file is part of the go-fractal library.
// Fractal implements the Fractal full node service.
package api
type StatusResult struct {
Status string
FastSyncMode string
FastSyncStatus string
}
type SynchronizerAPI struct {
ftl fractal
}
func NewSynchronizerAPI(ftl fractal) *SynchronizerAPI {
return &SynchronizerAPI{ftl}
}
func (s *SynchronizerAPI) Status() StatusResult {
status := s.ftl.Synchronizer().GetSyncStatus()
fastSyncMode := s.ftl.Synchronizer().GetFastSyncMode()
fastSyncStatus := s.ftl.Synchronizer().GetFastSyncStatus()
return StatusResult{
status.String(), fastSyncMode.String(), fastSyncStatus.String(),
}
}
// SynchronizerTestAPI provides an API to change config of sync
type SynchronizerTestAPI struct {
ftl fractal
}
// NewSynchronizerTestAPI creates a new SynchonizerTestAPI.
func NewSynchronizerTestAPI(ftl fractal) *SynchronizerTestAPI {
return &SynchronizerTestAPI{ftl}
}
//LongTimeOutOfFixPointPreBlock int
//LongTimeOutOfFixPointFinish int
//LongTimeOutOfFullfillLongList int
//LongTimeOutOfIntevalList int
//LongTimeOutOfLongList int
//
//ShortTimeOutOfSyncVeryHigh int
//ShortTimeOutOfShortLists int
func (s *SynchronizerTestAPI) ChangeLongTimeOutOfFixPointPreBlock(time int) string {
if s.ftl.Config().SyncTest {
s.ftl.Synchronizer().GetConfig().TimeOutOfFixPointPreBlock = time
return "set LongTimeOutOfFixPointPreBlock" + string(time)
} else {
return "not test network,forbidden to change"
}
}
func (s *SynchronizerTestAPI) ChangeLongTimeOutOfFixPointFinish(time int) string {
if s.ftl.Config().SyncTest {
s.ftl.Synchronizer().GetConfig().LongTimeOutOfFixPointFinish = time
return "set LongTimeOutOfFixPointFinish" + string(time)
} else {
return "not test network,forbidden to change"
}
}
func (s *SynchronizerTestAPI) ChangeLongTimeOutOfFullfillLongList(time int) string {
if s.ftl.Config().SyncTest {
s.ftl.Synchronizer().GetConfig().LongTimeOutOfFullfillLongList = time
return "set LongTimeOutOfFullfillLongList" + string(time)
} else {
return "not test network,forbidden to change"
}
}
func (s *SynchronizerTestAPI) ChangeLongTimeOutOfLongList(time int) string {
if s.ftl.Config().SyncTest {
s.ftl.Synchronizer().GetConfig().LongTimeOutOfLongList = time
return "set LongTimeOutOfLongList" + string(time)
} else {
return "not test network,forbidden to change"
}
}
func (s *SynchronizerTestAPI) ChangeLongTimeOutOfIntevalList(time int) string {
if s.ftl.Config().SyncTest {
s.ftl.Synchronizer().GetConfig().LongTimeOutOfIntevalList = time
return "set LongTimeOutOfIntevalList" + string(time)
} else {
return "not test network,forbidden to change"
}
}
func (s *SynchronizerTestAPI) ChangeShortTimeOutOfSyncVeryHigh(time int) string {
if s.ftl.Config().SyncTest {
s.ftl.Synchronizer().GetConfig().ShortTimeOutOfSyncVeryHigh = time
return "set ShortTimeOutOfSyncVeryHigh" + string(time)
} else {
return "not test network,forbidden to change"
}
}
func (s *SynchronizerTestAPI) ChangeShortTimeOutOfShortLists(time int) string {
if s.ftl.Config().SyncTest {
s.ftl.Synchronizer().GetConfig().ShortTimeOutOfShortLists = time
return "set ShortTimeOutOfShortLists" + string(time)
} else {
return "not test network,forbidden to change"
}
}