github.com/koko1123/flow-go-1@v0.29.6/model/chainsync/status.go (about)

     1  // (c) 2019 Dapper Labs - ALL RIGHTS RESERVED
     2  
     3  package chainsync
     4  
     5  import (
     6  	"time"
     7  
     8  	"github.com/koko1123/flow-go-1/model/flow"
     9  )
    10  
    11  // Status keeps track of a block download status.
    12  type Status struct {
    13  	BlockHeight uint64       // always present even if we haven't received the header
    14  	Queued      time.Time    // when we originally queued this block request
    15  	Requested   time.Time    // the last time we requested this block
    16  	Attempts    uint         // how many times we've requested this block
    17  	Header      *flow.Header // the requested header, if we've received it
    18  	Received    time.Time    // when we received a response
    19  }
    20  
    21  func (s *Status) WasQueued() bool {
    22  	return s != nil
    23  }
    24  
    25  func (s *Status) WasRequested() bool {
    26  	if s == nil {
    27  		return false
    28  	}
    29  	return !s.Requested.IsZero()
    30  }
    31  
    32  func (s *Status) WasReceived() bool {
    33  	if s == nil {
    34  		return false
    35  	}
    36  	return !s.Received.IsZero()
    37  }
    38  
    39  func (s *Status) StatusString() string {
    40  	if s.WasReceived() {
    41  		return "Received"
    42  	} else if s.WasRequested() {
    43  		return "Requested"
    44  	} else if s.WasQueued() {
    45  		return "Queued"
    46  	} else {
    47  		return "Unknown"
    48  	}
    49  }
    50  
    51  func NewQueuedStatus(height uint64) *Status {
    52  	return &Status{
    53  		Queued: time.Now(),
    54  	}
    55  }