github.com/arieschain/arieschain@v0.0.0-20191023063405-37c074544356/qct/downloader/modes.go (about) 1 package downloader 2 3 import "fmt" 4 5 // SyncMode represents the synchronisation mode of the downloader. 6 type SyncMode int 7 8 const ( 9 FullSync SyncMode = iota // Synchronise the entire blockchain history from full blocks 10 FastSync // Quickly download the headers, full sync only at the chain head 11 LightSync // Download only the headers and terminate afterwards 12 ) 13 14 func (mode SyncMode) IsValid() bool { 15 return mode >= FullSync && mode <= LightSync 16 } 17 18 // String implements the stringer interface. 19 func (mode SyncMode) String() string { 20 switch mode { 21 case FullSync: 22 return "full" 23 case FastSync: 24 return "fast" 25 case LightSync: 26 return "light" 27 default: 28 return "unknown" 29 } 30 } 31 32 func (mode SyncMode) MarshalText() ([]byte, error) { 33 switch mode { 34 case FullSync: 35 return []byte("full"), nil 36 case FastSync: 37 return []byte("fast"), nil 38 case LightSync: 39 return []byte("light"), nil 40 default: 41 return nil, fmt.Errorf("unknown sync mode %d", mode) 42 } 43 } 44 45 func (mode *SyncMode) UnmarshalText(text []byte) error { 46 switch string(text) { 47 case "full": 48 *mode = FullSync 49 case "fast": 50 *mode = FastSync 51 case "light": 52 *mode = LightSync 53 default: 54 return fmt.Errorf(`unknown sync mode %q, want "full", "fast" or "light"`, text) 55 } 56 return nil 57 }