github.com/network-quality/goresponsiveness@v0.0.0-20240129151524-343954285090/lgc/lgc.go (about) 1 /* 2 * This file is part of Go Responsiveness. 3 * 4 * Go Responsiveness is free software: you can redistribute it and/or modify it under 5 * the terms of the GNU General Public License as published by the Free Software Foundation, 6 * either version 2 of the License, or (at your option) any later version. 7 * Go Responsiveness is distributed in the hope that it will be useful, but WITHOUT ANY 8 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A 9 * PARTICULAR PURPOSE. See the GNU General Public License for more details. 10 * 11 * You should have received a copy of the GNU General Public License along 12 * with Go Responsiveness. If not, see <https://www.gnu.org/licenses/>. 13 */ 14 15 package lgc 16 17 import ( 18 "context" 19 "net/http" 20 "time" 21 22 "github.com/network-quality/goresponsiveness/debug" 23 "github.com/network-quality/goresponsiveness/stats" 24 ) 25 26 type LoadGeneratingConnection interface { 27 Start(context.Context, debug.DebugLevel) bool 28 TransferredInInterval() (uint64, time.Duration) 29 Client() *http.Client 30 Status() LgcStatus 31 ClientId() uint64 32 Stats() *stats.TraceStats 33 WaitUntilStarted(context.Context) bool 34 Direction() LgcDirection 35 } 36 37 type LgcDirection int 38 39 const ( 40 LGC_DOWN LgcDirection = iota 41 LGC_UP 42 ) 43 44 func (direction LgcDirection) String() string { 45 if direction == LGC_DOWN { 46 return "Download" 47 } else if direction == LGC_UP { 48 return "Upload" 49 } 50 return "Invalid load-generating connection direction" 51 } 52 53 type LgcStatus int 54 55 const ( 56 LGC_STATUS_NOT_STARTED LgcStatus = iota 57 LGC_STATUS_RUNNING 58 LGC_STATUS_DONE 59 LGC_STATUS_ERROR 60 ) 61 62 func (status LgcStatus) String() string { 63 switch status { 64 case LGC_STATUS_DONE: 65 return "Load-Generating Connection Done" 66 case LGC_STATUS_RUNNING: 67 return "Load-Generating Connection Running" 68 case LGC_STATUS_ERROR: 69 return "Load-Generating Connection Error" 70 case LGC_STATUS_NOT_STARTED: 71 return "Load-Generating Connection Not Started" 72 } 73 return "Load-Generating Connection in invalid state" 74 }