gitlab.com/SkynetLabs/skyd@v1.6.9/skymodules/gouging/gouging_helpers.go (about) 1 package gouging 2 3 // ReadSectorJobExpectedBandwidth is a helper function that returns the expected 4 // bandwidth consumption of a read sector job. This helper function takes a 5 // length parameter and is used to get the expected bandwidth without having to 6 // instantiate a job. 7 func ReadSectorJobExpectedBandwidth(length uint64) (ul, dl uint64) { 8 ul = 1 << 15 // 32 KiB 9 dl = uint64(float64(length)*1.01) + 1<<14 // (readSize * 1.01 + 16 KiB) 10 return 11 } 12 13 // HasSectorJobExpectedBandwidth is a helper function that returns the expected 14 // bandwidth consumption of a has sector job. This helper function enables 15 // getting at the expected bandwidth without having to instantiate a job. 16 func HasSectorJobExpectedBandwidth(numRoots int) (ul, dl uint64) { 17 // closestMultipleOf is a small helper function that essentially rounds up 18 // 'num' to the closest multiple of 'multipleOf'. 19 closestMultipleOf := func(num, multipleOf int) int { 20 mod := num % multipleOf 21 if mod != 0 { 22 num += (multipleOf - mod) 23 } 24 return num 25 } 26 27 // A HS job consumes more than one packet on download as soon as it contains 28 // 13 roots or more. In terms of upload bandwidth that threshold is at 17. 29 // To be conservative we use 10 and 15 as cutoff points. 30 downloadMultiplier := closestMultipleOf(numRoots, 10) / 10 31 uploadMultiplier := closestMultipleOf(numRoots, 15) / 15 32 33 // A base of 1500 is used for the packet size. On ipv4, it is technically 34 // smaller, but siamux is general and the packet size is the Ethernet MTU 35 // (1500 bytes) minus any protocol overheads. It's possible if the renter is 36 // connected directly over an interface to a host that there is no overhead, 37 // which means siamux could use the full 1500 bytes. So we use the most 38 // conservative value here as well. 39 ul = uint64(1500 * uploadMultiplier) 40 dl = uint64(1500 * downloadMultiplier) 41 return 42 }