This repository has been archived by the owner on Feb 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 773
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1343 from antsystem/feat/reconstruct-dfget-interface
Feat/reconstruct dfget interface
- Loading branch information
Showing
9 changed files
with
396 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright The Dragonfly Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package basic | ||
|
||
// Response defines the response. | ||
type Response interface { | ||
Success() bool | ||
Data() interface{} | ||
} | ||
|
||
// RangeRequest defines the range request. | ||
type RangeRequest interface { | ||
URL() string | ||
Offset() int64 | ||
Size() int64 | ||
Header() map[string]string | ||
|
||
// Extra gets the extra info. | ||
Extra() interface{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* Copyright The Dragonfly Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package clientwriter | ||
|
||
import ( | ||
"github.com/dragonflyoss/Dragonfly/pkg/protocol" | ||
) | ||
|
||
// ClientStream defines how to organize distribution data for range request. | ||
// An instance binds to a range request. | ||
// It may receive a lot of distribution data. | ||
// Developer could add a io.WriteCloser in constructor of instance, and the ClientWriter will | ||
// write request data to io.Writer. | ||
type ClientWriter interface { | ||
// WriteData writes the distribution data from other peers, it may be called more times. | ||
PutData(data protocol.DistributionData) error | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright The Dragonfly Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package datascheduler | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/dragonflyoss/Dragonfly/dfget/corev2/basic" | ||
|
||
strfmt "github.com/go-openapi/strfmt" | ||
) | ||
|
||
// PeerInfo represents the target address which is provided the download data. | ||
type PeerInfo struct { | ||
IP strfmt.IPv4 | ||
Port int32 | ||
Path string | ||
// ID represents the client ID of peer. | ||
ID string | ||
} | ||
|
||
// SchedulerResult defines the result of schedule of range data. | ||
type SchedulePieceDataResult struct { | ||
Off int64 | ||
Size int64 | ||
|
||
// PeerInfos represents the schedule peers which to get the range data. | ||
PeerInfos []*PeerInfo | ||
} | ||
|
||
// SchedulerResult defines the schedule result of request range. | ||
// For some implementation, developer could do more than one schedule for the same request range. | ||
type SchedulerResult interface { | ||
// Result get the schedule result for range data which may not include all data of request range. | ||
Result() []*SchedulePieceDataResult | ||
|
||
// State gets the temporary states of this schedule which binds to range request. | ||
State() ScheduleState | ||
} | ||
|
||
// ScheduleState defines the state of this schedule. | ||
type ScheduleState interface { | ||
// Continue tells user if reschedule the request range again. | ||
Continue() bool | ||
} | ||
|
||
// DataScheduler defines how to schedule peers for range request. | ||
type DataScheduler interface { | ||
// state should be got from SchedulerResult which is got from last caller for the same range request. | ||
Schedule(ctx context.Context, rr basic.RangeRequest, state ScheduleState) (SchedulerResult, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Copyright The Dragonfly Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package downloader | ||
|
||
import ( | ||
"context" | ||
"io" | ||
) | ||
|
||
// Downloader defines how to download file range from peer/cdn, an instance binds to <task, target address>. | ||
type Downloader interface { | ||
// Download downloads range data. | ||
Download(ctx context.Context, off, size int64) (io.ReadCloser, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Copyright The Dragonfly Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package regist | ||
|
||
import "github.com/dragonflyoss/Dragonfly/dfget/corev2/basic" | ||
|
||
// SupernodeRegister encapsulates the Register steps into a struct. | ||
type SupernodeRegister interface { | ||
Register(peerPort int) (response basic.Response, err error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Copyright The Dragonfly Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package report | ||
|
||
import ( | ||
"github.com/dragonflyoss/Dragonfly/dfget/corev2/basic" | ||
"github.com/dragonflyoss/Dragonfly/dfget/locator" | ||
) | ||
|
||
// Reporter defines how to report resource to suprnode. | ||
type Reporter interface { | ||
Report(supernode *locator.Supernode) (basic.Response, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/* | ||
* Copyright The Dragonfly Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package uploader | ||
|
||
import "io" | ||
|
||
// Uploader defines how to upload range by path. | ||
type Uploader interface { | ||
// UploadRange defines how to upload range by path. | ||
UploadRange(path string, off, size int64, opt interface{}) (io.ReadCloser, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Copyright The Dragonfly Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package protocol | ||
|
||
import ( | ||
"context" | ||
"io" | ||
) | ||
|
||
// DataEncoder defines how to encode/decode data. | ||
type DataEncoder interface { | ||
// Encode data. | ||
Encode(io.Reader) (io.Reader, error) | ||
|
||
// Decode data. | ||
Decode(io.Reader) (io.Reader, error) | ||
} | ||
|
||
// DataType defines the type of DistributionData. | ||
type DataType interface { | ||
// String return the type string. | ||
String() string | ||
|
||
// Encoder return the encoder of the type. | ||
Encoder() DataEncoder | ||
} | ||
|
||
// DistributionData defines the protocol of distribute data which is exchanged in peers. | ||
type DistributionData interface { | ||
// Type gets the data type. | ||
Type() DataType | ||
|
||
// Size gets the size of data. | ||
Size() int64 | ||
|
||
// Metadata gets the metadata. | ||
Metadata() interface{} | ||
|
||
// Content gets the content of data. | ||
Content(ctx context.Context) (io.Reader, error) | ||
} | ||
|
||
type eofDataType struct{} | ||
|
||
func (ty eofDataType) String() string { | ||
return "EOF" | ||
} | ||
|
||
func (ty *eofDataType) Encoder() DataEncoder { | ||
return nil | ||
} | ||
|
||
// EOFDistributionData represents the eof of file. | ||
type eofDistributionData struct{} | ||
|
||
func (eof *eofDistributionData) Size() int64 { | ||
return 0 | ||
} | ||
|
||
func (eof *eofDistributionData) Metadata() interface{} { | ||
return nil | ||
} | ||
|
||
func (eof *eofDistributionData) Content(ctx context.Context) (io.Reader, error) { | ||
return nil, io.EOF | ||
} | ||
|
||
func (eof *eofDistributionData) Type() DataType { | ||
return &eofDataType{} | ||
} | ||
|
||
func NewEoFDistributionData() DistributionData { | ||
return &eofDistributionData{} | ||
} |
Oops, something went wrong.