aboutsummaryrefslogtreecommitdiffstats
path: root/eth/downloader/modes.go
diff options
context:
space:
mode:
Diffstat (limited to 'eth/downloader/modes.go')
-rw-r--r--eth/downloader/modes.go33
1 files changed, 33 insertions, 0 deletions
diff --git a/eth/downloader/modes.go b/eth/downloader/modes.go
index ae3c43888..8ecdf91f1 100644
--- a/eth/downloader/modes.go
+++ b/eth/downloader/modes.go
@@ -16,6 +16,8 @@
package downloader
+import "fmt"
+
// SyncMode represents the synchronisation mode of the downloader.
type SyncMode int
@@ -25,6 +27,10 @@ const (
LightSync // Download only the headers and terminate afterwards
)
+func (mode SyncMode) IsValid() bool {
+ return mode >= FullSync && mode <= LightSync
+}
+
// String implements the stringer interface.
func (mode SyncMode) String() string {
switch mode {
@@ -38,3 +44,30 @@ func (mode SyncMode) String() string {
return "unknown"
}
}
+
+func (mode SyncMode) MarshalText() ([]byte, error) {
+ switch mode {
+ case FullSync:
+ return []byte("full"), nil
+ case FastSync:
+ return []byte("fast"), nil
+ case LightSync:
+ return []byte("light"), nil
+ default:
+ return nil, fmt.Errorf("unknown sync mode %d", mode)
+ }
+}
+
+func (mode *SyncMode) UnmarshalText(text []byte) error {
+ switch string(text) {
+ case "full":
+ *mode = FullSync
+ case "fast":
+ *mode = FastSync
+ case "light":
+ *mode = LightSync
+ default:
+ return fmt.Errorf(`unknown sync mode %q, want "full", "fast" or "light"`, text)
+ }
+ return nil
+}