-
-
Notifications
You must be signed in to change notification settings - Fork 634
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract HTTP tracker client into separate package
- Loading branch information
Showing
8 changed files
with
130 additions
and
89 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1 @@ | ||
package tracker | ||
|
||
import ( | ||
"expvar" | ||
) | ||
|
||
var vars = expvar.NewMap("tracker") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package http | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
|
||
"github.com/anacrolix/dht/v2/krpc" | ||
) | ||
|
||
type Peer struct { | ||
IP net.IP | ||
Port int | ||
ID []byte | ||
} | ||
|
||
func (p Peer) String() string { | ||
loc := net.JoinHostPort(p.IP.String(), fmt.Sprintf("%d", p.Port)) | ||
if len(p.ID) != 0 { | ||
return fmt.Sprintf("%x at %s", p.ID, loc) | ||
} else { | ||
return loc | ||
} | ||
} | ||
|
||
// Set from the non-compact form in BEP 3. | ||
func (p *Peer) FromDictInterface(d map[string]interface{}) { | ||
p.IP = net.ParseIP(d["ip"].(string)) | ||
if _, ok := d["peer id"]; ok { | ||
p.ID = []byte(d["peer id"].(string)) | ||
} | ||
p.Port = int(d["port"].(int64)) | ||
} | ||
|
||
func (p Peer) FromNodeAddr(na krpc.NodeAddr) Peer { | ||
p.IP = na.IP | ||
p.Port = na.Port | ||
return p | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1 @@ | ||
package tracker | ||
|
||
import ( | ||
"fmt" | ||
"net" | ||
|
||
"github.com/anacrolix/dht/v2/krpc" | ||
) | ||
|
||
type Peer struct { | ||
IP net.IP | ||
Port int | ||
ID []byte | ||
} | ||
|
||
func (p Peer) String() string { | ||
loc := net.JoinHostPort(p.IP.String(), fmt.Sprintf("%d", p.Port)) | ||
if len(p.ID) != 0 { | ||
return fmt.Sprintf("%x at %s", p.ID, loc) | ||
} else { | ||
return loc | ||
} | ||
} | ||
|
||
// Set from the non-compact form in BEP 3. | ||
func (p *Peer) FromDictInterface(d map[string]interface{}) { | ||
p.IP = net.ParseIP(d["ip"].(string)) | ||
if _, ok := d["peer id"]; ok { | ||
p.ID = []byte(d["peer id"].(string)) | ||
} | ||
p.Port = int(d["port"].(int64)) | ||
} | ||
|
||
func (p Peer) FromNodeAddr(na krpc.NodeAddr) Peer { | ||
p.IP = na.IP | ||
p.Port = na.Port | ||
return p | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package shared | ||
|
||
import "github.com/anacrolix/torrent/tracker/udp" | ||
|
||
const ( | ||
None udp.AnnounceEvent = iota | ||
Completed // The local peer just completed the torrent. | ||
Started // The local peer has just resumed this torrent. | ||
Stopped // The local peer is leaving the swarm. | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters