message.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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
  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
  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 ResponseMessage struct {
  43. Data []byte
  44. }
  45. type ClusterConfigMessage struct {
  46. ClientName string // max:64
  47. ClientVersion string // max:64
  48. Repositories []Repository // max:64
  49. Options []Option // max:64
  50. }
  51. type Repository struct {
  52. ID string // max:64
  53. Nodes []Node // max:64
  54. }
  55. type Node struct {
  56. ID []byte // max:32
  57. Flags uint32
  58. MaxLocalVersion uint64
  59. }
  60. type Option struct {
  61. Key string // max:64
  62. Value string // max:1024
  63. }
  64. type CloseMessage struct {
  65. Reason string // max:1024
  66. }
  67. type EmptyMessage struct{}