]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Expose StringAddr
authorMatt Joiner <anacrolix@gmail.com>
Mon, 3 Apr 2023 05:10:54 +0000 (15:10 +1000)
committerMatt Joiner <anacrolix@gmail.com>
Mon, 3 Apr 2023 05:10:54 +0000 (15:10 +1000)
client.go
string-addr.go [new file with mode: 0644]

index c66a65a095845b3244ad00cf68eda833e85e3a90..4d6761a8582e7e46beb14fc96d59efa74f18dfcb 100644 (file)
--- a/client.go
+++ b/client.go
@@ -1313,13 +1313,6 @@ func (cl *Client) AddTorrentSpec(spec *TorrentSpec) (t *Torrent, new bool, err e
        return
 }
 
-type stringAddr string
-
-var _ net.Addr = stringAddr("")
-
-func (stringAddr) Network() string   { return "" }
-func (me stringAddr) String() string { return string(me) }
-
 // The trackers will be merged with the existing ones. If the Info isn't yet known, it will be set.
 // spec.DisallowDataDownload/Upload will be read and applied
 // The display name is replaced if the new spec provides one. Note that any `Storage` is ignored.
@@ -1344,7 +1337,7 @@ func (t *Torrent) MergeSpec(spec *TorrentSpec) error {
        }
        for _, peerAddr := range spec.PeerAddrs {
                t.addPeer(PeerInfo{
-                       Addr:    stringAddr(peerAddr),
+                       Addr:    StringAddr(peerAddr),
                        Source:  PeerSourceDirect,
                        Trusted: true,
                })
diff --git a/string-addr.go b/string-addr.go
new file mode 100644 (file)
index 0000000..c124541
--- /dev/null
@@ -0,0 +1,11 @@
+package torrent
+
+import "net"
+
+// This adds a net.Addr interface to a string address that has no presumed Network.
+type StringAddr string
+
+var _ net.Addr = StringAddr("")
+
+func (StringAddr) Network() string   { return "" }
+func (me StringAddr) String() string { return string(me) }