本文整理汇总了Golang中github.com/syncthing/syncthing/lib/discover.NewLocal函数的典型用法代码示例。如果您正苦于以下问题:Golang NewLocal函数的具体用法?Golang NewLocal怎么用?Golang NewLocal使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewLocal函数的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: syncthingMain
//.........这里部分代码省略.........
}
// Start relay management
var relaySvc *relay.Svc
if opts.RelaysEnabled && (opts.GlobalAnnEnabled || opts.RelayWithoutGlobalAnn) {
relaySvc = relay.NewSvc(cfg, tlsCfg)
mainSvc.Add(relaySvc)
}
// Start discovery
cachedDiscovery := discover.NewCachingMux()
mainSvc.Add(cachedDiscovery)
if cfg.Options().GlobalAnnEnabled {
for _, srv := range cfg.GlobalDiscoveryServers() {
l.Infoln("Using discovery server", srv)
gd, err := discover.NewGlobal(srv, cert, addrList, relaySvc)
if err != nil {
l.Warnln("Global discovery:", err)
continue
}
// Each global discovery server gets its results cached for five
// minutes, and is not asked again for a minute when it's returned
// unsuccessfully.
cachedDiscovery.Add(gd, 5*time.Minute, time.Minute, globalDiscoveryPriority)
}
}
if cfg.Options().LocalAnnEnabled {
// v4 broadcasts
bcd, err := discover.NewLocal(myID, fmt.Sprintf(":%d", cfg.Options().LocalAnnPort), addrList, relaySvc)
if err != nil {
l.Warnln("IPv4 local discovery:", err)
} else {
cachedDiscovery.Add(bcd, 0, 0, ipv4LocalDiscoveryPriority)
}
// v6 multicasts
mcd, err := discover.NewLocal(myID, cfg.Options().LocalAnnMCAddr, addrList, relaySvc)
if err != nil {
l.Warnln("IPv6 local discovery:", err)
} else {
cachedDiscovery.Add(mcd, 0, 0, ipv6LocalDiscoveryPriority)
}
}
// GUI
setupGUI(mainSvc, cfg, m, apiSub, cachedDiscovery, relaySvc, errors, systemLog)
// Start connection management
connectionSvc := connections.NewConnectionSvc(cfg, myID, m, tlsCfg, cachedDiscovery, relaySvc, bepProtocolName, tlsDefaultCommonName, lans)
mainSvc.Add(connectionSvc)
if cpuProfile {
f, err := os.Create(fmt.Sprintf("cpu-%d.pprof", os.Getpid()))
if err != nil {
log.Fatal(err)
}
pprof.StartCPUProfile(f)
}
for _, device := range cfg.Devices() {
示例2: main
func main() {
flag.BoolVar(&showVersion, "version", false, "Show version")
flag.Usage = usageFor(flag.CommandLine, usage, fmt.Sprintf(extraUsage, baseDirs["config"]))
flag.Parse()
if showVersion {
fmt.Println(Version)
return
}
if err := expandLocations(); err != nil {
l.Fatalln(err)
}
// Ensure that our home directory exists.
ensureDir(baseDirs["config"], 0700)
// Ensure that that we have a certificate and key.
tlsCfg, cert := getTlsConfig()
// We reinitialize the predictable RNG with our device ID, to get a
// sequence that is always the same but unique to this syncthing instance.
predictableRandom.Seed(seedFromBytes(cert.Certificate[0]))
myID = protocol.NewDeviceID(cert.Certificate[0])
l.SetPrefix(fmt.Sprintf("[%s] ", myID.String()[:5]))
l.Infoln("Started syncthingfuse v.", LongVersion)
l.Infoln("My ID:", myID)
cfg := getConfiguration()
if info, err := os.Stat(cfg.Raw().MountPoint); err == nil {
if !info.Mode().IsDir() {
l.Fatalln("Mount point (", cfg.Raw().MountPoint, ") must be a directory, but isn't")
os.Exit(1)
}
} else {
l.Infoln("Mount point (", cfg.Raw().MountPoint, ") does not exist, creating it")
err = os.MkdirAll(cfg.Raw().MountPoint, 0700)
if err != nil {
l.Warnln("Error creating mount point", cfg.Raw().MountPoint, err)
l.Warnln("Sometimes, SyncthingFUSE doesn't shut down and unmount cleanly,")
l.Warnln("If you don't know of any other file systems you have mounted at")
l.Warnln("the mount point, try running the command below to unmount, then")
l.Warnln("start SyncthingFUSE again.")
l.Warnln(" umount", cfg.Raw().MountPoint)
l.Fatalln("Cannot create missing mount point")
os.Exit(1)
}
}
mainSvc := suture.New("main", suture.Spec{
Log: func(line string) {
l.Debugln(line)
},
})
mainSvc.ServeBackground()
database := openDatabase(cfg)
m = model.NewModel(cfg, database)
lans, _ := osutil.GetLans()
// Start discovery
cachedDiscovery := discover.NewCachingMux()
mainSvc.Add(cachedDiscovery)
// Start connection management
connectionsService := connections.NewService(cfg.AsStCfg(myID), myID, m, tlsCfg, cachedDiscovery, bepProtocolName, tlsDefaultCommonName, lans)
mainSvc.Add(connectionsService)
if cfg.Raw().Options.GlobalAnnounceEnabled {
for _, srv := range cfg.Raw().Options.GlobalAnnounceServers {
l.Infoln("Using discovery server", srv)
gd, err := discover.NewGlobal(srv, cert, connectionsService)
if err != nil {
l.Warnln("Global discovery:", err)
continue
}
// Each global discovery server gets its results cached for five
// minutes, and is not asked again for a minute when it's returned
// unsuccessfully.
cachedDiscovery.Add(gd, 5*time.Minute, time.Minute, globalDiscoveryPriority)
}
}
if cfg.Raw().Options.LocalAnnounceEnabled {
// v4 broadcasts
bcd, err := discover.NewLocal(myID, fmt.Sprintf(":%d", cfg.Raw().Options.LocalAnnouncePort), connectionsService)
if err != nil {
l.Warnln("IPv4 local discovery:", err)
} else {
cachedDiscovery.Add(bcd, 0, 0, ipv4LocalDiscoveryPriority)
}
// v6 multicasts
mcd, err := discover.NewLocal(myID, cfg.Raw().Options.LocalAnnounceMCAddr, connectionsService)
//.........这里部分代码省略.........