message.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. Blocks []BlockInfo // max:1000000
  16. }
  17. func (f FileInfo) String() string {
  18. return fmt.Sprintf("File{Name:%q, Flags:0%o, Modified:%d, Version:%d, Size:%d, Blocks:%v}",
  19. f.Name, f.Flags, f.Modified, f.Version, f.Size(), f.Blocks)
  20. }
  21. func (f FileInfo) Size() (bytes int64) {
  22. for _, b := range f.Blocks {
  23. bytes += int64(b.Size)
  24. }
  25. return
  26. }
  27. func (a FileInfo) Equals(b FileInfo) bool {
  28. return a.Version == b.Version
  29. }
  30. func (a FileInfo) NewerThan(b FileInfo) bool {
  31. return a.Version > b.Version
  32. }
  33. type BlockInfo struct {
  34. Offset int64 // noencode (cache only)
  35. Size uint32
  36. Hash []byte // max:64
  37. }
  38. func (b BlockInfo) String() string {
  39. return fmt.Sprintf("Block{%d/%d/%x}", b.Offset, b.Size, b.Hash)
  40. }
  41. type RequestMessage struct {
  42. Repository string // max:64
  43. Name string // max:1024
  44. Offset uint64
  45. Size uint32
  46. }
  47. type ClusterConfigMessage struct {
  48. ClientName string // max:64
  49. ClientVersion string // max:64
  50. Repositories []Repository // max:64
  51. Options []Option // max:64
  52. }
  53. type Repository struct {
  54. ID string // max:64
  55. Nodes []Node // max:64
  56. }
  57. type Node struct {
  58. ID []byte // max:32
  59. Flags uint32
  60. MaxVersion uint64
  61. }
  62. type Option struct {
  63. Key string // max:64
  64. Value string // max:1024
  65. }