Skip to content
This repository has been archived by the owner on Dec 20, 2024. It is now read-only.

[Fix] Supernode local cdn connet check is not necessary when --cdnPattern=s… #1518

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dfget/core/downloader/p2p_downloader/power_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (pc *PowerClient) downloadPiece() (content *pool.Buffer, e error) {
peerPort := pc.pieceTask.PeerPort

// check that the target download peer is available
if dstIP != "" && dstIP != pc.node {
if dstIP != "" && dstIP != pc.node && pc.pieceTask.Path != pc.cfg.URL {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use pc.cdnSource != apiTypes.CdnSourceSource is better? WDYT?

Copy link
Author

@PWZER PWZER Dec 11, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@starnop There are three scenarios.

  • pc.cdnSource == apiTypes.CdnSourceSource && dstIP != supernodeIp, connect check is very necessary.
  • Only pc.pieceTask.Path != pc.cfg.URL, need download piece from other peer, and dstIP != supernodeIp, connect check is very necessary.
  • Only pc.pieceTask.Path == pc.cfg.URL, need download piece from source,and dstIP == supernodeIp, connect check is not necessary.

if _, e = httputils.CheckConnect(dstIP, peerPort, -1); e != nil {
return nil, e
}
Expand Down
17 changes: 14 additions & 3 deletions dfget/core/downloader/p2p_downloader/power_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,14 @@ func (s *PowerClientTestSuite) TearDownTest(c *check.C) {
}

func (s *PowerClientTestSuite) TestDownloadPiece(c *check.C) {
// dstIP != pc.node && CheckConnect Fail
// dstIP != pc.node && pc.pieceTask.Path != pc.cfg.URL && CheckConnect Fail
s.powerClient.pieceTask.PeerIP = "127.0.0.2"
content, err := s.powerClient.downloadPiece()
c.Check(content, check.IsNil)
c.Check(err, check.NotNil)
s.reset()

// dstIP != pc.node && CheckConnect Success && Download Fail
// dstIP != pc.node && pc.pieceTask.Path != pc.cfg.URL && CheckConnect Success && Download Fail
s.powerClient.node = "127.0.0.2"
downloadMock = func() (*http.Response, error) {
return nil, fmt.Errorf("error")
Expand All @@ -75,6 +75,17 @@ func (s *PowerClientTestSuite) TestDownloadPiece(c *check.C) {
c.Check(err, check.DeepEquals, fmt.Errorf("error"))
s.reset()

// dstIP != pc.node && pc.pieceTask.Path == pc.cfg.URL && Download Fail
s.powerClient.node = "127.0.0.3"
s.powerClient.pieceTask.Path = s.powerClient.cfg.URL
downloadMock = func() (*http.Response, error) {
return nil, fmt.Errorf("error")
}
content, err = s.powerClient.downloadPiece()
c.Check(content, check.IsNil)
c.Check(err, check.DeepEquals, fmt.Errorf("error"))
s.reset()

// dstIP == pc.node && Download Success && StatusCode == 416
body1 := ioutil.NopCloser(bytes.NewReader([]byte("RangeNotSatisfiable")))
defer func() {
Expand Down Expand Up @@ -162,7 +173,7 @@ func (s *PowerClientTestSuite) TestReadBody(c *check.C) {

func (s *PowerClientTestSuite) reset() {
s.powerClient = &PowerClient{
cfg: &config.Config{RV: config.RuntimeVariable{Cid: ""}},
cfg: &config.Config{RV: config.RuntimeVariable{Cid: ""}, URL: "http://127.0.0.1/"},
node: "127.0.0.1",
rateLimiter: ratelimiter.NewRateLimiter(int64(5), 2),
downloadAPI: NewMockDownloadAPI(),
Expand Down