handler

package
v0.0.0-...-ebe581b Latest Latest
Warning

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

Go to latest
Published: Mar 22, 2024 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProxyExecutionMode = "Proxy"
	SelfExecutionMode  = "Self"
)

Define the ExecutionType of the executor, used to download sample files during task training

ProxyExecutionMode indicates to execute tasks using others' data
SelfExecutionMode indicates to execute tasks using own data

Variables

This section is empty.

Functions

This section is empty.

Types

type Blockchain

type Blockchain interface {
	// executor operation
	RegisterExecutorNode(opt *blockchain.AddNodeOptions) error
	GetExecutorNodeByID(id string) (blockchain.ExecutorNode, error)
	ListExecutorNodes() (blockchain.ExecutorNodes, error)

	// task operation
	ListTask(opt *blockchain.ListFLTaskOptions) (blockchain.FLTasks, error)
	PublishTask(opt *blockchain.PublishFLTaskOptions) error
	GetTaskById(id string) (blockchain.FLTask, error)
	ConfirmTask(opt *blockchain.FLTaskConfirmOptions) error
	RejectTask(opt *blockchain.FLTaskConfirmOptions) error
	ExecuteTask(opt *blockchain.FLTaskExeStatusOptions) error
	FinishTask(opt *blockchain.FLTaskExeStatusOptions) error
	// get file stored in xuperDB by id
	GetFileByID(id string) (xdbchain.File, error)
	// query the list of authorization applications
	ListFileAuthApplications(opt *xdbchain.ListFileAuthOptions) (xdbchain.FileAuthApplications, error)
	// publish sample file's authorization application
	PublishFileAuthApplication(opt *xdbchain.PublishFileAuthOptions) error
	// query the list of storage nodes
	ListNodes() (xdbchain.Nodes, error)

	Close()
}

Blockchain defines some contract methods

refer blockchain module for more

type FileDownload

type FileDownload struct {
	Type           string           // support 'Proxy' and 'Self'
	NodePrivateKey ecdsa.PrivateKey // the executor node's private key

	PrivateKey ecdsa.PrivateKey // key authorized by data owner node, used when the Type is 'Self'
	Host       string           // data owner host address, used when the Type is 'Self'
}

FileDownload mode for download the sample file during the task execution

func (*FileDownload) GetSampleFile

func (f *FileDownload) GetSampleFile(fileID string, chain Blockchain) (io.ReadCloser, error)

GetSampleFile download sample files, if f.Type is 'Self', download files from dataOwner nodes. If f.Type is 'Proxy', download slices from storage nodes and recover the sample file, the key required to decrypt the sample file and slices can be obtained through the file authorization application ID. only after the file owner has confirmed the executor's file authorization application, the executor node can get the sample file.

type FileStorage

type FileStorage struct {
	ModelStorage      Storage
	EvaluationStorage Storage
	PredictStorage    Storage
}

FileStorage contains model storage, evaluation storage and prediction result storage

type FlTask

type FlTask struct {
	// task detail info on chain
	pbTask.FLTask
	// timeout for task execution
	ExpiredTime int64
}

FlTask include task details and task execution expired time

type MpcHandler

type MpcHandler interface {
	// SaveModel persists a model
	// called by MPC
	SaveModel(*pbCom.TrainTaskResult) error

	// SavePredictOut persists predicting outcomes
	// outcomes will be zero-value if the holder does not have target feature
	// called by MPC
	SavePredictOut(*pbCom.PredictTaskResult) error

	// GetMpcClusterService returns mpc cluster service server
	GetMpcClusterService() *cluster.Service

	// TaskStartPrepare prepares resources needed by task, and adds task to execution pool.
	TaskStartPrepare(task blockchain.FLTask) (*pbCom.StartTaskRequest, error)

	// StartLocalMpcTask executes task
	StartLocalMpcTask(task *pbCom.StartTaskRequest, isSendTaskToOthers bool) error

	// GetAvailableTasksNum returns left number of tasks could be executed
	GetAvailableTasksNum() (int, int)

	// CheckMpcTimeOutTasks checks tasks in execution pool if they're expired,
	// and stops expired tasks
	CheckMpcTimeOutTasks()

	//Close closes all inner services
	Close()
}

MpcHandler starts mpc-training or mpc-prediction when gets task from blockchain,

persists the trained models and prediction outcomes.

type MpcModelHandler

type MpcModelHandler struct {
	Config             mpc.Config
	Node               Node          // executor node information
	Storage            FileStorage   // handler for computing results storage
	Download           FileDownload  // handler for file download, 'proxy' or 'self'
	Chain              Blockchain    // handler for blockchain operation
	MpcTaskMaxExecTime time.Duration // maximum execution time for mpc task
	Mpc                mpc.Mpc
	ClusterP2p         *p2p.P2P
	// store execution mpc tasks
	MpcTasks map[string]*FlTask
	sync.RWMutex
}

MpcModelHandler handler for mpc training or prediction tasks

func (*MpcModelHandler) CheckMpcTimeOutTasks

func (m *MpcModelHandler) CheckMpcTimeOutTasks()

CheckMpcTimeOutTasks checks tasks in execution pool if they're expired, and stops expired tasks

func (*MpcModelHandler) Close

func (m *MpcModelHandler) Close()

Close waits until all inner services stop

func (*MpcModelHandler) GetAvailableTasksNum

func (m *MpcModelHandler) GetAvailableTasksNum() (tNum int, pNum int)

GetAvailableTasksNum returns left number of tasks could be executed Returns the number of tasks that can participate in training or prediction

func (*MpcModelHandler) GetMpcClusterService

func (m *MpcModelHandler) GetMpcClusterService() *cluster.Service

GetMpcClusterService returns mpc cluster service

func (*MpcModelHandler) SaveModel

func (m *MpcModelHandler) SaveModel(result *pbCom.TrainTaskResult) error

SaveModel persists a model called by MPC

func (*MpcModelHandler) SavePredictOut

func (m *MpcModelHandler) SavePredictOut(result *pbCom.PredictTaskResult) error

SavePredictOut persists predicting outcomes Outcomes will be zero-value if the holder does not have target feature called by MPC

func (*MpcModelHandler) StartLocalMpcTask

func (m *MpcModelHandler) StartLocalMpcTask(startRequest *pbCom.StartTaskRequest, isSendTaskToOthers bool) error

StartLocalMpcTask executes task

func (*MpcModelHandler) TaskStartPrepare

func (m *MpcModelHandler) TaskStartPrepare(task blockchain.FLTask) (*pbCom.StartTaskRequest, error)

TaskStartPrepare prepares resources needed by task, and adds task to execution pool.

func (*MpcModelHandler) UpdateTaskFinishStatus

func (m *MpcModelHandler) UpdateTaskFinishStatus(taskId, taskErr, taskResult string) error

UpdateTaskFinishStatus updates task status in blockchain when task finished

type Node

type Node struct {
	peer.Local
	HttpAddress     string
	PaddleFLAddress string
	PaddleFLRole    int
}

func (*Node) Register

func (n *Node) Register(chain Blockchain) error

Register registers local node to blockchain

type ParticipantParams

type ParticipantParams struct {
	PaddleFLRole  int
	PaddleFLNodes [3]string
	// contains filtered or unexported fields
}

ParticipantParams local parameters required for task execution

type Storage

type Storage interface {
	Write(value io.Reader, key string) (string, error)
	Read(key string) (io.ReadCloser, error)
}

Storage files operations, read and write

supports local storage and xuperdb storage

Jump to

Keyboard shortcuts

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