Skip to content

Commit

Permalink
torrent uploading flag
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Masley committed May 18, 2017
1 parent 15c086c commit 8da9353
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 6 deletions.
2 changes: 2 additions & 0 deletions engine/NetStart.go
Expand Up @@ -91,6 +91,7 @@ func NetStart(s *state.State) {

// Torrent Plugin
tormanager := flag.Bool("tormanage", false, "Use torrent dbstate manager. Must have plugin binary installed and in $PATH")
torUploader := flag.Bool("torupload", false, "Be a torrent uploader")

flag.Parse()

Expand Down Expand Up @@ -539,6 +540,7 @@ func NetStart(s *state.State) {

// Initate dbstate plugin if enabled. Only does so for first node,
// any more nodes on sim control will use default method
fnodes[0].State.SetTorrentUploader(*torUploader)
if *tormanager {
fnodes[0].State.SetUseTorrent(true)
manager, err := LaunchDBStateManagePlugin(*pluginPath, fnodes[0].State.InMsgQueue(), fnodes[0].State, fnodes[0].State.GetServerPrivateKey(), *memProfileRate)
Expand Down
17 changes: 13 additions & 4 deletions state/plugins.go
Expand Up @@ -142,11 +142,20 @@ func (u *UploadController) handleErrors() {

// Only called once to set the torrent flag.
func (s *State) SetUseTorrent(setVal bool) {
s.useDBStateManager = setVal
s.useTorrents = setVal
}

func (s *State) UsingTorrent() bool {
return s.useDBStateManager
return s.useTorrents
}

// Only called once to set the torrent flag.
func (s *State) SetTorrentUploader(setVal bool) {
s.torrentUploader = setVal
}

func (s *State) TorrentUploader() bool {
return s.torrentUploader
}

/*****************
Expand Down Expand Up @@ -221,7 +230,7 @@ func (s *State) uploadDBState(sequence uint32) error {
}
fullData = append(fullData, data...)
}
if s.IsLeader() {
if s.IsLeader() || s.TorrentUploader() {
err := s.DBStateManager.UploadDBStateBytes(fullData, true)
if err != nil {
return fmt.Errorf("[TorrentUpload] Torrent failed to upload: %s\n", err.Error())
Expand All @@ -248,4 +257,4 @@ func (s *State) SetUseEtcd(setVal bool) {

func (s *State) UsingEtcd() bool {
return s.useEtcd
}
}
3 changes: 2 additions & 1 deletion state/state.go
Expand Up @@ -331,7 +331,8 @@ type State struct {
AckChange uint32

// Plugins
useDBStateManager bool
useTorrents bool
torrentUploader bool
Uploader *UploadController // Controls the uploads of torrents. Prevents backups
DBStateManager interfaces.IManagerController
HighestCompletedTorrent uint32
Expand Down
2 changes: 1 addition & 1 deletion state/torrentSync.go
Expand Up @@ -23,7 +23,7 @@ func (s *State) StartTorrentSyncing() error {
var done uint32 = 0
for {
// Leaders do not need to sync torrents, they need to upload
if s.IsLeader() {
if s.IsLeader() || s.TorrentUploader() {
// If we have not uploaded a height we have completed, increment done and upload
if done < s.EntryDBHeightComplete {
for done < s.EntryDBHeightComplete {
Expand Down

0 comments on commit 8da9353

Please sign in to comment.