diff --git a/client-peerconn_test.go b/client-peerconn_test.go index a26026f4b0..ab1a7a3fff 100644 --- a/client-peerconn_test.go +++ b/client-peerconn_test.go @@ -1,7 +1,6 @@ package torrent import ( - "errors" "io" "os" "testing" @@ -37,7 +36,7 @@ func TestPeerConnObserverReadStatusOk(t *testing.T) { status := readChannelTimeout(t, cfg.Observers.Peers.PeerStatus, 500*time.Millisecond).(PeerStatus) require.True(t, status.Ok) - require.Nil(t, status.Err) + require.Equal(t, "", status.Err) } func TestPeerConnObserverReadStatusErr(t *testing.T) { @@ -55,13 +54,13 @@ func TestPeerConnObserverReadStatusErr(t *testing.T) { go func() { cfg.Observers.Peers.PeerStatus <- PeerStatus{ - Err: errors.New("test error"), + Err: "test error", } }() status := readChannelTimeout(t, cfg.Observers.Peers.PeerStatus, 500*time.Millisecond).(PeerStatus) require.False(t, status.Ok) - require.EqualError(t, status.Err, "test error") + require.Equal(t, status.Err, "test error") } func TestPeerConnEstablished(t *testing.T) { @@ -92,13 +91,13 @@ func TestPeerConnEstablished(t *testing.T) { // FIXME converting [20]byte to string is not enough to pass the test // require.Equal(t, "12345123451234512345", fmt.Sprintf("%+q", status.Id)) require.True(t, status.Ok) - require.Nil(t, status.Err) + require.Equal(t, "", status.Err) // Peer conn is dropped after transfer is finished. This is the next update we receive. status = readChannelTimeout(t, obs.Peers.PeerStatus, 500*time.Millisecond).(PeerStatus) // TODO a check on PeerID require.False(t, status.Ok) - require.Nil(t, status.Err) + require.Equal(t, "", status.Err) } type ConfigureClient struct { diff --git a/client.go b/client.go index 1592dcbfda..335ab78d93 100644 --- a/client.go +++ b/client.go @@ -1095,11 +1095,19 @@ func (cl *Client) runHandshookConn(c *PeerConn, t *Torrent) error { // TODO here we could send an update to say the PeerConn state connected is true // perhaps could also use c.pex.IsEnabled() or something similar - c.UpdatePeerConnStatus(PeerStatus{c.PeerID, true, nil}) + c.UpdatePeerConnStatus(PeerStatus{ + Id: c.PeerID, + Ok: true, + }) err := c.mainReadLoop() if err != nil { - c.UpdatePeerConnStatus(PeerStatus{c.PeerID, false, err}) + // c.UpdatePeerConnStatus(PeerStatus{c.PeerID, false, err}) + c.UpdatePeerConnStatus(PeerStatus{ + Id: c.PeerID, + Ok: false, + Err: fmt.Sprintf("%s", err), + }) return fmt.Errorf("main read loop: %w", err) } return nil diff --git a/peerconn.go b/peerconn.go index ce087808b2..6df295777b 100644 --- a/peerconn.go +++ b/peerconn.go @@ -35,7 +35,7 @@ import ( type PeerStatus struct { Id PeerID Ok bool - Err error + Err string // see https://github.com/golang/go/issues/5161 } type PeerObserver struct { diff --git a/torrent.go b/torrent.go index 81bc2cf060..4e4356d5ab 100644 --- a/torrent.go +++ b/torrent.go @@ -1596,7 +1596,10 @@ func (t *Torrent) dropConnection(c *PeerConn) { t.cl.event.Broadcast() c.close() - c.UpdatePeerConnStatus(PeerStatus{c.PeerID, false, nil}) + c.UpdatePeerConnStatus(PeerStatus{ + Id: c.PeerID, + Ok: false, + }) t.logger.WithDefaultLevel(log.Debug).Printf("dropping connection to %+q, sent peerconn update", c.PeerID) if t.deletePeerConn(c) {