From: Matt Joiner Date: Sun, 16 Nov 2014 19:54:43 +0000 (-0600) Subject: Allow the client ID to be set in the config X-Git-Tag: v1.0.0~1537 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=77e064a0f5f09d3afb4345fa380d643128c46577;p=btrtrc.git Allow the client ID to be set in the config --- diff --git a/client.go b/client.go index e5466e22..58458087 100644 --- a/client.go +++ b/client.go @@ -134,6 +134,10 @@ type Client struct { dataWaits map[*torrent][]dataWait } +func (me *Client) PeerID() string { + return string(me.peerID[:]) +} + func (me *Client) ListenAddr() (addr net.Addr) { for _, l := range me.listeners { if addr != nil && l.Addr().String() != addr.String() { @@ -260,10 +264,14 @@ func NewClient(cfg *Config) (cl *Client, err error) { cl.event.L = &cl.mu cl.mu.Init(2) - o := copy(cl.peerID[:], BEP20) - _, err = rand.Read(cl.peerID[o:]) - if err != nil { - panic("error generating peer id") + if cfg.PeerID != "" { + CopyExact(&cl.peerID, cfg.PeerID) + } else { + o := copy(cl.peerID[:], BEP20) + _, err = rand.Read(cl.peerID[o:]) + if err != nil { + panic("error generating peer id") + } } if cl.downloadStrategy == nil { diff --git a/config.go b/config.go index 6f954bc5..3b3b0837 100644 --- a/config.go +++ b/config.go @@ -7,4 +7,5 @@ type Config struct { DownloadStrategy DownloadStrategy NoDHT bool NoUpload bool + PeerID string } diff --git a/fs/torrentfs_test.go b/fs/torrentfs_test.go index 45e75acf..8c48a006 100644 --- a/fs/torrentfs_test.go +++ b/fs/torrentfs_test.go @@ -152,6 +152,11 @@ func TestDownloadOnDemand(t *testing.T) { DownloadStrategy: torrent.NewResponsiveDownloadStrategy(0), DisableTrackers: true, NoDHT: true, + + // This can be used to check if clients can connect to other clients + // with the same ID. + + // PeerID: seeder.PeerID(), }) http.HandleFunc("/leecher", func(w http.ResponseWriter, req *http.Request) { leecher.WriteStatus(w)