Rename Repository -> Folder, Node -> Device (fixes #739)
This commit is contained in:
parent
f28367bcfc
commit
4b488a2d28
@ -11,7 +11,7 @@ import (
|
|||||||
|
|
||||||
type TestModel struct {
|
type TestModel struct {
|
||||||
data []byte
|
data []byte
|
||||||
repo string
|
folder string
|
||||||
name string
|
name string
|
||||||
offset int64
|
offset int64
|
||||||
size int
|
size int
|
||||||
@ -24,25 +24,25 @@ func newTestModel() *TestModel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TestModel) Index(nodeID NodeID, repo string, files []FileInfo) {
|
func (t *TestModel) Index(deviceID DeviceID, folder string, files []FileInfo) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TestModel) IndexUpdate(nodeID NodeID, repo string, files []FileInfo) {
|
func (t *TestModel) IndexUpdate(deviceID DeviceID, folder string, files []FileInfo) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TestModel) Request(nodeID NodeID, repo, name string, offset int64, size int) ([]byte, error) {
|
func (t *TestModel) Request(deviceID DeviceID, folder, name string, offset int64, size int) ([]byte, error) {
|
||||||
t.repo = repo
|
t.folder = folder
|
||||||
t.name = name
|
t.name = name
|
||||||
t.offset = offset
|
t.offset = offset
|
||||||
t.size = size
|
t.size = size
|
||||||
return t.data, nil
|
return t.data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TestModel) Close(nodeID NodeID, err error) {
|
func (t *TestModel) Close(deviceID DeviceID, err error) {
|
||||||
close(t.closedCh)
|
close(t.closedCh)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TestModel) ClusterConfig(nodeID NodeID, config ClusterConfigMessage) {
|
func (t *TestModel) ClusterConfig(deviceID DeviceID, config ClusterConfigMessage) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TestModel) isClosed() bool {
|
func (t *TestModel) isClosed() bool {
|
||||||
|
|||||||
@ -16,36 +16,36 @@ import (
|
|||||||
"github.com/syncthing/syncthing/internal/luhn"
|
"github.com/syncthing/syncthing/internal/luhn"
|
||||||
)
|
)
|
||||||
|
|
||||||
type NodeID [32]byte
|
type DeviceID [32]byte
|
||||||
|
|
||||||
var LocalNodeID = NodeID{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
|
var LocalDeviceID = DeviceID{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
|
||||||
|
|
||||||
// NewNodeID generates a new node ID from the raw bytes of a certificate
|
// NewDeviceID generates a new device ID from the raw bytes of a certificate
|
||||||
func NewNodeID(rawCert []byte) NodeID {
|
func NewDeviceID(rawCert []byte) DeviceID {
|
||||||
var n NodeID
|
var n DeviceID
|
||||||
hf := sha256.New()
|
hf := sha256.New()
|
||||||
hf.Write(rawCert)
|
hf.Write(rawCert)
|
||||||
hf.Sum(n[:0])
|
hf.Sum(n[:0])
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
func NodeIDFromString(s string) (NodeID, error) {
|
func DeviceIDFromString(s string) (DeviceID, error) {
|
||||||
var n NodeID
|
var n DeviceID
|
||||||
err := n.UnmarshalText([]byte(s))
|
err := n.UnmarshalText([]byte(s))
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func NodeIDFromBytes(bs []byte) NodeID {
|
func DeviceIDFromBytes(bs []byte) DeviceID {
|
||||||
var n NodeID
|
var n DeviceID
|
||||||
if len(bs) != len(n) {
|
if len(bs) != len(n) {
|
||||||
panic("incorrect length of byte slice representing node ID")
|
panic("incorrect length of byte slice representing device ID")
|
||||||
}
|
}
|
||||||
copy(n[:], bs)
|
copy(n[:], bs)
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
// String returns the canonical string representation of the node ID
|
// String returns the canonical string representation of the device ID
|
||||||
func (n NodeID) String() string {
|
func (n DeviceID) String() string {
|
||||||
id := base32.StdEncoding.EncodeToString(n[:])
|
id := base32.StdEncoding.EncodeToString(n[:])
|
||||||
id = strings.Trim(id, "=")
|
id = strings.Trim(id, "=")
|
||||||
id, err := luhnify(id)
|
id, err := luhnify(id)
|
||||||
@ -57,23 +57,23 @@ func (n NodeID) String() string {
|
|||||||
return id
|
return id
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n NodeID) GoString() string {
|
func (n DeviceID) GoString() string {
|
||||||
return n.String()
|
return n.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n NodeID) Compare(other NodeID) int {
|
func (n DeviceID) Compare(other DeviceID) int {
|
||||||
return bytes.Compare(n[:], other[:])
|
return bytes.Compare(n[:], other[:])
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n NodeID) Equals(other NodeID) bool {
|
func (n DeviceID) Equals(other DeviceID) bool {
|
||||||
return bytes.Compare(n[:], other[:]) == 0
|
return bytes.Compare(n[:], other[:]) == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NodeID) MarshalText() ([]byte, error) {
|
func (n *DeviceID) MarshalText() ([]byte, error) {
|
||||||
return []byte(n.String()), nil
|
return []byte(n.String()), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n *NodeID) UnmarshalText(bs []byte) error {
|
func (n *DeviceID) UnmarshalText(bs []byte) error {
|
||||||
id := string(bs)
|
id := string(bs)
|
||||||
id = strings.Trim(id, "=")
|
id = strings.Trim(id, "=")
|
||||||
id = strings.ToUpper(id)
|
id = strings.ToUpper(id)
|
||||||
@ -98,7 +98,7 @@ func (n *NodeID) UnmarshalText(bs []byte) error {
|
|||||||
copy(n[:], dec)
|
copy(n[:], dec)
|
||||||
return nil
|
return nil
|
||||||
default:
|
default:
|
||||||
return errors.New("node ID invalid: incorrect length")
|
return errors.New("device ID invalid: incorrect length")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -20,14 +20,14 @@ var formatCases = []string{
|
|||||||
"p561017mzjnu2yiqgdreydm2mgtimgl3bxnpq6w5bmt88z4tjxzwicq2",
|
"p561017mzjnu2yiqgdreydm2mgtimgl3bxnpq6w5bmt88z4tjxzwicq2",
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFormatNodeID(t *testing.T) {
|
func TestFormatDeviceID(t *testing.T) {
|
||||||
for i, tc := range formatCases {
|
for i, tc := range formatCases {
|
||||||
var id NodeID
|
var id DeviceID
|
||||||
err := id.UnmarshalText([]byte(tc))
|
err := id.UnmarshalText([]byte(tc))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("#%d UnmarshalText(%q); %v", i, tc, err)
|
t.Errorf("#%d UnmarshalText(%q); %v", i, tc, err)
|
||||||
} else if f := id.String(); f != formatted {
|
} else if f := id.String(); f != formatted {
|
||||||
t.Errorf("#%d FormatNodeID(%q)\n\t%q !=\n\t%q", i, tc, f, formatted)
|
t.Errorf("#%d FormatDeviceID(%q)\n\t%q !=\n\t%q", i, tc, f, formatted)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -46,20 +46,20 @@ var validateCases = []struct {
|
|||||||
{"p56ioi7mzjnu2iqgdreydm2mgtmgl3bxnpq6w5btbbz4tjxzwicqCCCC", false},
|
{"p56ioi7mzjnu2iqgdreydm2mgtmgl3bxnpq6w5btbbz4tjxzwicqCCCC", false},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestValidateNodeID(t *testing.T) {
|
func TestValidateDeviceID(t *testing.T) {
|
||||||
for _, tc := range validateCases {
|
for _, tc := range validateCases {
|
||||||
var id NodeID
|
var id DeviceID
|
||||||
err := id.UnmarshalText([]byte(tc.s))
|
err := id.UnmarshalText([]byte(tc.s))
|
||||||
if (err == nil && !tc.ok) || (err != nil && tc.ok) {
|
if (err == nil && !tc.ok) || (err != nil && tc.ok) {
|
||||||
t.Errorf("ValidateNodeID(%q); %v != %v", tc.s, err, tc.ok)
|
t.Errorf("ValidateDeviceID(%q); %v != %v", tc.s, err, tc.ok)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestMarshallingNodeID(t *testing.T) {
|
func TestMarshallingDeviceID(t *testing.T) {
|
||||||
n0 := NodeID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 10, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32}
|
n0 := DeviceID{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 10, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32}
|
||||||
n1 := NodeID{}
|
n1 := DeviceID{}
|
||||||
n2 := NodeID{}
|
n2 := DeviceID{}
|
||||||
|
|
||||||
bs, _ := n0.MarshalText()
|
bs, _ := n0.MarshalText()
|
||||||
n1.UnmarshalText(bs)
|
n1.UnmarshalText(bs)
|
||||||
12
message.go
12
message.go
@ -7,7 +7,7 @@ package protocol
|
|||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
type IndexMessage struct {
|
type IndexMessage struct {
|
||||||
Repository string // max:64
|
Folder string // max:64
|
||||||
Files []FileInfo
|
Files []FileInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -90,7 +90,7 @@ func (b BlockInfo) String() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type RequestMessage struct {
|
type RequestMessage struct {
|
||||||
Repository string // max:64
|
Folder string // max:64
|
||||||
Name string // max:8192
|
Name string // max:8192
|
||||||
Offset uint64
|
Offset uint64
|
||||||
Size uint32
|
Size uint32
|
||||||
@ -103,7 +103,7 @@ type ResponseMessage struct {
|
|||||||
type ClusterConfigMessage struct {
|
type ClusterConfigMessage struct {
|
||||||
ClientName string // max:64
|
ClientName string // max:64
|
||||||
ClientVersion string // max:64
|
ClientVersion string // max:64
|
||||||
Repositories []Repository // max:64
|
Folders []Folder // max:64
|
||||||
Options []Option // max:64
|
Options []Option // max:64
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -116,12 +116,12 @@ func (o *ClusterConfigMessage) GetOption(key string) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
type Repository struct {
|
type Folder struct {
|
||||||
ID string // max:64
|
ID string // max:64
|
||||||
Nodes []Node // max:64
|
Devices []Device // max:64
|
||||||
}
|
}
|
||||||
|
|
||||||
type Node struct {
|
type Device struct {
|
||||||
ID []byte // max:32
|
ID []byte // max:32
|
||||||
Flags uint32
|
Flags uint32
|
||||||
MaxLocalVersion uint64
|
MaxLocalVersion uint64
|
||||||
|
|||||||
108
message_xdr.go
108
message_xdr.go
@ -18,10 +18,10 @@ IndexMessage Structure:
|
|||||||
0 1 2 3
|
0 1 2 3
|
||||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
| Length of Repository |
|
| Length of Folder |
|
||||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
/ /
|
/ /
|
||||||
\ Repository (variable length) \
|
\ Folder (variable length) \
|
||||||
/ /
|
/ /
|
||||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
| Number of Files |
|
| Number of Files |
|
||||||
@ -33,7 +33,7 @@ IndexMessage Structure:
|
|||||||
|
|
||||||
|
|
||||||
struct IndexMessage {
|
struct IndexMessage {
|
||||||
string Repository<64>;
|
string Folder<64>;
|
||||||
FileInfo Files<>;
|
FileInfo Files<>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,10 +56,10 @@ func (o IndexMessage) AppendXDR(bs []byte) []byte {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (o IndexMessage) encodeXDR(xw *xdr.Writer) (int, error) {
|
func (o IndexMessage) encodeXDR(xw *xdr.Writer) (int, error) {
|
||||||
if len(o.Repository) > 64 {
|
if len(o.Folder) > 64 {
|
||||||
return xw.Tot(), xdr.ErrElementSizeExceeded
|
return xw.Tot(), xdr.ErrElementSizeExceeded
|
||||||
}
|
}
|
||||||
xw.WriteString(o.Repository)
|
xw.WriteString(o.Folder)
|
||||||
xw.WriteUint32(uint32(len(o.Files)))
|
xw.WriteUint32(uint32(len(o.Files)))
|
||||||
for i := range o.Files {
|
for i := range o.Files {
|
||||||
_, err := o.Files[i].encodeXDR(xw)
|
_, err := o.Files[i].encodeXDR(xw)
|
||||||
@ -82,7 +82,7 @@ func (o *IndexMessage) UnmarshalXDR(bs []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (o *IndexMessage) decodeXDR(xr *xdr.Reader) error {
|
func (o *IndexMessage) decodeXDR(xr *xdr.Reader) error {
|
||||||
o.Repository = xr.ReadStringMax(64)
|
o.Folder = xr.ReadStringMax(64)
|
||||||
_FilesSize := int(xr.ReadUint32())
|
_FilesSize := int(xr.ReadUint32())
|
||||||
o.Files = make([]FileInfo, _FilesSize)
|
o.Files = make([]FileInfo, _FilesSize)
|
||||||
for i := range o.Files {
|
for i := range o.Files {
|
||||||
@ -362,10 +362,10 @@ RequestMessage Structure:
|
|||||||
0 1 2 3
|
0 1 2 3
|
||||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
| Length of Repository |
|
| Length of Folder |
|
||||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
/ /
|
/ /
|
||||||
\ Repository (variable length) \
|
\ Folder (variable length) \
|
||||||
/ /
|
/ /
|
||||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
| Length of Name |
|
| Length of Name |
|
||||||
@ -383,7 +383,7 @@ RequestMessage Structure:
|
|||||||
|
|
||||||
|
|
||||||
struct RequestMessage {
|
struct RequestMessage {
|
||||||
string Repository<64>;
|
string Folder<64>;
|
||||||
string Name<8192>;
|
string Name<8192>;
|
||||||
unsigned hyper Offset;
|
unsigned hyper Offset;
|
||||||
unsigned int Size;
|
unsigned int Size;
|
||||||
@ -408,10 +408,10 @@ func (o RequestMessage) AppendXDR(bs []byte) []byte {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (o RequestMessage) encodeXDR(xw *xdr.Writer) (int, error) {
|
func (o RequestMessage) encodeXDR(xw *xdr.Writer) (int, error) {
|
||||||
if len(o.Repository) > 64 {
|
if len(o.Folder) > 64 {
|
||||||
return xw.Tot(), xdr.ErrElementSizeExceeded
|
return xw.Tot(), xdr.ErrElementSizeExceeded
|
||||||
}
|
}
|
||||||
xw.WriteString(o.Repository)
|
xw.WriteString(o.Folder)
|
||||||
if len(o.Name) > 8192 {
|
if len(o.Name) > 8192 {
|
||||||
return xw.Tot(), xdr.ErrElementSizeExceeded
|
return xw.Tot(), xdr.ErrElementSizeExceeded
|
||||||
}
|
}
|
||||||
@ -433,7 +433,7 @@ func (o *RequestMessage) UnmarshalXDR(bs []byte) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (o *RequestMessage) decodeXDR(xr *xdr.Reader) error {
|
func (o *RequestMessage) decodeXDR(xr *xdr.Reader) error {
|
||||||
o.Repository = xr.ReadStringMax(64)
|
o.Folder = xr.ReadStringMax(64)
|
||||||
o.Name = xr.ReadStringMax(8192)
|
o.Name = xr.ReadStringMax(8192)
|
||||||
o.Offset = xr.ReadUint64()
|
o.Offset = xr.ReadUint64()
|
||||||
o.Size = xr.ReadUint32()
|
o.Size = xr.ReadUint32()
|
||||||
@ -517,10 +517,10 @@ ClusterConfigMessage Structure:
|
|||||||
\ Client Version (variable length) \
|
\ Client Version (variable length) \
|
||||||
/ /
|
/ /
|
||||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
| Number of Repositories |
|
| Number of Folders |
|
||||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
/ /
|
/ /
|
||||||
\ Zero or more Repository Structures \
|
\ Zero or more Folder Structures \
|
||||||
/ /
|
/ /
|
||||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
| Number of Options |
|
| Number of Options |
|
||||||
@ -534,7 +534,7 @@ ClusterConfigMessage Structure:
|
|||||||
struct ClusterConfigMessage {
|
struct ClusterConfigMessage {
|
||||||
string ClientName<64>;
|
string ClientName<64>;
|
||||||
string ClientVersion<64>;
|
string ClientVersion<64>;
|
||||||
Repository Repositories<64>;
|
Folder Folders<64>;
|
||||||
Option Options<64>;
|
Option Options<64>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -565,12 +565,12 @@ func (o ClusterConfigMessage) encodeXDR(xw *xdr.Writer) (int, error) {
|
|||||||
return xw.Tot(), xdr.ErrElementSizeExceeded
|
return xw.Tot(), xdr.ErrElementSizeExceeded
|
||||||
}
|
}
|
||||||
xw.WriteString(o.ClientVersion)
|
xw.WriteString(o.ClientVersion)
|
||||||
if len(o.Repositories) > 64 {
|
if len(o.Folders) > 64 {
|
||||||
return xw.Tot(), xdr.ErrElementSizeExceeded
|
return xw.Tot(), xdr.ErrElementSizeExceeded
|
||||||
}
|
}
|
||||||
xw.WriteUint32(uint32(len(o.Repositories)))
|
xw.WriteUint32(uint32(len(o.Folders)))
|
||||||
for i := range o.Repositories {
|
for i := range o.Folders {
|
||||||
_, err := o.Repositories[i].encodeXDR(xw)
|
_, err := o.Folders[i].encodeXDR(xw)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xw.Tot(), err
|
return xw.Tot(), err
|
||||||
}
|
}
|
||||||
@ -602,13 +602,13 @@ func (o *ClusterConfigMessage) UnmarshalXDR(bs []byte) error {
|
|||||||
func (o *ClusterConfigMessage) decodeXDR(xr *xdr.Reader) error {
|
func (o *ClusterConfigMessage) decodeXDR(xr *xdr.Reader) error {
|
||||||
o.ClientName = xr.ReadStringMax(64)
|
o.ClientName = xr.ReadStringMax(64)
|
||||||
o.ClientVersion = xr.ReadStringMax(64)
|
o.ClientVersion = xr.ReadStringMax(64)
|
||||||
_RepositoriesSize := int(xr.ReadUint32())
|
_FoldersSize := int(xr.ReadUint32())
|
||||||
if _RepositoriesSize > 64 {
|
if _FoldersSize > 64 {
|
||||||
return xdr.ErrElementSizeExceeded
|
return xdr.ErrElementSizeExceeded
|
||||||
}
|
}
|
||||||
o.Repositories = make([]Repository, _RepositoriesSize)
|
o.Folders = make([]Folder, _FoldersSize)
|
||||||
for i := range o.Repositories {
|
for i := range o.Folders {
|
||||||
(&o.Repositories[i]).decodeXDR(xr)
|
(&o.Folders[i]).decodeXDR(xr)
|
||||||
}
|
}
|
||||||
_OptionsSize := int(xr.ReadUint32())
|
_OptionsSize := int(xr.ReadUint32())
|
||||||
if _OptionsSize > 64 {
|
if _OptionsSize > 64 {
|
||||||
@ -623,7 +623,7 @@ func (o *ClusterConfigMessage) decodeXDR(xr *xdr.Reader) error {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
Repository Structure:
|
Folder Structure:
|
||||||
|
|
||||||
0 1 2 3
|
0 1 2 3
|
||||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||||
@ -634,48 +634,48 @@ Repository Structure:
|
|||||||
\ ID (variable length) \
|
\ ID (variable length) \
|
||||||
/ /
|
/ /
|
||||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
| Number of Nodes |
|
| Number of Devices |
|
||||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
/ /
|
/ /
|
||||||
\ Zero or more Node Structures \
|
\ Zero or more Device Structures \
|
||||||
/ /
|
/ /
|
||||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
|
||||||
|
|
||||||
struct Repository {
|
struct Folder {
|
||||||
string ID<64>;
|
string ID<64>;
|
||||||
Node Nodes<64>;
|
Device Devices<64>;
|
||||||
}
|
}
|
||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
func (o Repository) EncodeXDR(w io.Writer) (int, error) {
|
func (o Folder) EncodeXDR(w io.Writer) (int, error) {
|
||||||
var xw = xdr.NewWriter(w)
|
var xw = xdr.NewWriter(w)
|
||||||
return o.encodeXDR(xw)
|
return o.encodeXDR(xw)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o Repository) MarshalXDR() []byte {
|
func (o Folder) MarshalXDR() []byte {
|
||||||
return o.AppendXDR(make([]byte, 0, 128))
|
return o.AppendXDR(make([]byte, 0, 128))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o Repository) AppendXDR(bs []byte) []byte {
|
func (o Folder) AppendXDR(bs []byte) []byte {
|
||||||
var aw = xdr.AppendWriter(bs)
|
var aw = xdr.AppendWriter(bs)
|
||||||
var xw = xdr.NewWriter(&aw)
|
var xw = xdr.NewWriter(&aw)
|
||||||
o.encodeXDR(xw)
|
o.encodeXDR(xw)
|
||||||
return []byte(aw)
|
return []byte(aw)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o Repository) encodeXDR(xw *xdr.Writer) (int, error) {
|
func (o Folder) encodeXDR(xw *xdr.Writer) (int, error) {
|
||||||
if len(o.ID) > 64 {
|
if len(o.ID) > 64 {
|
||||||
return xw.Tot(), xdr.ErrElementSizeExceeded
|
return xw.Tot(), xdr.ErrElementSizeExceeded
|
||||||
}
|
}
|
||||||
xw.WriteString(o.ID)
|
xw.WriteString(o.ID)
|
||||||
if len(o.Nodes) > 64 {
|
if len(o.Devices) > 64 {
|
||||||
return xw.Tot(), xdr.ErrElementSizeExceeded
|
return xw.Tot(), xdr.ErrElementSizeExceeded
|
||||||
}
|
}
|
||||||
xw.WriteUint32(uint32(len(o.Nodes)))
|
xw.WriteUint32(uint32(len(o.Devices)))
|
||||||
for i := range o.Nodes {
|
for i := range o.Devices {
|
||||||
_, err := o.Nodes[i].encodeXDR(xw)
|
_, err := o.Devices[i].encodeXDR(xw)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return xw.Tot(), err
|
return xw.Tot(), err
|
||||||
}
|
}
|
||||||
@ -683,33 +683,33 @@ func (o Repository) encodeXDR(xw *xdr.Writer) (int, error) {
|
|||||||
return xw.Tot(), xw.Error()
|
return xw.Tot(), xw.Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Repository) DecodeXDR(r io.Reader) error {
|
func (o *Folder) DecodeXDR(r io.Reader) error {
|
||||||
xr := xdr.NewReader(r)
|
xr := xdr.NewReader(r)
|
||||||
return o.decodeXDR(xr)
|
return o.decodeXDR(xr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Repository) UnmarshalXDR(bs []byte) error {
|
func (o *Folder) UnmarshalXDR(bs []byte) error {
|
||||||
var br = bytes.NewReader(bs)
|
var br = bytes.NewReader(bs)
|
||||||
var xr = xdr.NewReader(br)
|
var xr = xdr.NewReader(br)
|
||||||
return o.decodeXDR(xr)
|
return o.decodeXDR(xr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Repository) decodeXDR(xr *xdr.Reader) error {
|
func (o *Folder) decodeXDR(xr *xdr.Reader) error {
|
||||||
o.ID = xr.ReadStringMax(64)
|
o.ID = xr.ReadStringMax(64)
|
||||||
_NodesSize := int(xr.ReadUint32())
|
_DevicesSize := int(xr.ReadUint32())
|
||||||
if _NodesSize > 64 {
|
if _DevicesSize > 64 {
|
||||||
return xdr.ErrElementSizeExceeded
|
return xdr.ErrElementSizeExceeded
|
||||||
}
|
}
|
||||||
o.Nodes = make([]Node, _NodesSize)
|
o.Devices = make([]Device, _DevicesSize)
|
||||||
for i := range o.Nodes {
|
for i := range o.Devices {
|
||||||
(&o.Nodes[i]).decodeXDR(xr)
|
(&o.Devices[i]).decodeXDR(xr)
|
||||||
}
|
}
|
||||||
return xr.Error()
|
return xr.Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
Node Structure:
|
Device Structure:
|
||||||
|
|
||||||
0 1 2 3
|
0 1 2 3
|
||||||
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||||
@ -728,7 +728,7 @@ Node Structure:
|
|||||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
|
||||||
|
|
||||||
struct Node {
|
struct Device {
|
||||||
opaque ID<32>;
|
opaque ID<32>;
|
||||||
unsigned int Flags;
|
unsigned int Flags;
|
||||||
unsigned hyper MaxLocalVersion;
|
unsigned hyper MaxLocalVersion;
|
||||||
@ -736,23 +736,23 @@ struct Node {
|
|||||||
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
func (o Node) EncodeXDR(w io.Writer) (int, error) {
|
func (o Device) EncodeXDR(w io.Writer) (int, error) {
|
||||||
var xw = xdr.NewWriter(w)
|
var xw = xdr.NewWriter(w)
|
||||||
return o.encodeXDR(xw)
|
return o.encodeXDR(xw)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o Node) MarshalXDR() []byte {
|
func (o Device) MarshalXDR() []byte {
|
||||||
return o.AppendXDR(make([]byte, 0, 128))
|
return o.AppendXDR(make([]byte, 0, 128))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o Node) AppendXDR(bs []byte) []byte {
|
func (o Device) AppendXDR(bs []byte) []byte {
|
||||||
var aw = xdr.AppendWriter(bs)
|
var aw = xdr.AppendWriter(bs)
|
||||||
var xw = xdr.NewWriter(&aw)
|
var xw = xdr.NewWriter(&aw)
|
||||||
o.encodeXDR(xw)
|
o.encodeXDR(xw)
|
||||||
return []byte(aw)
|
return []byte(aw)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o Node) encodeXDR(xw *xdr.Writer) (int, error) {
|
func (o Device) encodeXDR(xw *xdr.Writer) (int, error) {
|
||||||
if len(o.ID) > 32 {
|
if len(o.ID) > 32 {
|
||||||
return xw.Tot(), xdr.ErrElementSizeExceeded
|
return xw.Tot(), xdr.ErrElementSizeExceeded
|
||||||
}
|
}
|
||||||
@ -762,18 +762,18 @@ func (o Node) encodeXDR(xw *xdr.Writer) (int, error) {
|
|||||||
return xw.Tot(), xw.Error()
|
return xw.Tot(), xw.Error()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Node) DecodeXDR(r io.Reader) error {
|
func (o *Device) DecodeXDR(r io.Reader) error {
|
||||||
xr := xdr.NewReader(r)
|
xr := xdr.NewReader(r)
|
||||||
return o.decodeXDR(xr)
|
return o.decodeXDR(xr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Node) UnmarshalXDR(bs []byte) error {
|
func (o *Device) UnmarshalXDR(bs []byte) error {
|
||||||
var br = bytes.NewReader(bs)
|
var br = bytes.NewReader(bs)
|
||||||
var xr = xdr.NewReader(br)
|
var xr = xdr.NewReader(br)
|
||||||
return o.decodeXDR(xr)
|
return o.decodeXDR(xr)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (o *Node) decodeXDR(xr *xdr.Reader) error {
|
func (o *Device) decodeXDR(xr *xdr.Reader) error {
|
||||||
o.ID = xr.ReadBytesMax(32)
|
o.ID = xr.ReadBytesMax(32)
|
||||||
o.Flags = xr.ReadUint32()
|
o.Flags = xr.ReadUint32()
|
||||||
o.MaxLocalVersion = xr.ReadUint64()
|
o.MaxLocalVersion = xr.ReadUint64()
|
||||||
|
|||||||
@ -14,29 +14,29 @@ type nativeModel struct {
|
|||||||
next Model
|
next Model
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m nativeModel) Index(nodeID NodeID, repo string, files []FileInfo) {
|
func (m nativeModel) Index(deviceID DeviceID, folder string, files []FileInfo) {
|
||||||
for i := range files {
|
for i := range files {
|
||||||
files[i].Name = norm.NFD.String(files[i].Name)
|
files[i].Name = norm.NFD.String(files[i].Name)
|
||||||
}
|
}
|
||||||
m.next.Index(nodeID, repo, files)
|
m.next.Index(deviceID, folder, files)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m nativeModel) IndexUpdate(nodeID NodeID, repo string, files []FileInfo) {
|
func (m nativeModel) IndexUpdate(deviceID DeviceID, folder string, files []FileInfo) {
|
||||||
for i := range files {
|
for i := range files {
|
||||||
files[i].Name = norm.NFD.String(files[i].Name)
|
files[i].Name = norm.NFD.String(files[i].Name)
|
||||||
}
|
}
|
||||||
m.next.IndexUpdate(nodeID, repo, files)
|
m.next.IndexUpdate(deviceID, folder, files)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m nativeModel) Request(nodeID NodeID, repo string, name string, offset int64, size int) ([]byte, error) {
|
func (m nativeModel) Request(deviceID DeviceID, folder string, name string, offset int64, size int) ([]byte, error) {
|
||||||
name = norm.NFD.String(name)
|
name = norm.NFD.String(name)
|
||||||
return m.next.Request(nodeID, repo, name, offset, size)
|
return m.next.Request(deviceID, folder, name, offset, size)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m nativeModel) ClusterConfig(nodeID NodeID, config ClusterConfigMessage) {
|
func (m nativeModel) ClusterConfig(deviceID DeviceID, config ClusterConfigMessage) {
|
||||||
m.next.ClusterConfig(nodeID, config)
|
m.next.ClusterConfig(deviceID, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m nativeModel) Close(nodeID NodeID, err error) {
|
func (m nativeModel) Close(deviceID DeviceID, err error) {
|
||||||
m.next.Close(nodeID, err)
|
m.next.Close(deviceID, err)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,22 +12,22 @@ type nativeModel struct {
|
|||||||
next Model
|
next Model
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m nativeModel) Index(nodeID NodeID, repo string, files []FileInfo) {
|
func (m nativeModel) Index(deviceID DeviceID, folder string, files []FileInfo) {
|
||||||
m.next.Index(nodeID, repo, files)
|
m.next.Index(deviceID, folder, files)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m nativeModel) IndexUpdate(nodeID NodeID, repo string, files []FileInfo) {
|
func (m nativeModel) IndexUpdate(deviceID DeviceID, folder string, files []FileInfo) {
|
||||||
m.next.IndexUpdate(nodeID, repo, files)
|
m.next.IndexUpdate(deviceID, folder, files)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m nativeModel) Request(nodeID NodeID, repo string, name string, offset int64, size int) ([]byte, error) {
|
func (m nativeModel) Request(deviceID DeviceID, folder string, name string, offset int64, size int) ([]byte, error) {
|
||||||
return m.next.Request(nodeID, repo, name, offset, size)
|
return m.next.Request(deviceID, folder, name, offset, size)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m nativeModel) ClusterConfig(nodeID NodeID, config ClusterConfigMessage) {
|
func (m nativeModel) ClusterConfig(deviceID DeviceID, config ClusterConfigMessage) {
|
||||||
m.next.ClusterConfig(nodeID, config)
|
m.next.ClusterConfig(deviceID, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m nativeModel) Close(nodeID NodeID, err error) {
|
func (m nativeModel) Close(deviceID DeviceID, err error) {
|
||||||
m.next.Close(nodeID, err)
|
m.next.Close(deviceID, err)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,7 +26,7 @@ type nativeModel struct {
|
|||||||
next Model
|
next Model
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m nativeModel) Index(nodeID NodeID, repo string, files []FileInfo) {
|
func (m nativeModel) Index(deviceID DeviceID, folder string, files []FileInfo) {
|
||||||
for i, f := range files {
|
for i, f := range files {
|
||||||
if strings.ContainsAny(f.Name, disallowedCharacters) {
|
if strings.ContainsAny(f.Name, disallowedCharacters) {
|
||||||
if f.IsDeleted() {
|
if f.IsDeleted() {
|
||||||
@ -39,10 +39,10 @@ func (m nativeModel) Index(nodeID NodeID, repo string, files []FileInfo) {
|
|||||||
}
|
}
|
||||||
files[i].Name = filepath.FromSlash(f.Name)
|
files[i].Name = filepath.FromSlash(f.Name)
|
||||||
}
|
}
|
||||||
m.next.Index(nodeID, repo, files)
|
m.next.Index(deviceID, folder, files)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m nativeModel) IndexUpdate(nodeID NodeID, repo string, files []FileInfo) {
|
func (m nativeModel) IndexUpdate(deviceID DeviceID, folder string, files []FileInfo) {
|
||||||
for i, f := range files {
|
for i, f := range files {
|
||||||
if strings.ContainsAny(f.Name, disallowedCharacters) {
|
if strings.ContainsAny(f.Name, disallowedCharacters) {
|
||||||
if f.IsDeleted() {
|
if f.IsDeleted() {
|
||||||
@ -55,18 +55,18 @@ func (m nativeModel) IndexUpdate(nodeID NodeID, repo string, files []FileInfo) {
|
|||||||
}
|
}
|
||||||
files[i].Name = filepath.FromSlash(files[i].Name)
|
files[i].Name = filepath.FromSlash(files[i].Name)
|
||||||
}
|
}
|
||||||
m.next.IndexUpdate(nodeID, repo, files)
|
m.next.IndexUpdate(deviceID, folder, files)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m nativeModel) Request(nodeID NodeID, repo string, name string, offset int64, size int) ([]byte, error) {
|
func (m nativeModel) Request(deviceID DeviceID, folder string, name string, offset int64, size int) ([]byte, error) {
|
||||||
name = filepath.FromSlash(name)
|
name = filepath.FromSlash(name)
|
||||||
return m.next.Request(nodeID, repo, name, offset, size)
|
return m.next.Request(deviceID, folder, name, offset, size)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m nativeModel) ClusterConfig(nodeID NodeID, config ClusterConfigMessage) {
|
func (m nativeModel) ClusterConfig(deviceID DeviceID, config ClusterConfigMessage) {
|
||||||
m.next.ClusterConfig(nodeID, config)
|
m.next.ClusterConfig(deviceID, config)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m nativeModel) Close(nodeID NodeID, err error) {
|
func (m nativeModel) Close(deviceID DeviceID, err error) {
|
||||||
m.next.Close(nodeID, err)
|
m.next.Close(deviceID, err)
|
||||||
}
|
}
|
||||||
|
|||||||
60
protocol.go
60
protocol.go
@ -57,30 +57,30 @@ var (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type Model interface {
|
type Model interface {
|
||||||
// An index was received from the peer node
|
// An index was received from the peer device
|
||||||
Index(nodeID NodeID, repo string, files []FileInfo)
|
Index(deviceID DeviceID, folder string, files []FileInfo)
|
||||||
// An index update was received from the peer node
|
// An index update was received from the peer device
|
||||||
IndexUpdate(nodeID NodeID, repo string, files []FileInfo)
|
IndexUpdate(deviceID DeviceID, folder string, files []FileInfo)
|
||||||
// A request was made by the peer node
|
// A request was made by the peer device
|
||||||
Request(nodeID NodeID, repo string, name string, offset int64, size int) ([]byte, error)
|
Request(deviceID DeviceID, folder string, name string, offset int64, size int) ([]byte, error)
|
||||||
// A cluster configuration message was received
|
// A cluster configuration message was received
|
||||||
ClusterConfig(nodeID NodeID, config ClusterConfigMessage)
|
ClusterConfig(deviceID DeviceID, config ClusterConfigMessage)
|
||||||
// The peer node closed the connection
|
// The peer device closed the connection
|
||||||
Close(nodeID NodeID, err error)
|
Close(deviceID DeviceID, err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type Connection interface {
|
type Connection interface {
|
||||||
ID() NodeID
|
ID() DeviceID
|
||||||
Name() string
|
Name() string
|
||||||
Index(repo string, files []FileInfo) error
|
Index(folder string, files []FileInfo) error
|
||||||
IndexUpdate(repo string, files []FileInfo) error
|
IndexUpdate(folder string, files []FileInfo) error
|
||||||
Request(repo string, name string, offset int64, size int) ([]byte, error)
|
Request(folder string, name string, offset int64, size int) ([]byte, error)
|
||||||
ClusterConfig(config ClusterConfigMessage)
|
ClusterConfig(config ClusterConfigMessage)
|
||||||
Statistics() Statistics
|
Statistics() Statistics
|
||||||
}
|
}
|
||||||
|
|
||||||
type rawConnection struct {
|
type rawConnection struct {
|
||||||
id NodeID
|
id DeviceID
|
||||||
name string
|
name string
|
||||||
receiver Model
|
receiver Model
|
||||||
state int
|
state int
|
||||||
@ -123,7 +123,7 @@ const (
|
|||||||
pingIdleTime = 60 * time.Second
|
pingIdleTime = 60 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewConnection(nodeID NodeID, reader io.Reader, writer io.Writer, receiver Model, name string, compress bool) Connection {
|
func NewConnection(deviceID DeviceID, reader io.Reader, writer io.Writer, receiver Model, name string, compress bool) Connection {
|
||||||
cr := &countingReader{Reader: reader}
|
cr := &countingReader{Reader: reader}
|
||||||
cw := &countingWriter{Writer: writer}
|
cw := &countingWriter{Writer: writer}
|
||||||
|
|
||||||
@ -132,7 +132,7 @@ func NewConnection(nodeID NodeID, reader io.Reader, writer io.Writer, receiver M
|
|||||||
compThres = 128 // compress messages that are 128 bytes long or larger
|
compThres = 128 // compress messages that are 128 bytes long or larger
|
||||||
}
|
}
|
||||||
c := rawConnection{
|
c := rawConnection{
|
||||||
id: nodeID,
|
id: deviceID,
|
||||||
name: name,
|
name: name,
|
||||||
receiver: nativeModel{receiver},
|
receiver: nativeModel{receiver},
|
||||||
state: stateInitial,
|
state: stateInitial,
|
||||||
@ -152,7 +152,7 @@ func NewConnection(nodeID NodeID, reader io.Reader, writer io.Writer, receiver M
|
|||||||
return wireFormatConnection{&c}
|
return wireFormatConnection{&c}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *rawConnection) ID() NodeID {
|
func (c *rawConnection) ID() DeviceID {
|
||||||
return c.id
|
return c.id
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,34 +160,34 @@ func (c *rawConnection) Name() string {
|
|||||||
return c.name
|
return c.name
|
||||||
}
|
}
|
||||||
|
|
||||||
// Index writes the list of file information to the connected peer node
|
// Index writes the list of file information to the connected peer device
|
||||||
func (c *rawConnection) Index(repo string, idx []FileInfo) error {
|
func (c *rawConnection) Index(folder string, idx []FileInfo) error {
|
||||||
select {
|
select {
|
||||||
case <-c.closed:
|
case <-c.closed:
|
||||||
return ErrClosed
|
return ErrClosed
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
c.idxMut.Lock()
|
c.idxMut.Lock()
|
||||||
c.send(-1, messageTypeIndex, IndexMessage{repo, idx})
|
c.send(-1, messageTypeIndex, IndexMessage{folder, idx})
|
||||||
c.idxMut.Unlock()
|
c.idxMut.Unlock()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// IndexUpdate writes the list of file information to the connected peer node as an update
|
// IndexUpdate writes the list of file information to the connected peer device as an update
|
||||||
func (c *rawConnection) IndexUpdate(repo string, idx []FileInfo) error {
|
func (c *rawConnection) IndexUpdate(folder string, idx []FileInfo) error {
|
||||||
select {
|
select {
|
||||||
case <-c.closed:
|
case <-c.closed:
|
||||||
return ErrClosed
|
return ErrClosed
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
c.idxMut.Lock()
|
c.idxMut.Lock()
|
||||||
c.send(-1, messageTypeIndexUpdate, IndexMessage{repo, idx})
|
c.send(-1, messageTypeIndexUpdate, IndexMessage{folder, idx})
|
||||||
c.idxMut.Unlock()
|
c.idxMut.Unlock()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Request returns the bytes for the specified block after fetching them from the connected peer.
|
// Request returns the bytes for the specified block after fetching them from the connected peer.
|
||||||
func (c *rawConnection) Request(repo string, name string, offset int64, size int) ([]byte, error) {
|
func (c *rawConnection) Request(folder string, name string, offset int64, size int) ([]byte, error) {
|
||||||
var id int
|
var id int
|
||||||
select {
|
select {
|
||||||
case id = <-c.nextID:
|
case id = <-c.nextID:
|
||||||
@ -203,7 +203,7 @@ func (c *rawConnection) Request(repo string, name string, offset int64, size int
|
|||||||
c.awaiting[id] = rc
|
c.awaiting[id] = rc
|
||||||
c.awaitingMut.Unlock()
|
c.awaitingMut.Unlock()
|
||||||
|
|
||||||
ok := c.send(id, messageTypeRequest, RequestMessage{repo, name, uint64(offset), uint32(size)})
|
ok := c.send(id, messageTypeRequest, RequestMessage{folder, name, uint64(offset), uint32(size)})
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, ErrClosed
|
return nil, ErrClosed
|
||||||
}
|
}
|
||||||
@ -399,20 +399,20 @@ func (c *rawConnection) readMessage() (hdr header, msg encodable, err error) {
|
|||||||
|
|
||||||
func (c *rawConnection) handleIndex(im IndexMessage) {
|
func (c *rawConnection) handleIndex(im IndexMessage) {
|
||||||
if debug {
|
if debug {
|
||||||
l.Debugf("Index(%v, %v, %d files)", c.id, im.Repository, len(im.Files))
|
l.Debugf("Index(%v, %v, %d files)", c.id, im.Folder, len(im.Files))
|
||||||
}
|
}
|
||||||
c.receiver.Index(c.id, im.Repository, im.Files)
|
c.receiver.Index(c.id, im.Folder, im.Files)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *rawConnection) handleIndexUpdate(im IndexMessage) {
|
func (c *rawConnection) handleIndexUpdate(im IndexMessage) {
|
||||||
if debug {
|
if debug {
|
||||||
l.Debugf("queueing IndexUpdate(%v, %v, %d files)", c.id, im.Repository, len(im.Files))
|
l.Debugf("queueing IndexUpdate(%v, %v, %d files)", c.id, im.Folder, len(im.Files))
|
||||||
}
|
}
|
||||||
c.receiver.IndexUpdate(c.id, im.Repository, im.Files)
|
c.receiver.IndexUpdate(c.id, im.Folder, im.Files)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *rawConnection) handleRequest(msgID int, req RequestMessage) {
|
func (c *rawConnection) handleRequest(msgID int, req RequestMessage) {
|
||||||
data, _ := c.receiver.Request(c.id, req.Repository, req.Name, int64(req.Offset), int(req.Size))
|
data, _ := c.receiver.Request(c.id, req.Folder, req.Name, int64(req.Offset), int(req.Size))
|
||||||
|
|
||||||
c.send(msgID, messageTypeResponse, ResponseMessage{data})
|
c.send(msgID, messageTypeResponse, ResponseMessage{data})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,8 +21,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
c0ID = NewNodeID([]byte{1})
|
c0ID = NewDeviceID([]byte{1})
|
||||||
c1ID = NewNodeID([]byte{2})
|
c1ID = NewDeviceID([]byte{2})
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestHeaderFunctions(t *testing.T) {
|
func TestHeaderFunctions(t *testing.T) {
|
||||||
@ -140,8 +140,8 @@ func TestPingErr(t *testing.T) {
|
|||||||
// if string(d) != "response data" {
|
// if string(d) != "response data" {
|
||||||
// t.Fatalf("Incorrect response data %q", string(d))
|
// t.Fatalf("Incorrect response data %q", string(d))
|
||||||
// }
|
// }
|
||||||
// if m0.repo != "default" {
|
// if m0.folder != "default" {
|
||||||
// t.Fatalf("Incorrect repo %q", m0.repo)
|
// t.Fatalf("Incorrect folder %q", m0.folder)
|
||||||
// }
|
// }
|
||||||
// if m0.name != "tn" {
|
// if m0.name != "tn" {
|
||||||
// t.Fatalf("Incorrect name %q", m0.name)
|
// t.Fatalf("Incorrect name %q", m0.name)
|
||||||
@ -240,13 +240,13 @@ func TestClose(t *testing.T) {
|
|||||||
|
|
||||||
func TestElementSizeExceededNested(t *testing.T) {
|
func TestElementSizeExceededNested(t *testing.T) {
|
||||||
m := ClusterConfigMessage{
|
m := ClusterConfigMessage{
|
||||||
Repositories: []Repository{
|
Folders: []Folder{
|
||||||
{ID: "longstringlongstringlongstringinglongstringlongstringlonlongstringlongstringlon"},
|
{ID: "longstringlongstringlongstringinglongstringlongstringlonlongstringlongstringlon"},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
_, err := m.EncodeXDR(ioutil.Discard)
|
_, err := m.EncodeXDR(ioutil.Discard)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Errorf("ID length %d > max 64, but no error", len(m.Repositories[0].ID))
|
t.Errorf("ID length %d > max 64, but no error", len(m.Folders[0].ID))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -14,7 +14,7 @@ type wireFormatConnection struct {
|
|||||||
next Connection
|
next Connection
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c wireFormatConnection) ID() NodeID {
|
func (c wireFormatConnection) ID() DeviceID {
|
||||||
return c.next.ID()
|
return c.next.ID()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ func (c wireFormatConnection) Name() string {
|
|||||||
return c.next.Name()
|
return c.next.Name()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c wireFormatConnection) Index(repo string, fs []FileInfo) error {
|
func (c wireFormatConnection) Index(folder string, fs []FileInfo) error {
|
||||||
var myFs = make([]FileInfo, len(fs))
|
var myFs = make([]FileInfo, len(fs))
|
||||||
copy(myFs, fs)
|
copy(myFs, fs)
|
||||||
|
|
||||||
@ -30,10 +30,10 @@ func (c wireFormatConnection) Index(repo string, fs []FileInfo) error {
|
|||||||
myFs[i].Name = norm.NFC.String(filepath.ToSlash(myFs[i].Name))
|
myFs[i].Name = norm.NFC.String(filepath.ToSlash(myFs[i].Name))
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.next.Index(repo, myFs)
|
return c.next.Index(folder, myFs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c wireFormatConnection) IndexUpdate(repo string, fs []FileInfo) error {
|
func (c wireFormatConnection) IndexUpdate(folder string, fs []FileInfo) error {
|
||||||
var myFs = make([]FileInfo, len(fs))
|
var myFs = make([]FileInfo, len(fs))
|
||||||
copy(myFs, fs)
|
copy(myFs, fs)
|
||||||
|
|
||||||
@ -41,12 +41,12 @@ func (c wireFormatConnection) IndexUpdate(repo string, fs []FileInfo) error {
|
|||||||
myFs[i].Name = norm.NFC.String(filepath.ToSlash(myFs[i].Name))
|
myFs[i].Name = norm.NFC.String(filepath.ToSlash(myFs[i].Name))
|
||||||
}
|
}
|
||||||
|
|
||||||
return c.next.IndexUpdate(repo, myFs)
|
return c.next.IndexUpdate(folder, myFs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c wireFormatConnection) Request(repo, name string, offset int64, size int) ([]byte, error) {
|
func (c wireFormatConnection) Request(folder, name string, offset int64, size int) ([]byte, error) {
|
||||||
name = norm.NFC.String(filepath.ToSlash(name))
|
name = norm.NFC.String(filepath.ToSlash(name))
|
||||||
return c.next.Request(repo, name, offset, size)
|
return c.next.Request(folder, name, offset, size)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c wireFormatConnection) ClusterConfig(config ClusterConfigMessage) {
|
func (c wireFormatConnection) ClusterConfig(config ClusterConfigMessage) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user