Skip to content

Commit b48cacd

Browse files
committed
Upgraded github.com/arduino/pluggable-discovery-protocol-handler
1 parent 1872894 commit b48cacd

File tree

3 files changed

+26
-26
lines changed

3 files changed

+26
-26
lines changed

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
module github.com/arduino/mdns-discovery
22

3-
go 1.14
3+
go 1.16
44

55
require (
6-
github.com/arduino/dummy-discovery v0.0.0-20210716130621-0e4004fbbf45
7-
github.com/arduino/go-paths-helper v1.3.2 // indirect
8-
github.com/arduino/go-properties-orderedmap v1.4.0
6+
github.com/arduino/go-paths-helper v1.6.1 // indirect
7+
github.com/arduino/go-properties-orderedmap v1.5.0
8+
github.com/arduino/pluggable-discovery-protocol-handler v1.1.0
99
github.com/brutella/dnssd v1.1.1
1010
github.com/miekg/dns v1.1.31 // indirect
1111
golang.org/x/crypto v0.0.0-20201002094018-c90954cbb977 // indirect

go.sum

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
github.com/arduino/dummy-discovery v0.0.0-20210716130621-0e4004fbbf45 h1:AkEBCu52hdOSIkdWxPGXDtSK+LLzsM/wdjnEfORa6XY=
2-
github.com/arduino/dummy-discovery v0.0.0-20210716130621-0e4004fbbf45/go.mod h1:9FI6/M3oPEn96pdNlDTjlU5MBFQ7OE+A8UB+tA/uD40=
31
github.com/arduino/go-paths-helper v1.0.1/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3v5YYu35Yb+w31Ck=
4-
github.com/arduino/go-paths-helper v1.3.2 h1:5U9TSKQODiwSVgTxskC0PNl0l0Vf40GUlp99Zy2SK8w=
5-
github.com/arduino/go-paths-helper v1.3.2/go.mod h1:HpxtKph+g238EJHq4geEPv9p+gl3v5YYu35Yb+w31Ck=
6-
github.com/arduino/go-properties-orderedmap v1.4.0 h1:YEbbzPqm1gXWDM/Jaq8tlvmh09z2qeHPJTUw9/VA4Dk=
2+
github.com/arduino/go-paths-helper v1.6.1 h1:lha+/BuuBsx0qTZ3gy6IO1kU23lObWdQ/UItkzVWQ+0=
3+
github.com/arduino/go-paths-helper v1.6.1/go.mod h1:V82BWgAAp4IbmlybxQdk9Bpkz8M4Qyx+RAFKaG9NuvU=
74
github.com/arduino/go-properties-orderedmap v1.4.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk=
5+
github.com/arduino/go-properties-orderedmap v1.5.0 h1:istmr13qQN3nneuU3lsqlMvI6jqB3u8QUfVU1tX/t/8=
6+
github.com/arduino/go-properties-orderedmap v1.5.0/go.mod h1:DKjD2VXY/NZmlingh4lSFMEYCVubfeArCsGPGDwb2yk=
7+
github.com/arduino/pluggable-discovery-protocol-handler v1.1.0 h1:/fYOQ9f6beV9+mv9rDs+kvkhNKJ1edIT0RvIRj5Jj4U=
8+
github.com/arduino/pluggable-discovery-protocol-handler v1.1.0/go.mod h1:vQfYGJnunfcscLoUcZKqJBlEkZ/qiE28TQj+RV9UT74=
89
github.com/brutella/dnssd v1.1.1 h1:Ar5ytE2Z9x5DTmuNnASlMTBpcQWQLm9ceHb326s0ykg=
910
github.com/brutella/dnssd v1.1.1/go.mod h1:9gIcMKQSJvYlO2x+HR50cqqjghb9IWK9hvykmyveVVs=
1011
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
1112
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
1213
github.com/miekg/dns v1.1.1/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
1314
github.com/miekg/dns v1.1.31 h1:sJFOl9BgwbYAWOGEwr61FU28pqsBNdpRBnhGXtO06Oo=
1415
github.com/miekg/dns v1.1.31/go.mod h1:KNUDUusw/aVsxyTYZM1oqvCicbwhgbNgztCETuNZ7xM=
16+
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
17+
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
1518
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
1619
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
1720
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=

main.go

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@ package main
1919

2020
import (
2121
"context"
22-
"fmt"
2322
"os"
2423
"strconv"
2524

26-
discovery "github.com/arduino/dummy-discovery"
2725
properties "github.com/arduino/go-properties-orderedmap"
26+
discovery "github.com/arduino/pluggable-discovery-protocol-handler"
2827
"github.com/brutella/dnssd"
2928
)
3029

@@ -38,7 +37,7 @@ func main() {
3837
const mdnsServiceName = "_arduino._tcp.local."
3938

4039
type MDNSDiscovery struct {
41-
started bool
40+
cancelFunc func()
4241
}
4342

4443
func (d *MDNSDiscovery) Hello(userAgent string, protocolVersion int) error {
@@ -50,14 +49,21 @@ func (d *MDNSDiscovery) Start() error {
5049
}
5150

5251
func (d *MDNSDiscovery) Stop() error {
52+
if d.cancelFunc != nil {
53+
d.cancelFunc()
54+
d.cancelFunc = nil
55+
}
5356
return nil
5457
}
5558

59+
func (d *MDNSDiscovery) Quit() {
60+
}
61+
5662
func (d *MDNSDiscovery) List() ([]*discovery.Port, error) {
5763
return []*discovery.Port{}, nil
5864
}
5965

60-
func (d *MDNSDiscovery) StartSync(eventCB discovery.EventCallback) (chan<- bool, error) {
66+
func (d *MDNSDiscovery) StartSync(eventCB discovery.EventCallback, errorCB discovery.ErrorCallback) error {
6167
addFn := func(srv dnssd.Service) {
6268
eventCB("add", newBoardPortJSON(&srv))
6369
}
@@ -68,20 +74,11 @@ func (d *MDNSDiscovery) StartSync(eventCB discovery.EventCallback) (chan<- bool,
6874

6975
go func() {
7076
if err := dnssd.LookupType(ctx, mdnsServiceName, addFn, remFn); err != nil {
71-
_ = err // TODO: report ERROR
77+
errorCB("mdns lookup error: " + err.Error())
7278
}
73-
fmt.Println("CANCELED!")
7479
}()
75-
76-
closeChan := make(chan bool)
77-
go func() {
78-
for range closeChan {
79-
cancel()
80-
return
81-
}
82-
}()
83-
84-
return closeChan, nil
80+
d.cancelFunc = cancel
81+
return nil
8582
}
8683

8784
func newBoardPortJSON(port *dnssd.Service) *discovery.Port {
@@ -91,7 +88,7 @@ func newBoardPortJSON(port *dnssd.Service) *discovery.Port {
9188
}
9289

9390
props := properties.NewMap()
94-
props.Set("ttl", port.TTL.String())
91+
props.Set("ttl", strconv.Itoa(int(port.TTL.Seconds())))
9592
props.Set("hostname", port.Hostname())
9693
props.Set("port", strconv.Itoa(port.Port))
9794
for key, value := range port.Text {

0 commit comments

Comments
 (0)