37 lines
1.1 KiB
Go
37 lines
1.1 KiB
Go
package torrent
|
|
|
|
import (
|
|
"github.com/looplab/fsm"
|
|
)
|
|
|
|
func NewTorrentState(initial string) *fsm.FSM {
|
|
return fsm.NewFSM(
|
|
initial,
|
|
fsm.Events{
|
|
// when enqueueing a torrent for repair
|
|
{Name: "break_torrent", Src: []string{"ok_torrent"}, Dst: "broken_torrent"},
|
|
// when repair has been started
|
|
{Name: "repair_torrent", Src: []string{"ok_torrent", "broken_torrent"}, Dst: "under_repair_torrent"},
|
|
// when converting to torrent
|
|
// when merging with another same hash torrent
|
|
// when a torrent is rar'ed and not extracting
|
|
{Name: "mark_as_repaired", Src: []string{"broken_torrent", "under_repair_torrent"}, Dst: "ok_torrent"},
|
|
// when resetting repair state
|
|
{Name: "reset_repair", Src: []string{"under_repair_torrent"}, Dst: "broken_torrent"},
|
|
},
|
|
fsm.Callbacks{},
|
|
)
|
|
}
|
|
|
|
func NewFileState(initial string) *fsm.FSM {
|
|
return fsm.NewFSM(
|
|
initial,
|
|
fsm.Events{
|
|
{Name: "break_file", Src: []string{"ok_file"}, Dst: "broken_file"},
|
|
{Name: "repair_file", Src: []string{"broken_file"}, Dst: "ok_file"},
|
|
{Name: "delete_file", Src: []string{"ok_file", "broken_file"}, Dst: "deleted_file"},
|
|
},
|
|
fsm.Callbacks{},
|
|
)
|
|
}
|