mirror of
https://github.com/syncthing/syncthing.git
synced 2024-11-16 10:28:49 -07:00
d507126101
This is in preparation for future changes, but also improves the handling when talking to pre-v0.13 clients. It breaks out the Hello message and magic from the rest of the protocol implementation, with the intention that this small part of the protocol will survive future changes. To enable this, and future testing, the new ExchangeHello function takes an interface that can be implemented by future Hello versions and returns a version indendent result type. It correctly detects pre-v0.13 protocols and returns a "too old" error message which gets logged to the user at warning level: [I6KAH] 09:21:36 WARNING: Connecting to [...]: the remote device speaks an older version of the protocol (v0.12) not compatible with this version Conversely, something entirely unknown will generate: [I6KAH] 09:40:27 WARNING: Connecting to [...]: the remote device speaks an unknown (newer?) version of the protocol The intention is that in future iterations the Hello exchange will succeed on at least one side and ExchangeHello will return the actual data from the Hello together with ErrTooOld and an even more precise message can be generated. GitHub-Pull-Request: https://github.com/syncthing/syncthing/pull/3289
86 lines
2.7 KiB
Go
86 lines
2.7 KiB
Go
// ************************************************************
|
|
// This file is automatically generated by genxdr. Do not edit.
|
|
// ************************************************************
|
|
|
|
package protocol
|
|
|
|
import (
|
|
"github.com/calmh/xdr"
|
|
)
|
|
|
|
/*
|
|
|
|
Version13HelloMessage Structure:
|
|
|
|
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
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
/ /
|
|
\ Device Name (length + padded data) \
|
|
/ /
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
/ /
|
|
\ Client Name (length + padded data) \
|
|
/ /
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
/ /
|
|
\ Client Version (length + padded data) \
|
|
/ /
|
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
|
|
|
|
|
struct Version13HelloMessage {
|
|
string DeviceName<64>;
|
|
string ClientName<64>;
|
|
string ClientVersion<64>;
|
|
}
|
|
|
|
*/
|
|
|
|
func (o Version13HelloMessage) XDRSize() int {
|
|
return 4 + len(o.DeviceName) + xdr.Padding(len(o.DeviceName)) +
|
|
4 + len(o.ClientName) + xdr.Padding(len(o.ClientName)) +
|
|
4 + len(o.ClientVersion) + xdr.Padding(len(o.ClientVersion))
|
|
}
|
|
|
|
func (o Version13HelloMessage) MarshalXDR() ([]byte, error) {
|
|
buf := make([]byte, o.XDRSize())
|
|
m := &xdr.Marshaller{Data: buf}
|
|
return buf, o.MarshalXDRInto(m)
|
|
}
|
|
|
|
func (o Version13HelloMessage) MustMarshalXDR() []byte {
|
|
bs, err := o.MarshalXDR()
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return bs
|
|
}
|
|
|
|
func (o Version13HelloMessage) MarshalXDRInto(m *xdr.Marshaller) error {
|
|
if l := len(o.DeviceName); l > 64 {
|
|
return xdr.ElementSizeExceeded("DeviceName", l, 64)
|
|
}
|
|
m.MarshalString(o.DeviceName)
|
|
if l := len(o.ClientName); l > 64 {
|
|
return xdr.ElementSizeExceeded("ClientName", l, 64)
|
|
}
|
|
m.MarshalString(o.ClientName)
|
|
if l := len(o.ClientVersion); l > 64 {
|
|
return xdr.ElementSizeExceeded("ClientVersion", l, 64)
|
|
}
|
|
m.MarshalString(o.ClientVersion)
|
|
return m.Error
|
|
}
|
|
|
|
func (o *Version13HelloMessage) UnmarshalXDR(bs []byte) error {
|
|
u := &xdr.Unmarshaller{Data: bs}
|
|
return o.UnmarshalXDRFrom(u)
|
|
}
|
|
func (o *Version13HelloMessage) UnmarshalXDRFrom(u *xdr.Unmarshaller) error {
|
|
o.DeviceName = u.UnmarshalStringMax(64)
|
|
o.ClientName = u.UnmarshalStringMax(64)
|
|
o.ClientVersion = u.UnmarshalStringMax(64)
|
|
return u.Error
|
|
}
|