当前位置: 首页>>代码示例>>Golang>>正文


Golang config.DeviceConfiguration类代码示例

本文整理汇总了Golang中github.com/syncthing/syncthing/internal/config.DeviceConfiguration的典型用法代码示例。如果您正苦于以下问题:Golang DeviceConfiguration类的具体用法?Golang DeviceConfiguration怎么用?Golang DeviceConfiguration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了DeviceConfiguration类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestFolderWithoutRestart

func TestFolderWithoutRestart(t *testing.T) {
	log.Println("Cleaning...")
	err := removeAll("testfolder-p1", "testfolder-p4", "h1/index*", "h4/index*")
	if err != nil {
		t.Fatal(err)
	}
	defer removeAll("testfolder-p1", "testfolder-p4")

	if err := generateFiles("testfolder-p1", 50, 18, "../LICENSE"); err != nil {
		t.Fatal(err)
	}

	p1 := startInstance(t, 1)
	defer checkedStop(t, p1)

	p4 := startInstance(t, 4)
	defer checkedStop(t, p4)

	if ok, err := p1.ConfigInSync(); err != nil || !ok {
		t.Fatal("p1 should be in sync;", ok, err)
	}

	if ok, err := p4.ConfigInSync(); err != nil || !ok {
		t.Fatal("p4 should be in sync;", ok, err)
	}

	// Add a new folder to p1, shared with p4. Back up and restore the config
	// first.

	log.Println("Adding testfolder to p1...")

	os.Remove("h1/config.xml.orig")
	os.Rename("h1/config.xml", "h1/config.xml.orig")
	defer os.Rename("h1/config.xml.orig", "h1/config.xml")

	cfg, err := p1.GetConfig()
	if err != nil {
		t.Fatal(err)
	}

	newFolder := config.FolderConfiguration{
		ID:              "testfolder",
		RawPath:         "testfolder-p1",
		RescanIntervalS: 86400,
		Copiers:         1,
		Hashers:         1,
		Pullers:         1,
		Devices:         []config.FolderDeviceConfiguration{{DeviceID: p4.ID()}},
	}
	newDevice := config.DeviceConfiguration{
		DeviceID:    p4.ID(),
		Name:        "p4",
		Addresses:   []string{"dynamic"},
		Compression: protocol.CompressMetadata,
	}

	cfg.Folders = append(cfg.Folders, newFolder)
	cfg.Devices = append(cfg.Devices, newDevice)

	if err = p1.PostConfig(cfg); err != nil {
		t.Fatal(err)
	}

	// Add a new folder to p4, shared with p1. Back up and restore the config
	// first.

	log.Println("Adding testfolder to p4...")

	os.Remove("h4/config.xml.orig")
	os.Rename("h4/config.xml", "h4/config.xml.orig")
	defer os.Rename("h4/config.xml.orig", "h4/config.xml")

	cfg, err = p4.GetConfig()
	if err != nil {
		t.Fatal(err)
	}

	newFolder.RawPath = "testfolder-p4"
	newFolder.Devices = []config.FolderDeviceConfiguration{{DeviceID: p1.ID()}}
	newDevice.DeviceID = p1.ID()
	newDevice.Name = "p1"
	newDevice.Addresses = []string{"127.0.0.1:22001"}

	cfg.Folders = append(cfg.Folders, newFolder)
	cfg.Devices = append(cfg.Devices, newDevice)

	if err = p4.PostConfig(cfg); err != nil {
		t.Fatal(err)
	}

	// The change should not require a restart, so the config should be "in sync"

	if ok, err := p1.ConfigInSync(); err != nil || !ok {
		t.Fatal("p1 should be in sync;", ok, err)
	}
	if ok, err := p4.ConfigInSync(); err != nil || !ok {
		t.Fatal("p4 should be in sync;", ok, err)
	}

	// The folder should start and scan - wait for the event that signals this
//.........这里部分代码省略.........
开发者ID:kattunga,项目名称:syncthing,代码行数:101,代码来源:norestart_test.go

示例2: ClusterConfig

func (m *Model) ClusterConfig(deviceID protocol.DeviceID, cm protocol.ClusterConfigMessage) {
	m.pmut.Lock()
	if cm.ClientName == "syncthing" {
		m.deviceVer[deviceID] = cm.ClientVersion
	} else {
		m.deviceVer[deviceID] = cm.ClientName + " " + cm.ClientVersion
	}

	event := map[string]string{
		"id":            deviceID.String(),
		"clientName":    cm.ClientName,
		"clientVersion": cm.ClientVersion,
	}

	if conn, ok := m.rawConn[deviceID].(*tls.Conn); ok {
		event["addr"] = conn.RemoteAddr().String()
	}

	m.pmut.Unlock()

	events.Default.Log(events.DeviceConnected, event)

	l.Infof(`Device %s client is "%s %s"`, deviceID, cm.ClientName, cm.ClientVersion)

	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
			m.cfg.SetDevice(device)
			changed = true
		}
	}

	if m.cfg.Devices()[deviceID].Introducer {
		// This device is an introducer. Go through the announced lists of folders
		// and devices and add what we are missing.

		for _, folder := range cm.Folders {
			// If we don't have this folder yet, skip it. Ideally, we'd
			// offer up something in the GUI to create the folder, but for the
			// moment we only handle folders that we already have.
			if _, ok := m.folderDevices[folder.ID]; !ok {
				continue
			}

		nextDevice:
			for _, device := range folder.Devices {
				var id protocol.DeviceID
				copy(id[:], device.ID)

				if _, ok := m.cfg.Devices()[id]; !ok {
					// The device is currently unknown. Add it to the config.

					l.Infof("Adding device %v to config (vouched for by introducer %v)", id, deviceID)
					newDeviceCfg := config.DeviceConfiguration{
						DeviceID:    id,
						Compression: m.cfg.Devices()[deviceID].Compression,
						Addresses:   []string{"dynamic"},
					}

					// The introducers' introducers are also our introducers.
					if device.Flags&protocol.FlagIntroducer != 0 {
						l.Infof("Device %v is now also an introducer", id)
						newDeviceCfg.Introducer = true
					}

					m.cfg.SetDevice(newDeviceCfg)
					changed = true
				}

				for _, er := range m.deviceFolders[id] {
					if er == folder.ID {
						// We already share the folder with this device, so
						// nothing to do.
						continue nextDevice
					}
				}

				// We don't yet share this folder with this device. Add the device
				// to sharing list of the folder.

				l.Infof("Adding device %v to share %q (vouched for by introducer %v)", id, folder.ID, deviceID)

				m.deviceFolders[id] = append(m.deviceFolders[id], folder.ID)
				m.folderDevices[folder.ID] = append(m.folderDevices[folder.ID], id)

				folderCfg := m.cfg.Folders()[folder.ID]
				folderCfg.Devices = append(folderCfg.Devices, config.FolderDeviceConfiguration{
					DeviceID: id,
				})
				m.cfg.SetFolder(folderCfg)

				changed = true
			}
		}
	}

//.........这里部分代码省略.........
开发者ID:gonggomedia,项目名称:syncthing,代码行数:101,代码来源:model.go


注:本文中的github.com/syncthing/syncthing/internal/config.DeviceConfiguration类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。