Skip to content

Commit

Permalink
fix: discovery mode netscan when using docker-compose (#176)
Browse files Browse the repository at this point in the history
Signed-off-by: edgego <tianxingguo@gmail.com>
  • Loading branch information
edgego authored Oct 12, 2022
1 parent bca8455 commit 6644798
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions internal/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,11 @@ func (d *Driver) addProvisionWatchers() error {

var errs []error
for _, file := range files {
// skip all directories, and files that do not end with .json
if file.IsDir() || !strings.HasSuffix(file.Name(), ".json") {
continue
}

filename := filepath.Join(provisionWatcherFolder, file.Name())
d.lc.Debugf("processing %s", filename)
var watcher dtos.ProvisionWatcher
Expand Down
8 changes: 4 additions & 4 deletions internal/driver/onvifdiscovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ func (d *Driver) createDiscoveredDevice(onvifDevice onvif.Device) (sdkModel.Disc
device.Protocols[OnvifProtocol][LastSeen] = time.Now().Format(time.UnixDate)
device.Protocols[OnvifProtocol][FriendlyName] = devInfo.Manufacturer + " " + devInfo.Model

// Spaces are not allowed in the device name
// Spaces and slashes are not allowed in the device name
deviceName := fmt.Sprintf("%s-%s-%s",
strings.ReplaceAll(devInfo.Manufacturer, " ", "-"),
strings.ReplaceAll(devInfo.Model, " ", "-"),
strings.ReplaceAll(strings.ReplaceAll(devInfo.Model, "/", "-"), " ", "-"),
endpointRefAddr)

netInfo, err := d.getNetworkInterfaces(device)
Expand Down Expand Up @@ -189,9 +189,9 @@ func executeRawProbe(conn net.Conn, params netscan.Params) ([]onvif.Device, erro

var responses []string
buf := make([]byte, bufSize)
// keep reading from the PacketConn until the read deadline expires or an error occurs
// keep reading responses from the connection until the read deadline expires or an error occurs
for {
n, _, err := (conn.(net.PacketConn)).ReadFrom(buf)
n, err := conn.Read(buf)
if err != nil {
// ErrDeadlineExceeded is expected once the read timeout is expired
if !stdErrors.Is(err, os.ErrDeadlineExceeded) {
Expand Down

0 comments on commit 6644798

Please # to comment.