import (
"context"
- "errors"
"log"
"net"
"time"
//GetDeviceList return device list
func GetDeviceList() ([]DeviceReturnInfo, error) {
- if gServer == nil {
- return nil, errors.New("zeroconf server is nil")
+
+ if err := getPollingOutBoundError(); err != nil {
+ return nil, err
+ }
+
+ //NOTE :
+ //it can be happend, pollingOutbound function is out,
+ //but gServer is not initialized because InitDiscovery go routine
+ for {
+ if IsNilServer() == true {
+ time.Sleep(0)
+ } else {
+ break
+ }
}
gServer.IsInterfaceChange()
//GetDeviceListWithService retune device list
func GetDeviceListWithService(target string) ([]string, error) {
- if gServer == nil {
- return nil, errors.New("zeroconf server is nil")
+
+ if err := getPollingOutBoundError(); err != nil {
+ return nil, err
+ }
+
+ //NOTE :
+ //it can be happend, pollingOutbound function is out,
+ //but gServer is not initialized because InitDiscovery go routine
+ for {
+ if IsNilServer() == true {
+ time.Sleep(0)
+ } else {
+ break
+ }
}
+
gServer.IsInterfaceChange()
zeroconf.MapMTX.Lock()
)
var gServer *zeroconf.Server
+var gPollingError error
//InitDiscovery deploy Orchestration service
func InitDiscovery() (err error) {
ExitPollingOutBoundCh = make(chan int, 1)
ExitChan = make(chan int, 1)
+ //NOTE : Need to gPollingError Because it can call not initialized.
+ _, gPollingError = common.GetOutboundIP()
+
+ log.Println("poilling Errrrrrrrrrrror ", gPollingError)
+
go func() {
gServer, err = registerDevice(getMacAddr(pollGettingOutBoundIP()))
}
func pollGettingOutBoundIP() (string, error) {
+
ticker := time.NewTicker(time.Duration(1) * time.Second)
defer func() { ticker.Stop() }()
select {
case <-ticker.C:
log.Println("pollGettingOutBoundIP")
- ip, _ := common.GetOutboundIP()
+ ip, gPollingError := common.GetOutboundIP()
if len(ip) != 0 {
- return ip, nil
+ return ip, gPollingError
}
case <-ExitPollingOutBoundCh:
log.Printf("ExitPollingOutBoundCh")
- return "", errors.New("polling outboundIP terminated")
+ return "", gPollingError
}
}
}
+
+func getPollingOutBoundError() error {
+ return gPollingError
+}