Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var StorageChallengeCmd = &cmds.Command{ Helptext: cmds.HelpText{ Tagline: "Interact with storage challenge requests and responses.", ShortDescription: ` These commands contain both client-side and host-side challenge functions. btfs storage challenge request <peer-id> <contract-id> <file-hash> <shard-hash> <chunk-index> <nonce> btfs storage challenge response <contract-id> <file-hash> <shard-hash> <chunk-index> <nonce>`, }, Subcommands: map[string]*cmds.Command{ "request": storageChallengeRequestCmd, "response": StorageChallengeResponseCmd, }, }
View Source
var StorageChallengeResponseCmd = &cmds.Command{ Helptext: cmds.HelpText{ Tagline: "Storage host responds to Proof-of-Storage requests.", ShortDescription: ` This command (on host) reads the challenge question and returns the answer to the challenge request back to the caller.`, }, Arguments: []cmds.Argument{ cmds.StringArg("contract-id", true, false, "Contract ID associated with the challenge requests."), cmds.StringArg("file-hash", true, false, "File root multihash for the data stored at this host."), cmds.StringArg("shard-hash", true, false, "Shard multihash for the data stored at this host."), cmds.StringArg("chunk-index", true, false, "Chunk index for this challenge. Chunks available on this host include root + metadata + shard chunks."), cmds.StringArg("nonce", true, false, "Nonce for this challenge. A random UUIDv4 string."), }, RunTimeout: 1 * time.Minute, Run: func(req *cmds.Request, res cmds.ResponseEmitter, env cmds.Environment) error { err := utils.CheckSimpleMode(env) if err != nil { return err } cfg, err := cmdenv.GetConfig(env) if err != nil { return err } if !cfg.Experimental.StorageHostEnabled { return fmt.Errorf("storage host api not enabled") } res.RecordEvent("HGetConfig") n, err := cmdenv.GetNode(env) if err != nil { return err } res.RecordEvent("HGetNode") api, err := cmdenv.GetApi(env, req) if err != nil { return err } res.RecordEvent("HGetApi") fileHash, err := cidlib.Parse(req.Arguments[1]) if err != nil { return err } res.RecordEvent("HParseFileCid") sh := req.Arguments[2] shardHash, err := cidlib.Parse(sh) if err != nil { return err } res.RecordEvent("HParseShardCid") chunkIndex, err := strconv.Atoi(req.Arguments[3]) if err != nil { return err } nonce := req.Arguments[4] sc, err := NewStorageChallengeResponse(req.Context, n, api, fileHash, shardHash, "", false, 0) if err != nil { return err } res.RecordEvent("HNewResponse") err = sc.SolveChallenge(chunkIndex, nonce) if err != nil { return err } res.RecordEvent("HSolveChallenge") return cmds.EmitOnce(res, &StorageChallengeRes{ Answer: sc.Hash, TimeEvaluate: []string{res.ShowEventReport()}, }) }, Type: StorageChallengeRes{}, }
Functions ¶
This section is empty.
Types ¶
type StorageChallenge ¶
type StorageChallenge struct { Ctx context.Context Node *core.IpfsNode API coreiface.CoreAPI sync.Mutex // Selections and generations for challenge ID string // Challenge ID (randomly generated on creation) RID cid.Cid // Root hash in multihash format (initial file root) SID cid.Cid // Shard hash in multihash format (selected shard on each host) CIndex int // Chunk index within each shard (selected index on each challenge request) CID cid.Cid // Chunk hash in multihash format (selected chunk on each challenge request) Nonce string // Random nonce for each challenge request (uuidv4) Hash string // Generated SHA-256 hash (chunk bytes + nonce bytes) for proof-of-file-existence Expiration uint64 // End date of the pinned chunks // contains filtered or unexported fields }
func NewStorageChallenge ¶
func (*StorageChallenge) GenChallenge ¶
func (sc *StorageChallenge) GenChallenge() error
GenChallenge picks a random cid from the internal cid list, then generates a random nonce, combined for the final hash. It is safe to call this function multiple times to re-gen a new challenge while re-using the same data structure and ID.
func (*StorageChallenge) SolveChallenge ¶
func (sc *StorageChallenge) SolveChallenge(chIndex int, chNonce string) error
SolveChallenge solves the given challenge chunk index + nonce's request and records the solved/responding value in Hash field.
type StorageChallengeRes ¶
Click to show internal directories.
Click to hide internal directories.