Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
This repository was archived by the owner on Dec 20, 2024. It is now read-only.

Commit d04b08c

Browse filesBrowse files
define the interface of downloader, data_scheduler, client_stream, register, uploader, data_protocol and url protocol.
Signed-off-by: allen.wq <allen.wq@alipay.com>
1 parent f131b5f commit d04b08c
Copy full SHA for d04b08c

File tree

Expand file treeCollapse file tree

9 files changed

+396
-0
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

9 files changed

+396
-0
lines changed
Open diff view settings
Collapse file

‎dfget/corev2/basic/interface.go‎

Copy file name to clipboard
+34Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright The Dragonfly Authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package basic
18+
19+
// Response defines the response.
20+
type Response interface {
21+
Success() bool
22+
Data() interface{}
23+
}
24+
25+
// RangeRequest defines the range request.
26+
type RangeRequest interface {
27+
URL() string
28+
Offset() int64
29+
Size() int64
30+
Header() map[string]string
31+
32+
// Extra gets the extra info.
33+
Extra() interface{}
34+
}
Collapse file
+31Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright The Dragonfly Authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package clientwriter
18+
19+
import (
20+
"github.com/dragonflyoss/Dragonfly/pkg/protocol"
21+
)
22+
23+
// ClientStream defines how to organize distribution data for range request.
24+
// An instance binds to a range request.
25+
// It may receive a lot of distribution data.
26+
// Developer could add a io.WriteCloser in constructor of instance, and the ClientWriter will
27+
// write request data to io.Writer.
28+
type ClientWriter interface {
29+
// WriteData writes the distribution data from other peers, it may be called more times.
30+
PutData(data protocol.DistributionData) error
31+
}
Collapse file
+65Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright The Dragonfly Authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package datascheduler
18+
19+
import (
20+
"context"
21+
22+
"github.com/dragonflyoss/Dragonfly/dfget/corev2/basic"
23+
24+
strfmt "github.com/go-openapi/strfmt"
25+
)
26+
27+
// PeerInfo represents the target address which is provided the download data.
28+
type PeerInfo struct {
29+
IP strfmt.IPv4
30+
Port int32
31+
Path string
32+
// ID represents the client ID of peer.
33+
ID string
34+
}
35+
36+
// SchedulerResult defines the result of schedule of range data.
37+
type SchedulePieceDataResult struct {
38+
Off int64
39+
Size int64
40+
41+
// PeerInfos represents the schedule peers which to get the range data.
42+
PeerInfos []*PeerInfo
43+
}
44+
45+
// SchedulerResult defines the schedule result of request range.
46+
// For some implementation, developer could do more than one schedule for the same request range.
47+
type SchedulerResult interface {
48+
// Result get the schedule result for range data which may not include all data of request range.
49+
Result() []*SchedulePieceDataResult
50+
51+
// State gets the temporary states of this schedule which binds to range request.
52+
State() ScheduleState
53+
}
54+
55+
// ScheduleState defines the state of this schedule.
56+
type ScheduleState interface {
57+
// Continue tells user if reschedule the request range again.
58+
Continue() bool
59+
}
60+
61+
// DataScheduler defines how to schedule peers for range request.
62+
type DataScheduler interface {
63+
// state should be got from SchedulerResult which is got from last caller for the same range request.
64+
Schedule(ctx context.Context, rr basic.RangeRequest, state ScheduleState) (SchedulerResult, error)
65+
}
Collapse file
+28Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright The Dragonfly Authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package downloader
18+
19+
import (
20+
"context"
21+
"io"
22+
)
23+
24+
// Downloader defines how to download file range from peer/cdn, an instance binds to <task, target address>.
25+
type Downloader interface {
26+
// Download downloads range data.
27+
Download(ctx context.Context, off, size int64) (io.ReadCloser, error)
28+
}
Collapse file

‎dfget/corev2/regist/register.go‎

Copy file name to clipboard
+24Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright The Dragonfly Authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package regist
18+
19+
import "github.com/dragonflyoss/Dragonfly/dfget/corev2/basic"
20+
21+
// SupernodeRegister encapsulates the Register steps into a struct.
22+
type SupernodeRegister interface {
23+
Register(peerPort int) (response basic.Response, err error)
24+
}
Collapse file

‎dfget/corev2/report/reporter.go‎

Copy file name to clipboard
+27Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright The Dragonfly Authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package report
18+
19+
import (
20+
"github.com/dragonflyoss/Dragonfly/dfget/corev2/basic"
21+
"github.com/dragonflyoss/Dragonfly/dfget/locator"
22+
)
23+
24+
// Reporter defines how to report resource to suprnode.
25+
type Reporter interface {
26+
Report(supernode *locator.Supernode) (basic.Response, error)
27+
}
Collapse file

‎dfget/corev2/uploader/uploader.go‎

Copy file name to clipboard
+25Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Copyright The Dragonfly Authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package uploader
18+
19+
import "io"
20+
21+
// Uploader defines how to upload range by path.
22+
type Uploader interface {
23+
// UploadRange defines how to upload range by path.
24+
UploadRange(path string, off, size int64, opt interface{}) (io.ReadCloser, error)
25+
}
Collapse file

‎pkg/protocol/distributiondata.go‎

Copy file name to clipboard
+88Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Copyright The Dragonfly Authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package protocol
18+
19+
import (
20+
"context"
21+
"io"
22+
)
23+
24+
// DataEncoder defines how to encode/decode data.
25+
type DataEncoder interface {
26+
// Encode data.
27+
Encode(io.Reader) (io.Reader, error)
28+
29+
// Decode data.
30+
Decode(io.Reader) (io.Reader, error)
31+
}
32+
33+
// DataType defines the type of DistributionData.
34+
type DataType interface {
35+
// String return the type string.
36+
String() string
37+
38+
// Encoder return the encoder of the type.
39+
Encoder() DataEncoder
40+
}
41+
42+
// DistributionData defines the protocol of distribute data which is exchanged in peers.
43+
type DistributionData interface {
44+
// Type gets the data type.
45+
Type() DataType
46+
47+
// Size gets the size of data.
48+
Size() int64
49+
50+
// Metadata gets the metadata.
51+
Metadata() interface{}
52+
53+
// Content gets the content of data.
54+
Content(ctx context.Context) (io.Reader, error)
55+
}
56+
57+
type eofDataType struct{}
58+
59+
func (ty eofDataType) String() string {
60+
return "EOF"
61+
}
62+
63+
func (ty *eofDataType) Encoder() DataEncoder {
64+
return nil
65+
}
66+
67+
// EOFDistributionData represents the eof of file.
68+
type eofDistributionData struct{}
69+
70+
func (eof *eofDistributionData) Size() int64 {
71+
return 0
72+
}
73+
74+
func (eof *eofDistributionData) Metadata() interface{} {
75+
return nil
76+
}
77+
78+
func (eof *eofDistributionData) Content(ctx context.Context) (io.Reader, error) {
79+
return nil, io.EOF
80+
}
81+
82+
func (eof *eofDistributionData) Type() DataType {
83+
return &eofDataType{}
84+
}
85+
86+
func NewEoFDistributionData() DistributionData {
87+
return &eofDistributionData{}
88+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.