message.go 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // Copyright (C) 2014 Jakob Borg and Contributors (see the CONTRIBUTORS file).
  2. // All rights reserved. Use of this source code is governed by an MIT-style
  3. // license that can be found in the LICENSE file.
  4. package protocol
  5. import "fmt"
  6. type IndexMessage struct {
  7. Repository string // max:64
  8. Files []FileInfo // max:10000000
  9. }
  10. type FileInfo struct {
  11. Name string // max:1024
  12. Flags uint32
  13. Modified int64
  14. Version uint64
  15. LocalVersion uint64
  16. Blocks []BlockInfo // max:1000000
  17. }
  18. func (f FileInfo) String() string {
  19. return fmt.Sprintf("File{Name:%q, Flags:0%o, Modified:%d, Version:%d, Size:%d, Blocks:%v}",
  20. f.Name, f.Flags, f.Modified, f.Version, f.Size(), f.Blocks)
  21. }
  22. func (f FileInfo) Size() (bytes int64) {
  23. for _, b := range f.Blocks {
  24. bytes += int64(b.Size)
  25. }
  26. return
  27. }
  28. type BlockInfo struct {
  29. Offset int64 // noencode (cache only)
  30. Size uint32
  31. Hash []byte // max:64
  32. }
  33. func (b BlockInfo) String() string {
  34. return fmt.Sprintf("Block{%d/%d/%x}", b.Offset, b.Size, b.Hash)
  35. }
  36. type RequestMessage struct {
  37. Repository string // max:64
  38. Name string // max:1024
  39. Offset uint64
  40. Size uint32
  41. }
  42. type ClusterConfigMessage struct {
  43. ClientName string // max:64
  44. ClientVersion string // max:64
  45. Repositories []Repository // max:64
  46. Options []Option // max:64
  47. }
  48. type Repository struct {
  49. ID string // max:64
  50. Nodes []Node // max:64
  51. }
  52. type Node struct {
  53. ID []byte // max:32
  54. Flags uint32
  55. MaxLocalVersion uint64
  56. }
  57. type Option struct {
  58. Key string // max:64
  59. Value string // max:1024
  60. }