mirror of
https://github.com/octoleo/syncthing.git
synced 2024-11-10 15:20:56 +00:00
Add more information about the device to ClusterConfig
This commit is contained in:
parent
491a33de0b
commit
a323d85d32
@ -632,11 +632,20 @@ func (m *Model) ClusterConfig(deviceID protocol.DeviceID, cm protocol.ClusterCon
|
|||||||
if _, ok := m.cfg.Devices()[id]; !ok {
|
if _, ok := m.cfg.Devices()[id]; !ok {
|
||||||
// The device is currently unknown. Add it to the config.
|
// The device is currently unknown. Add it to the config.
|
||||||
|
|
||||||
|
addresses := []string{"dynamic"}
|
||||||
|
for _, addr := range device.Addresses {
|
||||||
|
if addr != "dynamic" {
|
||||||
|
addresses = append(addresses, addr)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
l.Infof("Adding device %v to config (vouched for by introducer %v)", id, deviceID)
|
l.Infof("Adding device %v to config (vouched for by introducer %v)", id, deviceID)
|
||||||
newDeviceCfg := config.DeviceConfiguration{
|
newDeviceCfg := config.DeviceConfiguration{
|
||||||
DeviceID: id,
|
DeviceID: id,
|
||||||
|
Name: device.Name,
|
||||||
Compression: m.cfg.Devices()[deviceID].Compression,
|
Compression: m.cfg.Devices()[deviceID].Compression,
|
||||||
Addresses: []string{"dynamic"},
|
Addresses: addresses,
|
||||||
|
CertName: device.CertName,
|
||||||
}
|
}
|
||||||
|
|
||||||
// The introducers' introducers are also our introducers.
|
// The introducers' introducers are also our introducers.
|
||||||
@ -1477,12 +1486,19 @@ func (m *Model) clusterConfig(device protocol.DeviceID) protocol.ClusterConfigMe
|
|||||||
// DeviceID is a value type, but with an underlying array. Copy it
|
// DeviceID is a value type, but with an underlying array. Copy it
|
||||||
// so we don't grab aliases to the same array later on in device[:]
|
// so we don't grab aliases to the same array later on in device[:]
|
||||||
device := device
|
device := device
|
||||||
// TODO: Set read only bit when relevant
|
// TODO: Set read only bit when relevant, and when we have per device
|
||||||
|
// access controls.
|
||||||
|
deviceCfg := m.cfg.Devices()[device]
|
||||||
cn := protocol.Device{
|
cn := protocol.Device{
|
||||||
ID: device[:],
|
ID: device[:],
|
||||||
|
Name: deviceCfg.Name,
|
||||||
|
Addresses: deviceCfg.Addresses,
|
||||||
|
Compression: uint32(deviceCfg.Compression),
|
||||||
|
CertName: deviceCfg.CertName,
|
||||||
Flags: protocol.FlagShareTrusted,
|
Flags: protocol.FlagShareTrusted,
|
||||||
}
|
}
|
||||||
if deviceCfg := m.cfg.Devices()[device]; deviceCfg.Introducer {
|
|
||||||
|
if deviceCfg.Introducer {
|
||||||
cn.Flags |= protocol.FlagIntroducer
|
cn.Flags |= protocol.FlagIntroducer
|
||||||
}
|
}
|
||||||
cr.Devices = append(cr.Devices, cn)
|
cr.Devices = append(cr.Devices, cn)
|
||||||
|
@ -135,6 +135,10 @@ type Folder struct {
|
|||||||
|
|
||||||
type Device struct {
|
type Device struct {
|
||||||
ID []byte // max:32
|
ID []byte // max:32
|
||||||
|
Name string // max:64
|
||||||
|
Addresses []string // max:64,2083
|
||||||
|
Compression uint32
|
||||||
|
CertName string // max:64
|
||||||
MaxLocalVersion int64
|
MaxLocalVersion int64
|
||||||
Flags uint32
|
Flags uint32
|
||||||
Options []Option // max:64
|
Options []Option // max:64
|
||||||
|
@ -842,6 +842,28 @@ Device Structure:
|
|||||||
\ ID (variable length) \
|
\ ID (variable length) \
|
||||||
/ /
|
/ /
|
||||||
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| Length of Name |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
/ /
|
||||||
|
\ Name (variable length) \
|
||||||
|
/ /
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| Number of Addresses |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| Length of Addresses |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
/ /
|
||||||
|
\ Addresses (variable length) \
|
||||||
|
/ /
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| Compression |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
| Length of Cert Name |
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
|
/ /
|
||||||
|
\ Cert Name (variable length) \
|
||||||
|
/ /
|
||||||
|
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||||
| |
|
| |
|
||||||
+ Max Local Version (64 bits) +
|
+ Max Local Version (64 bits) +
|
||||||
| |
|
| |
|
||||||
@ -858,6 +880,10 @@ Device Structure:
|
|||||||
|
|
||||||
struct Device {
|
struct Device {
|
||||||
opaque ID<32>;
|
opaque ID<32>;
|
||||||
|
string Name<64>;
|
||||||
|
string Addresses<64>;
|
||||||
|
unsigned int Compression;
|
||||||
|
string CertName<64>;
|
||||||
hyper MaxLocalVersion;
|
hyper MaxLocalVersion;
|
||||||
unsigned int Flags;
|
unsigned int Flags;
|
||||||
Option Options<64>;
|
Option Options<64>;
|
||||||
@ -894,6 +920,22 @@ func (o Device) EncodeXDRInto(xw *xdr.Writer) (int, error) {
|
|||||||
return xw.Tot(), xdr.ElementSizeExceeded("ID", l, 32)
|
return xw.Tot(), xdr.ElementSizeExceeded("ID", l, 32)
|
||||||
}
|
}
|
||||||
xw.WriteBytes(o.ID)
|
xw.WriteBytes(o.ID)
|
||||||
|
if l := len(o.Name); l > 64 {
|
||||||
|
return xw.Tot(), xdr.ElementSizeExceeded("Name", l, 64)
|
||||||
|
}
|
||||||
|
xw.WriteString(o.Name)
|
||||||
|
if l := len(o.Addresses); l > 64 {
|
||||||
|
return xw.Tot(), xdr.ElementSizeExceeded("Addresses", l, 64)
|
||||||
|
}
|
||||||
|
xw.WriteUint32(uint32(len(o.Addresses)))
|
||||||
|
for i := range o.Addresses {
|
||||||
|
xw.WriteString(o.Addresses[i])
|
||||||
|
}
|
||||||
|
xw.WriteUint32(o.Compression)
|
||||||
|
if l := len(o.CertName); l > 64 {
|
||||||
|
return xw.Tot(), xdr.ElementSizeExceeded("CertName", l, 64)
|
||||||
|
}
|
||||||
|
xw.WriteString(o.CertName)
|
||||||
xw.WriteUint64(uint64(o.MaxLocalVersion))
|
xw.WriteUint64(uint64(o.MaxLocalVersion))
|
||||||
xw.WriteUint32(o.Flags)
|
xw.WriteUint32(o.Flags)
|
||||||
if l := len(o.Options); l > 64 {
|
if l := len(o.Options); l > 64 {
|
||||||
@ -922,6 +964,20 @@ func (o *Device) UnmarshalXDR(bs []byte) error {
|
|||||||
|
|
||||||
func (o *Device) DecodeXDRFrom(xr *xdr.Reader) error {
|
func (o *Device) DecodeXDRFrom(xr *xdr.Reader) error {
|
||||||
o.ID = xr.ReadBytesMax(32)
|
o.ID = xr.ReadBytesMax(32)
|
||||||
|
o.Name = xr.ReadStringMax(64)
|
||||||
|
_AddressesSize := int(xr.ReadUint32())
|
||||||
|
if _AddressesSize < 0 {
|
||||||
|
return xdr.ElementSizeExceeded("Addresses", _AddressesSize, 64)
|
||||||
|
}
|
||||||
|
if _AddressesSize > 64 {
|
||||||
|
return xdr.ElementSizeExceeded("Addresses", _AddressesSize, 64)
|
||||||
|
}
|
||||||
|
o.Addresses = make([]string, _AddressesSize)
|
||||||
|
for i := range o.Addresses {
|
||||||
|
o.Addresses[i] = xr.ReadStringMax(2083)
|
||||||
|
}
|
||||||
|
o.Compression = xr.ReadUint32()
|
||||||
|
o.CertName = xr.ReadStringMax(64)
|
||||||
o.MaxLocalVersion = int64(xr.ReadUint64())
|
o.MaxLocalVersion = int64(xr.ReadUint64())
|
||||||
o.Flags = xr.ReadUint32()
|
o.Flags = xr.ReadUint32()
|
||||||
_OptionsSize := int(xr.ReadUint32())
|
_OptionsSize := int(xr.ReadUint32())
|
||||||
|
Loading…
Reference in New Issue
Block a user