mirror of
https://github.com/octoleo/syncthing.git
synced 2025-01-03 15:17:25 +00:00
Move device name into the protocol messages
This commit is contained in:
parent
d6a0a44432
commit
491a33de0b
@ -584,6 +584,7 @@ func (m *Model) ClusterConfig(deviceID protocol.DeviceID, cm protocol.ClusterCon
|
||||
|
||||
event := map[string]string{
|
||||
"id": deviceID.String(),
|
||||
"deviceName": cm.DeviceName,
|
||||
"clientName": cm.ClientName,
|
||||
"clientVersion": cm.ClientVersion,
|
||||
}
|
||||
@ -600,19 +601,16 @@ func (m *Model) ClusterConfig(deviceID protocol.DeviceID, cm protocol.ClusterCon
|
||||
|
||||
events.Default.Log(events.DeviceConnected, event)
|
||||
|
||||
l.Infof(`Device %s client is "%s %s"`, deviceID, cm.ClientName, cm.ClientVersion)
|
||||
l.Infof(`Device %s client is "%s %s named %s"`, deviceID, cm.ClientName, cm.ClientVersion, cm.DeviceName)
|
||||
|
||||
var changed bool
|
||||
|
||||
if name := cm.GetOption("name"); name != "" {
|
||||
l.Infof("Device %s name is %q", deviceID, name)
|
||||
device, ok := m.cfg.Devices()[deviceID]
|
||||
if ok && device.Name == "" {
|
||||
device.Name = name
|
||||
device.Name = cm.DeviceName
|
||||
m.cfg.SetDevice(device)
|
||||
changed = true
|
||||
}
|
||||
}
|
||||
|
||||
if m.cfg.Devices()[deviceID].Introducer {
|
||||
// This device is an introducer. Go through the announced lists of folders
|
||||
@ -1465,14 +1463,9 @@ func (m *Model) numHashers(folder string) int {
|
||||
// clusterConfig returns a ClusterConfigMessage that is correct for the given peer device
|
||||
func (m *Model) clusterConfig(device protocol.DeviceID) protocol.ClusterConfigMessage {
|
||||
cm := protocol.ClusterConfigMessage{
|
||||
DeviceName: m.deviceName,
|
||||
ClientName: m.clientName,
|
||||
ClientVersion: m.clientVersion,
|
||||
Options: []protocol.Option{
|
||||
{
|
||||
Key: "name",
|
||||
Value: m.deviceName,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
m.fmut.RLock()
|
||||
|
@ -110,6 +110,7 @@ type ResponseMessage struct {
|
||||
}
|
||||
|
||||
type ClusterConfigMessage struct {
|
||||
DeviceName string // max:64
|
||||
ClientName string // max:64
|
||||
ClientVersion string // max:64
|
||||
Folders []Folder // max:1000000
|
||||
|
@ -557,6 +557,12 @@ ClusterConfigMessage 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
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Length of Device Name |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
/ /
|
||||
\ Device Name (variable length) \
|
||||
/ /
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
| Length of Client Name |
|
||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
/ /
|
||||
@ -584,6 +590,7 @@ ClusterConfigMessage Structure:
|
||||
|
||||
|
||||
struct ClusterConfigMessage {
|
||||
string DeviceName<64>;
|
||||
string ClientName<64>;
|
||||
string ClientVersion<64>;
|
||||
Folder Folders<1000000>;
|
||||
@ -617,6 +624,10 @@ func (o ClusterConfigMessage) AppendXDR(bs []byte) ([]byte, error) {
|
||||
}
|
||||
|
||||
func (o ClusterConfigMessage) EncodeXDRInto(xw *xdr.Writer) (int, error) {
|
||||
if l := len(o.DeviceName); l > 64 {
|
||||
return xw.Tot(), xdr.ElementSizeExceeded("DeviceName", l, 64)
|
||||
}
|
||||
xw.WriteString(o.DeviceName)
|
||||
if l := len(o.ClientName); l > 64 {
|
||||
return xw.Tot(), xdr.ElementSizeExceeded("ClientName", l, 64)
|
||||
}
|
||||
@ -660,6 +671,7 @@ func (o *ClusterConfigMessage) UnmarshalXDR(bs []byte) error {
|
||||
}
|
||||
|
||||
func (o *ClusterConfigMessage) DecodeXDRFrom(xr *xdr.Reader) error {
|
||||
o.DeviceName = xr.ReadStringMax(64)
|
||||
o.ClientName = xr.ReadStringMax(64)
|
||||
o.ClientVersion = xr.ReadStringMax(64)
|
||||
_FoldersSize := int(xr.ReadUint32())
|
||||
|
Loading…
Reference in New Issue
Block a user