message.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // Copyright (C) 2014 The Protocol Authors.
  2. //go:generate genxdr -o message_xdr.go message.go
  3. package protocol
  4. import "fmt"
  5. type IndexMessage struct {
  6. Folder string
  7. Files []FileInfo
  8. Flags uint32
  9. Options []Option // max:64
  10. }
  11. type FileInfo struct {
  12. Name string // max:8192
  13. Flags uint32
  14. Modified int64
  15. Version int64
  16. LocalVersion int64
  17. Blocks []BlockInfo
  18. }
  19. func (f FileInfo) String() string {
  20. return fmt.Sprintf("File{Name:%q, Flags:0%o, Modified:%d, Version:%d, Size:%d, Blocks:%v}",
  21. f.Name, f.Flags, f.Modified, f.Version, f.Size(), f.Blocks)
  22. }
  23. func (f FileInfo) Size() (bytes int64) {
  24. if f.IsDeleted() || f.IsDirectory() {
  25. return 128
  26. }
  27. for _, b := range f.Blocks {
  28. bytes += int64(b.Size)
  29. }
  30. return
  31. }
  32. func (f FileInfo) IsDeleted() bool {
  33. return f.Flags&FlagDeleted != 0
  34. }
  35. func (f FileInfo) IsInvalid() bool {
  36. return f.Flags&FlagInvalid != 0
  37. }
  38. func (f FileInfo) IsDirectory() bool {
  39. return f.Flags&FlagDirectory != 0
  40. }
  41. func (f FileInfo) IsSymlink() bool {
  42. return f.Flags&FlagSymlink != 0
  43. }
  44. func (f FileInfo) HasPermissionBits() bool {
  45. return f.Flags&FlagNoPermBits == 0
  46. }
  47. type BlockInfo struct {
  48. Offset int64 // noencode (cache only)
  49. Size int32
  50. Hash []byte // max:64
  51. }
  52. func (b BlockInfo) String() string {
  53. return fmt.Sprintf("Block{%d/%d/%x}", b.Offset, b.Size, b.Hash)
  54. }
  55. type RequestMessage struct {
  56. Folder string // max:64
  57. Name string // max:8192
  58. Offset int64
  59. Size int32
  60. Hash []byte // max:64
  61. Flags uint32
  62. Options []Option // max:64
  63. }
  64. type ResponseMessage struct {
  65. Data []byte
  66. Error int32
  67. }
  68. type ClusterConfigMessage struct {
  69. ClientName string // max:64
  70. ClientVersion string // max:64
  71. Folders []Folder
  72. Options []Option // max:64
  73. }
  74. func (o *ClusterConfigMessage) GetOption(key string) string {
  75. for _, option := range o.Options {
  76. if option.Key == key {
  77. return option.Value
  78. }
  79. }
  80. return ""
  81. }
  82. type Folder struct {
  83. ID string // max:64
  84. Devices []Device
  85. Flags uint32
  86. Options []Option // max:64
  87. }
  88. type Device struct {
  89. ID []byte // max:32
  90. MaxLocalVersion int64
  91. Flags uint32
  92. Options []Option // max:64
  93. }
  94. type Option struct {
  95. Key string // max:64
  96. Value string // max:1024
  97. }
  98. type CloseMessage struct {
  99. Reason string // max:1024
  100. Code int32
  101. }
  102. type EmptyMessage struct{}