Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var StorageUploadGetContractBatchCmd = &cmds.Command{ Helptext: cmds.HelpText{ Tagline: "Get all the contracts from the upload session (From BTFS SDK application's perspective).", ShortDescription: ` This command (on client) reads the unsigned contracts and returns the contracts to the caller.`, }, Arguments: []cmds.Argument{ cmds.StringArg("session-id", true, false, "ID for the entire storage upload session."), cmds.StringArg("peer-id", true, false, "Offline signs needed for this particular client."), cmds.StringArg("nonce-timestamp", true, false, "Nonce timestamp string for this upload signing."), cmds.StringArg("upload-session-signature", true, false, "Private key-signed string of <peer-id>:<nonce-timstamp>"), cmds.StringArg("contracts-type", true, false, "get guard or escrow contracts"), }, Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { ssId := req.Arguments[0] ctxParams, err := uh.ExtractContextParams(req, env) if err != nil { return err } if !ctxParams.Cfg.Experimental.StorageClientEnabled { return fmt.Errorf("storage client api not enabled") } rss, err := sessions.GetRenterSession(ctxParams, ssId, "", make([]string, 0)) if err != nil { return err } status, err := rss.Status() if err != nil { return err } err = verifyReceivedMessage(req, rss) if err != nil { return err } contracts := make([]*contract, 0) var cm cmap.ConcurrentMap if cm = uh.EscrowContractMaps; req.Arguments[4] == contractsTypeGuard { cm = uh.GuardContractMaps } for i, h := range status.ShardHashes { shardId := sessions.GetShardId(ssId, h, i) c := &contract{ Key: shardId, } if bytes, ok := cm.Get(shardId); ok { c.ContractData, err = helper.BytesToString(bytes.([]byte), helper.Base64) } else { return res.Emit(&getContractBatchRes{ Contracts: make([]*contract, 0), }) } contracts = append(contracts, c) } return res.Emit(&getContractBatchRes{ Contracts: contracts, }) }, Type: getContractBatchRes{}, }
View Source
var StorageUploadGetUnsignedCmd = &cmds.Command{ Helptext: cmds.HelpText{ Tagline: "Get the input data for upload signing.", ShortDescription: ` This command obtains the upload signing input data for from the upload session (From BTFS SDK application's perspective) and returns to the caller.`, }, Arguments: []cmds.Argument{ cmds.StringArg("session-id", true, false, "ID for the entire storage upload session."), cmds.StringArg("peer-id", true, false, "Offline signs needed for this particular client."), cmds.StringArg("nonce-timestamp", true, false, "Nonce timestamp string for this upload signing."), cmds.StringArg("upload-session-signature", true, false, "Private key-signed string of peer-id:nonce-timestamp"), cmds.StringArg("session-status", true, false, "current upload session status."), }, Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { ssId := req.Arguments[0] ctxParams, err := uh.ExtractContextParams(req, env) if err != nil { return err } rss, err := sessions.GetRenterSession(ctxParams, ssId, "", make([]string, 0)) if err != nil { return err } err = verifyReceivedMessage(req, rss) if err != nil { return err } rssStatus, err := rss.Status() if err != nil { return err } if req.Arguments[4] != rssStatus.Status { return errors.New("unexpected session status from SDK during communication in upload signing") } signing, err := rss.OfflineSigning() if err != nil { return err } rawString, err := helper.BytesToString(signing.Raw, helper.Base64) if err != nil { return err } return res.Emit(&GetUnsignedRes{Unsigned: rawString, Price: signing.Price}) }, Type: GetUnsignedRes{}, }
View Source
var StorageUploadSignCmd = &cmds.Command{ Helptext: cmds.HelpText{ Tagline: "Return the signed data to the upload session.", ShortDescription: ` This command returns the signed data (From BTFS SDK application's perspective) to the upload session.`, }, Arguments: []cmds.Argument{ cmds.StringArg("session-id", true, false, "ID for the entire storage upload session."), cmds.StringArg("peer-id", true, false, "Offline signs needed for this particular client."), cmds.StringArg("nonce-timestamp", true, false, "Nonce timestamp string for this upload signing."), cmds.StringArg("upload-session-signature", true, false, "Private key-signed string of peer-id:nonce-timestamp"), cmds.StringArg("session-status", true, false, "current upload session status."), cmds.StringArg("signed", true, false, "signed json data."), }, Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { ssId := req.Arguments[0] ctxParams, err := uh.ExtractContextParams(req, env) if err != nil { return err } rss, err := sessions.GetRenterSession(ctxParams, ssId, "", make([]string, 0)) if err != nil { return err } err = verifyReceivedMessage(req, rss) if err != nil { return err } status, err := rss.Status() if err != nil { return err } if status.Status != req.Arguments[4] { return fmt.Errorf("error status, want: %s, actual: %s", status.Status, req.Arguments[4]) } bytes, err := helper.StringToBytes(req.Arguments[5], helper.Base64) if err != nil { return err } var cm cmap.ConcurrentMap switch req.Arguments[4] { case sessions.RssSubmitStatus: cm = uh.BalanceChanMaps case sessions.RssSubmitBalanceReqSignedStatus: cm = uh.SignedChannelCommitChanMaps case sessions.RssPayStatus: cm = uh.PayinReqChanMaps case sessions.RssGuardStatus: cm = uh.FileMetaChanMaps case sessions.RssGuardFileMetaSignedStatus: cm = uh.QuestionsChanMaps case sessions.RssWaitUploadStatus: cm = uh.WaitUploadChanMap default: return errors.New("wrong status:" + req.Arguments[4]) } if bc, ok := cm.Get(ssId); ok { bc.(chan []byte) <- bytes } return rss.SaveOfflineSigning(&renterpb.OfflineSigning{ Sig: bytes, }) }, }
View Source
var StorageUploadSignContractBatchCmd = &cmds.Command{ Helptext: cmds.HelpText{ Tagline: "Get the unsigned contracts from the upload session.", ShortDescription: ` This command reads all the unsigned contracts from the upload session (From BTFS SDK application's perspective) and returns the contracts to the caller.`, }, Arguments: []cmds.Argument{ cmds.StringArg("session-id", true, false, "ID for the entire storage upload session."), cmds.StringArg("peer-id", true, false, "Offline signs needed for this particular client."), cmds.StringArg("nonce-timestamp", true, false, "Nonce timestamp string for this upload signing."), cmds.StringArg("upload-session-signature", true, false, "Private key-signed string of peer-id:nonce-timestamp"), cmds.StringArg("contracts-type", true, false, "get guard or escrow contracts"), cmds.StringArg("signed-data-items", true, false, "signed data items."), }, Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { ssID := req.Arguments[0] ctxParams, err := uh.ExtractContextParams(req, env) if err != nil { return err } rss, err := sessions.GetRenterSession(ctxParams, ssID, "", make([]string, 0)) if err != nil { return err } err = verifyReceivedMessage(req, rss) if err != nil { return err } var signedContracts []contract signedContractsString := req.Arguments[5] err = json.Unmarshal([]byte(signedContractsString), &signedContracts) if err != nil { return err } if len(signedContracts) != len(rss.ShardHashes) { return fmt.Errorf("number of received signed data items %d does not match number of shards %d", len(signedContracts), len(rss.ShardHashes)) } var cm cmap.ConcurrentMap if cm = uh.EscrowChanMaps; req.Arguments[4] == contractsTypeGuard { cm = uh.GuardChanMaps } for i := 0; i < len(rss.ShardHashes); i++ { shardId := signedContracts[i].Key ch, found := cm.Get(shardId) if !found { return fmt.Errorf("can not find an entry for key %s", shardId) } by, err := helper.StringToBytes(signedContracts[i].ContractData, helper.Base64) if err != nil { return err } ch.(chan []byte) <- by } return nil }, }
Functions ¶
This section is empty.
Types ¶
type GetUnsignedRes ¶
Click to show internal directories.
Click to hide internal directories.