helper

package
v1.0.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 20, 2020 License: Apache-2.0 Imports: 20 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateConfig

func CreateConfig(writer io.Writer, workHome string) *config.Config

CreateConfig creates a temporary config.

func CreateRandomString

func CreateRandomString(cap int) string

CreateRandomString creates a random string of specified length.

func CreateTestFile

func CreateTestFile(path string, content string) error

CreateTestFile creates a temp file and write a string.

func CreateTestFileWithMD5

func CreateTestFileWithMD5(path string, content string) string

CreateTestFileWithMD5 creates a temp file and write a string and return the md5 of the file.

func GetServiceFile

func GetServiceFile(taskFileName, dataDir string) string

GetServiceFile returns file path of service file.

func GetTaskFile

func GetTaskFile(taskFileName, dataDir string) string

GetTaskFile returns file path of task file.

func GetTaskName

func GetTaskName(serviceFile string) string

GetTaskName extracts and returns task name from serviceFile.

func IsCDN

func IsCDN(pattern string) bool

IsCDN returns whether the pattern is PatternCDN.

func IsP2P

func IsP2P(pattern string) bool

IsP2P returns whether the pattern is PatternP2P.

func IsSource

func IsSource(pattern string) bool

IsSource returns whether the pattern is PatternSource.

Types

type ClientErrorFuncType added in v0.3.1

type ClientErrorFuncType func(ip string, req *types.ClientErrorRequest) (*types.BaseResponse, error)

ClientErrorFuncType function type of SupernodeAPI#ReportClientError

type MockFileServer added in v1.0.1

type MockFileServer struct {
	sync.Mutex
	Port int
	// contains filtered or unexported fields
}

MockFileServer mocks the file server.

func NewMockFileServer added in v1.0.1

func NewMockFileServer() *MockFileServer

func (*MockFileServer) MockResp added in v1.0.1

func (fs *MockFileServer) MockResp(resp http.ResponseWriter, mf *mockFile, rangeSt *httputils.RangeStruct)

func (*MockFileServer) RegisterFile added in v1.0.1

func (fs *MockFileServer) RegisterFile(path string, size int64, repeatStr string) error

func (*MockFileServer) ServeHTTP added in v1.0.1

func (fs *MockFileServer) ServeHTTP(resp http.ResponseWriter, req *http.Request)

func (*MockFileServer) StartServer added in v1.0.1

func (fs *MockFileServer) StartServer(ctx context.Context, port int) error

StartServer asynchronously starts the server, it will not be blocked.

func (*MockFileServer) UnRegisterFile added in v1.0.1

func (fs *MockFileServer) UnRegisterFile(path string)

type MockSupernodeAPI

type MockSupernodeAPI struct {
	RegisterFunc      RegisterFuncType
	PullFunc          PullFuncType
	ReportFunc        ReportFuncType
	ServiceDownFunc   ServiceDownFuncType
	ClientErrorFunc   ClientErrorFuncType
	ReportMetricsFunc ReportMetricsFuncType
}

MockSupernodeAPI mocks the SupernodeAPI.

func (*MockSupernodeAPI) ApplyForSeedNode added in v1.0.5

func (m *MockSupernodeAPI) ApplyForSeedNode(node string, req *types.RegisterRequest) (resp *types.RegisterResponse, err error)

func (*MockSupernodeAPI) FetchP2PNetworkInfo added in v1.0.5

func (m *MockSupernodeAPI) FetchP2PNetworkInfo(node string, start int, limit int, req *api_types.NetworkInfoFetchRequest) (resp *api_types.NetworkInfoFetchResponse, e error)

func (*MockSupernodeAPI) HeartBeat added in v1.0.5

func (m *MockSupernodeAPI) HeartBeat(node string, req *api_types.HeartBeatRequest) (resp *types.HeartBeatResponse, err error)

func (*MockSupernodeAPI) PullPieceTask

PullPieceTask implements SupernodeAPI#PullPiece.

func (*MockSupernodeAPI) Register

Register implements SupernodeAPI#Register.

func (*MockSupernodeAPI) ReportClientError added in v0.3.1

func (m *MockSupernodeAPI) ReportClientError(ip string, req *types.ClientErrorRequest) (resp *types.BaseResponse, e error)

ReportClientError implements SupernodeAPI#ReportClientError.

func (*MockSupernodeAPI) ReportMetrics added in v1.0.0

func (m *MockSupernodeAPI) ReportMetrics(ip string, req *api_types.TaskMetricsRequest) (resp *types.BaseResponse, e error)

func (*MockSupernodeAPI) ReportPiece

func (m *MockSupernodeAPI) ReportPiece(ip string, req *types.ReportPieceRequest) (
	*types.BaseResponse, error)

ReportPiece implements SupernodeAPI#ReportPiece.

func (*MockSupernodeAPI) ReportResource added in v1.0.5

func (m *MockSupernodeAPI) ReportResource(node string, req *types.RegisterRequest) (resp *types.RegisterResponse, err error)

func (*MockSupernodeAPI) ReportResourceDeleted added in v1.0.5

func (m *MockSupernodeAPI) ReportResourceDeleted(node string, taskID string, cid string) (resp *types.BaseResponse, err error)

func (*MockSupernodeAPI) ServiceDown

func (m *MockSupernodeAPI) ServiceDown(ip string, taskID string, cid string) (
	*types.BaseResponse, error)

ServiceDown implements SupernodeAPI#ServiceDown.

type PullFuncType

type PullFuncType func(ip string, req *types.PullPieceTaskRequest) (*types.PullPieceTaskResponse, error)

PullFuncType function type of SupernodeAPI#PullPiece

type RegisterFuncType

type RegisterFuncType func(ip string, req *types.RegisterRequest) (*types.RegisterResponse, error)

RegisterFuncType function type of SupernodeAPI#Register

func CreateRegisterFunc

func CreateRegisterFunc() RegisterFuncType

CreateRegisterFunc creates a mock register function.

type ReportFuncType

type ReportFuncType func(ip string, req *types.ReportPieceRequest) (*types.BaseResponse, error)

ReportFuncType function type of SupernodeAPI#ReportPiece

type ReportMetricsFuncType added in v1.0.0

type ReportMetricsFuncType func(node string, req *api_types.TaskMetricsRequest) (*types.BaseResponse, error)

ClientErrorFuncType function type of SupernodeAPI#ReportMetricsType

type ServiceDownFuncType

type ServiceDownFuncType func(ip string, taskID string, cid string) (*types.BaseResponse, error)

ServiceDownFuncType function type of SupernodeAPI#ServiceDown

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL