Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: act api in wasm #654

Merged
merged 4 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ jobs:
run: |
git checkout .
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: latest
args: release --rm-dist --config .goreleaser-mobile.yaml
args: release --clean --config .goreleaser-mobile.yaml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
7 changes: 3 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ release:
-v `pwd`:/go/src/github.com/fairDataSociety/fairOS-dfs \
-v /var/run/docker.sock:/var/run/docker.sock \
-w /go/src/github.com/fairDataSociety/fairOS-dfs \
ghcr.io/goreleaser/goreleaser-cross:v1.21.0 release --rm-dist
ghcr.io/goreleaser/goreleaser-cross:v1.21.0 release --clean

.PHONY: release-dry-run
release-dry-run:
Expand All @@ -84,9 +84,8 @@ release-dry-run:
-v `pwd`:/go/src/github.com/fairDataSociety/fairOS-dfs \
-v /var/run/docker.sock:/var/run/docker.sock \
-w /go/src/github.com/fairDataSociety/fairOS-dfs \
ghcr.io/goreleaser/goreleaser-cross:v1.21.0 release --rm-dist \
--skip-validate=true \
--skip-publish
ghcr.io/goreleaser/goreleaser-cross:v1.21.0 release \
--clean --skip-validate=true --skip-publish

.PHONY: wasm
wasm:
Expand Down
12 changes: 9 additions & 3 deletions cmd/dfs/cmd/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -941,13 +941,19 @@ func TestApis(t *testing.T) {
t.Fatal(err)
}

if podForkResp.StatusCode != 200 {
forkRespErr, err := io.ReadAll(podForkResp.Body)
if err != nil {
t.Fatal(err)
}
t.Log(string(forkRespErr))
podForkResp.Body.Close()
t.Fatal("pod fork failed with status code:", podForkResp.StatusCode)
}
err = podForkResp.Body.Close()
if err != nil {
t.Fatal(err)
}
if podForkResp.StatusCode != 200 {
t.Fatal("pod fork failed")
}
podOpenRequest := &common.PodRequest{
PodName: podForkRequest.ForkName,
}
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ module github.com/fairdatasociety/fairOS-dfs
go 1.22.0

require (
github.com/asabya/swarm-act v0.0.0-20241022090815-9b494c0051de
github.com/asabya/swarm-blockstore v0.0.0-20241022084926-8d6753f32697
github.com/asabya/swarm-act v0.0.0-20241106102524-234e35a79f95
github.com/asabya/swarm-blockstore v0.0.0-20241106102400-00f682459f25
github.com/btcsuite/btcd/btcec/v2 v2.3.2
github.com/c-bata/go-prompt v0.2.6
github.com/dustin/go-humanize v1.0.1
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ github.com/VictoriaMetrics/fastcache v1.12.2/go.mod h1:AmC+Nzz1+3G2eCPapF6UcsnkT
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
github.com/armon/go-radix v1.0.0 h1:F4z6KzEeeQIMeLFa97iZU6vupzoecKdU5TX24SNppXI=
github.com/armon/go-radix v1.0.0/go.mod h1:ufUuZ+zHj4x4TnLV4JWEpy2hxWSpsRywHrMgIH9cCH8=
github.com/asabya/swarm-act v0.0.0-20241022090815-9b494c0051de h1:d5PDY+pU7QCIu3VNSftUq6rc4hNC6GfxH8vI1JItWNU=
github.com/asabya/swarm-act v0.0.0-20241022090815-9b494c0051de/go.mod h1:JKFHSirdVKLWOdJpk7cl8732JiI+a9G64dzB58CEO8w=
github.com/asabya/swarm-blockstore v0.0.0-20241022084926-8d6753f32697 h1:MhH/TMo8jvCafB/WcI8MKajuWuodymKHiLZLGAQ35nE=
github.com/asabya/swarm-blockstore v0.0.0-20241022084926-8d6753f32697/go.mod h1:Tc8wjIjbbV0Ofrr3JPmxDcbmg571M6yFEdKOqWelWgo=
github.com/asabya/swarm-act v0.0.0-20241106102524-234e35a79f95 h1:+wmDLRIO5eY+aSvZprue0wUJg2fr1IHjPLHzEfJd5yQ=
github.com/asabya/swarm-act v0.0.0-20241106102524-234e35a79f95/go.mod h1:dIzdN1DEQVpjvzXVyB1b1RPJWO3ChEHOJzG/TYxD9KU=
github.com/asabya/swarm-blockstore v0.0.0-20241106102400-00f682459f25 h1:sx+0OADMTo5/EaG1PA7/Egt2WLIriCK3fExlVQE5SvE=
github.com/asabya/swarm-blockstore v0.0.0-20241106102400-00f682459f25/go.mod h1:Tc8wjIjbbV0Ofrr3JPmxDcbmg571M6yFEdKOqWelWgo=
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/bits-and-blooms/bitset v1.13.0 h1:bAQ9OPNFYbGHV6Nez0tmNI0RiEu7/hxlYJRUA0wFAVE=
Expand Down
41 changes: 27 additions & 14 deletions pkg/act/act_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package act
package act_test

import (
"context"
Expand All @@ -11,6 +11,8 @@ import (
"testing"
"time"

"github.com/fairdatasociety/fairOS-dfs/pkg/act"

"github.com/asabya/swarm-blockstore/bee"
"github.com/asabya/swarm-blockstore/bee/mock"
"github.com/btcsuite/btcd/btcec/v2"
Expand Down Expand Up @@ -64,7 +66,7 @@ func TestACT(t *testing.T) {
acc := accounts[0]
fd := feed.New(acc.GetUserAccountInfo(), mockClient, -1, 0, logger)

ownerACT := NewACT(mockClient, fd, acc, tm, logger)
ownerACT := act.NewACT(mockClient, fd, acc, tm, logger)
actName := acts[0]
for i := 1; i < 10; i++ {
acc := accounts[i]
Expand All @@ -74,11 +76,12 @@ func TestACT(t *testing.T) {
}
<-time.After(1 * time.Second)
}
a, err := ownerACT.GetACT(actName)
_, err := ownerACT.GetACT(actName)
if err != nil {
t.Fatal(err)
}
pubKeys, err := ownerACT.act.GetGrantees(context.Background(), swarm.NewAddress(a.GranteesRef))

pubKeys, err := ownerACT.GetGrantees(actName)
if err != nil {
t.Fatal(err)
}
Expand All @@ -90,7 +93,7 @@ func TestACT(t *testing.T) {
acc := accounts[0]
fd := feed.New(acc.GetUserAccountInfo(), mockClient, -1, 0, logger)

ownerACT := NewACT(mockClient, fd, acc, tm, logger)
ownerACT := act.NewACT(mockClient, fd, acc, tm, logger)
actName := acts[1]
for i := 1; i < 2; i++ {
acc := accounts[i]
Expand All @@ -106,7 +109,11 @@ func TestACT(t *testing.T) {
if err != nil {
t.Fatal(err)
}
pubKeys, err := ownerACT.act.GetGrantees(context.Background(), swarm.NewAddress(a.GranteesRef))
_, err = swarm.ParseHexAddress(a.GranteesRef)
if err != nil {
t.Fatal(err)
}
pubKeys, err := ownerACT.GetGrantees(actName)
if err != nil {
t.Fatal(err)
}
Expand All @@ -126,8 +133,11 @@ func TestACT(t *testing.T) {
if err != nil {
t.Fatal(err)
}

pubKeys, err = ownerACT.act.GetGrantees(context.Background(), swarm.NewAddress(a.GranteesRef))
_, err = swarm.ParseHexAddress(a.GranteesRef)
if err != nil {
t.Fatal(err)
}
pubKeys, err = ownerACT.GetGrantees(actName)
if err != nil {
t.Fatal(err)
}
Expand All @@ -139,7 +149,7 @@ func TestACT(t *testing.T) {
acc := accounts[0]
fd := feed.New(acc.GetUserAccountInfo(), mockClient, -1, 0, logger)

ownerACT := NewACT(mockClient, fd, acc, tm, logger)
ownerACT := act.NewACT(mockClient, fd, acc, tm, logger)
for _, actName := range acts {
for i := 1; i < 10; i++ {
acc := accounts[i]
Expand Down Expand Up @@ -200,7 +210,7 @@ func TestACT(t *testing.T) {
t.Fatal(err)
}

ownerACT := NewACT(mockClient, fd, ownerAcc, tm, logger)
ownerACT := act.NewACT(mockClient, fd, ownerAcc, tm, logger)
granteeAcc := accounts[1]
_, err = ownerACT.CreateUpdateACT(acts[0], granteeAcc.GetUserAccountInfo().GetPublicKey(), nil)
if err != nil {
Expand All @@ -215,7 +225,7 @@ func TestACT(t *testing.T) {
<-time.After(1 * time.Second)

granteeFeed := feed.New(granteeAcc.GetUserAccountInfo(), mockClient, -1, 0, logger)
granteeACT := NewACT(mockClient, granteeFeed, granteeAcc, tm, logger)
granteeACT := act.NewACT(mockClient, granteeFeed, granteeAcc, tm, logger)
err = granteeACT.SaveGrantedPod(acts[0], respOne)
if err != nil {
t.Fatal(err)
Expand All @@ -237,8 +247,11 @@ func TestACT(t *testing.T) {
t.Fatal(err)
}
<-time.After(time.Second)

_, err = ownerACT.act.GetGrantees(context.Background(), swarm.NewAddress(actAfterRevoke.GranteesRef))
addr, err = swarm.ParseHexAddress(actAfterRevoke.GranteesRef)
if err != nil {
t.Fatal(err)
}
_, err = ownerACT.GetGrantees(acts[0])
if err != nil {
t.Fatal(err)
}
Expand All @@ -252,7 +265,7 @@ func TestACT(t *testing.T) {
ownerAcc := accounts[0]
fd := feed.New(ownerAcc.GetUserAccountInfo(), mockClient, -1, 0, logger)
pod1 := pod.NewPod(mockClient, fd, ownerAcc, tm, sm, -1, 0, logger)
ownerACT := NewACT(mockClient, fd, ownerAcc, tm, logger)
ownerACT := act.NewACT(mockClient, fd, ownerAcc, tm, logger)
granteeAcc := accounts[1]
_, err := ownerACT.CreateUpdateACT(acts[1], granteeAcc.GetUserAccountInfo().GetPublicKey(), nil)
if err != nil {
Expand Down
17 changes: 12 additions & 5 deletions pkg/act/grant.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,11 @@ func (t *ACT) GrantAccess(actName string, address swarm.Address) (*Content, erro
return nil, ErrACTDoesNowExist
}
owner := t.acc.GetUserAccountInfo().GetAddress()

uploadResp, err := t.act.HandleUpload(context.Background(), address, swarm.NewAddress(act.HistoryRef))
addr, err := swarm.ParseHexAddress(act.HistoryRef)
if err != nil {
return nil, err
}
uploadResp, err := t.act.HandleUpload(context.Background(), address, addr)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -124,8 +127,8 @@ func (t *ACT) SaveGrantedPod(actName string, c *Content) error {
a := &Act{
Name: actName,
CreatedAt: c.AddedAt,
HistoryRef: swarm.ZeroAddress.Bytes(),
GranteesRef: reference.Bytes(),
HistoryRef: swarm.ZeroAddress.String(),
GranteesRef: reference.String(),
Content: []*Content{c},
}
list[actName] = a
Expand All @@ -148,7 +151,11 @@ func (t *ACT) GetGrantees(actName string) ([]string, error) {
if !ok {
return nil, ErrACTDoesNowExist
}
grantees, err := t.act.GetGrantees(context.Background(), swarm.NewAddress(act.GranteesRef))
addr, err := swarm.ParseHexAddress(act.GranteesRef)
if err != nil {
return nil, err
}
grantees, err := t.act.GetGrantees(context.Background(), addr)
if err != nil {
return nil, err
}
Expand Down
33 changes: 22 additions & 11 deletions pkg/act/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (
"fmt"
"time"

swarm_act "github.com/asabya/swarm-act"
"github.com/btcsuite/btcd/btcec/v2"
"github.com/ethersphere/bee/v2/pkg/api"
"github.com/ethersphere/bee/v2/pkg/crypto"
"github.com/ethersphere/bee/v2/pkg/swarm"
"github.com/fairdatasociety/fairOS-dfs/pkg/utils"
Expand All @@ -22,8 +22,8 @@ type List map[string]*Act
// Act represents an Access Control Trie (ACT) with its metadata, grantees, and associated content.
type Act struct {
Name string `json:"name"`
HistoryRef []byte `json:"historyRef"`
GranteesRef []byte `json:"granteesRef"`
HistoryRef string `json:"historyRef"`
GranteesRef string `json:"granteesRef"`
CreatedAt time.Time `json:"createdAt"`
Content []*Content `json:"content"`
}
Expand Down Expand Up @@ -67,7 +67,7 @@ func (t *ACT) CreateUpdateACT(actName string, publicKeyGrant, publicKeyRevoke *e
}

var (
resp = &api.GranteesPostResponse{}
resp = &swarm_act.GranteesPostResponse{}
grantList []*ecdsa.PublicKey
revokeList []*ecdsa.PublicKey
owner = t.acc.GetUserAccountInfo().GetAddress()
Expand All @@ -80,12 +80,16 @@ func (t *ACT) CreateUpdateACT(actName string, publicKeyGrant, publicKeyRevoke *e
act = &Act{
Name: actName,
CreatedAt: time.Now(),
HistoryRef: swarm.ZeroAddress.Bytes(),
GranteesRef: swarm.ZeroAddress.Bytes(),
HistoryRef: swarm.ZeroAddress.String(),
GranteesRef: swarm.ZeroAddress.String(),
Content: []*Content{},
}
grantList = []*ecdsa.PublicKey{publicKeyGrant}
resp, err = t.act.CreateGrantee(context.Background(), swarm.NewAddress(act.HistoryRef), grantList)
addr, err := swarm.ParseHexAddress(act.HistoryRef)
if err != nil {
return nil, err
}
resp, err = t.act.CreateGrantee(context.Background(), addr, grantList)
if err != nil {
return nil, err
}
Expand All @@ -107,8 +111,15 @@ func (t *ACT) CreateUpdateACT(actName string, publicKeyGrant, publicKeyRevoke *e
} else {
revokeList = nil
}

resp, err = t.act.RevokeGrant(context.Background(), swarm.NewAddress(act.GranteesRef), swarm.NewAddress(act.HistoryRef), grantList, revokeList)
haddr, err := swarm.ParseHexAddress(act.HistoryRef)
if err != nil {
return nil, err
}
gaddr, err := swarm.ParseHexAddress(act.GranteesRef)
if err != nil {
return nil, err
}
resp, err = t.act.RevokeGrant(context.Background(), gaddr, haddr, grantList, revokeList)
if err != nil {
return nil, err
}
Expand All @@ -118,8 +129,8 @@ func (t *ACT) CreateUpdateACT(actName string, publicKeyGrant, publicKeyRevoke *e
}
}

act.GranteesRef = resp.Reference.Bytes()
act.HistoryRef = resp.HistoryReference.Bytes()
act.GranteesRef = resp.Reference.String()
act.HistoryRef = resp.HistoryReference.String()

list[actName] = act
err = t.storeUserACTs(list)
Expand Down
1 change: 1 addition & 0 deletions pkg/api/act.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Content struct {
// @Produce json
// @Param actName path string true "unique act identifier"
// @Param grantee query string true "grantee public key"
// @Param Cookie header string true "cookie parameter"
// @Success 201 {object} response
// @Failure 400 {object} response
// @Failure 500 {object} response
Expand Down
1 change: 0 additions & 1 deletion pkg/dfs/act_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ func (a *API) OpenACTPod(sessionId, actName string) error {
if err != nil {
return err
}

info, err := ui.GetPod().ReceivePodInfo(utils.NewReference(addr.Bytes()))
if err != nil {
return err
Expand Down
11 changes: 5 additions & 6 deletions pkg/dfs/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ func NewDfsAPI(ctx context.Context, opts *Options) (*API, error) {
logger.Errorf("dfs: bee client initialisation failed")
return nil, errBeeClient
}
// Setting cache size 0 will disable the cache. This is to change the default behaviour of lru itself.
// We have this -1 check hard coded in the feed package. -1 will disable the feed pool off. and write directly to swarm.
if opts.FeedCacheSize == 0 {
opts.FeedCacheSize = -1
}
users := user.NewUsers(c, ens, opts.FeedCacheSize, opts.FeedCacheTTL, logger)

var sm subscriptionManager.SubscriptionManager
Expand All @@ -91,12 +96,6 @@ func NewDfsAPI(ctx context.Context, opts *Options) (*API, error) {
}
}

// Setting cache size 0 will disable the cache. This is to change the default behaviour of lru itself.
// We have this -1 check hard coded in the feed package. -1 will disable the feed pool off. and write directly to swarm.
if opts.FeedCacheSize == 0 {
opts.FeedCacheSize = -1
}

// discard tm logs as it creates too much noise
tmLogger := logging.New(io.Discard, 0)
ctx2, cancel := context.WithCancel(ctx)
Expand Down
1 change: 0 additions & 1 deletion pkg/dfs/pod_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ func (a *API) CreatePod(podName, sessionId string) (*pod.Info, error) {
if ui == nil {
return nil, ErrUserNotLoggedIn
}

// open the pod
pi, err := a.prepareOwnPod(ui, podName)
if err != nil {
Expand Down
1 change: 0 additions & 1 deletion pkg/feed/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,6 @@ retry:
}
return epoch, nil, err
}

return req.Epoch, address, nil
}

Expand Down
2 changes: 0 additions & 2 deletions pkg/pod/new.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ func (p *Pod) CreatePod(podName, addressString, podPassword string) (*Info, erro
if err != nil {
return nil, err
}

// check if pods is present and get free index
podList, err := p.PodList()
if err != nil { // skipcq: TCV-001
Expand All @@ -56,7 +55,6 @@ func (p *Pod) CreatePod(podName, addressString, podPassword string) (*Info, erro
for _, pod := range podList.SharedPods {
sharedPods[pod.Address] = pod.Name
}

var accountInfo *account.Info
var fd *feed.API
var file *f.File
Expand Down
Loading
Loading