Move device name into the protocol messages

This commit is contained in:
Audrius Butkevicius 2015-09-26 14:58:53 +01:00
parent d6a0a44432
commit 491a33de0b
3 changed files with 21 additions and 15 deletions

View File

@ -584,6 +584,7 @@ func (m *Model) ClusterConfig(deviceID protocol.DeviceID, cm protocol.ClusterCon
event := map[string]string{ event := map[string]string{
"id": deviceID.String(), "id": deviceID.String(),
"deviceName": cm.DeviceName,
"clientName": cm.ClientName, "clientName": cm.ClientName,
"clientVersion": cm.ClientVersion, "clientVersion": cm.ClientVersion,
} }
@ -600,18 +601,15 @@ func (m *Model) ClusterConfig(deviceID protocol.DeviceID, cm protocol.ClusterCon
events.Default.Log(events.DeviceConnected, event) 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 var changed bool
if name := cm.GetOption("name"); name != "" { device, ok := m.cfg.Devices()[deviceID]
l.Infof("Device %s name is %q", deviceID, name) if ok && device.Name == "" {
device, ok := m.cfg.Devices()[deviceID] device.Name = cm.DeviceName
if ok && device.Name == "" { m.cfg.SetDevice(device)
device.Name = name changed = true
m.cfg.SetDevice(device)
changed = true
}
} }
if m.cfg.Devices()[deviceID].Introducer { if m.cfg.Devices()[deviceID].Introducer {
@ -1465,14 +1463,9 @@ func (m *Model) numHashers(folder string) int {
// clusterConfig returns a ClusterConfigMessage that is correct for the given peer device // clusterConfig returns a ClusterConfigMessage that is correct for the given peer device
func (m *Model) clusterConfig(device protocol.DeviceID) protocol.ClusterConfigMessage { func (m *Model) clusterConfig(device protocol.DeviceID) protocol.ClusterConfigMessage {
cm := protocol.ClusterConfigMessage{ cm := protocol.ClusterConfigMessage{
DeviceName: m.deviceName,
ClientName: m.clientName, ClientName: m.clientName,
ClientVersion: m.clientVersion, ClientVersion: m.clientVersion,
Options: []protocol.Option{
{
Key: "name",
Value: m.deviceName,
},
},
} }
m.fmut.RLock() m.fmut.RLock()

View File

@ -110,6 +110,7 @@ type ResponseMessage struct {
} }
type ClusterConfigMessage struct { type ClusterConfigMessage struct {
DeviceName string // max:64
ClientName string // max:64 ClientName string // max:64
ClientVersion string // max:64 ClientVersion string // max:64
Folders []Folder // max:1000000 Folders []Folder // max:1000000

View File

@ -557,6 +557,12 @@ ClusterConfigMessage 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 Device Name |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/ /
\ Device Name (variable length) \
/ /
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Length of Client Name | | Length of Client Name |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
/ / / /
@ -584,6 +590,7 @@ ClusterConfigMessage Structure:
struct ClusterConfigMessage { struct ClusterConfigMessage {
string DeviceName<64>;
string ClientName<64>; string ClientName<64>;
string ClientVersion<64>; string ClientVersion<64>;
Folder Folders<1000000>; Folder Folders<1000000>;
@ -617,6 +624,10 @@ func (o ClusterConfigMessage) AppendXDR(bs []byte) ([]byte, error) {
} }
func (o ClusterConfigMessage) EncodeXDRInto(xw *xdr.Writer) (int, 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 { if l := len(o.ClientName); l > 64 {
return xw.Tot(), xdr.ElementSizeExceeded("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 { func (o *ClusterConfigMessage) DecodeXDRFrom(xr *xdr.Reader) error {
o.DeviceName = xr.ReadStringMax(64)
o.ClientName = xr.ReadStringMax(64) o.ClientName = xr.ReadStringMax(64)
o.ClientVersion = xr.ReadStringMax(64) o.ClientVersion = xr.ReadStringMax(64)
_FoldersSize := int(xr.ReadUint32()) _FoldersSize := int(xr.ReadUint32())