You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

fromto.go 4.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. package ioswitch2
  2. import (
  3. "gitlink.org.cn/cloudream/common/pkgs/ioswitch/exec"
  4. cdssdk "gitlink.org.cn/cloudream/common/sdks/storage"
  5. "gitlink.org.cn/cloudream/common/utils/math2"
  6. stgmod "gitlink.org.cn/cloudream/storage/common/models"
  7. )
  8. type From interface {
  9. GetStreamIndex() StreamIndex
  10. }
  11. type To interface {
  12. // To所需要的文件流的范围。具体含义与DataIndex有关系:
  13. // 如果DataIndex == -1,则表示在整个文件的范围。
  14. // 如果DataIndex >= 0,则表示在文件的某个分片的范围。
  15. GetRange() math2.Range
  16. GetStreamIndex() StreamIndex
  17. }
  18. const (
  19. // 未处理的完整文件流
  20. StreamIndexRaw = iota
  21. // EC编码的某一块的流
  22. StreamIndexEC
  23. // 分段编码的某一段的流
  24. StreamIndexSegment
  25. )
  26. type StreamIndex struct {
  27. Type int
  28. Index int
  29. }
  30. func RawStream() StreamIndex {
  31. return StreamIndex{
  32. Type: StreamIndexRaw,
  33. }
  34. }
  35. func ECStream(index int) StreamIndex {
  36. return StreamIndex{
  37. Type: StreamIndexEC,
  38. Index: index,
  39. }
  40. }
  41. func SegmentStream(index int) StreamIndex {
  42. return StreamIndex{
  43. Type: StreamIndexSegment,
  44. Index: index,
  45. }
  46. }
  47. func (s StreamIndex) IsRaw() bool {
  48. return s.Type == StreamIndexRaw
  49. }
  50. func (s StreamIndex) IsEC() bool {
  51. return s.Type == StreamIndexEC
  52. }
  53. func (s StreamIndex) IsSegment() bool {
  54. return s.Type == StreamIndexSegment
  55. }
  56. type FromTos []FromTo
  57. type FromTo struct {
  58. // 如果输入或者输出用到了EC编码的流,则需要提供EC参数。
  59. ECParam *cdssdk.ECRedundancy
  60. // 同上
  61. SegmentParam *cdssdk.SegmentRedundancy
  62. Froms []From
  63. Toes []To
  64. }
  65. func NewFromTo() FromTo {
  66. return FromTo{}
  67. }
  68. func (ft *FromTo) AddFrom(from From) *FromTo {
  69. ft.Froms = append(ft.Froms, from)
  70. return ft
  71. }
  72. func (ft *FromTo) AddTo(to To) *FromTo {
  73. ft.Toes = append(ft.Toes, to)
  74. return ft
  75. }
  76. type FromDriver struct {
  77. Handle *exec.DriverWriteStream
  78. StreamIndex StreamIndex
  79. }
  80. func NewFromDriver(strIdx StreamIndex) (*FromDriver, *exec.DriverWriteStream) {
  81. handle := &exec.DriverWriteStream{
  82. RangeHint: &math2.Range{},
  83. }
  84. return &FromDriver{
  85. Handle: handle,
  86. StreamIndex: strIdx,
  87. }, handle
  88. }
  89. func (f *FromDriver) GetStreamIndex() StreamIndex {
  90. return f.StreamIndex
  91. }
  92. type FromShardstore struct {
  93. FileHash cdssdk.FileHash
  94. Hub cdssdk.Hub
  95. Storage stgmod.StorageDetail
  96. StreamIndex StreamIndex
  97. }
  98. func NewFromShardstore(fileHash cdssdk.FileHash, hub cdssdk.Hub, storage stgmod.StorageDetail, strIdx StreamIndex) *FromShardstore {
  99. return &FromShardstore{
  100. FileHash: fileHash,
  101. Hub: hub,
  102. Storage: storage,
  103. StreamIndex: strIdx,
  104. }
  105. }
  106. func (f *FromShardstore) GetStreamIndex() StreamIndex {
  107. return f.StreamIndex
  108. }
  109. type ToDriver struct {
  110. Handle *exec.DriverReadStream
  111. StreamIndex StreamIndex
  112. Range math2.Range
  113. }
  114. func NewToDriver(strIdx StreamIndex) (*ToDriver, *exec.DriverReadStream) {
  115. str := exec.DriverReadStream{}
  116. return &ToDriver{
  117. Handle: &str,
  118. StreamIndex: strIdx,
  119. }, &str
  120. }
  121. func NewToDriverWithRange(strIdx StreamIndex, rng math2.Range) (*ToDriver, *exec.DriverReadStream) {
  122. str := exec.DriverReadStream{}
  123. return &ToDriver{
  124. Handle: &str,
  125. StreamIndex: strIdx,
  126. Range: rng,
  127. }, &str
  128. }
  129. func (t *ToDriver) GetStreamIndex() StreamIndex {
  130. return t.StreamIndex
  131. }
  132. func (t *ToDriver) GetRange() math2.Range {
  133. return t.Range
  134. }
  135. type ToShardStore struct {
  136. Hub cdssdk.Hub
  137. Storage stgmod.StorageDetail
  138. StreamIndex StreamIndex
  139. Range math2.Range
  140. FileHashStoreKey string
  141. }
  142. func NewToShardStore(hub cdssdk.Hub, stg stgmod.StorageDetail, strIdx StreamIndex, fileHashStoreKey string) *ToShardStore {
  143. return &ToShardStore{
  144. Hub: hub,
  145. Storage: stg,
  146. StreamIndex: strIdx,
  147. FileHashStoreKey: fileHashStoreKey,
  148. }
  149. }
  150. func NewToShardStoreWithRange(hub cdssdk.Hub, stg stgmod.StorageDetail, streamIndex StreamIndex, fileHashStoreKey string, rng math2.Range) *ToShardStore {
  151. return &ToShardStore{
  152. Hub: hub,
  153. Storage: stg,
  154. StreamIndex: streamIndex,
  155. FileHashStoreKey: fileHashStoreKey,
  156. Range: rng,
  157. }
  158. }
  159. func (t *ToShardStore) GetStreamIndex() StreamIndex {
  160. return t.StreamIndex
  161. }
  162. func (t *ToShardStore) GetRange() math2.Range {
  163. return t.Range
  164. }
  165. type LoadToPublic struct {
  166. Hub cdssdk.Hub
  167. Storage stgmod.StorageDetail
  168. ObjectPath string
  169. }
  170. func NewLoadToPublic(hub cdssdk.Hub, storage stgmod.StorageDetail, objectPath string) *LoadToPublic {
  171. return &LoadToPublic{
  172. Hub: hub,
  173. Storage: storage,
  174. ObjectPath: objectPath,
  175. }
  176. }
  177. func (t *LoadToPublic) GetStreamIndex() StreamIndex {
  178. return StreamIndex{
  179. Type: StreamIndexRaw,
  180. }
  181. }
  182. func (t *LoadToPublic) GetRange() math2.Range {
  183. return math2.Range{}
  184. }

本项目旨在将云际存储公共基础设施化,使个人及企业可低门槛使用高效的云际存储服务(安装开箱即用云际存储客户端即可,无需关注其他组件的部署),同时支持用户灵活便捷定制云际存储的功能细节。