Skip to content

Commit

Permalink
Ipfs cluster reward mechanism (#217)
Browse files Browse the repository at this point in the history
* Update blox.go

* adde dbatchuplodamanifest to mobile

* Added replication request to cluster

* Update bl_manifest.go

* Update blockchain.go

* Update blockchain.go

* correctd typing

* added mechanism for host-pool

* Update blockchain.go

* corrections for ipfs

* Update main.go

* Update main.go

* corrected config.yaml path in ipfs-cluster script
  • Loading branch information
ehsan6sha authored Mar 2, 2024
1 parent 82cd6b0 commit ffddfa2
Show file tree
Hide file tree
Showing 15 changed files with 919 additions and 162 deletions.
1 change: 0 additions & 1 deletion blockchain/bl_account.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ func (bl *FxBlockchain) AccountBalance(ctx context.Context, to peer.ID, r Accoun
}

func (bl *FxBlockchain) HandleSeeded(ctx context.Context, req *SeededRequest) (string, error) {
// Call manifestBatchStore method
responseBody, statusCode, err := bl.callBlockchain(ctx, "POST", actionSeeded, req)
if err != nil {
// If there's an error, return it directly without processing the response body
Expand Down
62 changes: 62 additions & 0 deletions blockchain/bl_manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,68 @@ func (bl *FxBlockchain) ManifestAvailable(ctx context.Context, to peer.ID, r Man
}
}

func (bl *FxBlockchain) ManifestBatchStore(ctx context.Context, to peer.ID, r ManifestBatchStoreRequest) ([]byte, error) {

if bl.allowTransientConnection {
ctx = network.WithUseTransient(ctx, "fx.blockchain")
}

var buf bytes.Buffer
if err := json.NewEncoder(&buf).Encode(r); err != nil {
return nil, err
}

req, err := http.NewRequestWithContext(ctx, http.MethodGet, "http://"+to.String()+".invalid/"+actionManifestBatchStore, &buf)
if err != nil {
return nil, err
}
resp, err := bl.c.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
b, err := io.ReadAll(resp.Body)
switch {
case err != nil:
return nil, err
case resp.StatusCode != http.StatusAccepted:
return nil, fmt.Errorf("unexpected response: %d %s", resp.StatusCode, string(b))
default:
return b, nil
}
}

func (bl *FxBlockchain) ManifestBatchUpload(ctx context.Context, to peer.ID, r ManifestBatchUploadMobileRequest) ([]byte, error) {

if bl.allowTransientConnection {
ctx = network.WithUseTransient(ctx, "fx.blockchain")
}

var buf bytes.Buffer
if err := json.NewEncoder(&buf).Encode(r); err != nil {
return nil, err
}

req, err := http.NewRequestWithContext(ctx, http.MethodGet, "http://"+to.String()+".invalid/"+actionManifestBatchUpload, &buf)
if err != nil {
return nil, err
}
resp, err := bl.c.Do(req)
if err != nil {
return nil, err
}
defer resp.Body.Close()
b, err := io.ReadAll(resp.Body)
switch {
case err != nil:
return nil, err
case resp.StatusCode != http.StatusAccepted:
return nil, fmt.Errorf("unexpected response: %d %s", resp.StatusCode, string(b))
default:
return b, nil
}
}

func (bl *FxBlockchain) ManifestRemove(ctx context.Context, to peer.ID, r ManifestRemoveRequest) ([]byte, error) {

if bl.allowTransientConnection {
Expand Down
Loading

0 comments on commit ffddfa2

Please sign in to comment.