]> Sergey Matveev's repositories - btrtrc.git/commitdiff
Allow the client ID to be set in the config
authorMatt Joiner <anacrolix@gmail.com>
Sun, 16 Nov 2014 19:54:43 +0000 (13:54 -0600)
committerMatt Joiner <anacrolix@gmail.com>
Sun, 16 Nov 2014 19:54:43 +0000 (13:54 -0600)
client.go
config.go
fs/torrentfs_test.go

index e5466e22231b44e5d02f486f42d65e55f80be3fa..58458087e2f081186053aefd4ae7c6764129d2ee 100644 (file)
--- 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 {
index 6f954bc5d93591258b64f34a082b3005580f47d5..3b3b08378ff4ccab15ade5b3edfc3e5a8c169f96 100644 (file)
--- a/config.go
+++ b/config.go
@@ -7,4 +7,5 @@ type Config struct {
        DownloadStrategy DownloadStrategy
        NoDHT            bool
        NoUpload         bool
+       PeerID           string
 }
index 45e75acf25b51ced90d596b5b37fa601150b2d9a..8c48a00601603cf53012f93e08c1c4432380da87 100644 (file)
@@ -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)