本文整理汇总了Golang中github.com/syncthing/syncthing/lib/protocol.DeviceIDFromString函数的典型用法代码示例。如果您正苦于以下问题:Golang DeviceIDFromString函数的具体用法?Golang DeviceIDFromString怎么用?Golang DeviceIDFromString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DeviceIDFromString函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: init
func init() {
device1, _ = protocol.DeviceIDFromString("AIR6LPZ-7K4PTTV-UXQSMUU-CPQ5YWH-OEDFIIQ-JUG777G-2YQXXR5-YD6AWQR")
device2, _ = protocol.DeviceIDFromString("GYRZZQB-IRNPV4Z-T7TC52W-EQYJ3TT-FDQW6MW-DFLMU42-SSSU6EM-FBK2VAY")
defaultFolderConfig = config.FolderConfiguration{
ID: "default",
RawPath: "testdata",
Devices: []config.FolderDeviceConfiguration{
{
DeviceID: device1,
},
},
}
_defaultConfig := config.Configuration{
Folders: []config.FolderConfiguration{defaultFolderConfig},
Devices: []config.DeviceConfiguration{
{
DeviceID: device1,
},
},
Options: config.OptionsConfiguration{
// Don't remove temporaries directly on startup
KeepTemporariesH: 1,
},
}
defaultConfig = config.Wrap("/tmp/test", _defaultConfig)
}
开发者ID:vhuarui,项目名称:syncthing,代码行数:27,代码来源:model_test.go
示例2: performHandshakeAndValidation
func performHandshakeAndValidation(conn *tls.Conn, uri *url.URL) error {
if err := conn.Handshake(); err != nil {
return err
}
cs := conn.ConnectionState()
if !cs.NegotiatedProtocolIsMutual || cs.NegotiatedProtocol != protocol.ProtocolName {
return fmt.Errorf("protocol negotiation error")
}
q := uri.Query()
relayIDs := q.Get("id")
if relayIDs != "" {
relayID, err := syncthingprotocol.DeviceIDFromString(relayIDs)
if err != nil {
return fmt.Errorf("relay address contains invalid verification id: %s", err)
}
certs := cs.PeerCertificates
if cl := len(certs); cl != 1 {
return fmt.Errorf("unexpected certificate count: %d", cl)
}
remoteID := syncthingprotocol.NewDeviceID(certs[0].Raw)
if remoteID != relayID {
return fmt.Errorf("relay id does not match. Expected %v got %v", relayID, remoteID)
}
}
return nil
}
开发者ID:StefanScherer,项目名称:syncthing,代码行数:31,代码来源:client.go
示例3: main
func main() {
var server string
flag.StringVar(&server, "server", "", "Announce server (blank for default set)")
flag.DurationVar(&timeout, "timeout", timeout, "Query timeout")
flag.Usage = usage
flag.Parse()
if flag.NArg() != 1 {
flag.Usage()
os.Exit(64)
}
id, err := protocol.DeviceIDFromString(flag.Args()[0])
if err != nil {
fmt.Println(err)
os.Exit(1)
}
if server != "" {
checkServers(id, server)
} else {
checkServers(id, config.DefaultDiscoveryServers...)
}
}
开发者ID:carriercomm,项目名称:syncthing,代码行数:25,代码来源:main.go
示例4: NewGlobal
func NewGlobal(server string, cert tls.Certificate, addrList AddressLister) (FinderService, error) {
server, opts, err := parseOptions(server)
if err != nil {
return nil, err
}
var devID protocol.DeviceID
if opts.id != "" {
devID, err = protocol.DeviceIDFromString(opts.id)
if err != nil {
return nil, err
}
}
// The http.Client used for announcements. It needs to have our
// certificate to prove our identity, and may or may not verify the server
// certificate depending on the insecure setting.
var announceClient httpClient = &http.Client{
Timeout: requestTimeout,
Transport: &http.Transport{
Dial: dialer.Dial,
Proxy: http.ProxyFromEnvironment,
TLSClientConfig: &tls.Config{
InsecureSkipVerify: opts.insecure,
Certificates: []tls.Certificate{cert},
},
},
}
if opts.id != "" {
announceClient = newIDCheckingHTTPClient(announceClient, devID)
}
// The http.Client used for queries. We don't need to present our
// certificate here, so lets not include it. May be insecure if requested.
var queryClient httpClient = &http.Client{
Timeout: requestTimeout,
Transport: &http.Transport{
Dial: dialer.Dial,
Proxy: http.ProxyFromEnvironment,
TLSClientConfig: &tls.Config{
InsecureSkipVerify: opts.insecure,
},
},
}
if opts.id != "" {
queryClient = newIDCheckingHTTPClient(queryClient, devID)
}
cl := &globalClient{
server: server,
addrList: addrList,
announceClient: announceClient,
queryClient: queryClient,
noAnnounce: opts.noAnnounce,
stop: make(chan struct{}),
}
cl.setError(errors.New("not announced"))
return cl, nil
}
开发者ID:letiemble,项目名称:syncthing,代码行数:60,代码来源:global.go
示例5: parseDeviceID
func parseDeviceID(input string) protocol.DeviceID {
device, err := protocol.DeviceIDFromString(input)
if err != nil {
die(input + " is not a valid device id")
}
return device
}
开发者ID:modulexcite,项目名称:syncthing-cli,代码行数:7,代码来源:utils.go
示例6: GetEntryDevices
func (d *FileTreeCache) GetEntryDevices(filepath string) ([]protocol.DeviceID, bool) {
var devices []protocol.DeviceID
found := false
d.db.View(func(tx *bolt.Tx) error {
edb := tx.Bucket(d.folderBucketKey).Bucket(entryDevicesBucket)
d := edb.Get([]byte(filepath))
if d == nil {
devices = make([]protocol.DeviceID, 0)
} else {
found = true
var deviceMap map[string]bool
rbuf := bytes.NewBuffer(d)
dec := gob.NewDecoder(rbuf)
dec.Decode(&deviceMap)
devices = make([]protocol.DeviceID, len(deviceMap))
i := 0
for k, _ := range deviceMap {
devices[i], _ = protocol.DeviceIDFromString(k)
i += 1
}
}
return nil
})
return devices, found
}
开发者ID:burkemw3,项目名称:syncthingfuse,代码行数:30,代码来源:filetreecache.go
示例7: TestSyncClusterForcedRescan
func TestSyncClusterForcedRescan(t *testing.T) {
// Use no versioning
id, _ := protocol.DeviceIDFromString(id2)
cfg, _ := config.Load("h2/config.xml", id)
fld := cfg.Folders()["default"]
fld.Versioning = config.VersioningConfiguration{}
cfg.SetFolder(fld)
cfg.Save()
testSyncClusterForcedRescan(t)
}
开发者ID:raonyguimaraes,项目名称:syncthing,代码行数:11,代码来源:sync_test.go
示例8: postSystemResume
func (s *apiService) postSystemResume(w http.ResponseWriter, r *http.Request) {
var qs = r.URL.Query()
var deviceStr = qs.Get("device")
device, err := protocol.DeviceIDFromString(deviceStr)
if err != nil {
http.Error(w, err.Error(), 500)
return
}
s.model.ResumeDevice(device)
}
开发者ID:xduugu,项目名称:syncthing,代码行数:12,代码来源:gui.go
示例9: TestSyncClusterStaggeredVersioning
func TestSyncClusterStaggeredVersioning(t *testing.T) {
// Use staggered versioning
id, _ := protocol.DeviceIDFromString(id2)
cfg, _ := config.Load("h2/config.xml", id)
fld := cfg.Folders()["default"]
fld.Versioning = config.VersioningConfiguration{
Type: "staggered",
}
cfg.SetFolder(fld)
cfg.Save()
testSyncCluster(t)
}
开发者ID:raonyguimaraes,项目名称:syncthing,代码行数:13,代码来源:sync_test.go
示例10: handleGET
func (s *querysrv) handleGET(ctx context.Context, w http.ResponseWriter, req *http.Request) {
reqID := ctx.Value("id").(requestID)
deviceID, err := protocol.DeviceIDFromString(req.URL.Query().Get("device"))
if err != nil {
if debug {
log.Println(reqID, "bad device param")
}
globalStats.Error()
http.Error(w, "Bad Request", http.StatusBadRequest)
return
}
var ann announcement
ann.Seen, err = s.getDeviceSeen(deviceID)
negCache := strconv.Itoa(negCacheFor(ann.Seen))
w.Header().Set("Retry-After", negCache)
w.Header().Set("Cache-Control", "public, max-age="+negCache)
if err != nil {
// The device is not in the database.
globalStats.Query()
http.Error(w, "Not Found", http.StatusNotFound)
return
}
t0 := time.Now()
ann.Addresses, err = s.getAddresses(ctx, deviceID)
if err != nil {
log.Println(reqID, "getAddresses:", err)
globalStats.Error()
http.Error(w, "Internal Server Error", http.StatusInternalServerError)
return
}
if debug {
log.Println(reqID, "getAddresses in", time.Since(t0))
}
globalStats.Query()
if len(ann.Addresses) == 0 {
http.Error(w, "Not Found", http.StatusNotFound)
return
}
globalStats.Answer()
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(ann)
}
开发者ID:letiemble,项目名称:syncthing,代码行数:51,代码来源:querysrv.go
示例11: TestModelIndexWithRestart
func TestModelIndexWithRestart(t *testing.T) {
// init
dir, _ := ioutil.TempDir("", "stf-mt")
defer os.RemoveAll(dir)
deviceID, _ := protocol.DeviceIDFromString("FFR6LPZ-7K4PTTV-UXQSMUU-CPQ5YWH-OEDFIIQ-JUG777G-2YQXXR5-YD6AWQR")
cfg, database, folder := setup(deviceID, dir)
// Arrange
model := NewModel(cfg, database)
flags := uint32(0)
options := []protocol.Option{}
files := []protocol.FileInfo{
protocol.FileInfo{Name: "file1"},
protocol.FileInfo{Name: "file2"},
protocol.FileInfo{Name: "dir1", Flags: protocol.FlagDirectory},
protocol.FileInfo{Name: "dir1/dirfile1"},
protocol.FileInfo{Name: "dir1/dirfile2"},
}
model.Index(deviceID, folder, files, flags, options)
// Act (restart db and model)
databasePath := database.Path()
database.Close()
database, _ = bolt.Open(databasePath, 0600, nil)
model = NewModel(cfg, database)
// Assert
children := model.GetChildren(folder, ".")
assertContainsChild(t, children, "file2", 0)
assertContainsChild(t, children, "file2", 0)
assertContainsChild(t, children, "dir1", protocol.FlagDirectory)
if len(children) != 3 {
t.Error("expected 3 children, but got", len(children))
}
children = model.GetChildren(folder, "dir1")
assertContainsChild(t, children, "dir1/dirfile1", 0)
assertContainsChild(t, children, "dir1/dirfile2", 0)
if len(children) != 2 {
t.Error("expected 2 children, but got", len(children))
}
assertEntry(t, model.GetEntry(folder, "file1"), "file1", 0)
assertEntry(t, model.GetEntry(folder, "file2"), "file2", 0)
assertEntry(t, model.GetEntry(folder, "dir1"), "dir1", protocol.FlagDirectory)
assertEntry(t, model.GetEntry(folder, "dir1/dirfile1"), "dir1/dirfile1", 0)
assertEntry(t, model.GetEntry(folder, "dir1/dirfile2"), "dir1/dirfile2", 0)
}
开发者ID:jk-todo,项目名称:syncthing-fuse,代码行数:50,代码来源:model_test.go
示例12: TestSyncClusterTrashcanVersioning
func TestSyncClusterTrashcanVersioning(t *testing.T) {
// Use simple versioning
id, _ := protocol.DeviceIDFromString(id2)
cfg, _ := config.Load("h2/config.xml", id)
fld := cfg.Folders()["default"]
fld.Versioning = config.VersioningConfiguration{
Type: "trashcan",
Params: map[string]string{"cleanoutDays": "1"},
}
cfg.SetFolder(fld)
cfg.Save()
testSyncCluster(t)
}
开发者ID:raonyguimaraes,项目名称:syncthing,代码行数:14,代码来源:sync_test.go
示例13: TestFileTypeChangeSimpleVersioning
func TestFileTypeChangeSimpleVersioning(t *testing.T) {
// Use simple versioning
id, _ := protocol.DeviceIDFromString(id2)
cfg, _ := config.Load("h2/config.xml", id)
fld := cfg.Folders()["default"]
fld.Versioning = config.VersioningConfiguration{
Type: "simple",
Params: map[string]string{"keep": "5"},
}
cfg.SetFolder(fld)
cfg.Save()
testFileTypeChange(t)
}
开发者ID:wmwwmv,项目名称:syncthing,代码行数:14,代码来源:filetype_test.go
示例14: TestSymlinks
func TestSymlinks(t *testing.T) {
if !symlinksSupported() {
t.Skip("symlinks unsupported")
}
// Use no versioning
id, _ := protocol.DeviceIDFromString(id2)
cfg, _ := config.Load("h2/config.xml", id)
fld := cfg.Folders()["default"]
fld.Versioning = config.VersioningConfiguration{}
cfg.SetFolder(fld)
cfg.Save()
testSymlinks(t)
}
开发者ID:wmwwmv,项目名称:syncthing,代码行数:15,代码来源:symlink_test.go
示例15: getDeviceID
func (s *apiService) getDeviceID(w http.ResponseWriter, r *http.Request) {
qs := r.URL.Query()
idStr := qs.Get("id")
id, err := protocol.DeviceIDFromString(idStr)
if err == nil {
sendJSON(w, map[string]string{
"id": id.String(),
})
} else {
sendJSON(w, map[string]string{
"error": err.Error(),
})
}
}
开发者ID:xduugu,项目名称:syncthing,代码行数:15,代码来源:gui.go
示例16: getDBCompletion
func (s *apiService) getDBCompletion(w http.ResponseWriter, r *http.Request) {
var qs = r.URL.Query()
var folder = qs.Get("folder")
var deviceStr = qs.Get("device")
device, err := protocol.DeviceIDFromString(deviceStr)
if err != nil {
http.Error(w, err.Error(), 500)
return
}
sendJSON(w, map[string]float64{
"completion": s.model.Completion(device, folder),
})
}
开发者ID:xduugu,项目名称:syncthing,代码行数:15,代码来源:gui.go
示例17: getDeviceID
func (s *apiSvc) getDeviceID(w http.ResponseWriter, r *http.Request) {
qs := r.URL.Query()
idStr := qs.Get("id")
id, err := protocol.DeviceIDFromString(idStr)
w.Header().Set("Content-Type", "application/json; charset=utf-8")
if err == nil {
json.NewEncoder(w).Encode(map[string]string{
"id": id.String(),
})
} else {
json.NewEncoder(w).Encode(map[string]string{
"error": err.Error(),
})
}
}
开发者ID:kbreuni,项目名称:syncthing,代码行数:15,代码来源:gui.go
示例18: setup
func setup(t *testing.T, cacheSize string) (*config.Wrapper, *bolt.DB, config.FolderConfiguration) {
dir, _ := ioutil.TempDir("", "stf-mt")
configFile, _ := ioutil.TempFile(dir, "config")
deviceID, _ := protocol.DeviceIDFromString("FFR6LPZ-7K4PTTV-UXQSMUU-CPQ5YWH-OEDFIIQ-JUG777G-2YQXXR5-YD6AWQR")
realCfg := config.New(deviceID)
cfg := config.Wrap(configFile.Name(), realCfg)
databasePath := path.Join(path.Dir(cfg.ConfigPath()), "boltdb")
database, _ := bolt.Open(databasePath, 0600, nil)
folderCfg := config.FolderConfiguration{
ID: folder,
CacheSize: cacheSize,
}
cfg.SetFolder(folderCfg)
return cfg, database, folderCfg
}
开发者ID:jk-todo,项目名称:syncthing-fuse,代码行数:18,代码来源:fileblockcache_test.go
示例19: TestSymlinksSimpleVersioning
func TestSymlinksSimpleVersioning(t *testing.T) {
if !symlinksSupported() {
t.Skip("symlinks unsupported")
}
// Use simple versioning
id, _ := protocol.DeviceIDFromString(id2)
cfg, _ := config.Load("h2/config.xml", id)
fld := cfg.Folders()["default"]
fld.Versioning = config.VersioningConfiguration{
Type: "simple",
Params: map[string]string{"keep": "5"},
}
cfg.SetFolder(fld)
cfg.Save()
testSymlinks(t)
}
开发者ID:wmwwmv,项目名称:syncthing,代码行数:18,代码来源:symlink_test.go
示例20: getDBCompletion
func (s *apiSvc) getDBCompletion(w http.ResponseWriter, r *http.Request) {
var qs = r.URL.Query()
var folder = qs.Get("folder")
var deviceStr = qs.Get("device")
device, err := protocol.DeviceIDFromString(deviceStr)
if err != nil {
http.Error(w, err.Error(), 500)
return
}
res := map[string]float64{
"completion": s.model.Completion(device, folder),
}
w.Header().Set("Content-Type", "application/json; charset=utf-8")
json.NewEncoder(w).Encode(res)
}
开发者ID:kbreuni,项目名称:syncthing,代码行数:18,代码来源:gui.go
注:本文中的github.com/syncthing/syncthing/lib/protocol.DeviceIDFromString函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论