diff --git a/TODO.md b/TODO.md index f6f08f1..49e5fb9 100644 --- a/TODO.md +++ b/TODO.md @@ -14,7 +14,7 @@ - [x] Rework broadcast address as netip.AddrPort - [x] Rework listen address as netip.AddrPort - [x] Set socket.SO_REUSEADDR - - [ ] Rework Address as netip.AddrPort + - [x] Rework Address as netip.AddrPort - [x] Rename to `ControllerAddr` - [x] Rework as struct with embedded netip.AddrPort - [x] uhppote-core @@ -28,8 +28,8 @@ - [x] Rework uhppoted-lib::config Device Address - [x] Rework uhppote-cli::command Device - [x] Rework uhppoted-httpd::controller EndPoint - - [ ] Rework GetListenerResponse to use AddrPort - - Remove types.Listener `// FIXME remove (unused)` + - [x] Remove types.Listener + - [x] Rework Get/SetListener to use AddrPort - [ ] CLI get-devices EOF ``` diff --git a/messages/get_listener.go b/messages/get_listener.go index 17d4037..a18feda 100644 --- a/messages/get_listener.go +++ b/messages/get_listener.go @@ -2,7 +2,7 @@ package messages import ( "github.com/uhppoted/uhppote-core/types" - "net" + "net/netip" ) type GetListenerRequest struct { @@ -13,6 +13,5 @@ type GetListenerRequest struct { type GetListenerResponse struct { MsgType types.MsgType `uhppote:"value:0x92"` SerialNumber types.SerialNumber `uhppote:"offset:4"` - Address net.IP `uhppote:"offset:8"` - Port uint16 `uhppote:"offset:12"` + AddrPort netip.AddrPort `uhppote:"offset:8"` } diff --git a/messages/get_listener_test.go b/messages/get_listener_test.go index 9742b89..671e8e8 100644 --- a/messages/get_listener_test.go +++ b/messages/get_listener_test.go @@ -2,7 +2,7 @@ package messages import ( codec "github.com/uhppoted/uhppote-core/encoding/UTO311-L0x" - "net" + "net/netip" "reflect" "testing" ) @@ -73,19 +73,15 @@ func TestUnmarshalGetListenerResponse(t *testing.T) { } if reply.MsgType != 0x92 { - t.Errorf("Incorrect 'message type' - expected:%02X, got:%02x\n", 0x92, reply.MsgType) + t.Errorf("Incorrect 'message type' - expected:%02X, got:%02x", 0x92, reply.MsgType) } if reply.SerialNumber != 423187757 { - t.Errorf("Incorrect 'serial number' - expected:%v, got:%v\n", 423187757, reply.SerialNumber) + t.Errorf("Incorrect 'serial number' - expected:%v, got:%v", 423187757, reply.SerialNumber) } - if !reflect.DeepEqual(reply.Address, net.IPv4(192, 168, 0, 225)) { - t.Errorf("Incorrect IP address - expected:'%v', got:'%v'\n", net.IPv4(192, 168, 0, 225), reply.Address) - } - - if reply.Port != 9874 { - t.Errorf("Incorrect 'port' - expected:%d, got:%v\n", 9874, reply.Port) + if reply.AddrPort != netip.MustParseAddrPort("192.168.0.225:9874") { + t.Errorf("Incorrect IPv4 address:port - expected:'%v', got:'%v'", netip.MustParseAddrPort("192.168.0.225:9874"), reply.AddrPort) } } @@ -100,8 +96,7 @@ func TestFactoryUnmarshalGetListenerResponse(t *testing.T) { expected := GetListenerResponse{ MsgType: 0x92, SerialNumber: 423187757, - Address: net.IPv4(192, 168, 0, 225), - Port: 9874, + AddrPort: netip.MustParseAddrPort("192.168.0.225:9874"), } response, err := UnmarshalResponse(message) diff --git a/types/listener.go b/types/listener.go deleted file mode 100644 index 3b72aef..0000000 --- a/types/listener.go +++ /dev/null @@ -1,16 +0,0 @@ -package types - -// import ( -// "fmt" -// "net" -// ) -// -// FIXME remove (unused) -// type Listener struct { -// SerialNumber SerialNumber -// Address net.UDPAddr -// } -// -// func (l *Listener) String() string { -// return fmt.Sprintf("%v %v", l.SerialNumber, l.Address) -// } diff --git a/uhppote/get_listener.go b/uhppote/get_listener.go index fe21765..afa76f5 100644 --- a/uhppote/get_listener.go +++ b/uhppote/get_listener.go @@ -20,9 +20,6 @@ func (u *uhppote) GetListener(serialNumber uint32) (netip.AddrPort, error) { if reply, err := sendto[messages.GetListenerResponse](u, serialNumber, request); err != nil { return netip.AddrPort{}, err } else { - addr := reply.Address.To4() - slice := [4]byte{addr[0], addr[1], addr[2], addr[3]} - - return netip.AddrPortFrom(netip.AddrFrom4(slice), reply.Port), nil + return reply.AddrPort, nil } }