-func register(tracker string, tr *TrackerRegistration) error {
- conn, err := net.Dial("udp", tracker)
+// Dialer interface to abstract the dialing operation
+type Dialer interface {
+ Dial(network, address string) (net.Conn, error)
+}
+
+// RealDialer is the real implementation of the Dialer interface
+type RealDialer struct{}
+
+func (d *RealDialer) Dial(network, address string) (net.Conn, error) {
+ return net.Dial(network, address)
+}
+
+func register(dialer Dialer, tracker string, tr io.Reader) error {
+ conn, err := dialer.Dial("udp", tracker)