Skip to content
Snippets Groups Projects
Select Git revision
  • 30cc3fabd2d678a46dd8dac7b2e3a08ec4e20331
  • release default protected
  • 11-22-implement-kv-interface-defined-in-collectiveversionedkvgo
  • hotfix/TestHostPool_UpdateNdf_AddFilter
  • XX-4719/announcementChannels
  • xx-4717/logLevel
  • jonah/noob-channel
  • master protected
  • XX-4707/tagDiskJson
  • xx-4698/notification-retry
  • hotfix/notifylockup
  • syncNodes
  • hotfix/localCB
  • XX-4677/NewChanManagerMobile
  • XX-4689/DmSync
  • duplicatePrefix
  • XX-4601/HavenInvites
  • finalizedUICallbacks
  • XX-4673/AdminKeySync
  • debugNotifID
  • anne/test
  • v4.7.5
  • v4.7.4
  • v4.7.3
  • v4.7.2
  • v4.7.1
  • v4.6.3
  • v4.6.1
  • v4.5.0
  • v4.4.4
  • v4.3.11
  • v4.3.8
  • v4.3.7
  • v4.3.6
  • v4.3.5
  • v4.2.0
  • v4.3.0
  • v4.3.4
  • v4.3.3
  • v4.3.2
  • v4.3.1
41 results

dummy.go

Blame
  • dummy.go 2.64 KiB
    ////////////////////////////////////////////////////////////////////////////////
    // Copyright © 2020 xx network SEZC                                           //
    //                                                                            //
    // Use of this source code is governed by a license that can be found in the  //
    // LICENSE file                                                               //
    ////////////////////////////////////////////////////////////////////////////////
    
    package bindings
    
    import (
    	"gitlab.com/elixxir/client/dummy"
    	"time"
    )
    
    // DummyTraffic contains the file dummy traffic manager. The manager can be used
    // to set and get the status of the send thread.
    type DummyTraffic struct {
    	m *dummy.Manager
    }
    
    // NewDummyTrafficManager creates a DummyTraffic manager and initialises the
    // dummy traffic send thread. Note that the manager does not start sending dummy
    // traffic until its status is set to true using DummyTraffic.SetStatus.
    // The maxNumMessages is the upper bound of the random number of messages sent
    // each send. avgSendDeltaMS is the average duration, in milliseconds, to wait
    // between sends. Sends occur every avgSendDeltaMS +/- a random duration with an
    // upper bound of randomRangeMS.
    func NewDummyTrafficManager(client *Client, maxNumMessages, avgSendDeltaMS,
    	randomRangeMS int) (*DummyTraffic, error) {
    
    	avgSendDelta := time.Duration(avgSendDeltaMS) * time.Millisecond
    	randomRange := time.Duration(randomRangeMS) * time.Millisecond
    
    	m := dummy.NewManager(
    		maxNumMessages, avgSendDelta, randomRange, &client.api)
    
    	return &DummyTraffic{m}, client.api.AddService(m.StartDummyTraffic)
    }
    
    // SetStatus sets the state of the dummy traffic send thread, which determines
    // if the thread is running or paused. The possible statuses are:
    //  true  = send thread is sending dummy messages
    //  false = send thread is paused/stopped and not sending dummy messages
    // Returns an error if the channel is full.
    // Note that this function cannot change the status of the send thread if it has
    // yet to be started or stopped.
    func (dt *DummyTraffic) SetStatus(status bool) error {
    	return dt.m.SetStatus(status)
    }
    
    // GetStatus returns the current state of the dummy traffic send thread. It has
    // the following return values:
    //  true  = send thread is sending dummy messages
    //  false = send thread is paused/stopped and not sending dummy messages
    // Note that this function does not return the status set by SetStatus directly;
    // it returns the current status of the send thread, which means any call to
    // SetStatus will have a small delay before it is returned by GetStatus.
    func (dt *DummyTraffic) GetStatus() bool {
    	return dt.m.GetStatus()
    }